From: Pauli Date: Tue, 8 Jun 2021 03:50:38 +0000 (+1000) Subject: keymgmt: better detect when a key manager can be reused X-Git-Tag: openssl-3.0.0-beta1~126 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1af9b646e87115e0bd4782a9326564c9bef63bda;p=thirdparty%2Fopenssl.git keymgmt: better detect when a key manager can be reused Fixes #14159 Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/15652) --- diff --git a/crypto/evp/keymgmt_lib.c b/crypto/evp/keymgmt_lib.c index bbca3ddef53..f3dd876cfdf 100644 --- a/crypto/evp/keymgmt_lib.c +++ b/crypto/evp/keymgmt_lib.c @@ -107,8 +107,16 @@ void *evp_keymgmt_util_export_to_provider(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt) if (pk->keydata == NULL) return NULL; - /* If |keymgmt| matches the "origin" |keymgmt|, no more to do */ - if (pk->keymgmt == keymgmt) + /* + * If |keymgmt| matches the "origin" |keymgmt|, there is no more to do. + * The "origin" is determined by the |keymgmt| pointers being identical + * or when the provider and the name ID match. The latter case handles the + * situation where the fetch cache is flushed and a "new" key manager is + * created. + */ + if (pk->keymgmt == keymgmt + || (pk->keymgmt->name_id == keymgmt->name_id + && pk->keymgmt->prov == keymgmt->prov)) return pk->keydata; if (!CRYPTO_THREAD_read_lock(pk->lock))