X509_CHECK_PURPOSE(3ossl)
β¨ NAME β¨
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, X509_PURPOSE_set β bestie, these are the functions that check what a certificate's purpose is. Like, what was this cert literally born to do. πΈ
(it's the X509_CHECK_PURPOSE page from the OpenSSL manual, iykyk π
)
π¦ 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 π
X509_check_purpose() is the vibe check itself: it asks whether certificate x was created with the purpose represented by id. π
If ca is nonzero, then cert x gets checked to see if it's a possible CA β and ngl, it might hand you back various levels of certainty instead of a plain yes/no. The cert x must be a complete certificate, otherwise the function returns an error. no half-finished certificates in this house π
ββοΈ
Here are the potential ID's you can check, fr fr:
# 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 it runs take into account the X.509 extensions keyUsage, extendedKeyUsage, and basicConstraints. β¨
X509_PURPOSE_get_count() returns the number of currently defined purposes. count 'em up π
X509_PURPOSE_get_unused_id() returns the smallest purpose id not yet used, which is guaranteed to be unique and larger than X509_PURPOSE_MAX. The libctx parameter should be used to provide the library context. It is currently ignored, because the purpose mapping table is global. (she's a little bit decorative rn, but respect her π«Ά)
X509_PURPOSE_get_by_sname() returns the index of the purpose with the given short name, or -1 if not found.
X509_PURPOSE_get_by_id() returns the index of the purpose with the given id, or -1 if not found.
X509_PURPOSE_add() adds or modifies a purpose entry identified by sname. Unless the id stays the same for an existing entry, id must be fresh β and you get a fresh one by using the result of X509_PURPOSE_get_unused_id(). π The function also sets in the entry:
- the trust id
trust - the given
flags - the purpose (long) name
name - the short name
sname - the purpose checking function
ckof typeint (*) (const X509_PURPOSE *, const X509 *, int) - its user data
arg, which may be retrieved via theX509_PURPOSEpointer
X509_PURPOSE_cleanup() removes all purposes that are not pre-defined. bye-bye custom entries, the originals stay π
X509_PURPOSE_get0() returns an X509_PURPOSE pointer or NULL on error.
X509_PURPOSE_get_id() returns the id of the given X509_PURPOSE structure.
X509_PURPOSE_get0_name() returns the (long) name of the given X509_PURPOSE.
X509_PURPOSE_get0_sname() returns the short name of the given X509_PURPOSE.
X509_PURPOSE_get_trust() returns the trust id of the given X509_PURPOSE.
X509_PURPOSE_set() assigns the given purpose id to the location pointed at by p. This resets to the any purpose if purpose is X509_PURPOSE_DEFAULT_ANY. π¦
π RETURN VALUES π
X509_check_purpose() returns the following values. For non-CA checks:
-1β an error condition has occurred π1β the certificate was created to perform the purpose represented byid0β the certificate was not created to perform the purpose represented byid
For CA checks, the integers below could be returned, with these meanings:
-1β an error condition has occurred π0β not a CA, or does not have the purpose represented byid1β is a CA.2β Only possible in old versions of openSSL when basicConstraints are absent. New versions will not return this value. May be a CA3β basicConstraints absent but self signed V1.4β basicConstraints absent but keyUsage present and keyCertSign asserted.5β legacy Netscape specific CA Flags present
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 -1 if not found.
X509_PURPOSE_get_by_id() returns the index of the purpose with the given id or -1 if not found.
int X509_PURPOSE_add() returns 1 on success, 0 on error.
X509_PURPOSE_cleanup() does not return anything. she gives nothing and that's the point π
X509_PURPOSE_get0() returns an X509_PURPOSE pointer or NULL on error.
X509_PURPOSE_get_id() returns the id of the given X509_PURPOSE structure.
X509_PURPOSE_get0_name() returns the (long) name of the given X509_PURPOSE.
X509_PURPOSE_get0_sname() returns the short name of the given X509_PURPOSE.
X509_PURPOSE_get_trust() returns the trust id of the given X509_PURPOSE.
X509_PURPOSE_set() returns 1 on success, 0 on error.
π BUGS π
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.
okay so that one's lowkey scary, protect your threads bestie π
πΈ HISTORY πΈ
X509_PURPOSE_get_unused_id() was added in OpensSL 3.5. (yes, the capitalisation is theirs, we don't fix it, we respect the lore π)
π 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 OpenSSL 3.5.9, dated 2026-09-29, signed off with love from the X509_CHECK_PURPOSE(3ossl) girlies π«Άβ¨
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms