5 SSL_CTX_load_verify_locations, SSL_CTX_set_default_verify_paths,
6 SSL_CTX_set_default_verify_dir, SSL_CTX_set_default_verify_file - set
7 default locations for trusted CA certificates
11 #include <openssl/ssl.h>
13 int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
16 int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
18 int SSL_CTX_set_default_verify_dir(SSL_CTX *ctx);
20 int SSL_CTX_set_default_verify_file(SSL_CTX *ctx);
24 SSL_CTX_load_verify_locations() specifies the locations for B<ctx>, at
25 which CA certificates for verification purposes are located. The certificates
26 available via B<CAfile> and B<CApath> are trusted.
28 SSL_CTX_set_default_verify_paths() specifies that the default locations for
29 which CA certificates are loaded should be used. There is one default directory
32 SSL_CTX_set_default_verify_dir() is similar to
33 SSL_CTX_set_default_verify_paths() except that just the default directory is
36 SSL_CTX_set_default_verify_file() is similar to
37 SSL_CTX_set_default_verify_paths() except that just the default file is
42 If B<CAfile> is not NULL, it points to a file of CA certificates in PEM
43 format. The file can contain several CA certificates identified by
45 -----BEGIN CERTIFICATE-----
46 ... (CA certificate in base64 encoding) ...
47 -----END CERTIFICATE-----
49 sequences. Before, between, and after the certificates text is allowed
50 which can be used e.g. for descriptions of the certificates.
52 The B<CAfile> is processed on execution of the SSL_CTX_load_verify_locations()
55 If B<CApath> is not NULL, it points to a directory containing CA certificates
56 in PEM format. The files each contain one CA certificate. The files are
57 looked up by the CA subject name hash value, which must hence be available.
58 If more than one CA certificate with the same name hash value exist, the
59 extension must be different (e.g. 9d66eef0.0, 9d66eef0.1 etc). The search
60 is performed in the ordering of the extension number, regardless of other
61 properties of the certificates.
62 Use the B<c_rehash> utility to create the necessary links.
64 The certificates in B<CApath> are only looked up when required, e.g. when
65 building the certificate chain or when actually performing the verification
66 of a peer certificate.
68 When looking up CA certificates, the OpenSSL library will first search the
69 certificates in B<CAfile>, then those in B<CApath>. Certificate matching
70 is done based on the subject name, the key identifier (if present), and the
71 serial number as taken from the certificate to be verified. If these data
72 do not match, the next certificate will be tried. If a first certificate
73 matching the parameters is found, the verification process will be performed;
74 no other certificates for the same parameters will be searched in case of
77 In server mode, when requesting a client certificate, the server must send
78 the list of CAs of which it will accept client certificates. This list
79 is not influenced by the contents of B<CAfile> or B<CApath> and must
80 explicitly be set using the
81 L<SSL_CTX_set_client_CA_list(3)>
84 When building its own certificate chain, an OpenSSL client/server will
85 try to fill in missing certificates from B<CAfile>/B<CApath>, if the
86 certificate chain was not explicitly specified (see
87 L<SSL_CTX_add_extra_chain_cert(3)>,
88 L<SSL_CTX_use_certificate(3)>.
92 If several CA certificates matching the name, key identifier, and serial
93 number condition are available, only the first one will be examined. This
94 may lead to unexpected results if the same CA certificate is available
95 with different expiration dates. If a "certificate expired" verification
96 error occurs, no other certificate will be searched. Make sure to not
97 have expired certificates mixed with valid ones.
101 Generate a CA certificate file with descriptive text from the CA certificates
102 ca1.pem ca2.pem ca3.pem:
106 for i in ca1.pem ca2.pem ca3.pem ; do
107 openssl x509 -in $i -text >> CAfile.pem
110 Prepare the directory /some/where/certs containing several CA certificates
111 for use as B<CApath>:
118 For SSL_CTX_load_verify_locations the following return values can occur:
124 The operation failed because B<CAfile> and B<CApath> are NULL or the
125 processing at one of the locations specified failed. Check the error
126 stack to find out the reason.
130 The operation succeeded.
134 SSL_CTX_set_default_verify_paths(), SSL_CTX_set_default_verify_dir() and
135 SSL_CTX_set_default_verify_file() all return 1 on success or 0 on failure. A
136 missing default location is still treated as a success.
141 L<SSL_CTX_set_client_CA_list(3)>,
142 L<SSL_get_client_CA_list(3)>,
143 L<SSL_CTX_use_certificate(3)>,
144 L<SSL_CTX_add_extra_chain_cert(3)>,
145 L<SSL_CTX_set_cert_store(3)>,
146 L<SSL_CTX_set_client_CA_list(3)>
152 Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
154 Licensed under the OpenSSL license (the "License"). You may not use
155 this file except in compliance with the License. You can obtain a copy
156 in the file LICENSE in the source distribution or at
157 L<https://www.openssl.org/source/license.html>.