5 SSL_CTX_load_verify_locations - set default locations for trusted CA
10 #include <openssl/ssl.h>
12 int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
15 int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
17 int SSL_CTX_set_default_verify_dir(SSL_CTX *ctx);
19 int SSL_CTX_set_default_verify_file(SSL_CTX *ctx);
23 SSL_CTX_load_verify_locations() specifies the locations for B<ctx>, at
24 which CA certificates for verification purposes are located. The certificates
25 available via B<CAfile> and B<CApath> are trusted.
27 SSL_CTX_set_default_verify_paths() specifies that the default locations for
28 which CA certificates are loaded should be used. There is one default directory
31 SSL_CTX_set_default_verify_dir() is similar to
32 SSL_CTX_set_default_verify_paths() except that just the default directory is
35 SSL_CTX_set_default_verify_file() is similar to
36 SSL_CTX_set_default_verify_paths() except that just the default file is
41 If B<CAfile> is not NULL, it points to a file of CA certificates in PEM
42 format. The file can contain several CA certificates identified by
44 -----BEGIN CERTIFICATE-----
45 ... (CA certificate in base64 encoding) ...
46 -----END CERTIFICATE-----
48 sequences. Before, between, and after the certificates text is allowed
49 which can be used e.g. for descriptions of the certificates.
51 The B<CAfile> is processed on execution of the SSL_CTX_load_verify_locations()
54 If B<CApath> is not NULL, it points to a directory containing CA certificates
55 in PEM format. The files each contain one CA certificate. The files are
56 looked up by the CA subject name hash value, which must hence be available.
57 If more than one CA certificate with the same name hash value exist, the
58 extension must be different (e.g. 9d66eef0.0, 9d66eef0.1 etc). The search
59 is performed in the ordering of the extension number, regardless of other
60 properties of the certificates.
61 Use the B<c_rehash> utility to create the necessary links.
63 The certificates in B<CApath> are only looked up when required, e.g. when
64 building the certificate chain or when actually performing the verification
65 of a peer certificate.
67 When looking up CA certificates, the OpenSSL library will first search the
68 certificates in B<CAfile>, then those in B<CApath>. Certificate matching
69 is done based on the subject name, the key identifier (if present), and the
70 serial number as taken from the certificate to be verified. If these data
71 do not match, the next certificate will be tried. If a first certificate
72 matching the parameters is found, the verification process will be performed;
73 no other certificates for the same parameters will be searched in case of
76 In server mode, when requesting a client certificate, the server must send
77 the list of CAs of which it will accept client certificates. This list
78 is not influenced by the contents of B<CAfile> or B<CApath> and must
79 explicitly be set using the
80 L<SSL_CTX_set_client_CA_list(3)>
83 When building its own certificate chain, an OpenSSL client/server will
84 try to fill in missing certificates from B<CAfile>/B<CApath>, if the
85 certificate chain was not explicitly specified (see
86 L<SSL_CTX_add_extra_chain_cert(3)>,
87 L<SSL_CTX_use_certificate(3)>.
91 If several CA certificates matching the name, key identifier, and serial
92 number condition are available, only the first one will be examined. This
93 may lead to unexpected results if the same CA certificate is available
94 with different expiration dates. If a "certificate expired" verification
95 error occurs, no other certificate will be searched. Make sure to not
96 have expired certificates mixed with valid ones.
100 Generate a CA certificate file with descriptive text from the CA certificates
101 ca1.pem ca2.pem ca3.pem:
105 for i in ca1.pem ca2.pem ca3.pem ; do
106 openssl x509 -in $i -text >> CAfile.pem
109 Prepare the directory /some/where/certs containing several CA certificates
110 for use as B<CApath>:
117 For SSL_CTX_load_verify_locations the following return values can occur:
123 The operation failed because B<CAfile> and B<CApath> are NULL or the
124 processing at one of the locations specified failed. Check the error
125 stack to find out the reason.
129 The operation succeeded.
133 SSL_CTX_set_default_verify_paths(), SSL_CTX_set_default_verify_dir() and
134 SSL_CTX_set_default_verify_file() all return 1 on success or 0 on failure. A
135 missing default location is still treated as a success.
140 L<SSL_CTX_set_client_CA_list(3)>,
141 L<SSL_get_client_CA_list(3)>,
142 L<SSL_CTX_use_certificate(3)>,
143 L<SSL_CTX_add_extra_chain_cert(3)>,
144 L<SSL_CTX_set_cert_store(3)>,
145 L<SSL_CTX_set_client_CA_list(3)>