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