
#use wml::openssl-macros area=docs page=SSL_CTX_load_verify_locations

<title>Documents, SSL_CTX_load_verify_locations(3)</title>

<h1>SSL_CTX_load_verify_locations(3)</h1>

#use wml::imp::generic

{:
## What's this? [[s|(<STRONG>[^<].+?)</A>(</STRONG><DD>)|$1$2|sg]]
[[s|<P>\s+<P>|<P>|sg]]
[[s|<P>\s+</|</|sg]]
[[s|<DD>\s*<DT>|<DD>&nbsp;<DT>|sg]]
[[s|<DD>\s*</DL>|<DD>&nbsp;</DL>|sg]]
[[s|\[|&#91;|sg]]
[[s|\]|&#93;|sg]]

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<LI><A HREF="#NOTES">NOTES</A>
	<LI><A HREF="#WARNINGS">WARNINGS</A>
	<LI><A HREF="#EXAMPLES">EXAMPLES</A>
	<LI><A HREF="#RETURN_VALUES">RETURN VALUES</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
SSL_CTX_load_verify_locations - set default locations for trusted CA
certificates

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/ssl.h&gt;
</PRE>
<PRE> int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
                                   const char *CApath);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>SSL_CTX_load_verify_locations()</CODE> specifies the locations for <STRONG>ctx</STRONG>, at which CA certificates for verification purposes are located. The
certificates available via <STRONG>CAfile</STRONG> and <STRONG>CApath</STRONG> are trusted.

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
If <STRONG>CAfile</STRONG> is not NULL, it points to a file of CA certificates in PEM format. The file
can contain several CA certificates identified by

</P>
<PRE> -----BEGIN CERTIFICATE-----
 ... (CA certificate in base64 encoding) ...
 -----END CERTIFICATE-----
</PRE>
<P>
sequences. Before, between, and after the certificates text is allowed
which can be used e.g. for descriptions of the certificates.

</P>
<P>
The <STRONG>CAfile</STRONG> is processed on execution of the
<CODE>SSL_CTX_load_verify_locations()</CODE> function.

</P>
<P>
If <STRONG>CApath</STRONG> is not NULL, it points to a directory containing CA certificates in PEM
format. The files each contain one CA certificate. The files are looked up
by the CA subject name hash value, which must hence be available. If more
than one CA certificate with the same name hash value exist, the extension
must be different (e.g. 9d66eef0.0, 9d66eef0.1 etc). The search is
performed in the ordering of the extension number, regardless of other
properties of the certificates. Use the <STRONG>c_rehash</STRONG> utility to create the necessary links.

</P>
<P>
The certificates in <STRONG>CApath</STRONG> are only looked up when required, e.g. when building the certificate chain
or when actually performing the verification of a peer certificate.

</P>
<P>
When looking up CA certificates, the OpenSSL library will first search the
certificates in <STRONG>CAfile</STRONG>, then those in <STRONG>CApath</STRONG>. Certificate matching is done based on the subject name, the key
identifier (if present), and the serial number as taken from the
certificate to be verified. If these data do not match, the next
certificate will be tried. If a first certificate matching the parameters
is found, the verification process will be performed; no other certificates
for the same parameters will be searched in case of failure.

</P>
<P>
In server mode, when requesting a client certificate, the server must send
the list of CAs of which it will accept client certificates. This list is
not influenced by the contents of <STRONG>CAfile</STRONG> or <STRONG>CApath</STRONG> and must explicitly be set using the
<A HREF="../ssl/SSL_CTX_set_client_CA_list.html#">SSL_CTX_set_client_CA_list(3)</A>
family of functions.

</P>
<P>
When building its own certificate chain, an OpenSSL client/server will try
to fill in missing certificates from <STRONG>CAfile</STRONG>/<STRONG>CApath</STRONG>, if the certificate chain was not explicitly specified (see
<A HREF="../ssl/SSL_CTX_add_extra_chain_cert.html#">SSL_CTX_add_extra_chain_cert(3)</A>,
<A HREF="../ssl/SSL_CTX_use_certificate.html#">SSL_CTX_use_certificate(3)</A>.

</P>
<P>
<HR>
<H1><A NAME="WARNINGS">WARNINGS</A></H1>
<P>
If several CA certificates matching the name, key identifier, and serial
number condition are available, only the first one will be examined. This
may lead to unexpected results if the same CA certificate is available with
different expiration dates. If a ``certificate expired'' verification error
occurs, no other certificate will be searched. Make sure to not have
expired certificates mixed with valid ones.

</P>
<P>
<HR>
<H1><A NAME="EXAMPLES">EXAMPLES</A></H1>
<P>
Generate a CA certificate file with descriptive text from the CA
certificates ca1.pem ca2.pem ca3.pem:

</P>
<PRE> #!/bin/sh
 rm CAfile.pem
 for i in ca1.pem ca2.pem ca3.pem ; do
   openssl x509 -in $i -text &gt;&gt; CAfile.pem
 done
</PRE>
<P>
Prepare the directory /some/where/certs containing several CA certificates
for use as <STRONG>CApath</STRONG>:

</P>
<PRE> cd /some/where/certs
 c_rehash .
</PRE>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
The following return values can occur:

</P>
<DL>
<DT><STRONG><A NAME="item_0">0</A></STRONG><DD>
<P>
The operation failed because <STRONG>CAfile</STRONG> and <STRONG>CApath</STRONG> are NULL or the processing at one of the locations specified failed. Check
the error stack to find out the reason.

</P>
<DT><STRONG><A NAME="item_1">1</A></STRONG><DD>
<P>
The operation succeeded.

</P>
</DL>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<A HREF="../ssl/ssl.html#">ssl(3)</A>,
<A HREF="../ssl/SSL_CTX_set_client_CA_list.html#">SSL_CTX_set_client_CA_list(3)</A>,
<A HREF="../ssl/SSL_get_client_CA_list.html#">SSL_get_client_CA_list(3)</A>,
<A HREF="../ssl/SSL_CTX_use_certificate.html#">SSL_CTX_use_certificate(3)</A>,
<A HREF="../ssl/SSL_CTX_add_extra_chain_cert.html#">SSL_CTX_add_extra_chain_cert(3)</A>,
<A HREF="../ssl/SSL_CTX_set_cert_store.html#">SSL_CTX_set_cert_store(3)</A>



</P>
:}

