SSL_CTX_load_verify_locations.pod 6.4 KB

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