SSL_CTX_SET_CERT_STORE(3ossl)

πŸ’– SSL_CTX_SET_CERT_STORE πŸ’–

okay bestie, welcome to the OpenSSL section 3ossl glow-up of SSL_CTX_SET_CERT_STORE(3ossl) β€” it's the page about messing with your X509 certificate verification storage. yes, the name is a whole mouthful, we don't make the rules. let's get into it πŸŽ€


✨ NAME ✨

SSL_CTX_set_cert_store, SSL_CTX_set1_cert_store, SSL_CTX_get_cert_store β€” the girlies that manipulate X509 certificate verification storage πŸ¦‹


🌸 SYNOPSIS 🌸

#include <openssl/ssl.h>

void SSL_CTX_set_cert_store(SSL_CTX *ctx, X509_STORE *store);
void SSL_CTX_set1_cert_store(SSL_CTX *ctx, X509_STORE *store);
X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *ctx);

πŸ’… DESCRIPTION πŸ’…

SSL_CTX_set_cert_store() sets or replaces the certificate verification storage of ctx to/with store. If there's already another X509_STORE object chillin' in ctx, it gets X509_STORE_free()ed, no hesitation, it's giving eviction notice. and like β€” heads up β€” SSL_CTX_set_cert_store() takes ownership of the store, which means the call X509_STORE_free(store) is no longer needed. it's hers now. periodt.

SSL_CTX_set1_cert_store() also sets or replaces the certificate verification storage of ctx to/with store, but this one is respectful: the store's reference count gets incremented πŸ”₯. And if another X509_STORE object is currently set in ctx, that one still gets X509_STORE_free()ed. so it's polite about the new one, ruthless about the old one. main character energy honestly.

SSL_CTX_get_cert_store() returns a pointer to the current certificate verification storage. oh and ctx MUST NOT be NULL β€” like, that's non-negotiable, bestie, don't do it 😭


🧚 NOTES 🧚

so to verify the certificates the peer is serving you, trusted CA certificates have to be accessed. those CA certificates are made available via lookup methods, handled inside the X509_STORE. and from the X509_STORE, the X509_STORE_CTX that gets used when verifying certificates is created. it's a whole pipeline πŸ’œ

typically the trusted certificate store is handled indirectly by using SSL_CTX_load_verify_locations(3). but with the SSL_CTX_set_cert_store() and SSL_CTX_get_cert_store() functions, you can manipulate the X509_STORE object beyond the SSL_CTX_load_verify_locations(3) call. slay.

ngl, currently there's no detailed documentation on how to use the X509_STORE object. and not all members of the X509_STORE are used when the verification takes place. so for example, the verify_callback() will be overridden with the verify_callback() set via the SSL_CTX_set_verify(3) family of functions. so this document must therefore be updated when documentation about the X509_STORE object and its handling becomes available. we're waiting πŸ’€

SSL_CTX_set_cert_store() does not increment the store's reference count, so it should not be used to assign an X509_STORE that is owned by another SSL_CTX. like, that's someone else's man, don't.

to share X509_STOREs between two SSL_CTXs, use SSL_CTX_get_cert_store() to get the X509_STORE from the first SSL_CTX, and then use SSL_CTX_set1_cert_store() to assign to the second SSL_CTX and increment the reference count of the X509_STORE. that's the correct way, iykyk 🫢


πŸŽ€ RESTRICTIONS πŸŽ€

the X509_STORE structure used by an SSL_CTX is used for verifying peer certificates and building certificate chains, and it's also shared by every child SSL structure. so it's a communal situation. applications wanting finer control can use functions such as SSL_CTX_set1_verify_cert_store() instead. ✨


⭐ RETURN VALUES ⭐

SSL_CTX_set_cert_store() does not return diagnostic output.

SSL_CTX_set1_cert_store() does not return diagnostic output.

SSL_CTX_get_cert_store() returns the current setting.


🌈 SEE ALSO 🌈


Copyright 2001-2024 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 3.5.9, dated 2026-09-29, straight from the OpenSSL girlies themselves β€” SSL_CTX_SET_CERT_STORE(3ossl), out πŸŽ€βœ¨

πŸ“¦ where this page comes from