X509_CMP(3ossl)

πŸ’– X509_CMP β€” bestie edition πŸ’–

okay so this is the X509_CMP(3ossl) page from the OpenSSL manual, and we're about to get so good at comparing certificates. buckle up πŸŽ€


✨ NAME ✨

X509_cmp, X509_NAME_cmp, X509_issuer_and_serial_cmp, X509_issuer_name_cmp, X509_subject_name_cmp, X509_CRL_cmp, X509_CRL_match β€” the little squad of functions that compare X509 certificates and all the related values that come with them πŸ¦‹


🌸 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 whole friend group exists to compare X509 objects β€” that's X509 certificates, X509 CRL objects, and all the lil values that live inside an X509 certificate. it's giving matchmaker energy but for crypto objects, fr fr.

X509_cmp() compares two X509 objects, pointed at by the params 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. both. not one. periodt. πŸ’…

X509_NAME_cmp() compares two X509_NAME objects, pointed at by a and b β€” and plot twist: either of them may be NULL. 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 if you were thinking you could just shuffle those around, no bestie. 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 that part genuinely doesn't care. the way that nuance is everything 😭

X509_issuer_and_serial_cmp() compares the serial number and issuer values in the given X509 objects a and b. two things, one function, slay.

X509_issuer_name_cmp(), X509_subject_name_cmp() and X509_CRL_cmp() are effectively wrappers of X509_NAME_cmp() β€” iconic behaviour honestly. these functions 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. it's the overachiever of the group, no cap πŸ”₯


πŸ‘‘ 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 very simple, very demure 🌸

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. yes, a whole extra number. she contains multitudes πŸ’€


🫢 NOTES 🫢

these functions in fact utilize the underlying memcmp of the C library to do the comparison job. the data to be compared varies β€” it could be DER encoding data, a hash value, or an 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, use it for sorting, don't read too deep into it, iykyk.

⚠️ X509_NAME_cmp() and its wrappers utilize the value -2 to indicate errors in some circumstances, which could cause confusion for the applications. bestie. be aware. that -2 is lurking πŸ™ˆ

🌈 SEE ALSO 🌈

i2d_X509_NAME(3), i2d_X509(3)


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 version 3.5.9, dated 2026-09-29, and it's part of the OpenSSL collection. go forth and compare responsibly πŸ’…βœ¨

πŸ“¦ where this page comes from