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/SecBase.h>
29 #include <Security/SecureTransport.h>
30 #include <Security/SecTrust.h>
31 #include <Security/SecCertificate.h>
32 #include <Security/SecIdentity.h>
33 #include <Security/SecProtocolMetadata.h>
35 #include <dispatch/dispatch.h>
36 #include <os/object.h>
39 * The following diagram shows how clients interact with sec_protocol_options
40 * and sec_protocol_metadata when configuring and using network security protocols.
46 * +-------------+ +-------------+
48 * | options metadata |
49 * +-----\ /---------------+ +------------+----------+
50 * | sec_protocol_options | | sec_protocol_metadata |
51 * +-----------------------+ +-----------------------+
53 * Clients configure security protocols with `sec_protocol_options` instances.
54 * And they inspect protocol instances using `sec_protocol_metadata` instances.
57 #ifndef SEC_OBJECT_IMPL
59 * A `sec_protocol_options` instance is a container of options for security protocol instances,
60 * such as TLS. Protocol options are used to configure security protocols in the network stack.
61 * For example, clients may set the maximum and minimum allowed TLS versions through protocol
64 SEC_OBJECT_DECL(sec_protocol_options
);
65 #endif // !SEC_OBJECT_IMPL
69 SEC_ASSUME_NONNULL_BEGIN
72 * @function sec_protocol_options_set_local_identity
75 * Set the local identity to be used for this protocol instance.
78 * A `sec_protocol_options_t` instance.
81 * A `sec_identity_t` instance carrying the private key and certificate.
83 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
85 sec_protocol_options_set_local_identity(sec_protocol_options_t options
, sec_identity_t identity
);
88 * @function sec_protocol_options_add_tls_ciphersuite
91 * Add a TLS ciphersuite to the set of enabled ciphersuites.
94 * A `sec_protocol_options_t` instance.
97 * A SSLCipherSuite value.
99 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
101 sec_protocol_options_add_tls_ciphersuite(sec_protocol_options_t options
, SSLCipherSuite ciphersuite
);
104 * @function sec_protocol_options_add_tls_ciphersuite_group
107 * Add a TLS ciphersuite group to the set of enabled ciphersuites.
110 * A `sec_protocol_options_t` instance.
113 * A SSLCipherSuiteGroup value.
115 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
117 sec_protocol_options_add_tls_ciphersuite_group(sec_protocol_options_t options
, SSLCiphersuiteGroup group
);
120 * @function sec_protocol_options_set_tls_min_version
123 * Set the minimum support TLS version.
126 * A `sec_protocol_options_t` instance.
129 * A SSLProtocol enum value.
131 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
133 sec_protocol_options_set_tls_min_version(sec_protocol_options_t options
, SSLProtocol version
);
136 * @function sec_protocol_options_set_tls_max_version
139 * Set the maximum support TLS version.
142 * A `sec_protocol_options_t` instance.
145 * A SSLProtocol enum value.
147 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
149 sec_protocol_options_set_tls_max_version(sec_protocol_options_t options
, SSLProtocol version
);
152 * @function sec_protocol_options_add_tls_application_protocol
155 * Add an application protocol supported by clients of this protocol instance.
158 * A `sec_protocol_options_t` instance.
160 * @param application_protocol
161 * A NULL-terminated string defining the application protocol.
163 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
165 sec_protocol_options_add_tls_application_protocol(sec_protocol_options_t options
, const char *application_protocol
);
168 * @function sec_protocol_options_set_tls_server_name
171 * Set the server (domain) name to be used in the TLS SNI. This will override
172 * the server name obtained from the endpoint.
175 * A `sec_protocol_options_t` instance.
178 * A NULL-terminated string carrying the server (domain) name.
180 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
182 sec_protocol_options_set_tls_server_name(sec_protocol_options_t options
, const char *server_name
);
185 * @function sec_protocol_options_set_tls_diffie_hellman_parameters
188 * Set the supported Diffie-Hellman parameters.
191 * A `sec_protocol_options_t` instance.
194 * A dispatch_data_t containing legacy Diffie-Hellman parameters.
196 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
198 sec_protocol_options_set_tls_diffie_hellman_parameters(sec_protocol_options_t options
, dispatch_data_t params
);
201 * @function sec_protocol_options_add_pre_shared_key
204 * Add a pre-shared key (PSK) and its identity to the options.
207 * A `sec_protocol_options_t` instance.
210 * A dispatch_data_t containing a PSK blob.
212 * @param psk_identity
213 * A dispatch_data_t containing a PSK identity blob.
215 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
217 sec_protocol_options_add_pre_shared_key(sec_protocol_options_t options
, dispatch_data_t psk
, dispatch_data_t psk_identity
);
220 * @function sec_protocol_options_set_tls_tickets_enabled
223 * Enable or disable TLS session ticket support.
226 * A `sec_protocol_options_t` instance.
228 * @param tickets_enabled
229 * Flag to enable or disable TLS session ticket support.
231 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
233 sec_protocol_options_set_tls_tickets_enabled(sec_protocol_options_t options
, bool tickets_enabled
);
236 * @function sec_protocol_options_set_tls_is_fallback_attempt
239 * Signal if this is a TLS fallback attempt.
241 * A fallback attempt is one following a previously failed TLS connection
242 * due to version or parameter incompatibility, e.g., when speaking to a server
243 * that does not support a client-offered ciphersuite.
245 * Clients MUST NOT enable fallback for fresh connections.
248 * A `sec_protocol_options_t` instance.
250 * @param is_fallback_attempt
251 * Set a flag indicating that this is a TLS fallback attempt.
253 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
255 sec_protocol_options_set_tls_is_fallback_attempt(sec_protocol_options_t options
, bool is_fallback_attempt
);
258 * @function sec_protocol_options_set_tls_resumption_enabled
261 * Enable or disable TLS session resumption.
264 * A `sec_protocol_options_t` instance.
266 * @param resumption_enabled
267 * Flag to enable or disable TLS session resumption.
269 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
271 sec_protocol_options_set_tls_resumption_enabled(sec_protocol_options_t options
, bool resumption_enabled
);
274 * @function sec_protocol_options_set_tls_false_start_enabled
277 * Enable or disable TLS False Start.
280 * A `sec_protocol_options_t` instance.
282 * @param false_start_enabled
283 * Flag to enable or disable TLS False Start.
285 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
287 sec_protocol_options_set_tls_false_start_enabled(sec_protocol_options_t options
, bool false_start_enabled
);
290 * @function nw_protocol_options_set_tls_ocsp_enabled
293 * Enable or disable OCSP support.
296 * A `sec_protocol_options_t` instance.
298 * @param ocsp_enabled
299 * Flag to enable or disable OCSP support.
301 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
303 sec_protocol_options_set_tls_ocsp_enabled(sec_protocol_options_t options
, bool ocsp_enabled
);
306 * @function sec_protocol_options_set_tls_sct_enabled
309 * Enable or disable SCT (signed certificate timestamp) support.
312 * A `sec_protocol_options_t` instance.
315 * Flag to enable or disable SCT support.
317 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
319 sec_protocol_options_set_tls_sct_enabled(sec_protocol_options_t options
, bool sct_enabled
);
322 * @function sec_protocol_options_set_tls_renegotiation_enabled
325 * Enable or disable TLS (1.2 and prior) session renegotiation. This defaults to `true`.
328 * A `sec_protocol_options_t` instance.
330 * @param renegotiation_enabled
331 * Flag to enable or disable TLS (1.2 and prior) session renegotiation.
333 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
335 sec_protocol_options_set_tls_renegotiation_enabled(sec_protocol_options_t options
, bool renegotiation_enabled
);
338 * @function sec_protocol_options_set_peer_authentication_required
341 * Enable or disable peer authentication. Clients default to true, whereas servers default to false.
344 * A `sec_protocol_options_t` instance.
346 * @param peer_authentication_required
347 * Flag to enable or disable mandatory peer authentication.
349 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
351 sec_protocol_options_set_peer_authentication_required(sec_protocol_options_t options
, bool peer_authentication_required
);
356 * @block sec_protocol_key_update_complete_t
359 * Block to be invoked when a key update event is handled.
361 typedef void (^sec_protocol_key_update_complete_t
)(void);
364 * @block sec_protocol_key_update_t
367 * Block to be invoked when the protocol key MUST be updated.
370 * A `sec_protocol_metadata_t` instance.
373 * A `sec_protocol_key_update_complete_t` to be invoked when the key update is complete.
375 typedef void (^sec_protocol_key_update_t
)(sec_protocol_metadata_t metadata
, sec_protocol_key_update_complete_t complete
);
378 * @block sec_protocol_challenge_complete_t
381 * Block to be invoked when an identity (authentication) challenge is complete.
384 * A `sec_identity_t` containing the identity to use for this challenge.
386 typedef void (^sec_protocol_challenge_complete_t
)(sec_identity_t identity
);
389 * @block sec_protocol_challenge_t
392 * Block to be invoked when the protocol instance is issued a challenge (e.g., a TLS certificate request).
395 * A `sec_protocol_metadata_t` instance.
398 * A `sec_protocol_challenge_complete_t` to be invoked when the challenge is complete.
400 typedef void (^sec_protocol_challenge_t
)(sec_protocol_metadata_t metadata
, sec_protocol_challenge_complete_t complete
);
403 * @block sec_protocol_verify_complete_t
406 * Block to be invoked when verification is complete.
409 * A `bool` indicating if verification succeeded or failed.
411 typedef void (^sec_protocol_verify_complete_t
)(bool result
);
414 * @block sec_protocol_verify_t
417 * Block to be invoked when the protocol instance must verify the peer.
419 * NOTE: this may be called one or more times for a given connection.
422 * A `sec_protocol_metadata_t` instance.
425 * A `sec_trust_t` instance.
428 * A `sec_protocol_verify_finish_t` to be invoked when verification is complete.
430 typedef void (^sec_protocol_verify_t
)(sec_protocol_metadata_t metadata
, sec_trust_t trust_ref
, sec_protocol_verify_complete_t complete
);
433 * @function sec_protocol_options_set_key_update_block
436 * Set the key update block.
439 * A `sec_protocol_options_t` instance.
441 * @param key_update_block
442 * A `sec_protocol_key_update_t` block.
444 * @params key_update_queue
445 * A `dispatch_queue_t` on which the key update block should be called.
447 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
449 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
);
452 * @function sec_protocol_options_set_challenge_block
455 * Set the challenge block.
458 * A `sec_protocol_options_t` instance.
460 * @params challenge_block
461 * A `sec_protocol_challenge_t` block.
463 * @params challenge_queue
464 * A `dispatch_queue_t` on which the challenge block should be called.
466 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
468 sec_protocol_options_set_challenge_block(sec_protocol_options_t options
, sec_protocol_challenge_t challenge_block
, dispatch_queue_t challenge_queue
);
471 * @function sec_protocol_options_set_verify_block
474 * Set the verify block.
477 * A `sec_protocol_options_t` instance.
479 * @params verify_block
480 * A `sec_protocol_verify_t` block.
482 * @params verify_block_queue
483 * A `dispatch_queue_t` on which the verify block should be called.
485 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
487 sec_protocol_options_set_verify_block(sec_protocol_options_t options
, sec_protocol_verify_t verify_block
, dispatch_queue_t verify_block_queue
);
491 SEC_ASSUME_NONNULL_END
495 #endif // SecProtocolOptions_h