6 #ifndef SecProtocolPriv_h
7 #define SecProtocolPriv_h
9 #include <Security/SecProtocolOptions.h>
10 #include <Security/SecProtocolMetadata.h>
11 #include <Security/SecProtocolConfiguration.h>
12 #include <Security/SecureTransportPriv.h>
13 #include <Security/SecCertificatePriv.h>
19 /* See: https://tools.ietf.org/html/rfc8446#section-4.2.7 */
20 typedef CF_ENUM(uint16_t, tls_key_exchange_group_t
) {
21 tls_key_exchange_group_Secp256r1
= 0x0017,
22 tls_key_exchange_group_Secp384r1
= 0x0018,
23 tls_key_exchange_group_Secp521r1
= 0x0019,
24 tls_key_exchange_group_X25519
= 0x001D,
25 tls_key_exchange_group_X448
= 0x001E,
26 tls_key_exchange_group_FFDHE2048
= 0x0100,
27 tls_key_exchange_group_FFDHE3072
= 0x0101,
28 tls_key_exchange_group_FFDHE4096
= 0x0102,
29 tls_key_exchange_group_FFDHE6144
= 0x0103,
30 tls_key_exchange_group_FFDHE8192
= 0x0104,
34 * Convenience key exchange groups that collate group identifiers of
35 * comparable security into a single alias.
37 typedef CF_ENUM(uint16_t, tls_key_exchange_group_set_t
) {
38 tls_key_exchange_group_set_default
,
39 tls_key_exchange_group_set_compatibility
,
40 tls_key_exchange_group_set_legacy
,
43 SEC_ASSUME_NONNULL_BEGIN
45 #ifndef SEC_OBJECT_IMPL
46 SEC_OBJECT_DECL(sec_array
);
47 #endif // !SEC_OBJECT_IMPL
49 struct sec_protocol_options_content
;
50 typedef struct sec_protocol_options_content
*sec_protocol_options_content_t
;
52 struct sec_protocol_metadata_content
;
53 typedef struct sec_protocol_metadata_content
*sec_protocol_metadata_content_t
;
55 typedef void (^sec_protocol_tls_handshake_message_handler_t
)(uint8_t type
, dispatch_data_t message
);
57 typedef dispatch_data_t
_Nullable (*sec_protocol_metadata_exporter
)(void * handle
, size_t label_len
, const char *label
,
58 size_t context_len
, const uint8_t * __nullable context
, size_t exporter_len
);
60 typedef dispatch_data_t
_Nullable (*sec_protocol_metadata_session_exporter
)(void *handle
);
62 typedef bool (^sec_access_block_t
)(void *handle
);
64 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
65 SEC_RETURNS_RETAINED sec_array_t
66 sec_array_create(void);
68 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
70 sec_array_append(sec_array_t array
, sec_object_t object
);
72 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
74 sec_array_get_count(sec_array_t array
);
76 typedef bool (^sec_array_applier_t
) (size_t index
, sec_object_t object
);
78 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
80 sec_array_apply(sec_array_t array
, sec_array_applier_t applier
);
83 * @function sec_protocol_options_access_handle
86 * Access the internal handle of a `sec_protocol_options` object.
89 * A `sec_protocol_options_t` instance.
92 * A block to invoke with access to the internal handle.
94 * @return True if the access was successful
96 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
98 sec_protocol_options_access_handle(sec_protocol_options_t options
, sec_access_block_t access_block
);
101 * @function sec_protocol_options_contents_are_equal
104 * Compare two `sec_protocol_options_content_t` structs for equality.
107 * A `sec_protocol_options_t` instance.
110 * A `sec_protocol_options_t` instance.
112 * @return True if equal, and false otherwise.
114 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
116 sec_protocol_options_contents_are_equal(sec_protocol_options_content_t contentA
, sec_protocol_options_content_t contentB
);
119 * @function sec_protocol_options_set_tls_early_data_enabled
122 * Enable or disable early (0-RTT) data for TLS.
125 * A `sec_protocol_options_t` instance.
127 * @param early_data_enabled
128 * Flag to enable or disable early (0-RTT) data.
130 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
132 sec_protocol_options_set_tls_early_data_enabled(sec_protocol_options_t options
, bool early_data_enabled
);
135 * @function sec_protocol_options_set_tls_sni_disabled
138 * Enable or disable the TLS SNI extension. This defaults to `false`.
141 * A `sec_protocol_options_t` instance.
143 * @param sni_disabled
144 * Flag to enable or disable use of the TLS SNI extension.
146 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
148 sec_protocol_options_set_tls_sni_disabled(sec_protocol_options_t options
, bool sni_disabled
);
151 * @function sec_protocol_options_set_enforce_ev
154 * Enable or disable EV enforcement.
157 * A `sec_protocol_options_t` instance.
160 * Flag to determine if EV is enforced.
162 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
164 sec_protocol_options_set_enforce_ev(sec_protocol_options_t options
, bool enforce_ev
);
167 * @block sec_protocol_session_update_t
170 * Block to be invoked when a new session is established and ready.
173 * A `sec_protocol_metadata_t` instance.
175 typedef void (^sec_protocol_session_update_t
)(sec_protocol_metadata_t metadata
);
178 * @function sec_protocol_options_set_session_update_block
181 * Set the session update block. This is fired whenever a new session is
182 * created an inserted into the cache.
185 * A `sec_protocol_options_t` instance.
187 * @param update_block
188 * A `sec_protocol_session_update_t` instance.
190 * @params update_queue
191 * A `dispatch_queue_t` on which the update block should be called.
193 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
195 sec_protocol_options_set_session_update_block(sec_protocol_options_t options
,
196 sec_protocol_session_update_t update_block
,
197 dispatch_queue_t update_queue
);
200 * @function sec_protocol_options_set_session_state
203 * Set the session state using a serialized session blob.
205 * If the session state is invalid or otherwise corrupt, the state is ignored and
206 * the connection will proceed as if no state was provided.
209 * A `sec_protocol_options_t` instance.
211 * @param session_state
212 * A `dispatch_data_t` carrying serialized session state from a previous.
214 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
216 sec_protocol_options_set_session_state(sec_protocol_options_t options
, dispatch_data_t session_state
);
219 * @function sec_protocol_options_set_quic_transport_parameters
222 * Set the opaque QUIC transport parameters to be used for this connection.
225 * A `sec_protocol_options_t` instance.
227 * @param transport_parameters
228 * A `dispatch_data_t` carrying opqaue QUIC transport parameters.
230 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
232 sec_protocol_options_set_quic_transport_parameters(sec_protocol_options_t options
, dispatch_data_t transport_parameters
);
235 * @enum sec_protocol_tls_encryption_level_t
237 * @abstract An enumeration of the different TLS encryption levels.
240 sec_protocol_tls_encryption_level_initial
= 0,
241 sec_protocol_tls_encryption_level_early_data
,
242 sec_protocol_tls_encryption_level_handshake
,
243 sec_protocol_tls_encryption_level_application
,
244 } sec_protocol_tls_encryption_level_t
;
247 * @block sec_protocol_tls_encryption_secret_update_t
250 * Block to be invoked when a new session is established and ready.
253 * The `sec_protocol_tls_encryption_level_t` for this secret.
256 * True if this secret is for writing, and false if it's for reading.
259 * Secret wrapped in a `dispatch_data_t`
261 typedef void (^sec_protocol_tls_encryption_secret_update_t
)(sec_protocol_tls_encryption_level_t level
, bool is_write
, dispatch_data_t secret
);
264 * @function sec_protocol_options_set_tls_encryption_secret_update_block
267 * Set the TLS secret update block. This is fired whenever a new TLS secret is
271 * A `sec_protocol_options_t` instance.
273 * @param update_block
274 * A `sec_protocol_tls_encryption_secret_update_t` instance.
276 * @params update_queue
277 * A `dispatch_queue_t` on which the update block should be called.
279 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
281 sec_protocol_options_set_tls_encryption_secret_update_block(sec_protocol_options_t options
,
282 sec_protocol_tls_encryption_secret_update_t update_block
,
283 dispatch_queue_t update_queue
);
286 * @block sec_protocol_private_key_complete_t
289 * Block to be invoked when a private key operation is complete.
292 * A `dispatch_data_t` object containing the private key result.
294 typedef void (^sec_protocol_private_key_complete_t
)(dispatch_data_t result
);
297 * @block sec_protocol_private_key_sign_t
300 * Block to be invoked when a private key signature operation is required.
303 * The signature algorithm to use for the signature.
306 * The input to be signed.
309 * The `sec_protocol_private_key_complete_t` block to invoke when the operation is complete.
311 typedef void (^sec_protocol_private_key_sign_t
)(uint16_t algorithm
, dispatch_data_t input
, sec_protocol_private_key_complete_t complete
);
314 * @block sec_protocol_private_key_decrypt_t
317 * Block to be invoked when a private key decryption operation is required.
320 * The input to be decrypted.
323 * The `sec_protocol_private_key_complete_t` block to invoke when the operation is complete.
325 typedef void (^sec_protocol_private_key_decrypt_t
)(dispatch_data_t input
, sec_protocol_private_key_complete_t complete
);
328 * @block sec_protocol_options_set_private_key_blocks
331 * Set the private key operation blocks for this connection.
334 * A `sec_protocol_options_t` instance.
337 * A `sec_protocol_private_key_sign_t` block.
339 * @param decrypt_block
340 * A `sec_protocol_private_key_decrypt_t` block.
342 * @param operation_queue
343 * The `dispatch_queue_t` queue on which each private key operation is invoked.
345 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
347 sec_protocol_options_set_private_key_blocks(sec_protocol_options_t options
,
348 sec_protocol_private_key_sign_t sign_block
,
349 sec_protocol_private_key_decrypt_t decrypt_block
,
350 dispatch_queue_t operation_queue
);
353 * @block sec_protocol_options_set_local_certificates
356 * Set the local certificates to be used for this protocol instance.
359 * A `sec_protocol_options_t` instance.
361 * @param certificates
362 * A `sec_array_t` instance of `sec_certifiate_t` instances.
364 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
366 sec_protocol_options_set_local_certificates(sec_protocol_options_t options
, sec_array_t certificates
);
369 * @block sec_protocol_options_set_tls_certificate_compression_enabled
372 * Enable or disable TLS 1.3 certificate compression.
374 * See: https://tools.ietf.org/html/draft-ietf-tls-certificate-compression-04
377 * A `sec_protocol_options_t` instance.
379 * @param certificate_compression_enabled
380 * Flag to determine if certificate compression is enabled.
382 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
384 sec_protocol_options_set_tls_certificate_compression_enabled(sec_protocol_options_t options
, bool certificate_compression_enabled
);
387 * @block sec_protocol_options_tls_handshake_message_callback
390 * Set a callback to process each TLS handshake message. This function may be invoked at any point during
391 * the TLS handshake, if at all. Clients MUST NOT rely on any behavior aspect of this function as they
395 * A `sec_protocol_options_t` instance.
398 * A `sec_protocol_tls_handshake_message_handler_t`.
401 * The queue upon which to invoke the callback.
403 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
405 sec_protocol_options_tls_handshake_message_callback(sec_protocol_options_t options
, sec_protocol_tls_handshake_message_handler_t handler
, dispatch_queue_t queue
);
408 * @block sec_protocol_options_append_tls_key_exchange_group
411 * Append a TLS key exchange group to the set of enabled groups.
414 * A `sec_protocol_options_t` instance.
417 * A `tls_key_exchange_group_t` value.
419 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
421 sec_protocol_options_append_tls_key_exchange_group(sec_protocol_options_t options
, tls_key_exchange_group_t group
);
424 * @block sec_protocol_options_add_tls_key_exchange_group
427 * Add a TLS key exchange group to the set of enabled groups.
430 * A `sec_protocol_options_t` instance.
433 * A SSLKeyExchangeGroup value.
435 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
437 sec_protocol_options_add_tls_key_exchange_group(sec_protocol_options_t options
, SSLKeyExchangeGroup group
);
440 * @block sec_protocol_options_append_tls_key_exchange_group_set
443 * Append a TLS key exchange group set to the set of enabled groups.
446 * A `sec_protocol_options_t` instance.
449 * A `tls_key_exchange_group_set_t` value.
451 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
453 sec_protocol_options_append_tls_key_exchange_group_set(sec_protocol_options_t options
, tls_key_exchange_group_set_t set
);
456 * @block sec_protocol_options_tls_key_exchange_group_set
459 * Add a TLS key exchange group set to the set of enabled groups.
462 * A `sec_protocol_options_t` instance.
465 * A SSLKeyExchangeGroupSet value.
467 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
469 sec_protocol_options_add_tls_key_exchange_group_set(sec_protocol_options_t options
, SSLKeyExchangeGroupSet set
);
472 * @function sec_protocol_options_set_tls_SIKE503_exchange_enabled
475 * Enable SIKE using P503 for TLS 1.3 key exchange.
477 * DO NOT DEPEND ON THIS SPI. IT IS FOR EXPERIMENTAL PURPOSES AND SUBJECT TO REMOVAL WITHOUT ADVANCE NOTICE.
478 * BUILD BREAKAGE ISSUES WILL BE SENT TO THE CALLING PROJECT.
481 * A `sec_protocol_options_t` instance.
483 * @param tls_SIKE503_exchange_enabled
484 * Flag to enable SIKE with P503.
486 #define SEC_PROTOCOL_HAS_PQ_TLS_HANDLES 1
487 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
489 sec_protocol_options_set_tls_SIKE503_exchange_enabled(sec_protocol_options_t options
, bool tls_SIKE503_exchange_enabled
);
492 * @function sec_protocol_options_set_tls_HRSS_exchange_enabled
495 * Enable HRSS for TLS 1.3 key exchange.
497 * DO NOT DEPEND ON THIS SPI. IT IS FOR EXPERIMENTAL PURPOSES AND SUBJECT TO REMOVAL WITHOUT ADVANCE NOTICE.
498 * BUILD BREAKAGE ISSUES WILL BE SENT TO THE CALLING PROJECT.
501 * A `sec_protocol_options_t` instance.
503 * @param tls_HRSS_exchange_enabled
504 * Flag to enable HRSS.
506 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
508 sec_protocol_options_set_tls_HRSS_exchange_enabled(sec_protocol_options_t options
, bool tls_HRSS_exchange_enabled
);
511 * @function sec_protocol_options_set_eddsa_enabled
514 * Enable EDDSA support (for TLS 1.3).
517 * A `sec_protocol_options_t` instance.
519 * @param eddsa_enabled
520 * Flag to enable EDDSA.
522 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
524 sec_protocol_options_set_eddsa_enabled(sec_protocol_options_t options
, bool eddsa_enabled
);
527 * @function sec_protocol_options_set_tls_delegated_credentials_enabled
530 * Enable TLS delegated credentials support. See https://tools.ietf.org/html/draft-ietf-tls-subcerts-02.
532 * DO NOT DEPEND ON THIS SPI. IT IS FOR EXPERIMENTAL PURPOSES AND SUBJECT TO REMOVAL WITHOUT ADVANCE NOTICE.
533 * BUILD BREAKAGE ISSUES WILL BE SENT TO THE CALLING PROJECT.
536 * A `sec_protocol_options_t` instance.
538 * @param tls_delegated_credentials_enabled
539 * Flag to enable TLS delegated credentials.
541 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
543 sec_protocol_options_set_tls_delegated_credentials_enabled(sec_protocol_options_t options
, bool tls_delegated_credentials_enabled
);
546 * @function sec_protocol_options_set_tls_ticket_request_count
549 * Enable TLS ticket request support, and specify the count of tickets. Ticket support
550 * must also be explicitly enabled by `sec_protocol_options_set_tls_tickets_enabled`.
552 * DO NOT DEPEND ON THIS SPI. IT IS FOR EXPERIMENTAL PURPOSES AND SUBJECT TO REMOVAL WITHOUT ADVANCE NOTICE.
553 * BUILD BREAKAGE ISSUES WILL BE SENT TO THE CALLING PROJECT.
556 * A `sec_protocol_options_t` instance.
558 * @param tls_ticket_request_count
559 * Set the amount of tickets to request from the server.
561 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
563 sec_protocol_options_set_tls_ticket_request_count(sec_protocol_options_t options
, uint8_t tls_ticket_request_count
);
566 * @function sec_protocol_options_set_tls_grease_enabled
569 * Enable TLS GREASE support. See https://tools.ietf.org/html/draft-ietf-tls-grease-02.
571 * DO NOT DEPEND ON THIS SPI. IT IS FOR EXPERIMENTAL PURPOSES AND SUBJECT TO REMOVAL WITHOUT ADVANCE NOTICE.
572 * BUILD BREAKAGE ISSUES WILL BE SENT TO THE CALLING PROJECT.
575 * A `sec_protocol_options_t` instance.
577 * @param tls_grease_enabled
578 * Flag to enable TLS GREASE.
580 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
582 sec_protocol_options_set_tls_grease_enabled(sec_protocol_options_t options
, bool tls_grease_enabled
);
585 * @function sec_protocol_options_set_experiment_identifier
588 * Set the SecExperiment identifier for a given connection.
590 * Note: this SPI is meant to be called by libnetcore. It should not be called in any other circumstances.
593 * A `sec_protocol_options_t` instance.
595 * @param experiment_identifier
596 * The identifier for a secure connection experiment.
598 #define SEC_PROTOCOL_HAS_EXPERIMENT_IDENTIFIER 1
599 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
601 sec_protocol_options_set_experiment_identifier(sec_protocol_options_t options
, const char *experiment_identifier
);
604 * @function sec_protocol_options_set_connection_id
607 * Set the explciit connection identifier. If not set, one will be populated internally.
610 * A `sec_protocol_options_t` instance.
612 * @param connection_id
613 * The `uuid_t`` connection identifier.
615 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
617 sec_protocol_options_set_connection_id(sec_protocol_options_t options
, uuid_t _Nonnull connection_id
);
620 * @function sec_protocol_options_create_config
623 * Create a `xpc_object_t` instance carrying a configuration for the given `sec_protocol_options_t` instance.
626 * A `sec_protocol_options_t` instance.
628 * @return A `xpc_object_t` instance carrying a configuration, or nil on failure.
630 #define SEC_PROTOCOL_HAS_EXPERIMENT_HOOKS 1
631 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
632 SEC_RETURNS_RETAINED __nullable xpc_object_t
633 sec_protocol_options_create_config(sec_protocol_options_t options
);
636 * @function sec_protocol_options_matches_config
639 * Determine if a `sec_protocol_options_t` instance matches a given configuration.
642 * A `sec_protocol_options_t` instance.
645 * A `xpc_object_t` instance carrying a SecExperiment config.
647 * @return True if the parameters in `config` match that of `options`, and false otherwise.
649 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
651 sec_protocol_options_matches_config(sec_protocol_options_t options
, xpc_object_t config
);
654 * @function sec_protocol_options_apply_config
657 * Transform the given `sec_protocol_options_t` instance using the provided config.
660 * A `sec_protocol_options_t` instance.
663 * A `xpc_object_t` instance carrying a SecExperiment config.
665 * @return True if the options were applied successfully, and false otherwise.
668 sec_protocol_options_apply_config(sec_protocol_options_t options
, xpc_object_t config
);
671 * @function sec_protocol_metadata_get_tls_negotiated_group
674 * Get a human readable representation of the negotiated key exchange group.
677 * A `sec_protocol_metadata_t` instance.
679 * @return A string representation of the negotiated group, or NULL if it does not exist.
681 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
682 const char * __nullable
683 sec_protocol_metadata_get_tls_negotiated_group(sec_protocol_metadata_t metadata
);
686 * @function sec_protocol_metadata_get_experiment_identifier
689 * Get the SecExperiment identifier for a given connection.
691 * Note: this SPI is meant to be called by libnetcore. It should not be called in any other circumstances.
694 * A `sec_protocol_metadata_t` instance.
696 * @return The identifier for a secure connection experiment, or NULL if none was specified.
698 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
699 const char * __nullable
700 sec_protocol_metadata_get_experiment_identifier(sec_protocol_metadata_t metadata
);
703 * @function sec_protocol_metadata_copy_connection_id
706 * Copy the secure connection identifier.
709 * A `sec_protocol_metadata_t` instance.
712 * A `uuid_t` into which the connection identifier is written.
714 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
716 sec_protocol_metadata_copy_connection_id(sec_protocol_metadata_t metadata
, uuid_t _Nonnull output_uuid
);
719 * @function sec_protocol_metadata_get_tls_false_start_used
722 * Determine if False Start was used.
725 * A `sec_protocol_metadata_t` instance.
727 * @return True if False Start was used, and false otherwise.
729 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
731 sec_protocol_metadata_get_tls_false_start_used(sec_protocol_metadata_t metadata
);
734 * @function sec_protocol_metadata_get_ticket_offered
737 * Determine if a ticket was offered for session resumption.
740 * A `sec_protocol_metadata_t` instance.
742 * @return True if a ticket was offered for resumption, and false otherwise.
744 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
746 sec_protocol_metadata_get_ticket_offered(sec_protocol_metadata_t metadata
);
749 * @function sec_protocol_metadata_get_ticket_received
752 * Determine if a ticket was received upon completing the new connection.
755 * A `sec_protocol_metadata_t` instance.
757 * @return True if a ticket was received from the peer (server), and false otherwise.
759 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
761 sec_protocol_metadata_get_ticket_received(sec_protocol_metadata_t metadata
);
764 * @function sec_protocol_metadata_get_session_resumed
767 * Determine if this new connection was a session resumption.
770 * A `sec_protocol_metadata_t` instance.
772 * @return True if this new connection was resumed, and false otherwise.
774 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
776 sec_protocol_metadata_get_session_resumed(sec_protocol_metadata_t metadata
);
779 * @function sec_protocol_metadata_get_session_renewed
782 * Determine if this resumed connection was renewed with a new ticket.
785 * A `sec_protocol_metadata_t` instance.
787 * @return True if this resumed connection was renewed with a new ticket, and false otherwise.
789 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
791 sec_protocol_metadata_get_session_renewed(sec_protocol_metadata_t metadata
);
794 * @function sec_protocol_metadata_get_connection_strength
797 * Determine the TLS connection strength.
800 * A `sec_protocol_metadata_t` instance.
802 * @return An `SSLConnectionStrength` enum.
804 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
805 SSLConnectionStrength
806 sec_protocol_metadata_get_connection_strength(sec_protocol_metadata_t metadata
);
809 * @function sec_protocol_metadata_copy_serialized_session
812 * Copy a serialized representation of a session.
815 * A `sec_protocol_metadata_t` instance.
817 * @return A `dispatch_data_t` object containing a serialized session.
819 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
820 SEC_RETURNS_RETAINED __nullable dispatch_data_t
821 sec_protocol_metadata_copy_serialized_session(sec_protocol_metadata_t metadata
);
824 * @function sec_protocol_metadata_access_handle
827 * Access the internal handle of a `sec_protocol_metadata` object.
830 * A `sec_protocol_metadata_t` instance.
832 * @param access_block
833 * A block to invoke with access to the internal handle.
835 * @return True if the access was successful
837 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
839 sec_protocol_metadata_access_handle(sec_protocol_metadata_t metadata
, sec_access_block_t access_block
);
842 * @function sec_protocol_metadata_serialize_with_options
845 * Serialize a `sec_protocol_metadata_t` to an `xpc_object_t` dictionary using information
846 * contained in the `metadata` and `options` objects.
849 * A `sec_protocol_metadata_t` instance.
851 * @return A xpc_object_t carrying the serialized metadata.
853 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
854 SEC_RETURNS_RETAINED __nullable xpc_object_t
855 sec_protocol_metadata_serialize_with_options(sec_protocol_metadata_t metadata
, sec_protocol_options_t options
);
858 * @function sec_protocol_metadata_get_tls_certificate_compression_used
861 * Determine if certificate compression was used for a given connection.
863 * See: https://tools.ietf.org/html/draft-ietf-tls-certificate-compression-04
866 * A `sec_protocol_metadata_t` instance.
868 * @return True if certificate compression was negotiated and used.
870 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
872 sec_protocol_metadata_get_tls_certificate_compression_used(sec_protocol_metadata_t metadata
);
875 * @function sec_protocol_metadata_get_tls_certificate_compression_algorithm
878 * Return the certificate compression algorithm used. This will return 0
879 * if `sec_protocol_metadata_get_tls_certificate_compression_used` is false.
881 * See: https://tools.ietf.org/html/draft-ietf-tls-certificate-compression-04
884 * A `sec_protocol_metadata_t` instance.
886 * @return IANA codepoint for the certificate compression algorithm.
888 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
890 sec_protocol_metadata_get_tls_certificate_compression_algorithm(sec_protocol_metadata_t metadata
);
893 * @function sec_protocol_metadata_copy_quic_transport_parameters
896 * Copy the peer's QUIC transport parameters.
899 * A `sec_protocol_metadata_t` instance.
901 * @return A dispatch_data_t carrying the connection peer's opaque QUIC tranport parameters.
903 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
904 SEC_RETURNS_RETAINED __nullable dispatch_data_t
905 sec_protocol_metadata_copy_quic_transport_parameters(sec_protocol_metadata_t metadata
);
908 * @function sec_protocol_metadata_get_handshake_time_ms
911 * Get the TLS handshake time in miliseconds. The result is undefined
912 * for connections not yet connected.
915 * A `sec_protocol_metadata_t` instance.
917 * @return A millisecond measurement of the TLS handshake time from start to finish.
919 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
920 #define SEC_PROTOCOL_HAS_METRIC_SPI_V1
922 sec_protocol_metadata_get_handshake_time_ms(sec_protocol_metadata_t metadata
);
925 * @function sec_protocol_metadata_get_handshake_rtt
928 * Get the observed TLS handshake RTT. This function must only be
929 * called after the connection is established. Calling this before
930 * the connection completes will yields an undefined result.
932 * This is computed as the average RTT across all 1-RTT exchanges.
933 * For TLS 1.3, this will be the time for the normal exchange. For prior
934 * versions, or TLS 1.3 with HRR, this will be the average RTT across
935 * multiple message flights.
938 * A `sec_protocol_metadata_t` instance.
940 * @return A millisecond measurement of the TLS handshake RTT.
942 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
944 sec_protocol_metadata_get_handshake_rtt(sec_protocol_metadata_t metadata
);
947 * @function sec_protocol_metadata_get_handshake_byte_count
950 * Get the total number of bytes sent and received for the handshake.
953 * A `sec_protocol_metadata_t` instance.
955 * @return Number of bytes sent and received for the handshake.
957 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
959 sec_protocol_metadata_get_handshake_byte_count(sec_protocol_metadata_t metadata
);
962 * @function sec_protocol_metadata_get_handshake_sent_byte_count
965 * Get the total number of bytes sent for the handshake.
968 * A `sec_protocol_metadata_t` instance.
970 * @return Number of bytes sent for the handshake.
972 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
974 sec_protocol_metadata_get_handshake_sent_byte_count(sec_protocol_metadata_t metadata
);
977 * @function sec_protocol_metadata_get_handshake_received_byte_count
980 * Get the total number of bytes received for the handshake.
983 * A `sec_protocol_metadata_t` instance.
985 * @return Number of bytes received for the handshake.
987 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
989 sec_protocol_metadata_get_handshake_received_byte_count(sec_protocol_metadata_t metadata
);
992 * @function sec_protocol_metadata_get_handshake_read_stall_count
995 * Get the total number of read stalls during the handshake.
998 * A `sec_protocol_metadata_t` instance.
1000 * @return Number of read stalls.
1002 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
1004 sec_protocol_metadata_get_handshake_read_stall_count(sec_protocol_metadata_t metadata
);
1007 * @function sec_protocol_metadata_get_handshake_write_stall_count
1010 * Get the total number of write stalls during the handshake.
1013 * A `sec_protocol_metadata_t` instance.
1015 * @return Number of write stalls.
1017 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
1019 sec_protocol_metadata_get_handshake_write_stall_count(sec_protocol_metadata_t metadata
);
1022 * @function sec_protocol_metadata_get_handshake_async_call_count
1025 * Get the total number of asynchronous callbacks invoked during the handshake.
1028 * A `sec_protocol_metadata_t` instance.
1030 * @return Number of asynchronous callbacks.
1032 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
1034 sec_protocol_metadata_get_handshake_async_call_count(sec_protocol_metadata_t metadata
);
1037 * @function sec_protocol_metadata_copy_sec_trust
1040 * Copy the `sec_trust_t` associated with a connection.
1043 * A `sec_protocol_metadata_t` instance.
1045 * @return A `sec_trust_t` instance.
1047 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
1048 SEC_RETURNS_RETAINED __nullable sec_trust_t
1049 sec_protocol_metadata_copy_sec_trust(sec_protocol_metadata_t metadata
);
1052 * @function sec_protocol_metadata_copy_sec_identity
1055 * Copy the `sec_identity_t` associated with a connection.
1058 * A `sec_protocol_metadata_t` instance.
1060 * @return A `sec_identity_t` instance.
1062 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
1063 SEC_RETURNS_RETAINED __nullable sec_identity_t
1064 sec_protocol_metadata_copy_sec_identity(sec_protocol_metadata_t metadata
);
1067 * @function sec_protocol_metadata_access_sent_certificates
1070 * Access the certificates which were sent to the peer on this connection.
1073 * A `sec_protocol_metadata_t` instance.
1076 * A block to invoke one or more times with `sec_certificate_t` instances.
1078 * @return Returns true if the peer certificates were accessible, false otherwise.
1080 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
1082 sec_protocol_metadata_access_sent_certificates(sec_protocol_metadata_t metadata
,
1083 void (^handler
)(sec_certificate_t certificate
));
1086 * @function sec_protocol_metadata_get_tls_negotiated_group
1089 * Get a human readable representation of the negotiated key exchange group.
1092 * A `sec_protocol_metadata_t` instance.
1094 * @return A string representation of the negotiated group, or NULL if it does not exist.
1096 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
1097 const char * __nullable
1098 sec_protocol_metadata_get_tls_negotiated_group(sec_protocol_metadata_t metadata
);
1101 * @function sec_protocol_configuration_copy_singleton
1104 * Copy the per-process `sec_protocol_configuration_t` object.
1106 * @return A non-nil `sec_protocol_configuration_t` instance.
1108 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
1109 SEC_RETURNS_RETAINED sec_protocol_configuration_t
1110 sec_protocol_configuration_copy_singleton(void);
1112 #ifndef SEC_OBJECT_IMPL
1113 SEC_OBJECT_DECL(sec_protocol_configuration_builder
);
1114 #endif // !SEC_OBJECT_IMPL
1117 * @function sec_protocol_configuration_builder_create
1120 * This function is exposed for testing purposes only. It MUST NOT be called by clients.
1122 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
1123 SEC_RETURNS_RETAINED sec_protocol_configuration_builder_t
1124 sec_protocol_configuration_builder_create(CFDictionaryRef dictionary
, bool is_apple
);
1127 * @function sec_protocol_configuration_create_with_builder
1130 * This function is exposed for testing purposes only. It MUST NOT be called by clients.
1132 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
1133 SEC_RETURNS_RETAINED __nullable sec_protocol_configuration_t
1134 sec_protocol_configuration_create_with_builder(sec_protocol_configuration_builder_t builder
);
1137 * @block sec_protocol_output_handler_access_block_t
1140 * Block to be invoked to obtain the output handler for a given encryption level.
1142 typedef void *_Nullable(^sec_protocol_output_handler_access_block_t
)(sec_protocol_tls_encryption_level_t level
);
1145 * @function sec_protocol_options_set_output_handler_access_block
1148 * Set a block used to access output handler instances identified by encryption level.
1150 #define SEC_PROTOCOL_HAS_QUIC_OUTPUT_HANDLER_ACCESS_BLOCK 1
1151 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
1153 sec_protocol_options_set_output_handler_access_block(sec_protocol_options_t options
,
1154 sec_protocol_output_handler_access_block_t access_block
);
1157 * @function sec_protocol_helper_ciphersuite_group_to_ciphersuite_list
1160 * Return a pointer to a statically allocated list of ciphersuites corresponding to `group`.
1163 * A `tls_ciphersuite_group_t` instance.
1166 * Pointer to storage for the ciphersuite list length.
1168 * @return Pointer to a statically allocated list, or NULL if an error occurred.
1170 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
1171 const tls_ciphersuite_t
* __nullable
1172 sec_protocol_helper_ciphersuite_group_to_ciphersuite_list(tls_ciphersuite_group_t group
, size_t *list_count
);
1174 #define SEC_PROTOCOL_HAS_MULTI_PSK_SUPPORT 1
1176 struct sec_protocol_options_content
{
1177 SSLProtocol min_version
;
1178 SSLProtocol max_version
;
1181 char *experiment_identifier
;
1182 uuid_t connection_id
;
1183 __nullable xpc_object_t ciphersuites
;
1184 xpc_object_t application_protocols
;
1185 sec_identity_t identity
;
1186 sec_array_t certificates
;
1187 xpc_object_t pre_shared_keys
;
1188 dispatch_data_t psk_identity_hint
;
1189 sec_protocol_key_update_t key_update_block
;
1190 dispatch_queue_t key_update_queue
;
1191 sec_protocol_challenge_t challenge_block
;
1192 dispatch_queue_t challenge_queue
;
1193 sec_protocol_verify_t verify_block
;
1194 dispatch_queue_t verify_queue
;
1195 dispatch_data_t quic_transport_parameters
;
1196 sec_protocol_tls_encryption_secret_update_t tls_secret_update_block
;
1197 dispatch_queue_t tls_secret_update_queue
;
1198 sec_protocol_session_update_t session_update_block
;
1199 dispatch_queue_t session_update_queue
;
1200 dispatch_data_t session_state
;
1201 sec_protocol_private_key_sign_t private_key_sign_block
;
1202 sec_protocol_private_key_decrypt_t private_key_decrypt_block
;
1203 dispatch_queue_t private_key_queue
;
1204 dispatch_data_t dh_params
;
1205 xpc_object_t key_exchange_groups
;
1206 sec_protocol_tls_handshake_message_handler_t handshake_message_callback
;
1207 dispatch_queue_t handshake_message_callback_queue
;
1208 sec_protocol_pre_shared_key_selection_t psk_selection_block
;
1209 dispatch_queue_t psk_selection_queue
;
1212 size_t minimum_rsa_key_size
;
1213 size_t minimum_ecdsa_key_size
;
1214 SecSignatureHashAlgorithm minimum_signature_algorithm
;
1216 // Non-boolean options
1217 uint8_t tls_ticket_request_count
;
1219 // QUIC-specific access block
1220 sec_protocol_output_handler_access_block_t output_handler_access_block
;
1223 unsigned ats_required
: 1;
1224 unsigned ats_minimum_tls_version_allowed
: 1;
1225 unsigned ats_non_pfs_ciphersuite_allowed
: 1;
1226 unsigned trusted_peer_certificate
: 1;
1227 unsigned trusted_peer_certificate_override
: 1;
1228 unsigned disable_sni
: 1;
1229 unsigned disable_sni_override
: 1;
1230 unsigned enable_fallback_attempt
: 1;
1231 unsigned enable_fallback_attempt_override
: 1;
1232 unsigned enable_false_start
: 1;
1233 unsigned enable_false_start_override
: 1;
1234 unsigned enable_tickets
: 1;
1235 unsigned enable_tickets_override
: 1;
1236 unsigned enable_sct
: 1;
1237 unsigned enable_sct_override
: 1;
1238 unsigned enable_ocsp
: 1;
1239 unsigned enable_ocsp_override
: 1;
1240 unsigned enforce_ev
: 1;
1241 unsigned enforce_ev_override
: 1;
1242 unsigned enable_resumption
: 1;
1243 unsigned enable_resumption_override
: 1;
1244 unsigned enable_renegotiation
: 1;
1245 unsigned enable_renegotiation_override
: 1;
1246 unsigned enable_early_data
: 1;
1247 unsigned enable_early_data_override
: 1;
1248 unsigned peer_authentication_required
: 1;
1249 unsigned peer_authentication_override
: 1;
1250 unsigned certificate_compression_enabled
: 1;
1251 unsigned tls_SIKE503_exchange_enabled
: 1;
1252 unsigned tls_HRSS_exchange_enabled
: 1;
1253 unsigned eddsa_enabled
: 1;
1254 unsigned tls_delegated_credentials_enabled
: 1;
1255 unsigned tls_grease_enabled
: 1;
1258 struct sec_protocol_metadata_content
{
1259 void *exporter_context
; // Opaque context for the exporter function
1260 sec_protocol_metadata_exporter exporter_function
; // Exporter function pointer. This MUST be set by the metadata allocator.
1261 void *session_exporter_context
; // Opaque context for the session exporter function
1262 sec_protocol_metadata_session_exporter session_exporter_function
;
1264 SSLProtocol negotiated_protocol_version
;
1265 SSLCipherSuite negotiated_ciphersuite
;
1266 const char *negotiated_protocol
;
1267 const char *server_name
;
1268 const char *experiment_identifier
;
1269 uuid_t connection_id
;
1271 sec_array_t sent_certificate_chain
;
1272 sec_array_t peer_certificate_chain
;
1273 xpc_object_t pre_shared_keys
;
1274 dispatch_data_t peer_public_key
;
1275 xpc_object_t supported_signature_algorithms
;
1276 dispatch_data_t request_certificate_types
;
1277 sec_array_t signed_certificate_timestamps
;
1278 sec_array_t ocsp_response
;
1279 sec_array_t distinguished_names
;
1280 dispatch_data_t quic_transport_parameters
;
1281 sec_identity_t identity
;
1282 sec_trust_t trust_ref
;
1283 const char *negotiated_curve
;
1284 const char *peer_public_key_type
;
1285 const char *certificate_request_type
;
1286 uint64_t ticket_lifetime
;
1287 uint64_t max_early_data_supported
;
1288 uint64_t alert_type
;
1289 uint64_t alert_code
;
1290 uint64_t handshake_state
;
1291 uint64_t stack_error
;
1292 uint64_t handshake_rtt
;
1293 uint16_t certificate_compression_algorithm
;
1294 uint64_t handshake_time
;
1295 uint64_t total_byte_count
;
1296 uint64_t sent_byte_count
;
1297 uint64_t received_byte_count
;
1298 size_t read_stall_count
;
1299 size_t write_stall_count
;
1300 size_t async_call_count
;
1302 unsigned failure
: 1;
1303 unsigned sct_enabled
: 1;
1304 unsigned ocsp_enabled
: 1;
1305 unsigned early_data_accepted
: 1;
1306 unsigned false_start_used
: 1;
1307 unsigned ticket_offered
: 1;
1308 unsigned ticket_received
: 1;
1309 unsigned session_resumed
: 1;
1310 unsigned session_renewed
: 1;
1311 unsigned resumption_attempted
: 1;
1312 unsigned alpn_used
: 1;
1313 unsigned npn_used
: 1;
1314 unsigned early_data_sent
: 1;
1315 unsigned certificate_compression_used
: 1;
1318 SEC_ASSUME_NONNULL_END
1322 #endif /* SecProtocolPriv_h */