X509_CMP(3ossl)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’– X509_CMP πŸ’–

okay so this is the OpenSSL 3ossl manual page for X509_CMP, and bestie, it's literally all about comparing certificates and their little friends. no cap, it's a whole family of comparison functions and they all return numbers so you can sort stuff. let's go πŸŽ€


✨ 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 β€” compare 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 whole squad of functions exists to compare X509 objects β€” and that includes X509 certificates, X509 CRL objects, and like, various values inside an X509 certificate. it's giving "sorting hat but for certs" πŸ”₯

X509_cmp() compares two X509 objects, pointed at by the parameters 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. yeah, both. it's thorough like that πŸ’β€β™€οΈ

X509_NAME_cmp() compares two X509_NAME objects, pointed at by parameters a and b, and lowkey the slay here is that 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. 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. iykyk 🧚

X509_issuer_and_serial_cmp() compares the serial number and issuer values in the given X509 objects a and b. two-for-one deal, we love to see it ✨

X509_issuer_name_cmp(), X509_subject_name_cmp() and X509_CRL_cmp() are effectively wrappers of the X509_NAME_cmp() function. these functions compare issuer names and subject names of the objects, or issuers of X509_CRL objects, respectively. basically they're the name-cmp girlies wearing different fits πŸ‘‘

X509_CRL_match() compares two X509_CRL objects. unlike the X509_CRL_cmp() function, this function compares the whole CRL content instead of just the issuer name. main character energy, it does the most πŸ’€


⭐ 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. cute little trio, very readable 🫢

and then there's the plot twist: 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 bestie, -2 is a whole extra thing you have to check for 😭

🌈 NOTES 🌈

these functions in fact utilize the underlying memcmp of the C library to do the comparison job. the 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, don't read too much into it πŸ™ˆ

X509_NAME_cmp() and wrappers utilize the value -2 to indicate errors in some circumstances, which could cause confusion for the applications. fr fr, watch out for that one, it's giving chaotic πŸ’€


πŸ¦‹ 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.6, dated 2026-04-07, brought to you by the X509_CMP(3ossl) agenda. go compare your certs responsibly βœ¨πŸŽ€

πŸ“¦ where this page comes from