Commit 600251e767 for openssl.org
commit 600251e7672fa1466efd5cdb1b123ce4167a1f4d
Author: Bob Beck <beck@openssl.org>
Date: Fri Sep 4 12:02:31 2026 -0600
Fall back to comparing the encoding in X509_CRL_match()
X509_CRL_match() trusted the cached SHA-1 hash alone, and returned -2
when either hash was unavailable. Give it the same fallback X509_cmp()
has: when the hashes match or are unavailable, compare the cached
encoding of the to-be-signed part, then the signature algorithm and
signature value. It no longer returns -2; document that earlier
versions did.
Reviewed-by: Mounir Idrassi <mounir.idrassi@idrix.fr>
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
Merge-date: Thu Sep 17 16:44:31 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 20b0d0fe8b..89ada3a6bb 100644
--- a/crypto/x509/x509_cmp.c
+++ b/crypto/x509/x509_cmp.c
@@ -86,14 +86,29 @@ int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b)
int X509_CRL_match(const X509_CRL *a, const X509_CRL *b)
{
- int rv;
+ int rv = 0;
if ((a->flags & EXFLAG_NO_FINGERPRINT) == 0
&& (b->flags & EXFLAG_NO_FINGERPRINT) == 0)
rv = memcmp(a->sha1_hash, b->sha1_hash, SHA_DIGEST_LENGTH);
- else
- return -2;
+ if (rv != 0)
+ return rv < 0 ? -1 : 1;
+ /* Check for match against stored encoding too */
+ if (!a->crl.enc.modified && !b->crl.enc.modified) {
+ if (a->crl.enc.len < b->crl.enc.len)
+ return -1;
+ if (a->crl.enc.len > b->crl.enc.len)
+ return 1;
+ rv = memcmp(a->crl.enc.enc, b->crl.enc.enc, a->crl.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;
}
diff --git a/doc/man3/X509_cmp.pod b/doc/man3/X509_cmp.pod
index f22333d19e..cd939cab02 100644
--- a/doc/man3/X509_cmp.pod
+++ b/doc/man3/X509_cmp.pod
@@ -56,8 +56,10 @@ The B<X509> comparison functions return B<-1>, B<0>, or B<1> if object I<a> is
found to be less than, to match, or be greater than object I<b>, respectively.
X509_NAME_cmp(), X509_issuer_and_serial_cmp(), X509_issuer_name_cmp(),
-X509_subject_name_cmp(), X509_CRL_cmp(), and X509_CRL_match()
+X509_subject_name_cmp(), and X509_CRL_cmp()
may return B<-2> to indicate an error.
+X509_CRL_match() no longer returns B<-2>, but did so in earlier versions
+to indicate an error, and callers should still be prepared to receive it.
=head1 NOTES