maskit commented on code in PR #14130:
URL: https://github.com/apache/trafficserver/pull/14130#discussion_r4646686460
##########
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:
Thanks, done in `f748ed940c`. `TLSUsePrivateKey` and the helpers in the test
file now have plain comments. The only Doxygen block left in this PR is on the
`TLSReadPrivateKey` declaration in `P_SSLUtils.h`.
For the convention discussion: Doxygen has `@internal` for this. With
`INTERNAL_DOCS = NO`, which is the default and what our Doxyfile uses, the text
after it is left out of the generated reference. It doesn't help with checking,
though: Doxygen doesn't check `@param` names in that text, so it's no better
guarded than a plain comment.
--
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]