]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix NID bug in SSL_CERT_LOOKUP array construction
authorRichard Levitte <levitte@openssl.org>
Wed, 29 Oct 2025 09:03:51 +0000 (10:03 +0100)
committerRichard Levitte <levitte@openssl.org>
Thu, 30 Oct 2025 18:03:25 +0000 (19:03 +0100)
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 <viktor@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/29027)

ssl/t1_lib.c

index 98fe21338171894258a1fb86cbf97eeb2d63236c..dc22b4dbd42b3c267e06796acaaf1ad8f76f046c 100644 (file)
@@ -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;
         }
     }