SSL_CTX_load_verify_locations.pod 5.6 KB

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