SSL_CTX_load_verify_locations.pod 6.5 KB

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