1*10e00d17Sschwarze.\" $OpenBSD: SSL_CTX_load_verify_locations.3,v 1.4 2018/03/27 17:35:50 schwarze Exp $ 274cecf6cSschwarze.\" OpenSSL 9b86974e Aug 17 15:21:33 2015 -0400 3f1a3c524Sschwarze.\" 474cecf6cSschwarze.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>. 574cecf6cSschwarze.\" Copyright (c) 2000, 2001, 2015, 2016 The OpenSSL Project. 674cecf6cSschwarze.\" All rights reserved. 7f1a3c524Sschwarze.\" 874cecf6cSschwarze.\" Redistribution and use in source and binary forms, with or without 974cecf6cSschwarze.\" modification, are permitted provided that the following conditions 1074cecf6cSschwarze.\" are met: 1174cecf6cSschwarze.\" 1274cecf6cSschwarze.\" 1. Redistributions of source code must retain the above copyright 1374cecf6cSschwarze.\" notice, this list of conditions and the following disclaimer. 1474cecf6cSschwarze.\" 1574cecf6cSschwarze.\" 2. Redistributions in binary form must reproduce the above copyright 1674cecf6cSschwarze.\" notice, this list of conditions and the following disclaimer in 1774cecf6cSschwarze.\" the documentation and/or other materials provided with the 1874cecf6cSschwarze.\" distribution. 1974cecf6cSschwarze.\" 2074cecf6cSschwarze.\" 3. All advertising materials mentioning features or use of this 2174cecf6cSschwarze.\" software must display the following acknowledgment: 2274cecf6cSschwarze.\" "This product includes software developed by the OpenSSL Project 2374cecf6cSschwarze.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 2474cecf6cSschwarze.\" 2574cecf6cSschwarze.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 2674cecf6cSschwarze.\" endorse or promote products derived from this software without 2774cecf6cSschwarze.\" prior written permission. For written permission, please contact 2874cecf6cSschwarze.\" openssl-core@openssl.org. 2974cecf6cSschwarze.\" 3074cecf6cSschwarze.\" 5. Products derived from this software may not be called "OpenSSL" 3174cecf6cSschwarze.\" nor may "OpenSSL" appear in their names without prior written 3274cecf6cSschwarze.\" permission of the OpenSSL Project. 3374cecf6cSschwarze.\" 3474cecf6cSschwarze.\" 6. Redistributions of any form whatsoever must retain the following 3574cecf6cSschwarze.\" acknowledgment: 3674cecf6cSschwarze.\" "This product includes software developed by the OpenSSL Project 3774cecf6cSschwarze.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 3874cecf6cSschwarze.\" 3974cecf6cSschwarze.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 4074cecf6cSschwarze.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4174cecf6cSschwarze.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 4274cecf6cSschwarze.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 4374cecf6cSschwarze.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4474cecf6cSschwarze.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 4574cecf6cSschwarze.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 4674cecf6cSschwarze.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4774cecf6cSschwarze.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 4874cecf6cSschwarze.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 4974cecf6cSschwarze.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 5074cecf6cSschwarze.\" OF THE POSSIBILITY OF SUCH DAMAGE. 5174cecf6cSschwarze.\" 52*10e00d17Sschwarze.Dd $Mdocdate: March 27 2018 $ 53f1a3c524Sschwarze.Dt SSL_CTX_LOAD_VERIFY_LOCATIONS 3 54f1a3c524Sschwarze.Os 55f1a3c524Sschwarze.Sh NAME 5674cecf6cSschwarze.Nm SSL_CTX_load_verify_locations , 5774cecf6cSschwarze.Nm SSL_CTX_set_default_verify_paths 58f1a3c524Sschwarze.Nd set default locations for trusted CA certificates 59f1a3c524Sschwarze.Sh SYNOPSIS 60f1a3c524Sschwarze.In openssl/ssl.h 61f1a3c524Sschwarze.Ft int 62f1a3c524Sschwarze.Fo SSL_CTX_load_verify_locations 63f1a3c524Sschwarze.Fa "SSL_CTX *ctx" "const char *CAfile" "const char *CApath" 64f1a3c524Sschwarze.Fc 6574cecf6cSschwarze.Ft int 6674cecf6cSschwarze.Fo SSL_CTX_set_default_verify_paths 6774cecf6cSschwarze.Fa "SSL_CTX *ctx" 6874cecf6cSschwarze.Fc 69f1a3c524Sschwarze.Sh DESCRIPTION 70f1a3c524Sschwarze.Fn SSL_CTX_load_verify_locations 71f1a3c524Sschwarzespecifies the locations for 72f1a3c524Sschwarze.Fa ctx , 73f1a3c524Sschwarzeat which CA certificates for verification purposes are located. 74f1a3c524SschwarzeThe certificates available via 75f1a3c524Sschwarze.Fa CAfile 76f1a3c524Sschwarzeand 77f1a3c524Sschwarze.Fa CApath 78f1a3c524Sschwarzeare trusted. 7974cecf6cSschwarze.Pp 8074cecf6cSschwarze.Fn SSL_CTX_set_default_verify_paths 8174cecf6cSschwarzespecifies that the default locations from which CA certificates are 8274cecf6cSschwarzeloaded should be used. 8374cecf6cSschwarzeThere is one default directory and one default file. 8474cecf6cSschwarzeThe default CA certificates directory is called 8574cecf6cSschwarze.Pa certs 8674cecf6cSschwarzein the default OpenSSL directory. 8774cecf6cSschwarzeThe default CA certificates file is called 8874cecf6cSschwarze.Pa cert.pem 8974cecf6cSschwarzein the default OpenSSL directory. 9074cecf6cSschwarze.Pp 91f1a3c524SschwarzeIf 92f1a3c524Sschwarze.Fa CAfile 93f1a3c524Sschwarzeis not 94f1a3c524Sschwarze.Dv NULL , 95f1a3c524Sschwarzeit points to a file of CA certificates in PEM format. 96f1a3c524SschwarzeThe file can contain several CA certificates identified by sequences of: 97f1a3c524Sschwarze.Bd -literal 98f1a3c524Sschwarze -----BEGIN CERTIFICATE----- 99f1a3c524Sschwarze ... (CA certificate in base64 encoding) ... 100f1a3c524Sschwarze -----END CERTIFICATE----- 101f1a3c524Sschwarze.Ed 10274cecf6cSschwarze.Pp 103f1a3c524SschwarzeBefore, between, and after the certificates arbitrary text is allowed which can 104f1a3c524Sschwarzebe used, e.g., for descriptions of the certificates. 105f1a3c524Sschwarze.Pp 106f1a3c524SschwarzeThe 107f1a3c524Sschwarze.Fa CAfile 108f1a3c524Sschwarzeis processed on execution of the 109f1a3c524Sschwarze.Fn SSL_CTX_load_verify_locations 110f1a3c524Sschwarzefunction. 111f1a3c524Sschwarze.Pp 112f1a3c524SschwarzeIf 113f1a3c524Sschwarze.Fa CApath 114f1a3c524Sschwarzeis not NULL, it points to a directory containing CA certificates in PEM format. 115f1a3c524SschwarzeThe files each contain one CA certificate. 116f1a3c524SschwarzeThe files are looked up by the CA subject name hash value, 117f1a3c524Sschwarzewhich must hence be available. 118f1a3c524SschwarzeIf more than one CA certificate with the same name hash value exist, 119f1a3c524Sschwarzethe extension must be different (e.g., 120f1a3c524Sschwarze.Pa 9d66eef0.0 , 121f1a3c524Sschwarze.Pa 9d66eef0.1 , 122f1a3c524Sschwarzeetc.). 123f1a3c524SschwarzeThe search is performed in the ordering of the extension number, 124f1a3c524Sschwarzeregardless of other properties of the certificates. 125f1a3c524Sschwarze.Pp 126f1a3c524SschwarzeThe certificates in 127f1a3c524Sschwarze.Fa CApath 128f1a3c524Sschwarzeare only looked up when required, e.g., when building the certificate chain or 129f1a3c524Sschwarzewhen actually performing the verification of a peer certificate. 130f1a3c524Sschwarze.Pp 131f1a3c524SschwarzeWhen looking up CA certificates, the OpenSSL library will first search the 132f1a3c524Sschwarzecertificates in 133f1a3c524Sschwarze.Fa CAfile , 134f1a3c524Sschwarzethen those in 135f1a3c524Sschwarze.Fa CApath . 136f1a3c524SschwarzeCertificate matching is done based on the subject name, the key identifier (if 137f1a3c524Sschwarzepresent), and the serial number as taken from the certificate to be verified. 138f1a3c524SschwarzeIf these data do not match, the next certificate will be tried. 139f1a3c524SschwarzeIf a first certificate matching the parameters is found, 140f1a3c524Sschwarzethe verification process will be performed; 141f1a3c524Sschwarzeno other certificates for the same parameters will be searched in case of 142f1a3c524Sschwarzefailure. 143f1a3c524Sschwarze.Pp 144f1a3c524SschwarzeIn server mode, when requesting a client certificate, the server must send 145f1a3c524Sschwarzethe list of CAs of which it will accept client certificates. 146f1a3c524SschwarzeThis list is not influenced by the contents of 147f1a3c524Sschwarze.Fa CAfile 148f1a3c524Sschwarzeor 149f1a3c524Sschwarze.Fa CApath 150f1a3c524Sschwarzeand must explicitly be set using the 151f1a3c524Sschwarze.Xr SSL_CTX_set_client_CA_list 3 152f1a3c524Sschwarzefamily of functions. 153f1a3c524Sschwarze.Pp 154f1a3c524SschwarzeWhen building its own certificate chain, an OpenSSL client/server will try to 155f1a3c524Sschwarzefill in missing certificates from 156f1a3c524Sschwarze.Fa CAfile Ns / Fa CApath , 157f1a3c524Sschwarzeif the 158f1a3c524Sschwarzecertificate chain was not explicitly specified (see 159f1a3c524Sschwarze.Xr SSL_CTX_add_extra_chain_cert 3 160f1a3c524Sschwarzeand 161f1a3c524Sschwarze.Xr SSL_CTX_use_certificate 3 ) . 162f1a3c524Sschwarze.Sh RETURN VALUES 16374cecf6cSschwarzeFor 16474cecf6cSschwarze.Fn SSL_CTX_load_verify_locations , 16574cecf6cSschwarzethe following return values can occur: 166f1a3c524Sschwarze.Bl -tag -width Ds 167f1a3c524Sschwarze.It 0 168f1a3c524SschwarzeThe operation failed because 169f1a3c524Sschwarze.Fa CAfile 170f1a3c524Sschwarzeand 171f1a3c524Sschwarze.Fa CApath 172f1a3c524Sschwarzeare 173f1a3c524Sschwarze.Dv NULL 174f1a3c524Sschwarzeor the processing at one of the locations specified failed. 175f1a3c524SschwarzeCheck the error stack to find out the reason. 176f1a3c524Sschwarze.It 1 177f1a3c524SschwarzeThe operation succeeded. 178f1a3c524Sschwarze.El 17974cecf6cSschwarze.Pp 18074cecf6cSschwarze.Fn SSL_CTX_set_default_verify_paths 18174cecf6cSschwarzereturns 1 on success or 0 on failure. 18274cecf6cSschwarzeA missing default location is still treated as a success. 183f1a3c524Sschwarze.Sh EXAMPLES 184f1a3c524SschwarzeGenerate a CA certificate file with descriptive text from the CA certificates 185f1a3c524Sschwarze.Pa ca1.pem 186f1a3c524Sschwarze.Pa ca2.pem 187f1a3c524Sschwarze.Pa ca3.pem : 188f1a3c524Sschwarze.Bd -literal 189f1a3c524Sschwarze#!/bin/sh 190f1a3c524Sschwarzerm CAfile.pem 191f1a3c524Sschwarzefor i in ca1.pem ca2.pem ca3.pem; do 192f1a3c524Sschwarze openssl x509 -in $i -text >> CAfile.pem 193f1a3c524Sschwarzedone 194f1a3c524Sschwarze.Ed 195f1a3c524Sschwarze.Pp 196f1a3c524SschwarzePrepare the directory /some/where/certs containing several CA certificates 197f1a3c524Sschwarzefor use as 198f1a3c524Sschwarze.Fa CApath : 199f1a3c524Sschwarze.Bd -literal 200f1a3c524Sschwarze$ cd /some/where/certs 201f1a3c524Sschwarze$ rm -f *.[0-9]* *.r[0-9]* 202f1a3c524Sschwarze$ for c in *.pem; do 203f1a3c524Sschwarze> [ "$c" = "*.pem" ] && continue 204f1a3c524Sschwarze> hash=$(openssl x509 -noout -hash -in "$c") 205f1a3c524Sschwarze> if egrep -q -- '-BEGIN( X509 | TRUSTED | )CERTIFICATE-' "$c"; then 206f1a3c524Sschwarze> suf=0 207f1a3c524Sschwarze> while [ -e $hash.$suf ]; do suf=$(( $suf + 1 )); done 208f1a3c524Sschwarze> ln -s "$c" $hash.$suf 209f1a3c524Sschwarze> fi 210f1a3c524Sschwarze> if egrep -q -- '-BEGIN X509 CRL-' "$c"; then 211f1a3c524Sschwarze> suf=0 212f1a3c524Sschwarze> while [ -e $hash.r$suf ]; do suf=$(( $suf + 1 )); done 213f1a3c524Sschwarze> ln -s "$c" $hash.r$suf 214f1a3c524Sschwarze> fi 215f1a3c524Sschwarze> done 216f1a3c524Sschwarze.Ed 217f1a3c524Sschwarze.Sh SEE ALSO 218f1a3c524Sschwarze.Xr ssl 3 , 219f1a3c524Sschwarze.Xr SSL_CTX_add_extra_chain_cert 3 , 220f1a3c524Sschwarze.Xr SSL_CTX_set_cert_store 3 , 221f1a3c524Sschwarze.Xr SSL_CTX_set_client_CA_list 3 , 222f1a3c524Sschwarze.Xr SSL_CTX_use_certificate 3 , 223f1a3c524Sschwarze.Xr SSL_get_client_CA_list 3 2248fba1ec8Sschwarze.Sh HISTORY 2258fba1ec8Sschwarze.Fn SSL_CTX_load_verify_locations 2268fba1ec8Sschwarzeand 2278fba1ec8Sschwarze.Fn SSL_CTX_set_default_verify_paths 228*10e00d17Sschwarzefirst appeared in SSLeay 0.8.0 and have been available since 2298fba1ec8Sschwarze.Ox 2.4 . 23074cecf6cSschwarze.Sh CAVEATS 23174cecf6cSschwarzeIf several CA certificates matching the name, key identifier, and serial 23274cecf6cSschwarzenumber condition are available, only the first one will be examined. 23374cecf6cSschwarzeThis may lead to unexpected results if the same CA certificate is available 23474cecf6cSschwarzewith different expiration dates. 23574cecf6cSschwarzeIf a 23674cecf6cSschwarze.Dq certificate expired 23774cecf6cSschwarzeverification error occurs, no other certificate will be searched. 23874cecf6cSschwarzeMake sure to not have expired certificates mixed with valid ones. 239