2 * Copyright (c) 2018 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #ifndef SecProtocolOptions_h
25 #define SecProtocolOptions_h
27 #include <Security/SecProtocolObject.h>
28 #include <Security/SecProtocolTypes.h>
29 #include <Security/SecProtocolMetadata.h>
30 #include <Security/SecTrust.h>
31 #include <Security/SecCertificate.h>
32 #include <Security/SecIdentity.h>
34 #include <dispatch/dispatch.h>
35 #include <os/object.h>
38 * The following diagram shows how clients interact with sec_protocol_options
39 * and sec_protocol_metadata when configuring and using network security protocols.
45 * +-------------+ +-------------+
47 * | options metadata |
48 * +-----\ /---------------+ +------------+----------+
49 * | sec_protocol_options | | sec_protocol_metadata |
50 * +-----------------------+ +-----------------------+
52 * Clients configure security protocols with `sec_protocol_options` instances.
53 * And they inspect protocol instances using `sec_protocol_metadata` instances.
56 #ifndef SEC_OBJECT_IMPL
58 * A `sec_protocol_options` instance is a container of options for security protocol instances,
59 * such as TLS. Protocol options are used to configure security protocols in the network stack.
60 * For example, clients may set the maximum and minimum allowed TLS versions through protocol
63 SEC_OBJECT_DECL(sec_protocol_options
);
64 #endif // !SEC_OBJECT_IMPL
68 SEC_ASSUME_NONNULL_BEGIN
71 * @function sec_protocol_options_are_equal
74 * Compare two `sec_protocol_options_t` instances.
77 * A `sec_protocol_options_t` instance.
80 * A `sec_protocol_options_t` instance.
82 * @return True if equal, and false otherwise.
84 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
86 sec_protocol_options_are_equal(sec_protocol_options_t optionsA
, sec_protocol_options_t optionsB
);
89 * @function sec_protocol_options_set_local_identity
92 * Set the local identity to be used for this protocol instance.
95 * A `sec_protocol_options_t` instance.
98 * A `sec_identity_t` instance carrying the private key and certificate.
100 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
102 sec_protocol_options_set_local_identity(sec_protocol_options_t options
, sec_identity_t identity
);
105 * @function sec_protocol_options_append_tls_ciphersuite
108 * Append a TLS ciphersuite to the set of enabled ciphersuites.
111 * A `sec_protocol_options_t` instance.
114 * A `tls_ciphersuite_t` value.
116 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
118 sec_protocol_options_append_tls_ciphersuite(sec_protocol_options_t options
, tls_ciphersuite_t ciphersuite
);
121 * @function sec_protocol_options_add_tls_ciphersuite
124 * Add a TLS ciphersuite to the set of enabled ciphersuites.
127 * A `sec_protocol_options_t` instance.
130 * A SSLCipherSuite value.
132 API_DEPRECATED("Use sec_protocol_options_append_tls_ciphersuite", macos(10.14, 10.15), ios(12.0, 13.0), watchos(5.0, 6.0), tvos(12.0, 13.0), macCatalyst(13.0, 13.0))
134 sec_protocol_options_add_tls_ciphersuite(sec_protocol_options_t options
, SSLCipherSuite ciphersuite
);
137 * @function sec_protocol_options_append_tls_ciphersuite_group
140 * Append a TLS ciphersuite group to the set of enabled ciphersuites.
143 * A `sec_protocol_options_t` instance.
146 * A SSLCipherSuiteGroup value.
148 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
150 sec_protocol_options_append_tls_ciphersuite_group(sec_protocol_options_t options
, tls_ciphersuite_group_t group
);
153 * @function sec_protocol_options_add_tls_ciphersuite_group
156 * Add a TLS ciphersuite group to the set of enabled ciphersuites.
159 * A `sec_protocol_options_t` instance.
162 * A SSLCipherSuiteGroup value.
164 API_DEPRECATED("Use sec_protocol_options_append_tls_ciphersuite_group", macos(10.14, 10.15), ios(12.0, 13.0), watchos(5.0, 6.0), tvos(12.0, 13.0), macCatalyst(13.0, 13.0))
166 sec_protocol_options_add_tls_ciphersuite_group(sec_protocol_options_t options
, SSLCiphersuiteGroup group
);
169 * @function sec_protocol_options_set_tls_min_version
172 * Set the minimum support TLS version.
175 * A `sec_protocol_options_t` instance.
178 * A SSLProtocol enum value.
180 API_DEPRECATED_WITH_REPLACEMENT("sec_protocol_options_set_min_tls_protocol_version",
181 macos(10.14, 10.15), ios(12.0, 13.0), watchos(5.0, 6.0), tvos(12.0, 13.0), macCatalyst(13.0, 13.0))
183 sec_protocol_options_set_tls_min_version(sec_protocol_options_t options
, SSLProtocol version
);
186 * @function sec_protocol_options_set_min_tls_protocol_version
189 * Set the minimum support TLS version.
192 * A `sec_protocol_options_t` instance.
195 * A tls_protocol_version_t enum value.
197 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
199 sec_protocol_options_set_min_tls_protocol_version(sec_protocol_options_t options
, tls_protocol_version_t version
);
202 * @function sec_protocol_options_get_default_min_tls_protocol_version
205 * Get the system default minimum TLS protocol version.
207 * @return The default minimum TLS version.
209 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
210 tls_protocol_version_t
211 sec_protocol_options_get_default_min_tls_protocol_version(void);
214 * @function sec_protocol_options_get_default_min_dtls_protocol_version
217 * Get the system default minimum DTLS protocol version.
219 * @return The default minimum DTLS version.
221 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
222 tls_protocol_version_t
223 sec_protocol_options_get_default_min_dtls_protocol_version(void);
226 * @function sec_protocol_options_set_tls_max_version
229 * Set the maximum support TLS version.
232 * A `sec_protocol_options_t` instance.
235 * A SSLProtocol enum value.
237 API_DEPRECATED_WITH_REPLACEMENT("sec_protocol_options_set_max_tls_protocol_version",
238 macos(10.14, 10.15), ios(12.0, 13.0), watchos(5.0, 6.0), tvos(12.0, 13.0), macCatalyst(13.0, 13.0))
240 sec_protocol_options_set_tls_max_version(sec_protocol_options_t options
, SSLProtocol version
);
243 * @function sec_protocol_options_set_max_tls_protocol_version
246 * Set the maximum support TLS version.
249 * A `sec_protocol_options_t` instance.
252 * A tls_protocol_version_t enum value.
254 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
256 sec_protocol_options_set_max_tls_protocol_version(sec_protocol_options_t options
, tls_protocol_version_t version
);
259 * @function sec_protocol_options_get_default_max_tls_protocol_version
262 * Get the system default maximum TLS protocol version.
264 * @return The default maximum TLS version.
266 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
267 tls_protocol_version_t
268 sec_protocol_options_get_default_max_tls_protocol_version(void);
271 * @function sec_protocol_options_get_default_max_tls_protocol_version
274 * Get the system default maximum DTLS protocol version.
276 * @return The default maximum DTLS version.
278 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
279 tls_protocol_version_t
280 sec_protocol_options_get_default_max_dtls_protocol_version(void);
283 * @function sec_protocol_options_add_tls_application_protocol
286 * Add an application protocol supported by clients of this protocol instance.
289 * A `sec_protocol_options_t` instance.
291 * @param application_protocol
292 * A NULL-terminated string defining the application protocol.
294 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
296 sec_protocol_options_add_tls_application_protocol(sec_protocol_options_t options
, const char *application_protocol
);
299 * @function sec_protocol_options_set_tls_server_name
302 * Set the server name to be used when verifying the peer's certificate. This will override
303 * the server name obtained from the endpoint.
306 * A `sec_protocol_options_t` instance.
309 * A NULL-terminated string carrying the server name.
311 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
313 sec_protocol_options_set_tls_server_name(sec_protocol_options_t options
, const char *server_name
);
316 * @function sec_protocol_options_set_tls_diffie_hellman_parameters
319 * Set the supported Diffie-Hellman parameters.
322 * A `sec_protocol_options_t` instance.
325 * A dispatch_data_t containing legacy Diffie-Hellman parameters.
327 API_DEPRECATED("DHE ciphersuites are no longer supported", macos(10.14, 10.15), ios(12.0, 13.0), watchos(5.0, 6.0), tvos(12.0, 13.0))
329 sec_protocol_options_set_tls_diffie_hellman_parameters(sec_protocol_options_t options
, dispatch_data_t params
);
332 * @function sec_protocol_options_add_pre_shared_key
335 * Add a pre-shared key (PSK) and its identity to the options.
338 * A `sec_protocol_options_t` instance.
341 * A dispatch_data_t containing a PSK blob.
343 * @param psk_identity
344 * A dispatch_data_t containing a PSK identity blob.
346 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
348 sec_protocol_options_add_pre_shared_key(sec_protocol_options_t options
, dispatch_data_t psk
, dispatch_data_t psk_identity
);
351 * @function sec_protocol_options_set_tls_pre_shared_key_identity_hint
354 * Set the PSK identity hint to use by servers when negotiating a PSK ciphersuite.
355 * See https://tools.ietf.org/html/rfc4279 for more details.
358 * A `sec_protocol_options_t` instance.
360 * @param psk_identity_hint
361 * A dispatch_data_t containing a PSK identity hint.
363 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
365 sec_protocol_options_set_tls_pre_shared_key_identity_hint(sec_protocol_options_t options
, dispatch_data_t psk_identity_hint
);
370 * @block sec_protocol_pre_shared_key_selection_complete_t
373 * Block to be invoked when a PSK selection event is complete and a PSK identity is chosen.
375 * @param psk_identity
376 * A `dispatch_data_t` instance carrying the chosen PSK identity, or nil if one does not match.
378 typedef void (^sec_protocol_pre_shared_key_selection_complete_t
)(dispatch_data_t _Nullable psk_identity
);
381 * @block sec_protocol_pre_shared_key_selection_t
384 * Block to be invoked when the client must choose a PSK identity given a hint from its peer.
387 * A `sec_protocol_metadata_t` instance.
389 * @param psk_identity_hint
390 * A `dispatch_data_t` object carrying the peer's (optional) PSK identity hint.
393 * A `sec_protocol_pre_shared_key_selection_complete_t` block to be invoked when PSK selection is complete.
395 typedef void (^sec_protocol_pre_shared_key_selection_t
)(sec_protocol_metadata_t metadata
, dispatch_data_t _Nullable psk_identity_hint
, sec_protocol_pre_shared_key_selection_complete_t complete
);
398 * @function sec_protocol_options_set_pre_shared_key_selection_block
401 * Set the PSK selection block.
404 * A `sec_protocol_options_t` instance.
406 * @param psk_selection_block
407 * A `sec_protocol_pre_shared_key_selection_t` block.
409 * @params psk_selection_queue
410 * A `dispatch_queue_t` on which the PSK selection block should be called.
412 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
414 sec_protocol_options_set_pre_shared_key_selection_block(sec_protocol_options_t options
, sec_protocol_pre_shared_key_selection_t psk_selection_block
, dispatch_queue_t psk_selection_queue
);
419 * @function sec_protocol_options_set_tls_tickets_enabled
422 * Enable or disable TLS session ticket support.
425 * A `sec_protocol_options_t` instance.
427 * @param tickets_enabled
428 * Flag to enable or disable TLS session ticket support.
430 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
432 sec_protocol_options_set_tls_tickets_enabled(sec_protocol_options_t options
, bool tickets_enabled
);
435 * @function sec_protocol_options_set_tls_is_fallback_attempt
438 * Signal if this is a TLS fallback attempt.
440 * A fallback attempt is one following a previously failed TLS connection
441 * due to version or parameter incompatibility, e.g., when speaking to a server
442 * that does not support a client-offered ciphersuite.
444 * Clients MUST NOT enable fallback for fresh connections.
447 * A `sec_protocol_options_t` instance.
449 * @param is_fallback_attempt
450 * Set a flag indicating that this is a TLS fallback attempt.
452 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
454 sec_protocol_options_set_tls_is_fallback_attempt(sec_protocol_options_t options
, bool is_fallback_attempt
);
457 * @function sec_protocol_options_set_tls_resumption_enabled
460 * Enable or disable TLS session resumption.
463 * A `sec_protocol_options_t` instance.
465 * @param resumption_enabled
466 * Flag to enable or disable TLS session resumption.
468 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
470 sec_protocol_options_set_tls_resumption_enabled(sec_protocol_options_t options
, bool resumption_enabled
);
473 * @function sec_protocol_options_set_tls_false_start_enabled
476 * Enable or disable TLS False Start.
479 * A `sec_protocol_options_t` instance.
481 * @param false_start_enabled
482 * Flag to enable or disable TLS False Start.
484 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
486 sec_protocol_options_set_tls_false_start_enabled(sec_protocol_options_t options
, bool false_start_enabled
);
489 * @function nw_protocol_options_set_tls_ocsp_enabled
492 * Enable or disable OCSP support.
495 * A `sec_protocol_options_t` instance.
497 * @param ocsp_enabled
498 * Flag to enable or disable OCSP support.
500 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
502 sec_protocol_options_set_tls_ocsp_enabled(sec_protocol_options_t options
, bool ocsp_enabled
);
505 * @function sec_protocol_options_set_tls_sct_enabled
508 * Enable or disable SCT (signed certificate timestamp) support.
511 * A `sec_protocol_options_t` instance.
514 * Flag to enable or disable SCT support.
516 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
518 sec_protocol_options_set_tls_sct_enabled(sec_protocol_options_t options
, bool sct_enabled
);
521 * @function sec_protocol_options_set_tls_renegotiation_enabled
524 * Enable or disable TLS (1.2 and prior) session renegotiation. This defaults to `true`.
527 * A `sec_protocol_options_t` instance.
529 * @param renegotiation_enabled
530 * Flag to enable or disable TLS (1.2 and prior) session renegotiation.
532 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
534 sec_protocol_options_set_tls_renegotiation_enabled(sec_protocol_options_t options
, bool renegotiation_enabled
);
537 * @function sec_protocol_options_set_peer_authentication_required
540 * Enable or disable peer authentication. Clients default to true, whereas servers default to false.
543 * A `sec_protocol_options_t` instance.
545 * @param peer_authentication_required
546 * Flag to enable or disable mandatory peer authentication.
548 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
550 sec_protocol_options_set_peer_authentication_required(sec_protocol_options_t options
, bool peer_authentication_required
);
553 * @function sec_protocol_options_set_peer_authentication_optional
556 * When this is enabled, the endpoint requests the peer certificate, but if none is provided, the
557 * endpoint still proceeds with the connection. Default false for servers; always false for clients (this
558 * function is a no-op for clients). If peer_authentication_required is set to true via
559 * sec_protocol_options_set_peer_authentication_required(), peer_authentication_optional will be disregarded
560 * and the peer certificate will be required.
563 * A `sec_protocol_options_t` instance.
565 * @param peer_authentication_optional
566 * Flag to enable or disable requested peer authentication.
568 SPI_AVAILABLE(macos(10.16), ios(14.0), watchos(7.0), tvos(14.0))
570 sec_protocol_options_set_peer_authentication_optional(sec_protocol_options_t options
, bool peer_authentication_optional
);
575 * @block sec_protocol_key_update_complete_t
578 * Block to be invoked when a key update event is handled.
580 typedef void (^sec_protocol_key_update_complete_t
)(void);
583 * @block sec_protocol_key_update_t
586 * Block to be invoked when the protocol key MUST be updated.
589 * A `sec_protocol_metadata_t` instance.
592 * A `sec_protocol_key_update_complete_t` to be invoked when the key update is complete.
594 typedef void (^sec_protocol_key_update_t
)(sec_protocol_metadata_t metadata
, sec_protocol_key_update_complete_t complete
);
597 * @block sec_protocol_challenge_complete_t
600 * Block to be invoked when an identity (authentication) challenge is complete.
602 * Note: prior to macOS 10.15, iOS 13.0, watchOS 6.0, and tvOS 13.0, calling this
603 * block with a NULL `identity` argument was prohibited.
606 * A `sec_identity_t` containing the identity to use for this challenge.
608 typedef void (^sec_protocol_challenge_complete_t
)(sec_identity_t __nullable identity
);
611 * @block sec_protocol_challenge_t
614 * Block to be invoked when the protocol instance is issued a challenge (e.g., a TLS certificate request).
617 * A `sec_protocol_metadata_t` instance.
620 * A `sec_protocol_challenge_complete_t` to be invoked when the challenge is complete.
622 typedef void (^sec_protocol_challenge_t
)(sec_protocol_metadata_t metadata
, sec_protocol_challenge_complete_t complete
);
625 * @block sec_protocol_verify_complete_t
628 * Block to be invoked when verification is complete.
631 * A `bool` indicating if verification succeeded or failed.
633 typedef void (^sec_protocol_verify_complete_t
)(bool result
);
636 * @block sec_protocol_verify_t
639 * Block to be invoked when the protocol instance must verify the peer.
641 * NOTE: this may be called one or more times for a given connection.
644 * A `sec_protocol_metadata_t` instance.
647 * A `sec_trust_t` instance.
650 * A `sec_protocol_verify_finish_t` to be invoked when verification is complete.
652 typedef void (^sec_protocol_verify_t
)(sec_protocol_metadata_t metadata
, sec_trust_t trust_ref
, sec_protocol_verify_complete_t complete
);
655 * @function sec_protocol_options_set_key_update_block
658 * Set the key update block.
661 * A `sec_protocol_options_t` instance.
663 * @param key_update_block
664 * A `sec_protocol_key_update_t` block.
666 * @params key_update_queue
667 * A `dispatch_queue_t` on which the key update block should be called.
669 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
671 sec_protocol_options_set_key_update_block(sec_protocol_options_t options
, sec_protocol_key_update_t key_update_block
, dispatch_queue_t key_update_queue
);
674 * @function sec_protocol_options_set_challenge_block
677 * Set the challenge block.
680 * A `sec_protocol_options_t` instance.
682 * @params challenge_block
683 * A `sec_protocol_challenge_t` block.
685 * @params challenge_queue
686 * A `dispatch_queue_t` on which the challenge block should be called.
688 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
690 sec_protocol_options_set_challenge_block(sec_protocol_options_t options
, sec_protocol_challenge_t challenge_block
, dispatch_queue_t challenge_queue
);
693 * @function sec_protocol_options_set_verify_block
696 * Set the verify block.
699 * A `sec_protocol_options_t` instance.
701 * @params verify_block
702 * A `sec_protocol_verify_t` block.
704 * @params verify_block_queue
705 * A `dispatch_queue_t` on which the verify block should be called.
707 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
709 sec_protocol_options_set_verify_block(sec_protocol_options_t options
, sec_protocol_verify_t verify_block
, dispatch_queue_t verify_block_queue
);
713 SEC_ASSUME_NONNULL_END
717 #endif // SecProtocolOptions_h