Commit ad686dc0a8 for openssl.org

commit ad686dc0a848359a3785e0026322cb09acb50613
Author: Bob Beck <beck@openssl.org>
Date:   Fri Sep 4 11:54:11 2026 -0600

    Compare the signature in X509_cmp()

    When the cached SHA-1 hashes of two certificates match, X509_cmp()
    confirms the match by comparing only the cached encoding of the
    to-be-signed part, so a colliding pair differing only in its
    signature would compare equal. Compare the signature algorithm and
    signature value as well, so that a match means the whole certificate
    is identical.

    Reviewed-by: Mounir Idrassi <mounir.idrassi@idrix.fr>
    Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
    Merge-date: Thu Sep 17 16:44:30 2026
    Merged-from: https://github.com/openssl/openssl/pull/32686

diff --git a/crypto/x509/x509_cmp.c b/crypto/x509/x509_cmp.c
index 6cf674ea85..20b0d0fe8b 100644
--- a/crypto/x509/x509_cmp.c
+++ b/crypto/x509/x509_cmp.c
@@ -174,6 +174,13 @@ int X509_cmp(const X509 *a, const X509 *b)
             return 1;
         rv = memcmp(a->cert_info.enc.enc,
             b->cert_info.enc.enc, a->cert_info.enc.len);
+        if (rv != 0)
+            return rv < 0 ? -1 : 1;
+        /* Same TBS: the signature algorithm and signature must match too */
+        rv = X509_ALGOR_cmp(&a->sig_alg, &b->sig_alg);
+        if (rv != 0)
+            return rv < 0 ? -1 : 1;
+        rv = ASN1_STRING_cmp(&a->signature, &b->signature);
     }
     return rv < 0 ? -1 : rv > 0;
 }