1SSL_CTX_LOAD_VERIFY_LOCATIONS(3) OpenSSL SSL_CTX_LOAD_VERIFY_LOCATIONS(3)
2
3
4
6 SSL_CTX_load_verify_locations, SSL_CTX_set_default_verify_paths,
7 SSL_CTX_set_default_verify_dir, SSL_CTX_set_default_verify_file - set
8 default locations for trusted CA certificates
9
11 #include <openssl/ssl.h>
12
13 int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
14 const char *CApath);
15
16 int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
17
18 int SSL_CTX_set_default_verify_dir(SSL_CTX *ctx);
19
20 int SSL_CTX_set_default_verify_file(SSL_CTX *ctx);
21
23 SSL_CTX_load_verify_locations() specifies the locations for ctx, at
24 which CA certificates for verification purposes are located. The
25 certificates available via CAfile and CApath are trusted.
26
27 SSL_CTX_set_default_verify_paths() specifies that the default locations
28 from which CA certificates are loaded should be used. There is one
29 default directory and one default file. The default CA certificates
30 directory is called "certs" in the default OpenSSL directory.
31 Alternatively the SSL_CERT_DIR environment variable can be defined to
32 override this location. The default CA certificates file is called
33 "cert.pem" in the default OpenSSL directory. Alternatively the
34 SSL_CERT_FILE environment variable can be defined to override this
35 location.
36
37 SSL_CTX_set_default_verify_dir() is similar to
38 SSL_CTX_set_default_verify_paths() except that just the default
39 directory is used.
40
41 SSL_CTX_set_default_verify_file() is similar to
42 SSL_CTX_set_default_verify_paths() except that just the default file is
43 used.
44
46 If CAfile is not NULL, it points to a file of CA certificates in PEM
47 format. The file can contain several CA certificates identified by
48
49 -----BEGIN CERTIFICATE-----
50 ... (CA certificate in base64 encoding) ...
51 -----END CERTIFICATE-----
52
53 sequences. Before, between, and after the certificates text is allowed
54 which can be used e.g. for descriptions of the certificates.
55
56 The CAfile is processed on execution of the
57 SSL_CTX_load_verify_locations() function.
58
59 If CApath is not NULL, it points to a directory containing CA
60 certificates in PEM format. The files each contain one CA certificate.
61 The files are looked up by the CA subject name hash value, which must
62 hence be available. If more than one CA certificate with the same name
63 hash value exist, the extension must be different (e.g. 9d66eef0.0,
64 9d66eef0.1 etc). The search is performed in the ordering of the
65 extension number, regardless of other properties of the certificates.
66 Use the c_rehash utility to create the necessary links.
67
68 The certificates in CApath are only looked up when required, e.g. when
69 building the certificate chain or when actually performing the
70 verification of a peer certificate.
71
72 When looking up CA certificates, the OpenSSL library will first search
73 the certificates in CAfile, then those in CApath. Certificate matching
74 is done based on the subject name, the key identifier (if present), and
75 the serial number as taken from the certificate to be verified. If
76 these data do not match, the next certificate will be tried. If a first
77 certificate matching the parameters is found, the verification process
78 will be performed; no other certificates for the same parameters will
79 be searched in case of failure.
80
81 In server mode, when requesting a client certificate, the server must
82 send the list of CAs of which it will accept client certificates. This
83 list is not influenced by the contents of CAfile or CApath and must
84 explicitly be set using the SSL_CTX_set_client_CA_list(3) family of
85 functions.
86
87 When building its own certificate chain, an OpenSSL client/server will
88 try to fill in missing certificates from CAfile/CApath, if the
89 certificate chain was not explicitly specified (see
90 SSL_CTX_add_extra_chain_cert(3), SSL_CTX_use_certificate(3).
91
93 If several CA certificates matching the name, key identifier, and
94 serial number condition are available, only the first one will be
95 examined. This may lead to unexpected results if the same CA
96 certificate is available with different expiration dates. If a
97 "certificate expired" verification error occurs, no other certificate
98 will be searched. Make sure to not have expired certificates mixed with
99 valid ones.
100
102 For SSL_CTX_load_verify_locations the following return values can
103 occur:
104
105 0 The operation failed because CAfile and CApath are NULL or the
106 processing at one of the locations specified failed. Check the
107 error stack to find out the reason.
108
109 1 The operation succeeded.
110
111 SSL_CTX_set_default_verify_paths(), SSL_CTX_set_default_verify_dir()
112 and SSL_CTX_set_default_verify_file() all return 1 on success or 0 on
113 failure. A missing default location is still treated as a success.
114
116 Generate a CA certificate file with descriptive text from the CA
117 certificates ca1.pem ca2.pem ca3.pem:
118
119 #!/bin/sh
120 rm CAfile.pem
121 for i in ca1.pem ca2.pem ca3.pem ; do
122 openssl x509 -in $i -text >> CAfile.pem
123 done
124
125 Prepare the directory /some/where/certs containing several CA
126 certificates for use as CApath:
127
128 cd /some/where/certs
129 c_rehash .
130
132 ssl(7), SSL_CTX_set_client_CA_list(3), SSL_get_client_CA_list(3),
133 SSL_CTX_use_certificate(3), SSL_CTX_add_extra_chain_cert(3),
134 SSL_CTX_set_cert_store(3), SSL_CTX_set_client_CA_list(3)
135
137 Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
138
139 Licensed under the OpenSSL license (the "License"). You may not use
140 this file except in compliance with the License. You can obtain a copy
141 in the file LICENSE in the source distribution or at
142 <https://www.openssl.org/source/license.html>.
143
144
145
1461.1.1q 2022-07-21 SSL_CTX_LOAD_VERIFY_LOCATIONS(3)