support custom ssl ctx configuration for SSLServer (#1073)

This commit is contained in:
CarlosLeeGit 2021-10-15 19:13:16 +08:00 committed by GitHub
parent c384be02c9
commit b80aa7fee3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 83 additions and 0 deletions

View file

@ -1364,6 +1364,9 @@ public:
SSLServer(X509 *cert, EVP_PKEY *private_key,
X509_STORE *client_ca_cert_store = nullptr);
SSLServer(
const std::function<bool(SSL_CTX &ssl_ctx)> &setup_ssl_ctx_callback);
~SSLServer() override;
bool is_valid() const override;
@ -7105,6 +7108,17 @@ inline SSLServer::SSLServer(X509 *cert, EVP_PKEY *private_key,
}
}
inline SSLServer::SSLServer(
const std::function<bool(SSL_CTX &ssl_ctx)> &setup_ssl_ctx_callback) {
ctx_ = SSL_CTX_new(TLS_method());
if (ctx_) {
if (!setup_ssl_ctx_callback(*ctx_)) {
SSL_CTX_free(ctx_);
ctx_ = nullptr;
}
}
}
inline SSLServer::~SSLServer() {
if (ctx_) { SSL_CTX_free(ctx_); }
}