From: Richard Levitte Date: Wed, 29 Oct 2025 09:03:51 +0000 (+0100) Subject: Fix NID bug in SSL_CERT_LOOKUP array construction X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aedcdc6d0f5bfb16af7d0065157af84e671159e0;p=thirdparty%2Fopenssl.git Fix NID bug in SSL_CERT_LOOKUP array construction The SSL_CERT_LOOKUP NID should be for the public key algorithm (what is often called the "key type". Yet, when populating the SSL_CERT_LOOKUP table with 'ssl_load_sigalgs', only the sigalg name is used to find a NID. This is perfectly OK to do, *if* the sigalg and the associated key type share the same name. However, that's not always the case. This change infers the key type name in 'ssl_load_sigalgs' the same way as it was already done in 'add_provider_sigalgs'. Related-to: https://github.com/openssl/openssl/pull/29019#discussion_r2472219647 Reviewed-by: Viktor Dukhovni Reviewed-by: Matt Caswell Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/29027) --- diff --git a/ssl/t1_lib.c b/ssl/t1_lib.c index 98fe2133817..dc22b4dbd42 100644 --- a/ssl/t1_lib.c +++ b/ssl/t1_lib.c @@ -371,6 +371,15 @@ int ssl_load_groups(SSL_CTX *ctx) return SSL_CTX_set1_groups_list(ctx, TLS_DEFAULT_GROUP_LIST); } +static const char *inferred_keytype(const TLS_SIGALG_INFO *sinf) +{ + return (sinf->keytype != NULL + ? sinf->keytype + : (sinf->sig_name != NULL + ? sinf->sig_name + : sinf->sigalg_name)); +} + #define TLS_SIGALG_LIST_MALLOC_BLOCK_SIZE 10 static OSSL_CALLBACK add_provider_sigalgs; static int add_provider_sigalgs(const OSSL_PARAM params[], void *data) @@ -587,11 +596,7 @@ static int add_provider_sigalgs(const OSSL_PARAM params[], void *data) */ ret = 1; ERR_set_mark(); - keytype = (sinf->keytype != NULL - ? sinf->keytype - : (sinf->sig_name != NULL - ? sinf->sig_name - : sinf->sigalg_name)); + keytype = inferred_keytype(sinf); keymgmt = EVP_KEYMGMT_fetch(ctx->libctx, keytype, ctx->propq); if (keymgmt != NULL) { /* @@ -692,7 +697,8 @@ int ssl_load_sigalgs(SSL_CTX *ctx) if (ctx->ssl_cert_info == NULL) return 0; for(i = 0; i < ctx->sigalg_list_len; i++) { - ctx->ssl_cert_info[i].nid = OBJ_txt2nid(ctx->sigalg_list[i].sigalg_name); + const char *keytype = inferred_keytype(&ctx->sigalg_list[i]); + ctx->ssl_cert_info[i].nid = OBJ_txt2nid(keytype); ctx->ssl_cert_info[i].amask = SSL_aANY; } }