mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 01:08:27 +00:00
Add optional private key password to SSLServer ctor (#1205)
This commit is contained in:
parent
d73395e1dc
commit
8191fd8e6c
4 changed files with 32 additions and 2 deletions
11
httplib.h
11
httplib.h
|
@ -1384,7 +1384,8 @@ class SSLServer : public Server {
|
|||
public:
|
||||
SSLServer(const char *cert_path, const char *private_key_path,
|
||||
const char *client_ca_cert_file_path = nullptr,
|
||||
const char *client_ca_cert_dir_path = nullptr);
|
||||
const char *client_ca_cert_dir_path = nullptr,
|
||||
const char *private_key_password = nullptr);
|
||||
|
||||
SSLServer(X509 *cert, EVP_PKEY *private_key,
|
||||
X509_STORE *client_ca_cert_store = nullptr);
|
||||
|
@ -7250,7 +7251,8 @@ static SSLInit sslinit_;
|
|||
// SSL HTTP server implementation
|
||||
inline SSLServer::SSLServer(const char *cert_path, const char *private_key_path,
|
||||
const char *client_ca_cert_file_path,
|
||||
const char *client_ca_cert_dir_path) {
|
||||
const char *client_ca_cert_dir_path,
|
||||
const char *private_key_password) {
|
||||
ctx_ = SSL_CTX_new(TLS_server_method());
|
||||
|
||||
if (ctx_) {
|
||||
|
@ -7260,6 +7262,11 @@ inline SSLServer::SSLServer(const char *cert_path, const char *private_key_path,
|
|||
|
||||
SSL_CTX_set_min_proto_version(ctx_, TLS1_1_VERSION);
|
||||
|
||||
// add default password callback before opening encrypted private key
|
||||
if (private_key_password != nullptr && (private_key_password[0] != '\0') ) {
|
||||
SSL_CTX_set_default_passwd_cb_userdata(ctx_, (char *)private_key_password);
|
||||
}
|
||||
|
||||
if (SSL_CTX_use_certificate_chain_file(ctx_, cert_path) != 1 ||
|
||||
SSL_CTX_use_PrivateKey_file(ctx_, private_key_path, SSL_FILETYPE_PEM) !=
|
||||
1) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue