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))
133 API_UNAVAILABLE(iosmac
)
135 sec_protocol_options_add_tls_ciphersuite(sec_protocol_options_t options
, SSLCipherSuite ciphersuite
);
138 * @function sec_protocol_options_append_tls_ciphersuite_group
141 * Append a TLS ciphersuite group to the set of enabled ciphersuites.
144 * A `sec_protocol_options_t` instance.
147 * A SSLCipherSuiteGroup value.
149 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
151 sec_protocol_options_append_tls_ciphersuite_group(sec_protocol_options_t options
, tls_ciphersuite_group_t group
);
154 * @function sec_protocol_options_add_tls_ciphersuite_group
157 * Add a TLS ciphersuite group to the set of enabled ciphersuites.
160 * A `sec_protocol_options_t` instance.
163 * A SSLCipherSuiteGroup value.
165 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))
166 API_UNAVAILABLE(iosmac
)
168 sec_protocol_options_add_tls_ciphersuite_group(sec_protocol_options_t options
, SSLCiphersuiteGroup group
);
171 * @function sec_protocol_options_set_tls_min_version
174 * Set the minimum support TLS version.
177 * A `sec_protocol_options_t` instance.
180 * A SSLProtocol enum value.
182 API_DEPRECATED_WITH_REPLACEMENT("sec_protocol_options_set_min_tls_protocol_version",
183 macos(10.14, 10.15), ios(12.0, 13.0), watchos(5.0, 6.0), tvos(12.0, 13.0))
184 API_UNAVAILABLE(iosmac
)
186 sec_protocol_options_set_tls_min_version(sec_protocol_options_t options
, SSLProtocol version
);
189 * @function sec_protocol_options_set_min_tls_protocol_version
192 * Set the minimum support TLS version.
195 * A `sec_protocol_options_t` instance.
198 * A tls_protocol_version_t enum value.
200 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
202 sec_protocol_options_set_min_tls_protocol_version(sec_protocol_options_t options
, tls_protocol_version_t version
);
205 * @function sec_protocol_options_get_default_min_tls_protocol_version
208 * Get the system default minimum TLS protocol version.
210 * @return The default minimum TLS version.
212 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
213 tls_protocol_version_t
214 sec_protocol_options_get_default_min_tls_protocol_version(void);
217 * @function sec_protocol_options_get_default_min_dtls_protocol_version
220 * Get the system default minimum DTLS protocol version.
222 * @return The default minimum DTLS version.
224 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
225 tls_protocol_version_t
226 sec_protocol_options_get_default_min_dtls_protocol_version(void);
229 * @function sec_protocol_options_set_tls_max_version
232 * Set the maximum support TLS version.
235 * A `sec_protocol_options_t` instance.
238 * A SSLProtocol enum value.
240 API_DEPRECATED_WITH_REPLACEMENT("sec_protocol_options_set_max_tls_protocol_version",
241 macos(10.14, 10.15), ios(12.0, 13.0), watchos(5.0, 6.0), tvos(12.0, 13.0))
242 API_UNAVAILABLE(iosmac
)
244 sec_protocol_options_set_tls_max_version(sec_protocol_options_t options
, SSLProtocol version
);
247 * @function sec_protocol_options_set_max_tls_protocol_version
250 * Set the maximum support TLS version.
253 * A `sec_protocol_options_t` instance.
256 * A tls_protocol_version_t enum value.
258 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
260 sec_protocol_options_set_max_tls_protocol_version(sec_protocol_options_t options
, tls_protocol_version_t version
);
263 * @function sec_protocol_options_get_default_max_tls_protocol_version
266 * Get the system default maximum TLS protocol version.
268 * @return The default maximum TLS version.
270 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
271 tls_protocol_version_t
272 sec_protocol_options_get_default_max_tls_protocol_version(void);
275 * @function sec_protocol_options_get_default_max_tls_protocol_version
278 * Get the system default maximum DTLS protocol version.
280 * @return The default maximum DTLS version.
282 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
283 tls_protocol_version_t
284 sec_protocol_options_get_default_max_dtls_protocol_version(void);
287 * @function sec_protocol_options_add_tls_application_protocol
290 * Add an application protocol supported by clients of this protocol instance.
293 * A `sec_protocol_options_t` instance.
295 * @param application_protocol
296 * A NULL-terminated string defining the application protocol.
298 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
300 sec_protocol_options_add_tls_application_protocol(sec_protocol_options_t options
, const char *application_protocol
);
303 * @function sec_protocol_options_set_tls_server_name
306 * Set the server (domain) name to be used in the TLS SNI. This will override
307 * the server name obtained from the endpoint.
310 * A `sec_protocol_options_t` instance.
313 * A NULL-terminated string carrying the server (domain) name.
315 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
317 sec_protocol_options_set_tls_server_name(sec_protocol_options_t options
, const char *server_name
);
320 * @function sec_protocol_options_set_tls_diffie_hellman_parameters
323 * Set the supported Diffie-Hellman parameters.
326 * A `sec_protocol_options_t` instance.
329 * A dispatch_data_t containing legacy Diffie-Hellman parameters.
331 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))
333 sec_protocol_options_set_tls_diffie_hellman_parameters(sec_protocol_options_t options
, dispatch_data_t params
);
336 * @function sec_protocol_options_add_pre_shared_key
339 * Add a pre-shared key (PSK) and its identity to the options.
342 * A `sec_protocol_options_t` instance.
345 * A dispatch_data_t containing a PSK blob.
347 * @param psk_identity
348 * A dispatch_data_t containing a PSK identity blob.
350 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
352 sec_protocol_options_add_pre_shared_key(sec_protocol_options_t options
, dispatch_data_t psk
, dispatch_data_t psk_identity
);
355 * @function sec_protocol_options_set_tls_pre_shared_key_identity_hint
358 * Set the PSK identity hint to use by servers when negotiating a PSK ciphersuite.
359 * See https://tools.ietf.org/html/rfc4279 for more details.
362 * A `sec_protocol_options_t` instance.
364 * @param psk_identity_hint
365 * A dispatch_data_t containing a PSK identity hint.
367 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
369 sec_protocol_options_set_tls_pre_shared_key_identity_hint(sec_protocol_options_t options
, dispatch_data_t psk_identity_hint
);
374 * @block sec_protocol_pre_shared_key_selection_complete_t
377 * Block to be invoked when a PSK selection event is complete and a PSK identity is chosen.
379 * @param psk_identity
380 * A `dispatch_data_t` instance carrying the chosen PSK identity, or nil if one does not match.
382 typedef void (^sec_protocol_pre_shared_key_selection_complete_t
)(dispatch_data_t _Nullable psk_identity
);
385 * @block sec_protocol_pre_shared_key_selection_t
388 * Block to be invoked when the client must choose a PSK identity given a hint from its peer.
391 * A `sec_protocol_metadata_t` instance.
393 * @param psk_identity_hint
394 * A `dispatch_data_t` object carrying the peer's (optional) PSK identity hint.
397 * A `sec_protocol_pre_shared_key_selection_complete_t` block to be invoked when PSK selection is complete.
399 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
);
402 * @function sec_protocol_options_set_pre_shared_key_selection_block
405 * Set the PSK selection block.
408 * A `sec_protocol_options_t` instance.
410 * @param psk_selection_block
411 * A `sec_protocol_pre_shared_key_selection_t` block.
413 * @params psk_selection_queue
414 * A `dispatch_queue_t` on which the PSK selection block should be called.
416 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
418 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
);
423 * @function sec_protocol_options_set_tls_tickets_enabled
426 * Enable or disable TLS session ticket support.
429 * A `sec_protocol_options_t` instance.
431 * @param tickets_enabled
432 * Flag to enable or disable TLS session ticket support.
434 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
436 sec_protocol_options_set_tls_tickets_enabled(sec_protocol_options_t options
, bool tickets_enabled
);
439 * @function sec_protocol_options_set_tls_is_fallback_attempt
442 * Signal if this is a TLS fallback attempt.
444 * A fallback attempt is one following a previously failed TLS connection
445 * due to version or parameter incompatibility, e.g., when speaking to a server
446 * that does not support a client-offered ciphersuite.
448 * Clients MUST NOT enable fallback for fresh connections.
451 * A `sec_protocol_options_t` instance.
453 * @param is_fallback_attempt
454 * Set a flag indicating that this is a TLS fallback attempt.
456 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
458 sec_protocol_options_set_tls_is_fallback_attempt(sec_protocol_options_t options
, bool is_fallback_attempt
);
461 * @function sec_protocol_options_set_tls_resumption_enabled
464 * Enable or disable TLS session resumption.
467 * A `sec_protocol_options_t` instance.
469 * @param resumption_enabled
470 * Flag to enable or disable TLS session resumption.
472 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
474 sec_protocol_options_set_tls_resumption_enabled(sec_protocol_options_t options
, bool resumption_enabled
);
477 * @function sec_protocol_options_set_tls_false_start_enabled
480 * Enable or disable TLS False Start.
483 * A `sec_protocol_options_t` instance.
485 * @param false_start_enabled
486 * Flag to enable or disable TLS False Start.
488 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
490 sec_protocol_options_set_tls_false_start_enabled(sec_protocol_options_t options
, bool false_start_enabled
);
493 * @function nw_protocol_options_set_tls_ocsp_enabled
496 * Enable or disable OCSP support.
499 * A `sec_protocol_options_t` instance.
501 * @param ocsp_enabled
502 * Flag to enable or disable OCSP support.
504 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
506 sec_protocol_options_set_tls_ocsp_enabled(sec_protocol_options_t options
, bool ocsp_enabled
);
509 * @function sec_protocol_options_set_tls_sct_enabled
512 * Enable or disable SCT (signed certificate timestamp) support.
515 * A `sec_protocol_options_t` instance.
518 * Flag to enable or disable SCT support.
520 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
522 sec_protocol_options_set_tls_sct_enabled(sec_protocol_options_t options
, bool sct_enabled
);
525 * @function sec_protocol_options_set_tls_renegotiation_enabled
528 * Enable or disable TLS (1.2 and prior) session renegotiation. This defaults to `true`.
531 * A `sec_protocol_options_t` instance.
533 * @param renegotiation_enabled
534 * Flag to enable or disable TLS (1.2 and prior) session renegotiation.
536 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
538 sec_protocol_options_set_tls_renegotiation_enabled(sec_protocol_options_t options
, bool renegotiation_enabled
);
541 * @function sec_protocol_options_set_peer_authentication_required
544 * Enable or disable peer authentication. Clients default to true, whereas servers default to false.
547 * A `sec_protocol_options_t` instance.
549 * @param peer_authentication_required
550 * Flag to enable or disable mandatory peer authentication.
552 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
554 sec_protocol_options_set_peer_authentication_required(sec_protocol_options_t options
, bool peer_authentication_required
);
559 * @block sec_protocol_key_update_complete_t
562 * Block to be invoked when a key update event is handled.
564 typedef void (^sec_protocol_key_update_complete_t
)(void);
567 * @block sec_protocol_key_update_t
570 * Block to be invoked when the protocol key MUST be updated.
573 * A `sec_protocol_metadata_t` instance.
576 * A `sec_protocol_key_update_complete_t` to be invoked when the key update is complete.
578 typedef void (^sec_protocol_key_update_t
)(sec_protocol_metadata_t metadata
, sec_protocol_key_update_complete_t complete
);
581 * @block sec_protocol_challenge_complete_t
584 * Block to be invoked when an identity (authentication) challenge is complete.
586 * Note: prior to macOS 10.15, iOS 13.0, watchOS 6.0, and tvOS 13.0, calling this
587 * block with a NULL `identity` argument was prohibited.
590 * A `sec_identity_t` containing the identity to use for this challenge.
592 typedef void (^sec_protocol_challenge_complete_t
)(sec_identity_t __nullable identity
);
595 * @block sec_protocol_challenge_t
598 * Block to be invoked when the protocol instance is issued a challenge (e.g., a TLS certificate request).
601 * A `sec_protocol_metadata_t` instance.
604 * A `sec_protocol_challenge_complete_t` to be invoked when the challenge is complete.
606 typedef void (^sec_protocol_challenge_t
)(sec_protocol_metadata_t metadata
, sec_protocol_challenge_complete_t complete
);
609 * @block sec_protocol_verify_complete_t
612 * Block to be invoked when verification is complete.
615 * A `bool` indicating if verification succeeded or failed.
617 typedef void (^sec_protocol_verify_complete_t
)(bool result
);
620 * @block sec_protocol_verify_t
623 * Block to be invoked when the protocol instance must verify the peer.
625 * NOTE: this may be called one or more times for a given connection.
628 * A `sec_protocol_metadata_t` instance.
631 * A `sec_trust_t` instance.
634 * A `sec_protocol_verify_finish_t` to be invoked when verification is complete.
636 typedef void (^sec_protocol_verify_t
)(sec_protocol_metadata_t metadata
, sec_trust_t trust_ref
, sec_protocol_verify_complete_t complete
);
639 * @function sec_protocol_options_set_key_update_block
642 * Set the key update block.
645 * A `sec_protocol_options_t` instance.
647 * @param key_update_block
648 * A `sec_protocol_key_update_t` block.
650 * @params key_update_queue
651 * A `dispatch_queue_t` on which the key update block should be called.
653 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
655 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
);
658 * @function sec_protocol_options_set_challenge_block
661 * Set the challenge block.
664 * A `sec_protocol_options_t` instance.
666 * @params challenge_block
667 * A `sec_protocol_challenge_t` block.
669 * @params challenge_queue
670 * A `dispatch_queue_t` on which the challenge block should be called.
672 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
674 sec_protocol_options_set_challenge_block(sec_protocol_options_t options
, sec_protocol_challenge_t challenge_block
, dispatch_queue_t challenge_queue
);
677 * @function sec_protocol_options_set_verify_block
680 * Set the verify block.
683 * A `sec_protocol_options_t` instance.
685 * @params verify_block
686 * A `sec_protocol_verify_t` block.
688 * @params verify_block_queue
689 * A `dispatch_queue_t` on which the verify block should be called.
691 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
693 sec_protocol_options_set_verify_block(sec_protocol_options_t options
, sec_protocol_verify_t verify_block
, dispatch_queue_t verify_block_queue
);
697 SEC_ASSUME_NONNULL_END
701 #endif // SecProtocolOptions_h