xref: /openssl/doc/man3/SSL_CTX_set_options.pod (revision ef39dd05)
1=pod
2
3=head1 NAME
4
5SSL_CTX_set_options, SSL_set_options, SSL_CTX_clear_options,
6SSL_clear_options, SSL_CTX_get_options, SSL_get_options,
7SSL_get_secure_renegotiation_support - manipulate SSL options
8
9=head1 SYNOPSIS
10
11 #include <openssl/ssl.h>
12
13 uint64_t SSL_CTX_set_options(SSL_CTX *ctx, uint64_t options);
14 uint64_t SSL_set_options(SSL *ssl, uint64_t options);
15
16 uint64_t SSL_CTX_clear_options(SSL_CTX *ctx, uint64_t options);
17 uint64_t SSL_clear_options(SSL *ssl, uint64_t options);
18
19 uint64_t SSL_CTX_get_options(const SSL_CTX *ctx);
20 uint64_t SSL_get_options(const SSL *ssl);
21
22 long SSL_get_secure_renegotiation_support(SSL *ssl);
23
24=head1 DESCRIPTION
25
26SSL_CTX_set_options() adds the options set via bit-mask in B<options> to B<ctx>.
27B<ctx> B<MUST NOT> be NULL.
28Options already set before are not cleared!
29
30SSL_set_options() adds the options set via bit-mask in B<options> to B<ssl>.
31Options already set before are not cleared!
32
33SSL_CTX_clear_options() clears the options set via bit-mask in B<options>
34to B<ctx>.
35
36SSL_clear_options() clears the options set via bit-mask in B<options> to B<ssl>.
37
38SSL_CTX_get_options() returns the options set for B<ctx>.
39
40SSL_get_options() returns the options set for B<ssl>.
41
42SSL_get_secure_renegotiation_support() indicates whether the peer supports
43secure renegotiation.
44Note, this is implemented via a macro.
45
46=head1 NOTES
47
48The behaviour of the SSL library can be changed by setting several options.
49The options are coded as bit-masks and can be combined by a bitwise B<or>
50operation (|).
51
52SSL_CTX_set_options() and SSL_set_options() affect the (external)
53protocol behaviour of the SSL library. The (internal) behaviour of
54the API can be changed by using the similar
55L<SSL_CTX_set_mode(3)> and SSL_set_mode() functions.
56
57During a handshake, the option settings of the SSL object are used. When
58a new SSL object is created from a context using SSL_new(), the current
59option setting is copied. Changes to B<ctx> do not affect already created
60SSL objects. SSL_clear() does not affect the settings.
61
62The following B<bug workaround> options are available:
63
64=over 4
65
66=item SSL_OP_CRYPTOPRO_TLSEXT_BUG
67
68Add server-hello extension from the early version of cryptopro draft
69when GOST ciphersuite is negotiated. Required for interoperability with CryptoPro
70CSP 3.x.
71
72=item SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
73
74Disables a countermeasure against an SSL 3.0/TLS 1.0 protocol
75vulnerability affecting CBC ciphers, which cannot be handled by some
76broken SSL implementations.  This option has no effect for connections
77using other ciphers.
78
79=item SSL_OP_SAFARI_ECDHE_ECDSA_BUG
80
81Don't prefer ECDHE-ECDSA ciphers when the client appears to be Safari on OS X.
82OS X 10.8..10.8.3 has broken support for ECDHE-ECDSA ciphers.
83
84=item SSL_OP_TLSEXT_PADDING
85
86Adds a padding extension to ensure the ClientHello size is never between
87256 and 511 bytes in length. This is needed as a workaround for some
88implementations.
89
90=item SSL_OP_ALL
91
92All of the above bug workarounds.
93
94=back
95
96It is usually safe to use B<SSL_OP_ALL> to enable the bug workaround
97options if compatibility with somewhat broken implementations is
98desired.
99
100The following B<modifying> options are available:
101
102=over 4
103
104=item SSL_OP_ALLOW_CLIENT_RENEGOTIATION
105
106Client-initiated renegotiation is disabled by default. Use
107this option to enable it.
108
109=item SSL_OP_ALLOW_NO_DHE_KEX
110
111In TLSv1.3 allow a non-(ec)dhe based key exchange mode on resumption. This means
112that there will be no forward secrecy for the resumed session.
113
114=item SSL_OP_PREFER_NO_DHE_KEX
115
116In TLSv1.3, on resumption let the server prefer a non-(ec)dhe based key
117exchange mode over an (ec)dhe based one. Ignored without B<SSL_OP_ALLOW_NO_DHE_KEX>
118being set as well. Always ignored on the client.
119
120=item SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION
121
122Allow legacy insecure renegotiation between OpenSSL and unpatched clients or
123servers. See the B<SECURE RENEGOTIATION> section for more details.
124
125=item SSL_OP_CIPHER_SERVER_PREFERENCE
126
127When choosing a cipher, use the server's preferences instead of the client
128preferences. When not set, the SSL server will always follow the clients
129preferences. When set, the SSL/TLS server will choose following its
130own preferences.
131
132=item SSL_OP_CISCO_ANYCONNECT
133
134Use Cisco's version identifier of DTLS_BAD_VER when establishing a DTLSv1
135connection. Only available when using the deprecated DTLSv1_client_method() API.
136
137=item SSL_OP_CLEANSE_PLAINTEXT
138
139By default TLS and QUIC SSL objects keep a copy of received plaintext
140application data in a static buffer until it is overwritten by the
141next portion of data. When enabling SSL_OP_CLEANSE_PLAINTEXT
142deciphered application data is cleansed by calling OPENSSL_cleanse(3)
143after passing data to the application. Data is also cleansed when
144releasing the connection (e.g. L<SSL_free(3)>).
145
146Since OpenSSL only cleanses internal buffers, the application is still
147responsible for cleansing all other buffers. Most notably, this
148applies to buffers passed to functions like L<SSL_read(3)>,
149L<SSL_peek(3)> but also like L<SSL_write(3)>.
150
151TLS connections do not buffer data to be sent in plaintext. QUIC stream
152objects do buffer plaintext data to be sent and this option will also cause
153that data to be cleansed when it is discarded.
154
155This option can be set differently on individual QUIC stream objects and
156has no effect on QUIC connection objects (except where a default stream is
157being used).
158
159=item SSL_OP_COOKIE_EXCHANGE
160
161Turn on Cookie Exchange as described in RFC4347 Section 4.2.1. Only affects
162DTLS connections.
163
164=item SSL_OP_DISABLE_TLSEXT_CA_NAMES
165
166Disable TLS Extension CA Names. You may want to disable it for security reasons
167or for compatibility with some Windows TLS implementations crashing when this
168extension is larger than 1024 bytes.
169
170=item SSL_OP_ENABLE_KTLS
171
172Enable the use of kernel TLS. In order to benefit from kernel TLS OpenSSL must
173have been compiled with support for it, and it must be supported by the
174negotiated ciphersuites and extensions. The specific ciphersuites and extensions
175that are supported may vary by platform and kernel version.
176
177The kernel TLS data-path implements the record layer, and the encryption
178algorithm. The kernel will utilize the best hardware
179available for encryption. Using the kernel data-path should reduce the memory
180footprint of OpenSSL because no buffering is required. Also, the throughput
181should improve because data copy is avoided when user data is encrypted into
182kernel memory instead of the usual encrypt then copy to kernel.
183
184Kernel TLS might not support all the features of OpenSSL. For instance,
185renegotiation, and setting the maximum fragment size is not possible as of
186Linux 4.20.
187
188Note that with kernel TLS enabled some cryptographic operations are performed
189by the kernel directly and not via any available OpenSSL Providers. This might
190be undesirable if, for example, the application requires all cryptographic
191operations to be performed by the FIPS provider.
192
193=item SSL_OP_ENABLE_KTLS_TX_ZEROCOPY_SENDFILE
194
195With this option, sendfile() will use the zerocopy mode, which gives a
196performance boost when used with KTLS hardware offload. Note that invalid TLS
197records might be transmitted if the file is changed while being sent. This
198option has no effect if B<SSL_OP_ENABLE_KTLS> is not enabled.
199
200This option only applies to Linux. KTLS sendfile on FreeBSD doesn't offer an
201option to disable zerocopy and always runs in this mode.
202
203=item SSL_OP_ENABLE_MIDDLEBOX_COMPAT
204
205If set then dummy Change Cipher Spec (CCS) messages are sent in TLSv1.3. This
206has the effect of making TLSv1.3 look more like TLSv1.2 so that middleboxes that
207do not understand TLSv1.3 will not drop the connection. Regardless of whether
208this option is set or not CCS messages received from the peer will always be
209ignored in TLSv1.3. This option is set by default. To switch it off use
210SSL_clear_options(). A future version of OpenSSL may not set this by default.
211
212=item SSL_OP_IGNORE_UNEXPECTED_EOF
213
214Some TLS implementations do not send the mandatory close_notify alert on
215shutdown. If the application tries to wait for the close_notify alert but the
216peer closes the connection without sending it, an error is generated. When this
217option is enabled the peer does not need to send the close_notify alert and a
218closed connection will be treated as if the close_notify alert was received.
219
220You should only enable this option if the protocol running over TLS
221can detect a truncation attack itself, and that the application is checking for
222that truncation attack.
223
224For more information on shutting down a connection, see L<SSL_shutdown(3)>.
225
226=item SSL_OP_LEGACY_SERVER_CONNECT
227
228Allow legacy insecure renegotiation between OpenSSL and unpatched servers
229B<only>. See the B<SECURE RENEGOTIATION> section for more details.
230
231=item SSL_OP_NO_ANTI_REPLAY
232
233By default, when a server is configured for early data (i.e., max_early_data > 0),
234OpenSSL will switch on replay protection. See L<SSL_read_early_data(3)> for a
235description of the replay protection feature. Anti-replay measures are required
236to comply with the TLSv1.3 specification. Some applications may be able to
237mitigate the replay risks in other ways and in such cases the built in OpenSSL
238functionality is not required. Those applications can turn this feature off by
239setting this option. This is a server-side option only. It is ignored by
240clients.
241
242=item SSL_OP_NO_TX_CERTIFICATE_COMPRESSION
243
244Normally clients and servers will transparently attempt to negotiate the
245RFC8879 certificate compression option on TLSv1.3 connections.
246
247If this option is set, the certificate compression extension is ignored
248upon receipt and compressed certificates will not be sent to the peer.
249
250=item SSL_OP_NO_RX_CERTIFICATE_COMPRESSION
251
252Normally clients and servers will transparently attempt to negotiate the
253RFC8879 certificate compression option on TLSv1.3 connections.
254
255If this option is set, the certificate compression extension will not be sent
256and compressed certificates will not be accepted from the peer.
257
258=item SSL_OP_NO_COMPRESSION
259
260Do not use TLS record compression even if it is supported. This option is set by
261default. To switch it off use SSL_clear_options(). Note that TLS record
262compression is not recommended and is not available at security level 2 or
263above. From OpenSSL 3.2 the default security level is 2, so clearing this option
264will have no effect without also changing the default security level. See
265L<SSL_CTX_set_security_level(3)>.
266
267=item SSL_OP_NO_ENCRYPT_THEN_MAC
268
269Normally clients and servers will transparently attempt to negotiate the
270RFC7366 Encrypt-then-MAC option on TLS and DTLS connection.
271
272If this option is set, Encrypt-then-MAC is disabled. Clients will not
273propose, and servers will not accept the extension.
274
275=item SSL_OP_NO_EXTENDED_MASTER_SECRET
276
277Normally clients and servers will transparently attempt to negotiate the
278RFC7627 Extended Master Secret option on TLS and DTLS connection.
279
280If this option is set, Extended Master Secret is disabled. Clients will
281not propose, and servers will not accept the extension.
282
283=item SSL_OP_NO_QUERY_MTU
284
285Do not query the MTU. Only affects DTLS connections.
286
287=item SSL_OP_NO_RENEGOTIATION
288
289Disable all renegotiation in TLSv1.2 and earlier. Do not send HelloRequest
290messages, and ignore renegotiation requests via ClientHello.
291
292=item SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
293
294When performing renegotiation as a server, always start a new session
295(i.e., session resumption requests are only accepted in the initial
296handshake). This option is not needed for clients.
297
298=item SSL_OP_NO_SSLv3, SSL_OP_NO_TLSv1, SSL_OP_NO_TLSv1_1,
299SSL_OP_NO_TLSv1_2, SSL_OP_NO_TLSv1_3, SSL_OP_NO_DTLSv1, SSL_OP_NO_DTLSv1_2
300
301These options turn off the SSLv3, TLSv1, TLSv1.1, TLSv1.2 or TLSv1.3 protocol
302versions with TLS or the DTLSv1, DTLSv1.2 versions with DTLS,
303respectively.
304As of OpenSSL 1.1.0, these options are deprecated, use
305L<SSL_CTX_set_min_proto_version(3)> and
306L<SSL_CTX_set_max_proto_version(3)> instead.
307
308=item SSL_OP_NO_TICKET
309
310SSL/TLS supports two mechanisms for resuming sessions: session ids and stateless
311session tickets.
312
313When using session ids a copy of the session information is
314cached on the server and a unique id is sent to the client. When the client
315wishes to resume it provides the unique id so that the server can retrieve the
316session information from its cache.
317
318When using stateless session tickets the server uses a session ticket encryption
319key to encrypt the session information. This encrypted data is sent to the
320client as a "ticket". When the client wishes to resume it sends the encrypted
321data back to the server. The server uses its key to decrypt the data and resume
322the session. In this way the server can operate statelessly - no session
323information needs to be cached locally.
324
325The TLSv1.3 protocol only supports tickets and does not directly support session
326ids. However, OpenSSL allows two modes of ticket operation in TLSv1.3: stateful
327and stateless. Stateless tickets work the same way as in TLSv1.2 and below.
328Stateful tickets mimic the session id behaviour available in TLSv1.2 and below.
329The session information is cached on the server and the session id is wrapped up
330in a ticket and sent back to the client. When the client wishes to resume, it
331presents a ticket in the same way as for stateless tickets. The server can then
332extract the session id from the ticket and retrieve the session information from
333its cache.
334
335By default OpenSSL will use stateless tickets. The SSL_OP_NO_TICKET option will
336cause stateless tickets to not be issued. In TLSv1.2 and below this means no
337ticket gets sent to the client at all. In TLSv1.3 a stateful ticket will be
338sent. This is a server-side option only.
339
340In TLSv1.3 it is possible to suppress all tickets (stateful and stateless) from
341being sent by calling L<SSL_CTX_set_num_tickets(3)> or
342L<SSL_set_num_tickets(3)>.
343
344=item SSL_OP_PRIORITIZE_CHACHA
345
346When SSL_OP_CIPHER_SERVER_PREFERENCE is set, temporarily reprioritize
347ChaCha20-Poly1305 ciphers to the top of the server cipher list if a
348ChaCha20-Poly1305 cipher is at the top of the client cipher list. This helps
349those clients (e.g. mobile) use ChaCha20-Poly1305 if that cipher is anywhere
350in the server cipher list; but still allows other clients to use AES and other
351ciphers. Requires B<SSL_OP_CIPHER_SERVER_PREFERENCE>.
352
353=item SSL_OP_TLS_ROLLBACK_BUG
354
355Disable version rollback attack detection.
356
357During the client key exchange, the client must send the same information
358about acceptable SSL/TLS protocol levels as during the first hello. Some
359clients violate this rule by adapting to the server's answer. (Example:
360the client sends an SSLv2 hello and accepts up to SSLv3.1=TLSv1, the server
361only understands up to SSLv3. In this case the client must still use the
362same SSLv3.1=TLSv1 announcement. Some clients step down to SSLv3 with respect
363to the server's answer and violate the version rollback protection.)
364
365=back
366
367The following options no longer have any effect but their identifiers are
368retained for compatibility purposes:
369
370=over 4
371
372=item SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG
373
374=item SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER
375
376=item SSL_OP_SSLEAY_080_CLIENT_DH_BUG
377
378=item SSL_OP_TLS_D5_BUG
379
380=item SSL_OP_TLS_BLOCK_PADDING_BUG
381
382=item SSL_OP_MSIE_SSLV2_RSA_PADDING
383
384=item SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG
385
386=item SSL_OP_MICROSOFT_SESS_ID_BUG
387
388=item SSL_OP_NETSCAPE_CHALLENGE_BUG
389
390=item SSL_OP_PKCS1_CHECK_1
391
392=item SSL_OP_PKCS1_CHECK_2
393
394=item SSL_OP_SINGLE_DH_USE
395
396=item SSL_OP_SINGLE_ECDH_USE
397
398=item SSL_OP_EPHEMERAL_RSA
399
400=item SSL_OP_NETSCAPE_CA_DN_BUG
401
402=item SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG
403
404=back
405
406=head1 SECURE RENEGOTIATION
407
408OpenSSL always attempts to use secure renegotiation as
409described in RFC5746. This counters the prefix attack described in
410CVE-2009-3555 and elsewhere.
411
412This attack has far reaching consequences which application writers should be
413aware of. In the description below an implementation supporting secure
414renegotiation is referred to as I<patched>. A server not supporting secure
415renegotiation is referred to as I<unpatched>.
416
417The following sections describe the operations permitted by OpenSSL's secure
418renegotiation implementation.
419
420=head2 Patched client and server
421
422Connections and renegotiation are always permitted by OpenSSL implementations.
423
424=head2 Unpatched client and patched OpenSSL server
425
426The initial connection succeeds but client renegotiation is denied by the
427server with a B<no_renegotiation> warning alert if TLS v1.0 is used or a fatal
428B<handshake_failure> alert in SSL v3.0.
429
430If the patched OpenSSL server attempts to renegotiate a fatal
431B<handshake_failure> alert is sent. This is because the server code may be
432unaware of the unpatched nature of the client.
433
434If the option B<SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION> is set then
435renegotiation B<always> succeeds.
436
437=head2 Patched OpenSSL client and unpatched server
438
439If the option B<SSL_OP_LEGACY_SERVER_CONNECT> or
440B<SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION> is set then initial connections
441and renegotiation between patched OpenSSL clients and unpatched servers
442succeeds. If neither option is set then initial connections to unpatched
443servers will fail.
444
445Setting the option B<SSL_OP_LEGACY_SERVER_CONNECT> has security implications;
446clients that are willing to connect to servers that do not implement
447RFC 5746 secure renegotiation are subject to attacks such as
448CVE-2009-3555.
449
450OpenSSL client applications wishing to ensure they can connect to unpatched
451servers should always B<set> B<SSL_OP_LEGACY_SERVER_CONNECT>
452
453OpenSSL client applications that want to ensure they can B<not> connect to
454unpatched servers (and thus avoid any security issues) should always B<clear>
455B<SSL_OP_LEGACY_SERVER_CONNECT> using SSL_CTX_clear_options() or
456SSL_clear_options().
457
458The difference between the B<SSL_OP_LEGACY_SERVER_CONNECT> and
459B<SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION> options is that
460B<SSL_OP_LEGACY_SERVER_CONNECT> enables initial connections and secure
461renegotiation between OpenSSL clients and unpatched servers B<only>, while
462B<SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION> allows initial connections
463and renegotiation between OpenSSL and unpatched clients or servers.
464
465=head2 Applicability of options to QUIC connections and streams
466
467These options apply to SSL objects referencing a QUIC connection:
468
469=over 4
470
471=item SSL_OP_ALLOW_NO_DHE_KEX
472
473=item SSL_OP_NO_TX_CERTIFICATE_COMPRESSION
474
475=item SSL_OP_NO_RX_CERTIFICATE_COMPRESSION
476
477=item SSL_OP_NO_TICKET
478
479=item SSL_OP_PRIORITIZE_CHACHA
480
481=back
482
483These options apply to SSL objects referencing a QUIC stream:
484
485=over 4
486
487=item SSL_OP_CLEANSE_PLAINTEXT
488
489=back
490
491Options on QUIC connections are initialized from the options set on SSL_CTX
492before a QUIC connection SSL object is created. Options on QUIC streams are
493initialised from the options configured on the QUIC connection SSL object
494they are created from.
495
496Setting options which relate to QUIC streams on a QUIC connection SSL object has
497no direct effect on the QUIC connection SSL object itself, but will change the
498options set on the default stream (if there is one) and will also determine the
499default options set on any future streams which are created.
500
501Other options not mentioned above do not have an effect and will be ignored.
502
503Options which relate to QUIC streams may also be set directly on QUIC stream SSL
504objects. Setting connection-related options on such an object has no effect.
505
506=head1 RETURN VALUES
507
508SSL_CTX_set_options() and SSL_set_options() return the new options bit-mask
509after adding B<options>.
510
511SSL_CTX_clear_options() and SSL_clear_options() return the new options bit-mask
512after clearing B<options>.
513
514SSL_CTX_get_options() and SSL_get_options() return the current bit-mask.
515
516SSL_get_secure_renegotiation_support() returns 1 is the peer supports
517secure renegotiation and 0 if it does not.
518
519=head1 SEE ALSO
520
521L<ssl(7)>, L<SSL_new(3)>, L<SSL_clear(3)>, L<SSL_shutdown(3)>
522L<SSL_CTX_set_tmp_dh_callback(3)>,
523L<SSL_CTX_set_min_proto_version(3)>,
524L<openssl-dhparam(1)>
525
526=head1 HISTORY
527
528The attempt to always try to use secure renegotiation was added in
529OpenSSL 0.9.8m.
530
531The B<SSL_OP_PRIORITIZE_CHACHA> and B<SSL_OP_NO_RENEGOTIATION> options
532were added in OpenSSL 1.1.1.
533
534The B<SSL_OP_NO_EXTENDED_MASTER_SECRET> and B<SSL_OP_IGNORE_UNEXPECTED_EOF>
535options were added in OpenSSL 3.0.
536
537The B<SSL_OP_> constants and the corresponding parameter and return values
538of the affected functions were changed to C<uint64_t> type in OpenSSL 3.0.
539For that reason it is no longer possible use the B<SSL_OP_> macro values
540in preprocessor C<#if> conditions. However it is still possible to test
541whether these macros are defined or not.
542
543=head1 COPYRIGHT
544
545Copyright 2001-2023 The OpenSSL Project Authors. All Rights Reserved.
546
547Licensed under the Apache License 2.0 (the "License").  You may not use
548this file except in compliance with the License.  You can obtain a copy
549in the file LICENSE in the source distribution or at
550L<https://www.openssl.org/source/license.html>.
551
552=cut
553