JosiahWI commented on code in PR #14130:
URL: https://github.com/apache/trafficserver/pull/14130#discussion_r4646087384
##########
src/iocore/net/SSLUtils.cc:
##########
@@ -1520,25 +1520,33 @@ SSLMultiCertConfigLoader::default_server_ssl_ctx()
return SSL_CTX_new(SSLv23_server_method());
}
-static bool
-SSLPrivateKeyHandler(SSL_CTX *ctx, const char *keyPath, const char
*secret_data, int secret_data_len)
+scoped_PKEY
+TLSReadPrivateKey(SSL_CTX *ctx, std::string_view key_path, std::string_view
secret)
{
- // SSL_CTX_use_PrivateKey() takes its own reference on the key, so this
- // reference must be released on every exit.
- scoped_BIO bio(BIO_new_mem_buf(secret_data, secret_data_len));
+ scoped_BIO bio(BIO_new_mem_buf(secret.data(), secret.size()));
+ if (bio == nullptr) {
+ return nullptr;
+ }
pem_password_cb *password_cb = SSL_CTX_get_default_passwd_cb(ctx);
void *u = SSL_CTX_get_default_passwd_cb_userdata(ctx);
- scoped_PKEY const pkey{PEM_read_bio_PrivateKey(bio.get(), nullptr,
password_cb, u)};
- if (nullptr == pkey) {
- Dbg(dbg_ctl_ssl_load, "failed to load server private key (%.*s) from %s",
secret_data_len < 50 ? secret_data_len : 50,
- secret_data, (!keyPath || keyPath[0] == '\0') ? "[empty key path]" :
keyPath);
- return false;
+ scoped_PKEY pkey{PEM_read_bio_PrivateKey(bio.get(), nullptr, password_cb,
u)};
+ if (pkey == nullptr) {
+ std::string_view const source = key_path.empty() ?
std::string_view{"[empty key path]"} : key_path;
+ Dbg(dbg_ctl_ssl_load, "failed to load server private key (%.*s) from %.*s",
+ static_cast<int>(std::min(secret.size(), size_t{50})), secret.data(),
static_cast<int>(source.size()), source.data());
}
- if (!SSL_CTX_use_PrivateKey(ctx, pkey.get())) {
- Dbg(dbg_ctl_ssl_load, "failed to attach server private key loaded from %s",
- (!keyPath || keyPath[0] == '\0') ? "[empty key path]" : keyPath);
+ return pkey;
+}
+
+/// Sets @a pkey, read from @a key_path, as the private key of @a ctx and
checks that it matches the certificate already set.
Review Comment:
Yes, we haven't had a chance to discuss it as a community yet, but people
have been asking for a convention on how we use Doxygen comments. Doxygen is
used to build an API reference that can be published, and an internal helper
should not be published to an API reference.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]