1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5e71b7053SJung-uk KimTLSv1_2_method, TLSv1_2_server_method, TLSv1_2_client_method, 6*b077aed3SPierre ProncherySSL_CTX_new, SSL_CTX_new_ex, SSL_CTX_up_ref, SSLv3_method, 7*b077aed3SPierre ProncherySSLv3_server_method, SSLv3_client_method, TLSv1_method, TLSv1_server_method, 8*b077aed3SPierre ProncheryTLSv1_client_method, TLSv1_1_method, TLSv1_1_server_method, 9*b077aed3SPierre ProncheryTLSv1_1_client_method, TLS_method, TLS_server_method, TLS_client_method, 10*b077aed3SPierre ProncherySSLv23_method, SSLv23_server_method, SSLv23_client_method, DTLS_method, 11*b077aed3SPierre ProncheryDTLS_server_method, DTLS_client_method, DTLSv1_method, DTLSv1_server_method, 12*b077aed3SPierre ProncheryDTLSv1_client_method, DTLSv1_2_method, DTLSv1_2_server_method, 13*b077aed3SPierre ProncheryDTLSv1_2_client_method 14e71b7053SJung-uk Kim- create a new SSL_CTX object as framework for TLS/SSL or DTLS enabled 15e71b7053SJung-uk Kimfunctions 16e71b7053SJung-uk Kim 17e71b7053SJung-uk Kim=head1 SYNOPSIS 18e71b7053SJung-uk Kim 19e71b7053SJung-uk Kim #include <openssl/ssl.h> 20e71b7053SJung-uk Kim 21*b077aed3SPierre Pronchery SSL_CTX *SSL_CTX_new_ex(OSSL_LIB_CTX *libctx, const char *propq, 22*b077aed3SPierre Pronchery const SSL_METHOD *method); 23e71b7053SJung-uk Kim SSL_CTX *SSL_CTX_new(const SSL_METHOD *method); 24e71b7053SJung-uk Kim int SSL_CTX_up_ref(SSL_CTX *ctx); 25e71b7053SJung-uk Kim 26e71b7053SJung-uk Kim const SSL_METHOD *TLS_method(void); 27e71b7053SJung-uk Kim const SSL_METHOD *TLS_server_method(void); 28e71b7053SJung-uk Kim const SSL_METHOD *TLS_client_method(void); 29e71b7053SJung-uk Kim 30e71b7053SJung-uk Kim const SSL_METHOD *SSLv23_method(void); 31e71b7053SJung-uk Kim const SSL_METHOD *SSLv23_server_method(void); 32e71b7053SJung-uk Kim const SSL_METHOD *SSLv23_client_method(void); 33e71b7053SJung-uk Kim 34e71b7053SJung-uk Kim #ifndef OPENSSL_NO_SSL3_METHOD 35e71b7053SJung-uk Kim const SSL_METHOD *SSLv3_method(void); 36e71b7053SJung-uk Kim const SSL_METHOD *SSLv3_server_method(void); 37e71b7053SJung-uk Kim const SSL_METHOD *SSLv3_client_method(void); 38e71b7053SJung-uk Kim #endif 39e71b7053SJung-uk Kim 40e71b7053SJung-uk Kim #ifndef OPENSSL_NO_TLS1_METHOD 41e71b7053SJung-uk Kim const SSL_METHOD *TLSv1_method(void); 42e71b7053SJung-uk Kim const SSL_METHOD *TLSv1_server_method(void); 43e71b7053SJung-uk Kim const SSL_METHOD *TLSv1_client_method(void); 44e71b7053SJung-uk Kim #endif 45e71b7053SJung-uk Kim 46e71b7053SJung-uk Kim #ifndef OPENSSL_NO_TLS1_1_METHOD 47e71b7053SJung-uk Kim const SSL_METHOD *TLSv1_1_method(void); 48e71b7053SJung-uk Kim const SSL_METHOD *TLSv1_1_server_method(void); 49e71b7053SJung-uk Kim const SSL_METHOD *TLSv1_1_client_method(void); 50e71b7053SJung-uk Kim #endif 51e71b7053SJung-uk Kim 52e71b7053SJung-uk Kim #ifndef OPENSSL_NO_TLS1_2_METHOD 53e71b7053SJung-uk Kim const SSL_METHOD *TLSv1_2_method(void); 54e71b7053SJung-uk Kim const SSL_METHOD *TLSv1_2_server_method(void); 55e71b7053SJung-uk Kim const SSL_METHOD *TLSv1_2_client_method(void); 56e71b7053SJung-uk Kim #endif 57e71b7053SJung-uk Kim 58e71b7053SJung-uk Kim const SSL_METHOD *DTLS_method(void); 59e71b7053SJung-uk Kim const SSL_METHOD *DTLS_server_method(void); 60e71b7053SJung-uk Kim const SSL_METHOD *DTLS_client_method(void); 61e71b7053SJung-uk Kim 62e71b7053SJung-uk Kim #ifndef OPENSSL_NO_DTLS1_METHOD 63e71b7053SJung-uk Kim const SSL_METHOD *DTLSv1_method(void); 64e71b7053SJung-uk Kim const SSL_METHOD *DTLSv1_server_method(void); 65e71b7053SJung-uk Kim const SSL_METHOD *DTLSv1_client_method(void); 66e71b7053SJung-uk Kim #endif 67e71b7053SJung-uk Kim 68e71b7053SJung-uk Kim #ifndef OPENSSL_NO_DTLS1_2_METHOD 69e71b7053SJung-uk Kim const SSL_METHOD *DTLSv1_2_method(void); 70e71b7053SJung-uk Kim const SSL_METHOD *DTLSv1_2_server_method(void); 71e71b7053SJung-uk Kim const SSL_METHOD *DTLSv1_2_client_method(void); 72e71b7053SJung-uk Kim #endif 73e71b7053SJung-uk Kim 74e71b7053SJung-uk Kim=head1 DESCRIPTION 75e71b7053SJung-uk Kim 76*b077aed3SPierre ProncherySSL_CTX_new_ex() creates a new B<SSL_CTX> object, which holds various 77*b077aed3SPierre Proncheryconfiguration and data relevant to SSL/TLS or DTLS session establishment. 78*b077aed3SPierre ProncheryThese are later inherited by the B<SSL> object representing an active session. 79*b077aed3SPierre ProncheryThe I<method> parameter specifies whether the context will be used for the 80*b077aed3SPierre Proncheryclient or server side or both - for details see the L</NOTES> below. 81*b077aed3SPierre ProncheryThe library context I<libctx> (see L<OSSL_LIB_CTX(3)>) is used to provide the 82*b077aed3SPierre Proncherycryptographic algorithms needed for the session. Any cryptographic algorithms 83*b077aed3SPierre Proncherythat are used by any B<SSL> objects created from this B<SSL_CTX> will be fetched 84*b077aed3SPierre Proncheryfrom the I<libctx> using the property query string I<propq> (see 85*b077aed3SPierre ProncheryL<crypto(7)/ALGORITHM FETCHING>. Either or both the I<libctx> or I<propq> 86*b077aed3SPierre Proncheryparameters may be NULL. 87*b077aed3SPierre Pronchery 88*b077aed3SPierre ProncherySSL_CTX_new() does the same as SSL_CTX_new_ex() except that the default 89*b077aed3SPierre Proncherylibrary context is used and no property query string is specified. 90*b077aed3SPierre Pronchery 91*b077aed3SPierre ProncheryAn B<SSL_CTX> object is reference counted. Creating an B<SSL_CTX> object for the 92*b077aed3SPierre Proncheryfirst time increments the reference count. Freeing the B<SSL_CTX> (using 93*b077aed3SPierre ProncherySSL_CTX_free) decrements it. When the reference count drops to zero, any memory 94*b077aed3SPierre Proncheryor resources allocated to the B<SSL_CTX> object are freed. SSL_CTX_up_ref() 95*b077aed3SPierre Proncheryincrements the reference count for an existing B<SSL_CTX> structure. 96*b077aed3SPierre Pronchery 97*b077aed3SPierre ProncheryAn B<SSL_CTX> object should not be changed after it is used to create any B<SSL> 98*b077aed3SPierre Proncheryobjects or from multiple threads concurrently, since the implementation does not 99*b077aed3SPierre Proncheryprovide serialization of access for these cases. 100e71b7053SJung-uk Kim 101e71b7053SJung-uk Kim=head1 NOTES 102e71b7053SJung-uk Kim 103*b077aed3SPierre ProncheryOn session estabilishment, by default, no peer credentials verification is done. 104*b077aed3SPierre ProncheryThis must be explicitly requested, typically using L<SSL_CTX_set_verify(3)>. 105*b077aed3SPierre ProncheryFor verifying peer certificates many options can be set using various functions 106*b077aed3SPierre Proncherysuch as L<SSL_CTX_load_verify_locations(3)> and L<SSL_CTX_set1_param(3)>. 107*b077aed3SPierre ProncheryThe L<X509_VERIFY_PARAM_set_purpose(3)> function can be used, also in conjunction 108*b077aed3SPierre Proncherywith L<SSL_CTX_get0_param(3)>, to set the intended purpose of the session. 109*b077aed3SPierre ProncheryThe default is B<X509_PURPOSE_SSL_SERVER> on the client side 110*b077aed3SPierre Proncheryand B<X509_PURPOSE_SSL_CLIENT> on the server side. 111*b077aed3SPierre Pronchery 112*b077aed3SPierre ProncheryThe SSL_CTX object uses I<method> as the connection method. 113*b077aed3SPierre ProncheryThree method variants are available: a generic method (for either client or 114*b077aed3SPierre Proncheryserver use), a server-only method, and a client-only method. 115*b077aed3SPierre Pronchery 116*b077aed3SPierre ProncheryThe I<method> parameter of SSL_CTX_new_ex() and SSL_CTX_new() 117*b077aed3SPierre Proncherycan be one of the following: 118e71b7053SJung-uk Kim 119e71b7053SJung-uk Kim=over 4 120e71b7053SJung-uk Kim 121e71b7053SJung-uk Kim=item TLS_method(), TLS_server_method(), TLS_client_method() 122e71b7053SJung-uk Kim 123e71b7053SJung-uk KimThese are the general-purpose I<version-flexible> SSL/TLS methods. 124e71b7053SJung-uk KimThe actual protocol version used will be negotiated to the highest version 125e71b7053SJung-uk Kimmutually supported by the client and the server. 126e71b7053SJung-uk KimThe supported protocols are SSLv3, TLSv1, TLSv1.1, TLSv1.2 and TLSv1.3. 127e71b7053SJung-uk KimApplications should use these methods, and avoid the version-specific 128da327cd2SJung-uk Kimmethods described below, which are deprecated. 129e71b7053SJung-uk Kim 130e71b7053SJung-uk Kim=item SSLv23_method(), SSLv23_server_method(), SSLv23_client_method() 131e71b7053SJung-uk Kim 132da327cd2SJung-uk KimThese functions do not exist anymore, they have been renamed to 133da327cd2SJung-uk KimTLS_method(), TLS_server_method() and TLS_client_method() respectively. 134da327cd2SJung-uk KimCurrently, the old function calls are renamed to the corresponding new 135da327cd2SJung-uk Kimones by preprocessor macros, to ensure that existing code which uses the 136da327cd2SJung-uk Kimold function names still compiles. However, using the old function names 137da327cd2SJung-uk Kimis deprecated and new code should call the new functions instead. 138e71b7053SJung-uk Kim 139e71b7053SJung-uk Kim=item TLSv1_2_method(), TLSv1_2_server_method(), TLSv1_2_client_method() 140e71b7053SJung-uk Kim 141e71b7053SJung-uk KimA TLS/SSL connection established with these methods will only understand the 142da327cd2SJung-uk KimTLSv1.2 protocol. These methods are deprecated. 143e71b7053SJung-uk Kim 144e71b7053SJung-uk Kim=item TLSv1_1_method(), TLSv1_1_server_method(), TLSv1_1_client_method() 145e71b7053SJung-uk Kim 146e71b7053SJung-uk KimA TLS/SSL connection established with these methods will only understand the 147da327cd2SJung-uk KimTLSv1.1 protocol. These methods are deprecated. 148e71b7053SJung-uk Kim 149e71b7053SJung-uk Kim=item TLSv1_method(), TLSv1_server_method(), TLSv1_client_method() 150e71b7053SJung-uk Kim 151e71b7053SJung-uk KimA TLS/SSL connection established with these methods will only understand the 152da327cd2SJung-uk KimTLSv1 protocol. These methods are deprecated. 153e71b7053SJung-uk Kim 154e71b7053SJung-uk Kim=item SSLv3_method(), SSLv3_server_method(), SSLv3_client_method() 155e71b7053SJung-uk Kim 156e71b7053SJung-uk KimA TLS/SSL connection established with these methods will only understand the 157e71b7053SJung-uk KimSSLv3 protocol. 158e71b7053SJung-uk KimThe SSLv3 protocol is deprecated and should not be used. 159e71b7053SJung-uk Kim 160e71b7053SJung-uk Kim=item DTLS_method(), DTLS_server_method(), DTLS_client_method() 161e71b7053SJung-uk Kim 162e71b7053SJung-uk KimThese are the version-flexible DTLS methods. 163e71b7053SJung-uk KimCurrently supported protocols are DTLS 1.0 and DTLS 1.2. 164e71b7053SJung-uk Kim 165e71b7053SJung-uk Kim=item DTLSv1_2_method(), DTLSv1_2_server_method(), DTLSv1_2_client_method() 166e71b7053SJung-uk Kim 167e71b7053SJung-uk KimThese are the version-specific methods for DTLSv1.2. 168da327cd2SJung-uk KimThese methods are deprecated. 169e71b7053SJung-uk Kim 170e71b7053SJung-uk Kim=item DTLSv1_method(), DTLSv1_server_method(), DTLSv1_client_method() 171e71b7053SJung-uk Kim 172e71b7053SJung-uk KimThese are the version-specific methods for DTLSv1. 173da327cd2SJung-uk KimThese methods are deprecated. 174e71b7053SJung-uk Kim 175e71b7053SJung-uk Kim=back 176e71b7053SJung-uk Kim 177e71b7053SJung-uk KimSSL_CTX_new() initializes the list of ciphers, the session cache setting, the 178e71b7053SJung-uk Kimcallbacks, the keys and certificates and the options to their default values. 179e71b7053SJung-uk Kim 180e71b7053SJung-uk KimTLS_method(), TLS_server_method(), TLS_client_method(), DTLS_method(), 181e71b7053SJung-uk KimDTLS_server_method() and DTLS_client_method() are the I<version-flexible> 182e71b7053SJung-uk Kimmethods. 183e71b7053SJung-uk KimAll other methods only support one specific protocol version. 184e71b7053SJung-uk KimUse the I<version-flexible> methods instead of the version specific methods. 185e71b7053SJung-uk Kim 186e71b7053SJung-uk KimIf you want to limit the supported protocols for the version flexible 187e71b7053SJung-uk Kimmethods you can use L<SSL_CTX_set_min_proto_version(3)>, 188e71b7053SJung-uk KimL<SSL_set_min_proto_version(3)>, L<SSL_CTX_set_max_proto_version(3)> and 189e71b7053SJung-uk KimL<SSL_set_max_proto_version(3)> functions. 190e71b7053SJung-uk KimUsing these functions it is possible to choose e.g. TLS_server_method() 191e71b7053SJung-uk Kimand be able to negotiate with all possible clients, but to only 192e71b7053SJung-uk Kimallow newer protocols like TLS 1.0, TLS 1.1, TLS 1.2 or TLS 1.3. 193e71b7053SJung-uk Kim 194e71b7053SJung-uk KimThe list of protocols available can also be limited using the 195e71b7053SJung-uk KimB<SSL_OP_NO_SSLv3>, B<SSL_OP_NO_TLSv1>, B<SSL_OP_NO_TLSv1_1>, 196e71b7053SJung-uk KimB<SSL_OP_NO_TLSv1_3>, B<SSL_OP_NO_TLSv1_2> and B<SSL_OP_NO_TLSv1_3> 197e71b7053SJung-uk Kimoptions of the 198e71b7053SJung-uk KimL<SSL_CTX_set_options(3)> or L<SSL_set_options(3)> functions, but this approach 199e71b7053SJung-uk Kimis not recommended. Clients should avoid creating "holes" in the set of 200e71b7053SJung-uk Kimprotocols they support. When disabling a protocol, make sure that you also 201e71b7053SJung-uk Kimdisable either all previous or all subsequent protocol versions. 202e71b7053SJung-uk KimIn clients, when a protocol version is disabled without disabling I<all> 203e71b7053SJung-uk Kimprevious protocol versions, the effect is to also disable all subsequent 204e71b7053SJung-uk Kimprotocol versions. 205e71b7053SJung-uk Kim 206e71b7053SJung-uk KimThe SSLv3 protocol is deprecated and should generally not be used. 207e71b7053SJung-uk KimApplications should typically use L<SSL_CTX_set_min_proto_version(3)> to set 208e71b7053SJung-uk Kimthe minimum protocol to at least B<TLS1_VERSION>. 209e71b7053SJung-uk Kim 210e71b7053SJung-uk Kim=head1 RETURN VALUES 211e71b7053SJung-uk Kim 212e71b7053SJung-uk KimThe following return values can occur: 213e71b7053SJung-uk Kim 214e71b7053SJung-uk Kim=over 4 215e71b7053SJung-uk Kim 216e71b7053SJung-uk Kim=item NULL 217e71b7053SJung-uk Kim 218e71b7053SJung-uk KimThe creation of a new SSL_CTX object failed. Check the error stack to find out 219e71b7053SJung-uk Kimthe reason. 220e71b7053SJung-uk Kim 221e71b7053SJung-uk Kim=item Pointer to an SSL_CTX object 222e71b7053SJung-uk Kim 223e71b7053SJung-uk KimThe return value points to an allocated SSL_CTX object. 224e71b7053SJung-uk Kim 225e71b7053SJung-uk KimSSL_CTX_up_ref() returns 1 for success and 0 for failure. 226e71b7053SJung-uk Kim 227e71b7053SJung-uk Kim=back 228e71b7053SJung-uk Kim 229610a21fdSJung-uk Kim=head1 SEE ALSO 230610a21fdSJung-uk Kim 231*b077aed3SPierre ProncheryL<SSL_CTX_set_options(3)>, L<SSL_CTX_free(3)>, 232*b077aed3SPierre ProncherySSL_CTX_set_verify(3), L<SSL_CTX_set1_param(3)>, L<SSL_CTX_get0_param(3)>, 233*b077aed3SPierre ProncheryL<SSL_connect(3)>, L<SSL_accept(3)>, 234610a21fdSJung-uk KimL<SSL_CTX_set_min_proto_version(3)>, L<ssl(7)>, L<SSL_set_connect_state(3)> 235610a21fdSJung-uk Kim 236e71b7053SJung-uk Kim=head1 HISTORY 237e71b7053SJung-uk Kim 238e71b7053SJung-uk KimSupport for SSLv2 and the corresponding SSLv2_method(), 239e71b7053SJung-uk KimSSLv2_server_method() and SSLv2_client_method() functions where 240e71b7053SJung-uk Kimremoved in OpenSSL 1.1.0. 241e71b7053SJung-uk Kim 242e71b7053SJung-uk KimSSLv23_method(), SSLv23_server_method() and SSLv23_client_method() 243e71b7053SJung-uk Kimwere deprecated and the preferred TLS_method(), TLS_server_method() 244610a21fdSJung-uk Kimand TLS_client_method() functions were added in OpenSSL 1.1.0. 245e71b7053SJung-uk Kim 246e71b7053SJung-uk KimAll version-specific methods were deprecated in OpenSSL 1.1.0. 247e71b7053SJung-uk Kim 248*b077aed3SPierre ProncherySSL_CTX_new_ex() was added in OpenSSL 3.0. 249*b077aed3SPierre Pronchery 250e71b7053SJung-uk Kim=head1 COPYRIGHT 251e71b7053SJung-uk Kim 252*b077aed3SPierre ProncheryCopyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved. 253e71b7053SJung-uk Kim 254*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 255e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 256e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 257e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 258e71b7053SJung-uk Kim 259e71b7053SJung-uk Kim=cut 260