Blame doc/man3/SSL_CTX_add1_chain_cert.pod

Packit c4476c
=pod
Packit c4476c
Packit c4476c
=head1 NAME
Packit c4476c
Packit c4476c
SSL_CTX_set0_chain, SSL_CTX_set1_chain, SSL_CTX_add0_chain_cert,
Packit c4476c
SSL_CTX_add1_chain_cert, SSL_CTX_get0_chain_certs, SSL_CTX_clear_chain_certs,
Packit c4476c
SSL_set0_chain, SSL_set1_chain, SSL_add0_chain_cert, SSL_add1_chain_cert,
Packit c4476c
SSL_get0_chain_certs, SSL_clear_chain_certs, SSL_CTX_build_cert_chain,
Packit c4476c
SSL_build_cert_chain, SSL_CTX_select_current_cert,
Packit c4476c
SSL_select_current_cert, SSL_CTX_set_current_cert, SSL_set_current_cert - extra
Packit c4476c
chain certificate processing
Packit c4476c
Packit c4476c
=head1 SYNOPSIS
Packit c4476c
Packit c4476c
 #include <openssl/ssl.h>
Packit c4476c
Packit c4476c
 int SSL_CTX_set0_chain(SSL_CTX *ctx, STACK_OF(X509) *sk);
Packit c4476c
 int SSL_CTX_set1_chain(SSL_CTX *ctx, STACK_OF(X509) *sk);
Packit c4476c
 int SSL_CTX_add0_chain_cert(SSL_CTX *ctx, X509 *x509);
Packit c4476c
 int SSL_CTX_add1_chain_cert(SSL_CTX *ctx, X509 *x509);
Packit c4476c
 int SSL_CTX_get0_chain_certs(SSL_CTX *ctx, STACK_OF(X509) **sk);
Packit c4476c
 int SSL_CTX_clear_chain_certs(SSL_CTX *ctx);
Packit c4476c
Packit c4476c
 int SSL_set0_chain(SSL *ssl, STACK_OF(X509) *sk);
Packit c4476c
 int SSL_set1_chain(SSL *ssl, STACK_OF(X509) *sk);
Packit c4476c
 int SSL_add0_chain_cert(SSL *ssl, X509 *x509);
Packit c4476c
 int SSL_add1_chain_cert(SSL *ssl, X509 *x509);
Packit c4476c
 int SSL_get0_chain_certs(SSL *ssl, STACK_OF(X509) **sk);
Packit c4476c
 int SSL_clear_chain_certs(SSL *ssl);
Packit c4476c
Packit c4476c
 int SSL_CTX_build_cert_chain(SSL_CTX *ctx, flags);
Packit c4476c
 int SSL_build_cert_chain(SSL *ssl, flags);
Packit c4476c
Packit c4476c
 int SSL_CTX_select_current_cert(SSL_CTX *ctx, X509 *x509);
Packit c4476c
 int SSL_select_current_cert(SSL *ssl, X509 *x509);
Packit c4476c
 int SSL_CTX_set_current_cert(SSL_CTX *ctx, long op);
Packit c4476c
 int SSL_set_current_cert(SSL *ssl, long op);
