SSL_CTX_new.pod 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. =pod
  2. =head1 NAME
  3. TLSv1_2_method, TLSv1_2_server_method, TLSv1_2_client_method,
  4. SSL_CTX_new, SSL_CTX_new_ex, SSL_CTX_up_ref, SSLv3_method,
  5. SSLv3_server_method, SSLv3_client_method, TLSv1_method, TLSv1_server_method,
  6. TLSv1_client_method, TLSv1_1_method, TLSv1_1_server_method,
  7. TLSv1_1_client_method, TLS_method, TLS_server_method, TLS_client_method,
  8. SSLv23_method, SSLv23_server_method, SSLv23_client_method, DTLS_method,
  9. DTLS_server_method, DTLS_client_method, DTLSv1_method, DTLSv1_server_method,
  10. DTLSv1_client_method, DTLSv1_2_method, DTLSv1_2_server_method,
  11. DTLSv1_2_client_method
  12. - create a new SSL_CTX object as framework for TLS/SSL or DTLS enabled
  13. functions
  14. =head1 SYNOPSIS
  15. #include <openssl/ssl.h>
  16. SSL_CTX *SSL_CTX_new_ex(OSSL_LIB_CTX *libctx, const char *propq,
  17. const SSL_METHOD *method);
  18. SSL_CTX *SSL_CTX_new(const SSL_METHOD *method);
  19. int SSL_CTX_up_ref(SSL_CTX *ctx);
  20. const SSL_METHOD *TLS_method(void);
  21. const SSL_METHOD *TLS_server_method(void);
  22. const SSL_METHOD *TLS_client_method(void);
  23. const SSL_METHOD *SSLv23_method(void);
  24. const SSL_METHOD *SSLv23_server_method(void);
  25. const SSL_METHOD *SSLv23_client_method(void);
  26. #ifndef OPENSSL_NO_SSL3_METHOD
  27. const SSL_METHOD *SSLv3_method(void);
  28. const SSL_METHOD *SSLv3_server_method(void);
  29. const SSL_METHOD *SSLv3_client_method(void);
  30. #endif
  31. #ifndef OPENSSL_NO_TLS1_METHOD
  32. const SSL_METHOD *TLSv1_method(void);
  33. const SSL_METHOD *TLSv1_server_method(void);
  34. const SSL_METHOD *TLSv1_client_method(void);
  35. #endif
  36. #ifndef OPENSSL_NO_TLS1_1_METHOD
  37. const SSL_METHOD *TLSv1_1_method(void);
  38. const SSL_METHOD *TLSv1_1_server_method(void);
  39. const SSL_METHOD *TLSv1_1_client_method(void);
  40. #endif
  41. #ifndef OPENSSL_NO_TLS1_2_METHOD
  42. const SSL_METHOD *TLSv1_2_method(void);
  43. const SSL_METHOD *TLSv1_2_server_method(void);
  44. const SSL_METHOD *TLSv1_2_client_method(void);
  45. #endif
  46. const SSL_METHOD *DTLS_method(void);
  47. const SSL_METHOD *DTLS_server_method(void);
  48. const SSL_METHOD *DTLS_client_method(void);
  49. #ifndef OPENSSL_NO_DTLS1_METHOD
  50. const SSL_METHOD *DTLSv1_method(void);
  51. const SSL_METHOD *DTLSv1_server_method(void);
  52. const SSL_METHOD *DTLSv1_client_method(void);
  53. #endif
  54. #ifndef OPENSSL_NO_DTLS1_2_METHOD
  55. const SSL_METHOD *DTLSv1_2_method(void);
  56. const SSL_METHOD *DTLSv1_2_server_method(void);
  57. const SSL_METHOD *DTLSv1_2_client_method(void);
  58. #endif
  59. =head1 DESCRIPTION
  60. SSL_CTX_new_ex() creates a new B<SSL_CTX> object, which holds various
  61. configuration and data relevant to SSL/TLS or DTLS session establishment.
  62. These are later inherited by the B<SSL> object representing an active session.
  63. The I<method> parameter specifies whether the context will be used for the
  64. client or server side or both - for details see the L</NOTES> below.
  65. The library context I<libctx> (see L<OSSL_LIB_CTX(3)>) is used to provide the
  66. cryptographic algorithms needed for the session. Any cryptographic algorithms
  67. that are used by any B<SSL> objects created from this B<SSL_CTX> will be fetched
  68. from the I<libctx> using the property query string I<propq> (see
  69. L<crypto(7)/ALGORITHM FETCHING>. Either or both the I<libctx> or I<propq>
  70. parameters may be NULL.
  71. SSL_CTX_new() does the same as SSL_CTX_new_ex() except that the default
  72. library context is used and no property query string is specified.
  73. An B<SSL_CTX> object is reference counted. Creating an B<SSL_CTX> object for the
  74. first time increments the reference count. Freeing the B<SSL_CTX> (using
  75. SSL_CTX_free) decrements it. When the reference count drops to zero, any memory
  76. or resources allocated to the B<SSL_CTX> object are freed. SSL_CTX_up_ref()
  77. increments the reference count for an existing B<SSL_CTX> structure.
  78. An B<SSL_CTX> object should not be changed after it is used to create any B<SSL>
  79. objects or from multiple threads concurrently, since the implementation does not
  80. provide serialization of access for these cases.
  81. =head1 NOTES
  82. On session estabilishment, by default, no peer credentials verification is done.
  83. This must be explicitly requested, typically using L<SSL_CTX_set_verify(3)>.
  84. For verifying peer certificates many options can be set using various functions
  85. such as L<SSL_CTX_load_verify_locations(3)> and L<SSL_CTX_set1_param(3)>.
  86. The L<X509_VERIFY_PARAM_set_purpose(3)> function can be used, also in conjunction
  87. with L<SSL_CTX_get0_param(3)>, to set the intended purpose of the session.
  88. The default is B<X509_PURPOSE_SSL_SERVER> on the client side
  89. and B<X509_PURPOSE_SSL_CLIENT> on the server side.
  90. The SSL_CTX object uses I<method> as the connection method.
  91. Three method variants are available: a generic method (for either client or
  92. server use), a server-only method, and a client-only method.
  93. The I<method> parameter of SSL_CTX_new_ex() and SSL_CTX_new()
  94. can be one of the following:
  95. =over 4
  96. =item TLS_method(), TLS_server_method(), TLS_client_method()
  97. These are the general-purpose I<version-flexible> SSL/TLS methods.
  98. The actual protocol version used will be negotiated to the highest version
  99. mutually supported by the client and the server.
  100. The supported protocols are SSLv3, TLSv1, TLSv1.1, TLSv1.2 and TLSv1.3.
  101. Applications should use these methods, and avoid the version-specific
  102. methods described below, which are deprecated.
  103. =item SSLv23_method(), SSLv23_server_method(), SSLv23_client_method()
  104. These functions do not exist anymore, they have been renamed to
  105. TLS_method(), TLS_server_method() and TLS_client_method() respectively.
  106. Currently, the old function calls are renamed to the corresponding new
  107. ones by preprocessor macros, to ensure that existing code which uses the
  108. old function names still compiles. However, using the old function names
  109. is deprecated and new code should call the new functions instead.
  110. =item TLSv1_2_method(), TLSv1_2_server_method(), TLSv1_2_client_method()
  111. A TLS/SSL connection established with these methods will only understand the
  112. TLSv1.2 protocol. These methods are deprecated.
  113. =item TLSv1_1_method(), TLSv1_1_server_method(), TLSv1_1_client_method()
  114. A TLS/SSL connection established with these methods will only understand the
  115. TLSv1.1 protocol. These methods are deprecated.
  116. =item TLSv1_method(), TLSv1_server_method(), TLSv1_client_method()
  117. A TLS/SSL connection established with these methods will only understand the
  118. TLSv1 protocol. These methods are deprecated.
  119. =item SSLv3_method(), SSLv3_server_method(), SSLv3_client_method()
  120. A TLS/SSL connection established with these methods will only understand the
  121. SSLv3 protocol.
  122. The SSLv3 protocol is deprecated and should not be used.
  123. =item DTLS_method(), DTLS_server_method(), DTLS_client_method()
  124. These are the version-flexible DTLS methods.
  125. Currently supported protocols are DTLS 1.0 and DTLS 1.2.
  126. =item DTLSv1_2_method(), DTLSv1_2_server_method(), DTLSv1_2_client_method()
  127. These are the version-specific methods for DTLSv1.2.
  128. These methods are deprecated.
  129. =item DTLSv1_method(), DTLSv1_server_method(), DTLSv1_client_method()
  130. These are the version-specific methods for DTLSv1.
  131. These methods are deprecated.
  132. =back
  133. SSL_CTX_new() initializes the list of ciphers, the session cache setting, the
  134. callbacks, the keys and certificates and the options to their default values.
  135. TLS_method(), TLS_server_method(), TLS_client_method(), DTLS_method(),
  136. DTLS_server_method() and DTLS_client_method() are the I<version-flexible>
  137. methods.
  138. All other methods only support one specific protocol version.
  139. Use the I<version-flexible> methods instead of the version specific methods.
  140. If you want to limit the supported protocols for the version flexible
  141. methods you can use L<SSL_CTX_set_min_proto_version(3)>,
  142. L<SSL_set_min_proto_version(3)>, L<SSL_CTX_set_max_proto_version(3)> and
  143. L<SSL_set_max_proto_version(3)> functions.
  144. Using these functions it is possible to choose e.g. TLS_server_method()
  145. and be able to negotiate with all possible clients, but to only
  146. allow newer protocols like TLS 1.0, TLS 1.1, TLS 1.2 or TLS 1.3.
  147. The list of protocols available can also be limited using the
  148. B<SSL_OP_NO_SSLv3>, B<SSL_OP_NO_TLSv1>, B<SSL_OP_NO_TLSv1_1>,
  149. B<SSL_OP_NO_TLSv1_3>, B<SSL_OP_NO_TLSv1_2> and B<SSL_OP_NO_TLSv1_3>
  150. options of the
  151. L<SSL_CTX_set_options(3)> or L<SSL_set_options(3)> functions, but this approach
  152. is not recommended. Clients should avoid creating "holes" in the set of
  153. protocols they support. When disabling a protocol, make sure that you also
  154. disable either all previous or all subsequent protocol versions.
  155. In clients, when a protocol version is disabled without disabling I<all>
  156. previous protocol versions, the effect is to also disable all subsequent
  157. protocol versions.
  158. The SSLv3 protocol is deprecated and should generally not be used.
  159. Applications should typically use L<SSL_CTX_set_min_proto_version(3)> to set
  160. the minimum protocol to at least B<TLS1_VERSION>.
  161. =head1 RETURN VALUES
  162. The following return values can occur:
  163. =over 4
  164. =item NULL
  165. The creation of a new SSL_CTX object failed. Check the error stack to find out
  166. the reason.
  167. =item Pointer to an SSL_CTX object
  168. The return value points to an allocated SSL_CTX object.
  169. SSL_CTX_up_ref() returns 1 for success and 0 for failure.
  170. =back
  171. =head1 SEE ALSO
  172. L<SSL_CTX_set_options(3)>, L<SSL_CTX_free(3)>,
  173. SSL_CTX_set_verify(3), L<SSL_CTX_set1_param(3)>, L<SSL_CTX_get0_param(3)>,
  174. L<SSL_connect(3)>, L<SSL_accept(3)>,
  175. L<SSL_CTX_set_min_proto_version(3)>, L<ssl(7)>, L<SSL_set_connect_state(3)>
  176. =head1 HISTORY
  177. Support for SSLv2 and the corresponding SSLv2_method(),
  178. SSLv2_server_method() and SSLv2_client_method() functions where
  179. removed in OpenSSL 1.1.0.
  180. SSLv23_method(), SSLv23_server_method() and SSLv23_client_method()
  181. were deprecated and the preferred TLS_method(), TLS_server_method()
  182. and TLS_client_method() functions were added in OpenSSL 1.1.0.
  183. All version-specific methods were deprecated in OpenSSL 1.1.0.
  184. SSL_CTX_new_ex() was added in OpenSSL 3.0.
  185. =head1 COPYRIGHT
  186. Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
  187. Licensed under the Apache License 2.0 (the "License"). You may not use
  188. this file except in compliance with the License. You can obtain a copy
  189. in the file LICENSE in the source distribution or at
  190. L<https://www.openssl.org/source/license.html>.
  191. =cut