5 SSL_CTX_load_verify_dir, SSL_CTX_load_verify_file,
6 SSL_CTX_load_verify_store, SSL_CTX_set_default_verify_paths,
7 SSL_CTX_set_default_verify_dir, SSL_CTX_set_default_verify_file,
8 SSL_CTX_set_default_verify_store, SSL_CTX_load_verify_locations
9 - set default locations for trusted CA certificates
13 #include <openssl/ssl.h>
15 int SSL_CTX_load_verify_dir(SSL_CTX *ctx, const char *CApath);
16 int SSL_CTX_load_verify_file(SSL_CTX *ctx, const char *CAfile);
17 int SSL_CTX_load_verify_store(SSL_CTX *ctx, const char *CAstore);
19 int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
21 int SSL_CTX_set_default_verify_dir(SSL_CTX *ctx);
22 int SSL_CTX_set_default_verify_file(SSL_CTX *ctx);
23 int SSL_CTX_set_default_verify_store(SSL_CTX *ctx);
25 Deprecated since OpenSSL 3.0, can be hidden entirely by defining
26 B<OPENSSL_API_COMPAT> with a suitable version value, see
27 L<openssl_user_macros(7)>:
29 int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
34 SSL_CTX_load_verify_dir(), SSL_CTX_load_verify_file(),
35 SSL_CTX_load_verify_store() specifies the locations for B<ctx>, at
36 which CA certificates for verification purposes are located. The
37 certificates available via B<CAfile>, B<CApath> and B<CAstore> are
40 SSL_CTX_set_default_verify_paths() specifies that the default locations from
41 which CA certificates are loaded should be used. There is one default directory,
42 one default file and one default store.
43 The default CA certificates directory is called F<certs> in the default OpenSSL
44 directory, and this is also the default store.
45 Alternatively the B<SSL_CERT_DIR> environment variable can be defined to
46 override this location.
47 The default CA certificates file is called F<cert.pem> in the default
49 Alternatively the B<SSL_CERT_FILE> environment variable can be defined to
50 override this location.
52 SSL_CTX_set_default_verify_dir() is similar to
53 SSL_CTX_set_default_verify_paths() except that just the default directory is
56 SSL_CTX_set_default_verify_file() is similar to
57 SSL_CTX_set_default_verify_paths() except that just the default file is
60 SSL_CTX_set_default_verify_store() is similar to
61 SSL_CTX_set_default_verify_paths() except that just the default store is
66 If B<CAfile> is not NULL, it points to a file of CA certificates in PEM
67 format. The file can contain several CA certificates identified by
69 -----BEGIN CERTIFICATE-----
70 ... (CA certificate in base64 encoding) ...
71 -----END CERTIFICATE-----
73 sequences. Before, between, and after the certificates text is allowed
74 which can be used e.g. for descriptions of the certificates.
76 The B<CAfile> is processed on execution of the SSL_CTX_load_verify_locations()
79 If B<CApath> is not NULL, it points to a directory containing CA certificates
80 in PEM format. The files each contain one CA certificate. The files are
81 looked up by the CA subject name hash value, which must hence be available.
82 If more than one CA certificate with the same name hash value exist, the
83 extension must be different (e.g. 9d66eef0.0, 9d66eef0.1 etc). The search
84 is performed in the ordering of the extension number, regardless of other
85 properties of the certificates.
86 Use the B<c_rehash> utility to create the necessary links.
88 The certificates in B<CApath> are only looked up when required, e.g. when
89 building the certificate chain or when actually performing the verification
90 of a peer certificate.
92 When looking up CA certificates, the OpenSSL library will first search the
93 certificates in B<CAfile>, then those in B<CApath>. Certificate matching
94 is done based on the subject name, the key identifier (if present), and the
95 serial number as taken from the certificate to be verified. If these data
96 do not match, the next certificate will be tried. If a first certificate
97 matching the parameters is found, the verification process will be performed;
98 no other certificates for the same parameters will be searched in case of
101 If B<CAstore> is not NULL, it's a URI for to a store, which may
102 represent a single container or a whole catalogue of containers.
103 Apart from the B<CAstore> not necessarily being a local file or
104 directory, it's generally treated the same way as a B<CApath>.
106 In server mode, when requesting a client certificate, the server must send
107 the list of CAs of which it will accept client certificates. This list
108 is not influenced by the contents of B<CAfile> or B<CApath> and must
109 explicitly be set using the
110 L<SSL_CTX_set_client_CA_list(3)>
113 When building its own certificate chain, an OpenSSL client/server will
114 try to fill in missing certificates from B<CAfile>/B<CApath>, if the
115 certificate chain was not explicitly specified (see
116 L<SSL_CTX_add_extra_chain_cert(3)>,
117 L<SSL_CTX_use_certificate(3)>.
121 If several CA certificates matching the name, key identifier, and serial
122 number condition are available, only the first one will be examined. This
123 may lead to unexpected results if the same CA certificate is available
124 with different expiration dates. If a "certificate expired" verification
125 error occurs, no other certificate will be searched. Make sure to not
126 have expired certificates mixed with valid ones.
130 For SSL_CTX_load_verify_locations the following return values can occur:
136 The operation failed because B<CAfile> and B<CApath> are NULL or the
137 processing at one of the locations specified failed. Check the error
138 stack to find out the reason.
142 The operation succeeded.
146 SSL_CTX_set_default_verify_paths(), SSL_CTX_set_default_verify_dir() and
147 SSL_CTX_set_default_verify_file() all return 1 on success or 0 on failure. A
148 missing default location is still treated as a success.
152 Generate a CA certificate file with descriptive text from the CA certificates
153 ca1.pem ca2.pem ca3.pem:
157 for i in ca1.pem ca2.pem ca3.pem ; do
158 openssl x509 -in $i -text >> CAfile.pem
161 Prepare the directory /some/where/certs containing several CA certificates
162 for use as B<CApath>:
170 L<SSL_CTX_set_client_CA_list(3)>,
171 L<SSL_get_client_CA_list(3)>,
172 L<SSL_CTX_use_certificate(3)>,
173 L<SSL_CTX_add_extra_chain_cert(3)>,
174 L<SSL_CTX_set_cert_store(3)>,
175 L<SSL_CTX_set_client_CA_list(3)>
179 Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
181 Licensed under the Apache License 2.0 (the "License"). You may not use
182 this file except in compliance with the License. You can obtain a copy
183 in the file LICENSE in the source distribution or at
184 L<https://www.openssl.org/source/license.html>.