SSL_CTX_load_verify_locations.pod 6.6 KB

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