SSL_CTX_SET_CERT_STORE(3ossl)
π SSL_CTX_SET_CERT_STORE(3ossl) π
okay so this is one of those OpenSSL pages, bestie β from the OpenSSL manual fam β and it's literally all about the certificate verification storage. the vibes? very "who owns this pointer". let's get into it π
β¨ NAME β¨
SSL_CTX_set_cert_store, SSL_CTX_set1_cert_store, SSL_CTX_get_cert_store β 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 β¨
okay so first up, SSL_CTX_set_cert_store() sets/replaces the certificate verification storage of ctx to/with store. and here's the tea β β if another X509_STORE object is currently set in ctx, it will be X509_STORE_free()ed. also, SSL_CTX_set_cert_store() will take ownership of the store, which means like... the call X509_STORE_free(store) is no longer needed. she's yours now, congrats π
SSL_CTX_set1_cert_store() also sets/replaces the certificate verification storage of ctx to/with store β but the difference is that the store's reference count is incremented. and yeah, if another X509_STORE object is currently set in ctx, it will be X509_STORE_free()ed. same cleanup energy, different ownership situation π
SSL_CTX_get_cert_store() returns a pointer to the current certificate verification storage. and ctx MUST NOT be NULL β like, don't do that, it's not giving π
β¨ NOTES β¨
so like, in order to verify the certificates presented by the peer, trusted CA certificates must 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 used when verifying certificates is created. iconic little pipeline honestly π₯
typically the trusted certificate store is handled indirectly via using SSL_CTX_load_verify_locations(3). but with the SSL_CTX_set_cert_store() and SSL_CTX_get_cert_store() functions, it's possible to manipulate the X509_STORE object beyond the SSL_CTX_load_verify_locations(3) call. so like, you can go deeper π«Ά
currently no detailed documentation on how to use the X509_STORE object is available. and ngl, not all members of the X509_STORE are used when the verification takes place. so like, for example, the verify_callback() will be overridden with the verify_callback() set via the SSL_CTX_set_verify(3) family of functions. this document must therefore be updated when documentation about the X509_STORE object and its handling becomes available. so like... future homework for the maintainers π
β οΈ important one, bestie:SSL_CTX_set_cert_store()does not increment the store's reference count, so it should not be used to assign anX509_STOREthat is owned by anotherSSL_CTX. that's a double-free waiting to happen and we do NOT stan undefined behaviour π
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 little dance π§
β¨ 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 like, it's a group project store π
applications wanting finer control can use functions such as SSL_CTX_set1_verify_cert_store() instead. go be specific, queen π
β¨ 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.
so basically the setters give you β¨nothingβ¨ (they're void, it's fine, it's fine) and the getter gives you the current setting. that's the whole personality π
β¨ SEE ALSO β¨
ssl(7), SSL_CTX_load_verify_locations(3), SSL_CTX_set_verify(3)
β¨ COPYRIGHT β¨
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>.
aaand that's the page, bestie π«Ά this one's from version 3.5.0, dated 2026-09-25, and it's the SSL_CTX_SET_CERT_STORE(3ossl) page β go forth and manage your reference counts responsibly, mwah πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms