1*74cecf6cSschwarze.\" $OpenBSD: SSL_CTX_load_verify_locations.3,v 1.2 2016/11/30 14:16:38 schwarze Exp $ 2*74cecf6cSschwarze.\" OpenSSL 9b86974e Aug 17 15:21:33 2015 -0400 3f1a3c524Sschwarze.\" 4*74cecf6cSschwarze.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>. 5*74cecf6cSschwarze.\" Copyright (c) 2000, 2001, 2015, 2016 The OpenSSL Project. 6*74cecf6cSschwarze.\" All rights reserved. 7f1a3c524Sschwarze.\" 8*74cecf6cSschwarze.\" Redistribution and use in source and binary forms, with or without 9*74cecf6cSschwarze.\" modification, are permitted provided that the following conditions 10*74cecf6cSschwarze.\" are met: 11*74cecf6cSschwarze.\" 12*74cecf6cSschwarze.\" 1. Redistributions of source code must retain the above copyright 13*74cecf6cSschwarze.\" notice, this list of conditions and the following disclaimer. 14*74cecf6cSschwarze.\" 15*74cecf6cSschwarze.\" 2. Redistributions in binary form must reproduce the above copyright 16*74cecf6cSschwarze.\" notice, this list of conditions and the following disclaimer in 17*74cecf6cSschwarze.\" the documentation and/or other materials provided with the 18*74cecf6cSschwarze.\" distribution. 19*74cecf6cSschwarze.\" 20*74cecf6cSschwarze.\" 3. All advertising materials mentioning features or use of this 21*74cecf6cSschwarze.\" software must display the following acknowledgment: 22*74cecf6cSschwarze.\" "This product includes software developed by the OpenSSL Project 23*74cecf6cSschwarze.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 24*74cecf6cSschwarze.\" 25*74cecf6cSschwarze.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26*74cecf6cSschwarze.\" endorse or promote products derived from this software without 27*74cecf6cSschwarze.\" prior written permission. For written permission, please contact 28*74cecf6cSschwarze.\" openssl-core@openssl.org. 29*74cecf6cSschwarze.\" 30*74cecf6cSschwarze.\" 5. Products derived from this software may not be called "OpenSSL" 31*74cecf6cSschwarze.\" nor may "OpenSSL" appear in their names without prior written 32*74cecf6cSschwarze.\" permission of the OpenSSL Project. 33*74cecf6cSschwarze.\" 34*74cecf6cSschwarze.\" 6. Redistributions of any form whatsoever must retain the following 35*74cecf6cSschwarze.\" acknowledgment: 36*74cecf6cSschwarze.\" "This product includes software developed by the OpenSSL Project 37*74cecf6cSschwarze.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 38*74cecf6cSschwarze.\" 39*74cecf6cSschwarze.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 40*74cecf6cSschwarze.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41*74cecf6cSschwarze.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42*74cecf6cSschwarze.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 43*74cecf6cSschwarze.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44*74cecf6cSschwarze.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45*74cecf6cSschwarze.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 46*74cecf6cSschwarze.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47*74cecf6cSschwarze.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 48*74cecf6cSschwarze.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49*74cecf6cSschwarze.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50*74cecf6cSschwarze.\" OF THE POSSIBILITY OF SUCH DAMAGE. 51*74cecf6cSschwarze.\" 52*74cecf6cSschwarze.Dd $Mdocdate: November 30 2016 $ 53f1a3c524Sschwarze.Dt SSL_CTX_LOAD_VERIFY_LOCATIONS 3 54f1a3c524Sschwarze.Os 55f1a3c524Sschwarze.Sh NAME 56*74cecf6cSschwarze.Nm SSL_CTX_load_verify_locations , 57*74cecf6cSschwarze.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 65*74cecf6cSschwarze.Ft int 66*74cecf6cSschwarze.Fo SSL_CTX_set_default_verify_paths 67*74cecf6cSschwarze.Fa "SSL_CTX *ctx" 68*74cecf6cSschwarze.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. 79*74cecf6cSschwarze.Pp 80*74cecf6cSschwarze.Fn SSL_CTX_set_default_verify_paths 81*74cecf6cSschwarzespecifies that the default locations from which CA certificates are 82*74cecf6cSschwarzeloaded should be used. 83*74cecf6cSschwarzeThere is one default directory and one default file. 84*74cecf6cSschwarzeThe default CA certificates directory is called 85*74cecf6cSschwarze.Pa certs 86*74cecf6cSschwarzein the default OpenSSL directory. 87*74cecf6cSschwarzeThe default CA certificates file is called 88*74cecf6cSschwarze.Pa cert.pem 89*74cecf6cSschwarzein the default OpenSSL directory. 90*74cecf6cSschwarze.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 102*74cecf6cSschwarze.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 163*74cecf6cSschwarzeFor 164*74cecf6cSschwarze.Fn SSL_CTX_load_verify_locations , 165*74cecf6cSschwarzethe 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 179*74cecf6cSschwarze.Pp 180*74cecf6cSschwarze.Fn SSL_CTX_set_default_verify_paths 181*74cecf6cSschwarzereturns 1 on success or 0 on failure. 182*74cecf6cSschwarzeA 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 224*74cecf6cSschwarze.Sh CAVEATS 225*74cecf6cSschwarzeIf several CA certificates matching the name, key identifier, and serial 226*74cecf6cSschwarzenumber condition are available, only the first one will be examined. 227*74cecf6cSschwarzeThis may lead to unexpected results if the same CA certificate is available 228*74cecf6cSschwarzewith different expiration dates. 229*74cecf6cSschwarzeIf a 230*74cecf6cSschwarze.Dq certificate expired 231*74cecf6cSschwarzeverification error occurs, no other certificate will be searched. 232*74cecf6cSschwarzeMake sure to not have expired certificates mixed with valid ones. 233