62 lines
2.2 KiB
C++
62 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include "openssl/ssl.h"
|
|
#include "openssl/err.h"
|
|
#include <Definitions.h>
|
|
#include <map>
|
|
#include <pipes/ssl.h>
|
|
|
|
namespace ts {
|
|
namespace ssl {
|
|
struct SSLContext {
|
|
std::shared_ptr<SSL_CTX> context = nullptr;
|
|
std::shared_ptr<EVP_PKEY> privateKey = nullptr;
|
|
std::shared_ptr<X509> certificate = nullptr;
|
|
};
|
|
|
|
struct SSLGenerator {
|
|
std::deque<std::pair<std::string, std::string>> subjects;
|
|
std::deque<std::pair<std::string, std::string>> issues;
|
|
|
|
EVP_PKEY* generateKey();
|
|
X509* generateCertificate(EVP_PKEY*);
|
|
};
|
|
|
|
struct SSLKeyPair {
|
|
bool contains_private = false;
|
|
std::shared_ptr<EVP_PKEY> key = nullptr;
|
|
};
|
|
|
|
class SSLManager {
|
|
public:
|
|
SSLManager();
|
|
virtual ~SSLManager();
|
|
|
|
bool initialize();
|
|
void printDetails();
|
|
|
|
std::shared_ptr<SSLKeyPair> initializeSSLKey(const std::string &key, const std::string &rsaKey, std::string &error, bool raw = false);
|
|
std::shared_ptr<SSLContext> initializeContext(const std::string& key, std::string& privateKey, std::string& certificate, std::string& error, bool raw = false, const std::shared_ptr<SSLGenerator>& = nullptr);
|
|
|
|
std::shared_ptr<SSLContext> getContext(const std::string& key){ return this->contexts[key]; }
|
|
std::shared_ptr<SSLKeyPair> getRsaKey(const std::string& key){ return this->rsa[key]; }
|
|
|
|
bool verifySign(const std::shared_ptr<SSLKeyPair>& key, const std::string& message, const std::string& sign);
|
|
|
|
void disable_web() { this->_web_disabled = true; }
|
|
std::shared_ptr<pipes::SSL::Options> web_ssl_options();
|
|
std::shared_ptr<SSLContext> getQueryContext() { return this->getContext("query"); }
|
|
|
|
private:
|
|
std::map<std::string, std::shared_ptr<SSLContext>> contexts;
|
|
std::map<std::string, std::shared_ptr<SSLKeyPair>> rsa;
|
|
|
|
std::mutex _web_options_lock;
|
|
bool _web_disabled = false;
|
|
std::shared_ptr<pipes::SSL::Options> _web_options;
|
|
|
|
std::shared_ptr<SSLContext> loadContext(std::string& rawKey, std::string& rawCert, std::string& error, bool rawData = false, const std::shared_ptr<SSLGenerator>& = nullptr);
|
|
std::shared_ptr<SSLKeyPair> loadSSL(const std::string &key, std::string &error, bool rawData = false, bool readPublic = false);
|
|
};
|
|
}
|
|
} |