X509_CHECK_PURPOSE(3ossl)
π X509_CHECK_PURPOSE β the OpenSSL 3ossl era, bestie
okay so buckle up π this is the whole x509v3.h purpose-checking family: X509_check_purpose, X509_PURPOSE_get_count, X509_PURPOSE_get_unused_id, X509_PURPOSE_get_by_sname, X509_PURPOSE_get_by_id, X509_PURPOSE_add, X509_PURPOSE_cleanup, X509_PURPOSE_get0, X509_PURPOSE_get_id, X509_PURPOSE_get0_name, X509_PURPOSE_get0_sname, X509_PURPOSE_get_trust, and X509_PURPOSE_set β literally all the functions related to checking the purpose of a certificate. iconic honestly π
β¨ SYNOPSIS β¨
#include <openssl/x509v3.h>
int X509_check_purpose(X509 *x, int id, int ca);
int X509_PURPOSE_get_count(void);
int X509_PURPOSE_get_unused_id(OSSL_LIB_CTX *libctx);
int X509_PURPOSE_get_by_sname(const char *sname);
int X509_PURPOSE_get_by_id(int id);
int X509_PURPOSE_add(int id, int trust, int flags,
int (*ck) (const X509_PURPOSE *, const X509 *, int),
const char *name, const char *sname, void *arg);
void X509_PURPOSE_cleanup(void);
X509_PURPOSE *X509_PURPOSE_get0(int idx);
int X509_PURPOSE_get_id(const X509_PURPOSE *);
char *X509_PURPOSE_get0_name(const X509_PURPOSE *xp);
char *X509_PURPOSE_get0_sname(const X509_PURPOSE *xp);
int X509_PURPOSE_get_trust(const X509_PURPOSE *xp);
int X509_PURPOSE_set(int *p, int purpose);
πΈ DESCRIPTION πΈ
the main character: X509_check_purpose
X509_check_purpose() asks the question "was certificate x literally made for the purpose represented by id?" π¦ If ca is nonzero, then certificate x gets checked to see whether it's a possible CA, and you may get back various levels of certainty. heads up tho: certificate x must be a complete certificate, otherwise the function just returns an error. no vibes, no partial certs, periodt π
Below are the potential ID's that can be checked β copy these exactly, iykyk:
# define X509_PURPOSE_SSL_CLIENT 1
# define X509_PURPOSE_SSL_SERVER 2
# define X509_PURPOSE_NS_SSL_SERVER 3
# define X509_PURPOSE_SMIME_SIGN 4
# define X509_PURPOSE_SMIME_ENCRYPT 5
# define X509_PURPOSE_CRL_SIGN 6
# define X509_PURPOSE_ANY 7
# define X509_PURPOSE_OCSP_HELPER 8
# define X509_PURPOSE_TIMESTAMP_SIGN 9
# define X509_PURPOSE_CODE_SIGN 10
The checks performed take into account the X.509 extensions keyUsage, extendedKeyUsage, and basicConstraints. so like, it's actually reading the receipts π
the rest of the squad β¨
X509_PURPOSE_get_count()β returns the number of currently defined purposes. that's the headcount, bestie π«ΆX509_PURPOSE_get_unused_id()β returns the smallest purpose id not yet used, which is guaranteed to be unique and larger thanX509_PURPOSE_MAX. thelibctxparameter should be used to provide the library context β but it is currently ignored, since the purpose mapping table is global. yeah. it's giving placeholder πX509_PURPOSE_get_by_sname()β returns the index of the purpose with the given short name, or-1if not found.X509_PURPOSE_get_by_id()β returns the index of the purpose with the givenid, or-1if not found.X509_PURPOSE_add()β adds or modifies a purpose entry identified bysname. Unless theidstays the same for an existing entry,idmust be fresh, which can be achieved by using the result ofX509_PURPOSE_get_unused_id(). This function also sets in the entry the trust idtrust, the givenflags, the purpose (long) namename, the short namesname, the purpose checking functionckof typeint (*) (const X509_PURPOSE *, const X509 *, int), and its user dataargwhich may be retrieved via theX509_PURPOSEpointer. so much going on in one call, she's multitasking πX509_PURPOSE_cleanup()β removes all purposes that are not pre-defined. spring cleaning energy π§ΉX509_PURPOSE_get0()β returns anX509_PURPOSEpointer orNULLon error.X509_PURPOSE_get_id()β returns theidof the givenX509_PURPOSEstructure.X509_PURPOSE_get0_name()β returns the (long) name of the givenX509_PURPOSE.X509_PURPOSE_get0_sname()β returns the short name of the givenX509_PURPOSE.X509_PURPOSE_get_trust()β returns the trust id of the givenX509_PURPOSE.X509_PURPOSE_set()β assigns the given purpose id to the location pointed at byp. oh and it resets to the any purpose ifpurposeisX509_PURPOSE_DEFAULT_ANY. plot twist π
π RETURN VALUES π
non-CA checks π
X509_check_purpose() returns the following values. For non-CA checks:
-1β an error condition has occurred1β the certificate was created to perform the purpose represented byid0β the certificate was not created to perform the purpose represented byid
CA checks π
For CA checks the below integers could be returned with the following meanings:
-1β an error condition has occurred0β not a CA or does not have the purpose represented byid1β is a CA.2β Only possible in old versions of openSSL whenbasicConstraintsare absent. New versions will not return this value. May be a CA3βbasicConstraintsabsent but self signed V1.4βbasicConstraintsabsent butkeyUsagepresent andkeyCertSignasserted.5β legacy Netscape specific CA Flags present
everyone else π
X509_PURPOSE_get_count()β returns the number of currently defined purposes.X509_PURPOSE_get_unused_id()β returns the smallest purpose id not yet used.X509_PURPOSE_get_by_sname()β returns the index of the purpose with the given short name or-1if not found.X509_PURPOSE_get_by_id()β returns the index of the purpose with the givenidor-1if not found.int X509_PURPOSE_add()β returns1on success,0on error.X509_PURPOSE_cleanup()β does not return anything. she simply leaves π¨X509_PURPOSE_get0()β returns anX509_PURPOSEpointer orNULLon error.X509_PURPOSE_get_id()β returns theidof the givenX509_PURPOSEstructure.X509_PURPOSE_get0_name()β returns the (long) name of the givenX509_PURPOSE.X509_PURPOSE_get0_sname()β returns the short name of the givenX509_PURPOSE.X509_PURPOSE_get_trust()β returns the trust id of the givenX509_PURPOSE.X509_PURPOSE_set()β returns1on success,0on error.
π BUGS π
not thread-safe, bestie. theX509_PURPOSEimplementation so far is not thread-safe. There may be race conditions retrieving purpose information whileX509_PURPOSE_add()orX509_PURPOSE_cleanup(void)is being called. so likeβ¦ don't do that. fr fr π
π¦ HISTORY π¦
X509_PURPOSE_get_unused_id() was added in OpenSSL 3.5. glow-up era β¨
π COPYRIGHT π
Copyright 2019-2025 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 the OpenSSL 3ossl manual, version 3.5.6, dated 2026-04-07 β go forth and check those purposes ππ
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms