SSL_CTX_ADD1_CHAIN_CERT(3ossl)
π SSL_CTX_ADD1_CHAIN_CERT π
okay bestie, welcome to the OpenSSL 3ossl manual page for extra chain certificate processing β¨ this one is all about the cert chain attached to your current end-entity cert, and how to set it, add to it, fetch it, clear it, build it, and pick which cert is βcurrentβ π
πΈ NAME πΈ
This page covers the whole squad: SSL_CTX_set0_chain, SSL_CTX_set1_chain, SSL_CTX_add0_chain_cert, SSL_CTX_add1_chain_cert, SSL_CTX_get0_chain_certs, SSL_CTX_clear_chain_certs, SSL_set0_chain, SSL_set1_chain, SSL_add0_chain_cert, SSL_add1_chain_cert, SSL_get0_chain_certs, SSL_clear_chain_certs, SSL_CTX_build_cert_chain, SSL_build_cert_chain, SSL_CTX_select_current_cert, SSL_select_current_cert, SSL_CTX_set_current_cert, and SSL_set_current_cert β all of them are about extra chain certificate processing π
π¦ SYNOPSIS π¦
#include <openssl/ssl.h>
int SSL_CTX_set0_chain(SSL_CTX *ctx, STACK_OF(X509) *sk);
int SSL_CTX_set1_chain(SSL_CTX *ctx, STACK_OF(X509) *sk);
int SSL_CTX_add0_chain_cert(SSL_CTX *ctx, X509 *x509);
int SSL_CTX_add1_chain_cert(SSL_CTX *ctx, X509 *x509);
int SSL_CTX_get0_chain_certs(SSL_CTX *ctx, STACK_OF(X509) **sk);
int SSL_CTX_clear_chain_certs(SSL_CTX *ctx);
int SSL_set0_chain(SSL *ssl, STACK_OF(X509) *sk);
int SSL_set1_chain(SSL *ssl, STACK_OF(X509) *sk);
int SSL_add0_chain_cert(SSL *ssl, X509 *x509);
int SSL_add1_chain_cert(SSL *ssl, X509 *x509);
int SSL_get0_chain_certs(SSL *ssl, STACK_OF(X509) **sk);
int SSL_clear_chain_certs(SSL *ssl);
int SSL_CTX_build_cert_chain(SSL_CTX *ctx, flags);
int SSL_build_cert_chain(SSL *ssl, flags);
int SSL_CTX_select_current_cert(SSL_CTX *ctx, X509 *x509);
int SSL_select_current_cert(SSL *ssl, X509 *x509);
int SSL_CTX_set_current_cert(SSL_CTX *ctx, long op);
int SSL_set_current_cert(SSL *ssl, long op);
β¨ DESCRIPTION β¨
okay so hereβs the tea β
SSL_CTX_set0_chain()andSSL_CTX_set1_chain()β set the certificate chain associated with the current certificate ofctxtosk.SSL_CTX_add0_chain_cert()andSSL_CTX_add1_chain_cert()β append the single certificatex509to the chain associated with the current certificate ofctx.SSL_CTX_get0_chain_certs()β retrieves the chain associated with the current certificate ofctx.SSL_CTX_clear_chain_certs()β clears any existing chain associated with the current certificate ofctx. (This is implemented by callingSSL_CTX_set0_chain()withskset toNULL.)SSL_CTX_build_cert_chain()β builds the certificate chain forctx. Normally this uses the chain store or the verify store if the chain store is not set. If the function is successful the built chain will replace any existing chain. Theflagsparameter can be set toSSL_BUILD_CHAIN_FLAG_UNTRUSTEDto use existing chain certificates as untrusted CAs,SSL_BUILD_CHAIN_FLAG_NO_ROOTto omit the root CA from the built chain,SSL_BUILD_CHAIN_FLAG_CHECKto use all existing chain certificates only to build the chain (effectively sanity checking and rearranging them if necessary), the flagSSL_BUILD_CHAIN_FLAG_IGNORE_ERRORignores any errors during verification: if flagSSL_BUILD_CHAIN_FLAG_CLEAR_ERRORis also set verification errors are cleared from the error queue. Details of the chain building process are described in βCertification Path Buildingβ inopenssl-verification-options(1).- current end entity vibes β each of these functions operates on the current end entity (i.e. server or client) certificate. This is the last certificate loaded or selected on the corresponding
ctxstructure. SSL_CTX_select_current_cert()β selectsx509as the current end entity certificate, but only ifx509has already been loaded intoctxusing a function such asSSL_CTX_use_certificate().- SSL-side twins β
SSL_set0_chain(),SSL_set1_chain(),SSL_add0_chain_cert(),SSL_add1_chain_cert(),SSL_get0_chain_certs(),SSL_clear_chain_certs(),SSL_build_cert_chain(),SSL_select_current_cert()andSSL_set_current_cert()are similar except they apply toSSLstructuressl. SSL_CTX_set_current_cert()β changes the current certificate to a value based on theopargument. Currentlyopcan beSSL_CERT_SET_FIRSTto use the first valid certificate orSSL_CERT_SET_NEXTto set the next valid certificate after the current certificate. These two operations can be used to iterate over all certificates in anSSL_CTXstructure.SSL_set_current_cert()β also supports the optionSSL_CERT_SET_SERVER. Ifsslis a server and has sent a certificate to a connected client this option sets that certificate to the current certificate and returns 1. If the negotiated cipher suite is anonymous (and thus no certificate will be sent) 2 is returned and the current certificate is unchanged. Ifsslis not a server or a certificate has not been sent 0 is returned and the current certificate is unchanged.- macro moment β all these functions are implemented as macros. Those containing a 1 increment the reference count of the supplied certificate or chain so it must be freed at some point after the operation. Those containing a 0 do not increment reference counts and the supplied certificate or chain MUST NOT be freed after the operation.
bestie please clock the 1 vs 0 difference:1means it bumps the ref count and you gotta free it later;0means it does not bump the ref count and you MUST NOT free it after the operation ππ
π NOTES π
- The chains associate with an
SSL_CTXstructure are copied to anySSLstructures whenSSL_new()is called.SSLstructures will not be affected by any chains subsequently changed in the parentSSL_CTX. - One chain can be set for each key type supported by a server. So, for example, an RSA and a DSA certificate can (and often will) have different chains.
- The functions
SSL_CTX_build_cert_chain()andSSL_build_cert_chain()can be used to check application configuration and to ensure any necessary subordinate CAs are sent in the correct order. Misconfigured applications sending incorrect certificate chains often cause problems with peers. - For example an application can add any set of certificates using
SSL_CTX_use_certificate_chain_file()then callSSL_CTX_build_cert_chain()with the optionSSL_BUILD_CHAIN_FLAG_CHECKto check and reorder them. - Applications can issue non fatal warnings when checking chains by setting the flag
SSL_BUILD_CHAIN_FLAG_IGNORE_ERRORSand checking the return value. - Calling
SSL_CTX_build_cert_chain()orSSL_build_cert_chain()is more efficient than the automatic chain building as it is only performed once. Automatic chain building is performed on each new session. - If any certificates are added using these functions no certificates added using
SSL_CTX_add_extra_chain_cert()will be used.
π RETURN VALUES π
SSL_set_current_cert()withSSL_CERT_SET_SERVERreturn 1 for success, 2 if no server certificate is used because the cipher suites is anonymous and 0 for failure.SSL_CTX_build_cert_chain()andSSL_build_cert_chain()return 1 for success and 0 for failure. If the flagSSL_BUILD_CHAIN_FLAG_IGNORE_ERRORand a verification error occurs then 2 is returned.- All other functions return 1 for success and 0 for failure.
π₯ SEE ALSO π₯
ssl(7), SSL_CTX_add_extra_chain_cert(3)
π HISTORY π
These functions were added in OpenSSL 1.0.2.
π COPYRIGHT π
Copyright 2013-2021 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.
okay bye bestie π this page is from OpenSSL 3.5.6, dated 2026-04-07, and it lives under the SSL_CTX_ADD1_CHAIN_CERT(3ossl) manual name β slay β¨π«Ά
π¦ 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