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