Packit c4476c
Packit c4476c
=head1 DESCRIPTION
Packit c4476c
Packit c4476c
SSL_CTX_set0_chain() and SSL_CTX_set1_chain() set the certificate chain
Packit c4476c
associated with the current certificate of B<ctx> to B<sk>.
Packit c4476c
Packit c4476c
SSL_CTX_add0_chain_cert() and SSL_CTX_add1_chain_cert() append the single
Packit c4476c
certificate B<x509> to the chain associated with the current certificate of
Packit c4476c
B<ctx>.
Packit c4476c
Packit c4476c
SSL_CTX_get0_chain_certs() retrieves the chain associated with the current
Packit c4476c
certificate of B<ctx>.
Packit c4476c
Packit c4476c
SSL_CTX_clear_chain_certs() clears any existing chain associated with the
Packit c4476c
current certificate of B<ctx>.  (This is implemented by calling
Packit c4476c
SSL_CTX_set0_chain() with B<sk> set to B<NULL>).
Packit c4476c
Packit c4476c
SSL_CTX_build_cert_chain() builds the certificate chain for B<ctx> normally
Packit c4476c
this uses the chain store or the verify store if the chain store is not set.
Packit c4476c
If the function is successful the built chain will replace any existing chain.
Packit c4476c
The B<flags> parameter can be set to B<SSL_BUILD_CHAIN_FLAG_UNTRUSTED> to use
Packit c4476c
existing chain certificates as untrusted CAs, B<SSL_BUILD_CHAIN_FLAG_NO_ROOT>
Packit c4476c
to omit the root CA from the built chain, B<SSL_BUILD_CHAIN_FLAG_CHECK> to
Packit c4476c
use all existing chain certificates only to build the chain (effectively
Packit c4476c
sanity checking and rearranging them if necessary), the flag
Packit c4476c
B<SSL_BUILD_CHAIN_FLAG_IGNORE_ERROR> ignores any errors during verification:
Packit c4476c
if flag B<SSL_BUILD_CHAIN_FLAG_CLEAR_ERROR> is also set verification errors
Packit c4476c
are cleared from the error queue.
Packit c4476c
Packit c4476c
Each of these functions operates on the I<current> end entity
Packit c4476c
(i.e. server or client) certificate. This is the last certificate loaded or
Packit c4476c
selected on the corresponding B<ctx> structure.
Packit c4476c
Packit c4476c
SSL_CTX_select_current_cert() selects B<x509> as the current end entity
Packit c4476c
certificate, but only if B<x509> has already been loaded into B<ctx> using a
Packit c4476c
function such as SSL_CTX_use_certificate().
Packit c4476c
Packit c4476c
SSL_set0_chain(), SSL_set1_chain(), SSL_add0_chain_cert(),
Packit c4476c
SSL_add1_chain_cert(), SSL_get0_chain_certs(), SSL_clear_chain_certs(),
Packit c4476c
SSL_build_cert_chain(), SSL_select_current_cert() and SSL_set_current_cert()
Packit c4476c
are similar except they apply to SSL structure B<ssl>.
Packit c4476c
Packit c4476c
SSL_CTX_set_current_cert() changes the current certificate to a value based
Packit c4476c
on the B<op> argument. Currently B<op> can be B<SSL_CERT_SET_FIRST> to use
Packit c4476c
the first valid certificate or B<SSL_CERT_SET_NEXT> to set the next valid
Packit c4476c
certificate after the current certificate. These two operations can be
Packit c4476c
used to iterate over all certificates in an B<SSL_CTX> structure.
Packit c4476c
Packit c4476c
SSL_set_current_cert() also supports the option B<SSL_CERT_SET_SERVER>.
Packit c4476c
If B<ssl> is a server and has sent a certificate to a connected client
Packit c4476c
this option sets that certificate to the current certificate and returns 1.
Packit c4476c
If the negotiated cipher suite is anonymous (and thus no certificate will
Packit c4476c
be sent) 2 is returned and the current certificate is unchanged. If B<ssl>
Packit c4476c
is not a server or a certificate has not been sent 0 is returned and
Packit c4476c
the current certificate is unchanged.
Packit c4476c
Packit c4476c
All these functions are implemented as macros. Those containing a B<1>
Packit c4476c
increment the reference count of the supplied certificate or chain so it must
Packit c4476c
be freed at some point after the operation. Those containing a B<0> do
Packit c4476c
not increment reference counts and the supplied certificate or chain
Packit c4476c
B<MUST NOT> be freed after the operation.
Packit c4476c
Packit c4476c
=head1 NOTES
Packit c4476c
Packit c4476c
The chains associate with an SSL_CTX structure are copied to any SSL
Packit c4476c
structures when SSL_new() is called. SSL structures will not be affected
Packit c4476c
by any chains subsequently changed in the parent SSL_CTX.
Packit c4476c
Packit c4476c
One chain can be set for each key type supported by a server. So, for example,
Packit c4476c
an RSA and a DSA certificate can (and often will) have different chains.
Packit c4476c
Packit c4476c
The functions SSL_CTX_build_cert_chain() and SSL_build_cert_chain() can
Packit c4476c
be used to check application configuration and to ensure any necessary
Packit c4476c
subordinate CAs are sent in the correct order. Misconfigured applications
Packit c4476c
sending incorrect certificate chains often cause problems with peers.
Packit c4476c
Packit c4476c
For example an application can add any set of certificates using
Packit c4476c
SSL_CTX_use_certificate_chain_file() then call SSL_CTX_build_cert_chain()
Packit c4476c
with the option B<SSL_BUILD_CHAIN_FLAG_CHECK> to check and reorder them.
Packit c4476c
Packit c4476c
Applications can issue non fatal warnings when checking chains by setting
Packit c4476c
the flag B<SSL_BUILD_CHAIN_FLAG_IGNORE_ERRORS> and checking the return
Packit c4476c
value.
Packit c4476c
Packit c4476c
Calling SSL_CTX_build_cert_chain() or SSL_build_cert_chain() is more
Packit c4476c
efficient than the automatic chain building as it is only performed once.
Packit c4476c
Automatic chain building is performed on each new session.
Packit c4476c
Packit c4476c
If any certificates are added using these functions no certificates added
Packit c4476c
using SSL_CTX_add_extra_chain_cert() will be used.
Packit c4476c
Packit c4476c
=head1 RETURN VALUES
Packit c4476c
Packit c4476c
SSL_set_current_cert() with B<SSL_CERT_SET_SERVER> return 1 for success, 2 if
Packit c4476c
no server certificate is used because the cipher suites is anonymous and 0
Packit c4476c
for failure.
Packit c4476c
Packit c4476c
SSL_CTX_build_cert_chain() and SSL_build_cert_chain() return 1 for success
Packit c4476c
and 0 for failure. If the flag B<SSL_BUILD_CHAIN_FLAG_IGNORE_ERROR> and
Packit c4476c
a verification error occurs then 2 is returned.
Packit c4476c
Packit c4476c
All other functions return 1 for success and 0 for failure.
Packit c4476c
Packit c4476c
=head1 SEE ALSO
Packit c4476c
Packit c4476c
L<SSL_CTX_add_extra_chain_cert(3)>
Packit c4476c
Packit c4476c
=head1 HISTORY
Packit c4476c
Packit c4476c
These functions were added in OpenSSL 1.0.2.
Packit c4476c
Packit c4476c
=head1 COPYRIGHT
Packit c4476c
Packit c4476c
Copyright 2013-2016 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
Packit c4476c
Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
this file except in compliance with the License.  You can obtain a copy
Packit c4476c
in the file LICENSE in the source distribution or at
Packit c4476c
L<https://www.openssl.org/source/license.html>.
Packit c4476c
Packit c4476c
=cut