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