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