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