-
Notifications
You must be signed in to change notification settings - Fork 872
Replace ENGINE support with PROVIDER support on OpenSSL3+ #13458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
43db37c
7c761e3
26602cf
ce220e5
89f0b97
7f9e874
5b24080
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -856,43 +856,24 @@ SSLMultiCertConfigLoader::default_server_ssl_ctx() | |
| static bool | ||
| SSLPrivateKeyHandler(SSL_CTX *ctx, const char *keyPath, const char *secret_data, int secret_data_len) | ||
| { | ||
| EVP_PKEY *pkey = nullptr; | ||
| #if HAVE_ENGINE_GET_DEFAULT_RSA && HAVE_ENGINE_LOAD_PRIVATE_KEY | ||
| ENGINE *e = ENGINE_get_default_RSA(); | ||
| if (e != nullptr) { | ||
| pkey = ENGINE_load_private_key(e, keyPath, nullptr, nullptr); | ||
| if (pkey) { | ||
| if (!SSL_CTX_use_PrivateKey(ctx, pkey)) { | ||
| Dbg(dbg_ctl_ssl_load, "failed to load server private key from engine"); | ||
| EVP_PKEY_free(pkey); | ||
| return false; | ||
| } | ||
| } | ||
| bool result{false}; | ||
| if (keyPath && keyPath[0] != '\0') { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P1] Keep SSL-secret plugin data authoritative Trying |
||
| result = use_pkey_from_file(ctx, keyPath); | ||
| } | ||
| #else | ||
| void *e = nullptr; | ||
| #endif | ||
| if (pkey == nullptr) { | ||
| scoped_BIO bio(BIO_new_mem_buf(secret_data, secret_data_len)); | ||
|
|
||
| pem_password_cb *password_cb = SSL_CTX_get_default_passwd_cb(ctx); | ||
| void *u = SSL_CTX_get_default_passwd_cb_userdata(ctx); | ||
| 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; | ||
| } | ||
| if (!SSL_CTX_use_PrivateKey(ctx, pkey)) { | ||
| Dbg(dbg_ctl_ssl_load, "failed to attach server private key loaded from %s", | ||
| (!keyPath || keyPath[0] == '\0') ? "[empty key path]" : keyPath); | ||
| EVP_PKEY_free(pkey); | ||
| return false; | ||
| } | ||
| if (e == nullptr && !SSL_CTX_check_private_key(ctx)) { | ||
| Dbg(dbg_ctl_ssl_load, "server private key does not match the certificate public key"); | ||
| return false; | ||
| } | ||
|
|
||
| if (!result) { | ||
| result = use_pkey_from_secret_data(ctx, secret_data, secret_data_len); | ||
| } | ||
|
|
||
| if (!result) { | ||
| 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; | ||
| } | ||
|
|
||
| if (!SSL_CTX_check_private_key(ctx)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P1] Do not require this comparison for opaque hardware keys The previous |
||
| Dbg(dbg_ctl_ssl_load, "server private key does not match the certificate public key"); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Release the functional ENGINE reference
ENGINE_get_default_RSA()returns an incremented functional reference that must be released withENGINE_finish()before it is discarded. Neither the successful early return nor the failure/fallback path releasese, so repeated certificate loads and configuration reloads leak ENGINE references. Please manage this with an RAII deleter or explicitly finish the ENGINE on every path.