X509_CMP(3SSL)

πŸ’… X509_CMP β€” comparing certs and their little friends

okay bestie so this is a page from the OpenSSL manual, section 3SSL, and it's literally all about comparing X509 stuff. No cap.


✨ NAME ✨

so the whole girl gang here is: X509_cmp, X509_NAME_cmp, X509_issuer_and_serial_cmp, X509_issuer_name_cmp, X509_subject_name_cmp, X509_CRL_cmp, X509_CRL_match β€” and their whole job is comparing X509 certificates and related values. πŸ’–


🌸 SYNOPSIS 🌸

#include <openssl/x509.h>

int X509_cmp(const X509 *a, const X509 *b);
int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b);
int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b);
int X509_issuer_name_cmp(const X509 *a, const X509 *b);
int X509_subject_name_cmp(const X509 *a, const X509 *b);
int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b);
int X509_CRL_match(const X509_CRL *a, const X509_CRL *b);

πŸ¦‹ DESCRIPTION πŸ¦‹

so this little set of functions is what you use to compare X509 objects β€” X509 certificates, X509 CRL objects, and all the various values hanging out inside an X509 certificate. it's giving comparison, but make it cryptographic. ✨

  • X509_cmp() β€” compares two X509 objects, the ones you passed in as a and b. The comparison is based on the memcmp result of the hash values of the two X509 objects AND the canonical (DER) encoding values. Two things at once, she's multifaceted. πŸ’…
  • X509_NAME_cmp() β€” compares two X509_NAME objects, passed as a and b, and either of them may be NULL (yes really, NULL is allowed, be free). The comparison is based on the memcmp result of the canonical (DER) encoding values of the two objects, using i2d_X509_NAME(3). This procedure adheres to the matching rules for Distinguished Names (DN) given in RFC 4517 section 4.2.15 and RFC 5280 section 7.1. In particular, the order of Relative Distinguished Names (RDNs) is relevant β€” so like, RDN order actually matters, periodt. On the other hand, if an RDN is multi-valued, i.e., it contains a set of AttributeValueAssertions (AVAs), its members are effectively not ordered. so inside a multi-valued RDN, the AVAs are chill and unordered, but the RDNs themselves? order counts. iykyk.
  • X509_issuer_and_serial_cmp() β€” compares the serial number and issuer values in the given X509 objects a and b. that's it, that's the whole vibe.
  • X509_issuer_name_cmp(), X509_subject_name_cmp() and X509_CRL_cmp() β€” these are effectively wrappers of the X509_NAME_cmp() function. iconic behavior honestly. They compare issuer names and subject names of the objects, or issuers of X509_CRL objects, respectively.
  • X509_CRL_match() β€” compares two X509_CRL objects. Unlike the X509_CRL_cmp() function, this one compares the whole CRL content instead of just the issuer name. she does the full deep dive, not just the surface. πŸ”₯

πŸŽ€ RETURN VALUES πŸŽ€

The X509 comparison functions return -1, 0, or 1 if object a is found to be less than, to match, or be greater than object b, respectively. it's giving leaderboard energy.

X509_NAME_cmp(), X509_issuer_and_serial_cmp(), X509_issuer_name_cmp(), X509_subject_name_cmp(), X509_CRL_cmp(), and X509_CRL_match() may return -2 to indicate an error. ⚠️


πŸ’œ NOTES πŸ’œ

These functions in fact utilize the underlying memcmp of the C library to do the comparison job β€” classic, reliable, lowkey the moment. Data to be compared varies from DER encoding data, hash value or ASN1_STRING. The sign of the comparison can be used to order the objects but it does not have a special meaning in some cases. so like, the sign is useful for sorting, but don't read too much into it every time. πŸ™ˆ

bestie listen. X509_NAME_cmp() and its wrappers utilize the value -2 to indicate errors in some circumstances, which could cause confusion for the applications. so like, -2 is a thing, don't get got by it. 😭

🌈 SEE ALSO 🌈


Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


and that's the whole page, bestie ✨ this was OpenSSL version 4.0.3, dated 2026-09-29, from the X509_CMP(3SSL) manual. go forth and compare your certs responsibly πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from