SSL_CTX_add1_chain_cert.pod 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. =pod
  2. =head1 NAME
  3. SSL_CTX_set0_chain, SSL_CTX_set1_chain, SSL_CTX_add0_chain_cert,
  4. SSL_CTX_add1_chain_cert, SSL_CTX_get0_chain_certs, SSL_CTX_clear_chain_certs,
  5. SSL_set0_chain, SSL_set1_chain, SSL_add0_chain_cert, SSL_add1_chain_cert,
  6. SSL_get0_chain_certs, SSL_clear_chain_certs, SSL_CTX_build_cert_chain,
  7. SSL_build_cert_chain, SSL_CTX_select_current_cert,
  8. SSL_select_current_cert, SSL_CTX_set_current_cert, SSL_set_current_cert - extra
  9. chain certificate processing
  10. =head1 SYNOPSIS
  11. #include <openssl/ssl.h>
  12. int SSL_CTX_set0_chain(SSL_CTX *ctx, STACK_OF(X509) *sk);
  13. int SSL_CTX_set1_chain(SSL_CTX *ctx, STACK_OF(X509) *sk);
  14. int SSL_CTX_add0_chain_cert(SSL_CTX *ctx, X509 *x509);
  15. int SSL_CTX_add1_chain_cert(SSL_CTX *ctx, X509 *x509);
  16. int SSL_CTX_get0_chain_certs(SSL_CTX *ctx, STACK_OF(X509) **sk);
  17. int SSL_CTX_clear_chain_certs(SSL_CTX *ctx);
  18. int SSL_set0_chain(SSL *ssl, STACK_OF(X509) *sk);
  19. int SSL_set1_chain(SSL *ssl, STACK_OF(X509) *sk);
  20. int SSL_add0_chain_cert(SSL *ssl, X509 *x509);
  21. int SSL_add1_chain_cert(SSL *ssl, X509 *x509);
  22. int SSL_get0_chain_certs(SSL *ssl, STACK_OF(X509) **sk);
  23. int SSL_clear_chain_certs(SSL *ssl);
  24. int SSL_CTX_build_cert_chain(SSL_CTX *ctx, flags);
  25. int SSL_build_cert_chain(SSL *ssl, flags);
  26. int SSL_CTX_select_current_cert(SSL_CTX *ctx, X509 *x509);
  27. int SSL_select_current_cert(SSL *ssl, X509 *x509);
  28. int SSL_CTX_set_current_cert(SSL_CTX *ctx, long op);
  29. int SSL_set_current_cert(SSL *ssl, long op);
  30. =head1 DESCRIPTION
  31. SSL_CTX_set0_chain() and SSL_CTX_set1_chain() set the certificate chain
  32. associated with the current certificate of B<ctx> to B<sk>.
  33. SSL_CTX_add0_chain_cert() and SSL_CTX_add1_chain_cert() append the single
  34. certificate B<x509> to the chain associated with the current certificate of
  35. B<ctx>.
  36. SSL_CTX_get0_chain_certs() retrieves the chain associated with the current
  37. certificate of B<ctx>.
  38. SSL_CTX_clear_chain_certs() clears any existing chain associated with the
  39. current certificate of B<ctx>. (This is implemented by calling
  40. SSL_CTX_set0_chain() with B<sk> set to B<NULL>).
  41. SSL_CTX_build_cert_chain() builds the certificate chain for B<ctx>.
  42. Normally this uses the chain store
  43. or the verify store if the chain store is not set.
  44. If the function is successful the built chain will replace any existing chain.
  45. The B<flags> parameter can be set to B<SSL_BUILD_CHAIN_FLAG_UNTRUSTED> to use
  46. existing chain certificates as untrusted CAs, B<SSL_BUILD_CHAIN_FLAG_NO_ROOT>
  47. to omit the root CA from the built chain, B<SSL_BUILD_CHAIN_FLAG_CHECK> to
  48. use all existing chain certificates only to build the chain (effectively
  49. sanity checking and rearranging them if necessary), the flag
  50. B<SSL_BUILD_CHAIN_FLAG_IGNORE_ERROR> ignores any errors during verification:
  51. if flag B<SSL_BUILD_CHAIN_FLAG_CLEAR_ERROR> is also set verification errors
  52. are cleared from the error queue.
  53. Details of the chain building process are described in
  54. L<openssl-verification-options(1)/Certification Path Building>.
  55. Each of these functions operates on the I<current> end entity
  56. (i.e. server or client) certificate. This is the last certificate loaded or
  57. selected on the corresponding B<ctx> structure.
  58. SSL_CTX_select_current_cert() selects B<x509> as the current end entity
  59. certificate, but only if B<x509> has already been loaded into B<ctx> using a
  60. function such as SSL_CTX_use_certificate().
  61. SSL_set0_chain(), SSL_set1_chain(), SSL_add0_chain_cert(),
  62. SSL_add1_chain_cert(), SSL_get0_chain_certs(), SSL_clear_chain_certs(),
  63. SSL_build_cert_chain(), SSL_select_current_cert() and SSL_set_current_cert()
  64. are similar except they apply to SSL structure B<ssl>.
  65. SSL_CTX_set_current_cert() changes the current certificate to a value based
  66. on the B<op> argument. Currently B<op> can be B<SSL_CERT_SET_FIRST> to use
  67. the first valid certificate or B<SSL_CERT_SET_NEXT> to set the next valid
  68. certificate after the current certificate. These two operations can be
  69. used to iterate over all certificates in an B<SSL_CTX> structure.
  70. SSL_set_current_cert() also supports the option B<SSL_CERT_SET_SERVER>.
  71. If B<ssl> is a server and has sent a certificate to a connected client
  72. this option sets that certificate to the current certificate and returns 1.
  73. If the negotiated cipher suite is anonymous (and thus no certificate will
  74. be sent) 2 is returned and the current certificate is unchanged. If B<ssl>
  75. is not a server or a certificate has not been sent 0 is returned and
  76. the current certificate is unchanged.
  77. All these functions are implemented as macros. Those containing a B<1>
  78. increment the reference count of the supplied certificate or chain so it must
  79. be freed at some point after the operation. Those containing a B<0> do
  80. not increment reference counts and the supplied certificate or chain
  81. B<MUST NOT> be freed after the operation.
  82. =head1 NOTES
  83. The chains associate with an SSL_CTX structure are copied to any SSL
  84. structures when SSL_new() is called. SSL structures will not be affected
  85. by any chains subsequently changed in the parent SSL_CTX.
  86. One chain can be set for each key type supported by a server. So, for example,
  87. an RSA and a DSA certificate can (and often will) have different chains.
  88. The functions SSL_CTX_build_cert_chain() and SSL_build_cert_chain() can
  89. be used to check application configuration and to ensure any necessary
  90. subordinate CAs are sent in the correct order. Misconfigured applications
  91. sending incorrect certificate chains often cause problems with peers.
  92. For example an application can add any set of certificates using
  93. SSL_CTX_use_certificate_chain_file() then call SSL_CTX_build_cert_chain()
  94. with the option B<SSL_BUILD_CHAIN_FLAG_CHECK> to check and reorder them.
  95. Applications can issue non fatal warnings when checking chains by setting
  96. the flag B<SSL_BUILD_CHAIN_FLAG_IGNORE_ERRORS> and checking the return
  97. value.
  98. Calling SSL_CTX_build_cert_chain() or SSL_build_cert_chain() is more
  99. efficient than the automatic chain building as it is only performed once.
  100. Automatic chain building is performed on each new session.
  101. If any certificates are added using these functions no certificates added
  102. using SSL_CTX_add_extra_chain_cert() will be used.
  103. =head1 RETURN VALUES
  104. SSL_set_current_cert() with B<SSL_CERT_SET_SERVER> return 1 for success, 2 if
  105. no server certificate is used because the cipher suites is anonymous and 0
  106. for failure.
  107. SSL_CTX_build_cert_chain() and SSL_build_cert_chain() return 1 for success
  108. and 0 for failure. If the flag B<SSL_BUILD_CHAIN_FLAG_IGNORE_ERROR> and
  109. a verification error occurs then 2 is returned.
  110. All other functions return 1 for success and 0 for failure.
  111. =head1 SEE ALSO
  112. L<ssl(7)>,
  113. L<SSL_CTX_add_extra_chain_cert(3)>
  114. =head1 HISTORY
  115. These functions were added in OpenSSL 1.0.2.
  116. =head1 COPYRIGHT
  117. Copyright 2013-2021 The OpenSSL Project Authors. All Rights Reserved.
  118. Licensed under the Apache License 2.0 (the "License"). You may not use
  119. this file except in compliance with the License. You can obtain a copy
  120. in the file LICENSE in the source distribution or at
  121. L<https://www.openssl.org/source/license.html>.
  122. =cut