MCPcopy Create free account
hub / github.com/chrxh/alien / SSLServer

Method SSLServer

external/cpp-httplib/httplib.h:7412–7445  ·  view source on GitHub ↗

SSL HTTP server implementation

Source from the content-addressed store, hash-verified

7410
7411 // SSL HTTP server implementation
7412 inline SSLServer::SSLServer(const char* cert_path, const char* private_key_path,
7413 const char* client_ca_cert_file_path,
7414 const char* client_ca_cert_dir_path,
7415 const char* private_key_password) {
7416 ctx_ = SSL_CTX_new(TLS_server_method());
7417
7418 if (ctx_) {
7419 SSL_CTX_set_options(ctx_,
7420 SSL_OP_NO_COMPRESSION |
7421 SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);
7422
7423 SSL_CTX_set_min_proto_version(ctx_, TLS1_1_VERSION);
7424
7425 // add default password callback before opening encrypted private key
7426 if (private_key_password != nullptr && (private_key_password[0] != '\0')) {
7427 SSL_CTX_set_default_passwd_cb_userdata(ctx_,
7428 (char*)private_key_password);
7429 }
7430
7431 if (SSL_CTX_use_certificate_chain_file(ctx_, cert_path) != 1 ||
7432 SSL_CTX_use_PrivateKey_file(ctx_, private_key_path, SSL_FILETYPE_PEM) !=
7433 1) {
7434 SSL_CTX_free(ctx_);
7435 ctx_ = nullptr;
7436 }
7437 else if (client_ca_cert_file_path || client_ca_cert_dir_path) {
7438 SSL_CTX_load_verify_locations(ctx_, client_ca_cert_file_path,
7439 client_ca_cert_dir_path);
7440
7441 SSL_CTX_set_verify(
7442 ctx_, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, nullptr);
7443 }
7444 }
7445 }
7446
7447 inline SSLServer::SSLServer(X509 * cert, EVP_PKEY * private_key,
7448 X509_STORE * client_ca_cert_store) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected