nghttpx: Use ImmutableString for private_key_file
This commit is contained in:
parent
ac81003669
commit
35ebdd35bc
|
@ -1754,7 +1754,7 @@ int parse_config(const char *opt, const char *optarg,
|
||||||
LOG(ERROR) << opt << ": Couldn't read key file's passwd from " << optarg;
|
LOG(ERROR) << opt << ": Couldn't read key file's passwd from " << optarg;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
mod_config()->tls.private_key_passwd = strcopy(passwd);
|
mod_config()->tls.private_key_passwd = passwd;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -427,7 +427,7 @@ struct TLSConfig {
|
||||||
std::string backend_sni_name;
|
std::string backend_sni_name;
|
||||||
std::chrono::seconds session_timeout;
|
std::chrono::seconds session_timeout;
|
||||||
ImmutableString private_key_file;
|
ImmutableString private_key_file;
|
||||||
std::unique_ptr<char[]> private_key_passwd;
|
ImmutableString private_key_passwd;
|
||||||
ImmutableString cert_file;
|
ImmutableString cert_file;
|
||||||
std::unique_ptr<char[]> dh_param_file;
|
std::unique_ptr<char[]> dh_param_file;
|
||||||
std::unique_ptr<char[]> ciphers;
|
std::unique_ptr<char[]> ciphers;
|
||||||
|
|
|
@ -124,13 +124,13 @@ set_alpn_prefs(const std::vector<std::string> &protos) {
|
||||||
namespace {
|
namespace {
|
||||||
int ssl_pem_passwd_cb(char *buf, int size, int rwflag, void *user_data) {
|
int ssl_pem_passwd_cb(char *buf, int size, int rwflag, void *user_data) {
|
||||||
auto config = static_cast<Config *>(user_data);
|
auto config = static_cast<Config *>(user_data);
|
||||||
int len = (int)strlen(config->tls.private_key_passwd.get());
|
auto len = static_cast<int>(config->tls.private_key_passwd.size());
|
||||||
if (size < len + 1) {
|
if (size < len + 1) {
|
||||||
LOG(ERROR) << "ssl_pem_passwd_cb: buf is too small " << size;
|
LOG(ERROR) << "ssl_pem_passwd_cb: buf is too small " << size;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// Copy string including last '\0'.
|
// Copy string including last '\0'.
|
||||||
memcpy(buf, config->tls.private_key_passwd.get(), len + 1);
|
memcpy(buf, config->tls.private_key_passwd.c_str(), len + 1);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -548,7 +548,7 @@ SSL_CTX *create_ssl_context(const char *private_key_file, const char *cert_file
|
||||||
|
|
||||||
SSL_CTX_set_mode(ssl_ctx, SSL_MODE_AUTO_RETRY);
|
SSL_CTX_set_mode(ssl_ctx, SSL_MODE_AUTO_RETRY);
|
||||||
SSL_CTX_set_mode(ssl_ctx, SSL_MODE_RELEASE_BUFFERS);
|
SSL_CTX_set_mode(ssl_ctx, SSL_MODE_RELEASE_BUFFERS);
|
||||||
if (tlsconf.private_key_passwd) {
|
if (!tlsconf.private_key_passwd.empty()) {
|
||||||
SSL_CTX_set_default_passwd_cb(ssl_ctx, ssl_pem_passwd_cb);
|
SSL_CTX_set_default_passwd_cb(ssl_ctx, ssl_pem_passwd_cb);
|
||||||
SSL_CTX_set_default_passwd_cb_userdata(ssl_ctx, (void *)get_config());
|
SSL_CTX_set_default_passwd_cb_userdata(ssl_ctx, (void *)get_config());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue