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 SecProtocolMetadata_h
25 #define SecProtocolMetadata_h
27 #include <Security/SecProtocolObject.h>
28 #include <Security/SecProtocolTypes.h>
29 #include <Security/SecProtocolOptions.h>
31 #include <dispatch/dispatch.h>
32 #include <os/object.h>
35 * The following diagram shows how clients interact with sec_protocol_options
36 * and sec_protocol_metadata when configuring and using network security protocols.
42 * +-------------+ +-------------+
44 * | options metadata |
45 * +-----\ /---------------+ +------------+----------+
46 * | sec_protocol_options | | sec_protocol_metadata |
47 * +-----------------------+ +-----------------------+
49 * Clients configure security protocols with `sec_protocol_options` instances.
50 * And they inspect protocol instances using `sec_protocol_metadata` instances.
53 #ifndef SEC_OBJECT_IMPL
55 * A `sec_protocol_metadata` instance conatins read-only properties of a connected and configured
56 * security protocol. Clients use this object to read information about a protocol instance. Properties
57 * include, for example, the negotiated TLS version, ciphersuite, and peer certificates.
59 SEC_OBJECT_DECL(sec_protocol_metadata
);
60 #endif // !SEC_OBJECT_IMPL
64 SEC_ASSUME_NONNULL_BEGIN
67 * @function sec_protocol_metadata_get_negotiated_protocol
70 * Get the application protocol negotiated, e.g., via the TLS ALPN extension.
73 * A `sec_protocol_metadata_t` instance.
75 * @return A NULL-terminated string carrying the negotiated protocol.
77 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
78 const char * _Nullable
79 sec_protocol_metadata_get_negotiated_protocol(sec_protocol_metadata_t metadata
);
82 * @function sec_protocol_metadata_copy_peer_public_key
85 * Get the protocol instance peer's public key.
88 * A `sec_protocol_metadata_t` instance.
90 * @return A `dispatch_data_t` containing the peer's raw public key.
92 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
93 SEC_RETURNS_RETAINED _Nullable dispatch_data_t
94 sec_protocol_metadata_copy_peer_public_key(sec_protocol_metadata_t metadata
);
97 * @function sec_protocol_metadata_get_negotiated_tls_protocol_version
100 * Get the negotiated TLS version.
103 * A `sec_protocol_metadata_t` instance.
105 * @return A `tls_protocol_version_t` value.
107 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
108 tls_protocol_version_t
109 sec_protocol_metadata_get_negotiated_tls_protocol_version(sec_protocol_metadata_t metadata
);
112 * @function sec_protocol_metadata_get_negotiated_protocol_version
115 * Get the negotiated TLS version.
118 * A `sec_protocol_metadata_t` instance.
120 * @return A SSLProtocol enum of the TLS version.
122 API_DEPRECATED_WITH_REPLACEMENT("sec_protocol_metadata_get_negotiated_tls_protocol_version",
123 macos(10.14, 10.15), ios(12.0, 13.0), watchos(5.0, 6.0), tvos(12.0, 13.0))
125 sec_protocol_metadata_get_negotiated_protocol_version(sec_protocol_metadata_t metadata
);
128 * @function sec_protocol_metadata_get_negotiated_tls_ciphersuite
131 * Get the negotiated TLS ciphersuite.
134 * A `sec_protocol_metadata_t` instance.
136 * @return A `tls_ciphersuite_t`.
138 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
140 sec_protocol_metadata_get_negotiated_tls_ciphersuite(sec_protocol_metadata_t metadata
);
143 * @function sec_protocol_metadata_get_negotiated_ciphersuite
146 * Get the negotiated TLS ciphersuite.
149 * A `sec_protocol_metadata_t` instance.
151 * @return A SSLCipherSuite.
153 API_DEPRECATED_WITH_REPLACEMENT("sec_protocol_metadata_get_negotiated_tls_ciphersuite",
154 macos(10.14, 10.15), ios(12.0, 13.0), watchos(5.0, 6.0), tvos(12.0, 13.0))
155 API_UNAVAILABLE(iosmac
)
157 sec_protocol_metadata_get_negotiated_ciphersuite(sec_protocol_metadata_t metadata
);
160 * @function sec_protocol_metadata_get_early_data_accepted
163 * Determine if early data was accepted by the peer.
166 * A `sec_protocol_metadata_t` instance.
168 * @return A bool indicating if early data was accepted.
170 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
172 sec_protocol_metadata_get_early_data_accepted(sec_protocol_metadata_t metadata
);
176 * @function sec_protocol_metadata_access_peer_certificate_chain
179 * Get the certificate chain of the protocol instance peer.
182 * A `sec_protocol_metadata_t` instance.
185 * A block to invoke one or more times with sec_certificate_t objects
187 * @return Returns true if the peer certificates were accessible, false otherwise.
189 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
191 sec_protocol_metadata_access_peer_certificate_chain(sec_protocol_metadata_t metadata
,
192 void (^handler
)(sec_certificate_t certificate
));
195 * @function sec_protocol_metadata_copy_ocsp_response
198 * Get the OCSP response from the protocol instance peer.
201 * A `sec_protocol_metadata_t` instance.
204 * A block to invoke one or more times with OCSP data
206 * @return Returns true if the OSCP response was accessible, false otherwise.
208 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
210 sec_protocol_metadata_access_ocsp_response(sec_protocol_metadata_t metadata
,
211 void (^handler
)(dispatch_data_t ocsp_data
));
214 * @function sec_protocol_metadata_access_supported_signature_algorithms
217 * Get the signature algorithms supported by the peer. Clients may call this
218 * in response to a challenge block.
221 * A `sec_protocol_metadata_t` instance.
224 * A block to invoke one or more times with OCSP data
226 * @return Returns true if the supported signature list was accessible, false otherwise.
228 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
230 sec_protocol_metadata_access_supported_signature_algorithms(sec_protocol_metadata_t metadata
,
231 void (^handler
)(uint16_t signature_algorithm
));
234 * @function sec_protocol_metadata_access_distinguished_names
237 * Get the X.509 Distinguished Names from the protocol instance peer.
240 * A `sec_protocol_metadata_t` instance.
243 * A block to invoke one or more times with distinguished_name data
245 * @return Returns true if the distinguished names were accessible, false otherwise.
247 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
249 sec_protocol_metadata_access_distinguished_names(sec_protocol_metadata_t metadata
,
250 void (^handler
)(dispatch_data_t distinguished_name
));
253 * @function sec_protocol_metadata_access_pre_shared_keys
256 * Get the PSKs supported by the local instance.
259 * A `sec_protocol_metadata_t` instance.
262 * A block to invoke one or more times with tuples of dispatch_data_t objects carrying PSKs and their corresponding identities.
264 * @return Returns true if the PSKs were accessible, false otherwise.
266 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
268 sec_protocol_metadata_access_pre_shared_keys(sec_protocol_metadata_t metadata
, void (^handler
)(dispatch_data_t psk
, dispatch_data_t psk_identity
));
273 * @function sec_protocol_metadata_get_server_name
276 * Obtain the server name offered by a client or server during
277 * connection establishmet. This is the value commonly carried
278 * in the TLS SNI extesion.
281 * A `sec_protocol_metadata_t` instance.
283 * @return Returns A NULL-terminated string carrying the server name, or NULL
284 * if none was provided.
286 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
287 const char * _Nullable
288 sec_protocol_metadata_get_server_name(sec_protocol_metadata_t metadata
);
291 * @function sec_protocol_metadata_peers_are_equal
294 * Compare peer information for two `sec_protocol_metadata` instances.
295 * This comparison does not include protocol configuration options, e.g., ciphersuites.
298 * A `sec_protocol_metadata_t` instance.
301 * A `sec_protocol_metadata_t` instance.
303 * @return Returns true if both metadata values refer to the same peer, and false otherwise.
305 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
307 sec_protocol_metadata_peers_are_equal(sec_protocol_metadata_t metadataA
, sec_protocol_metadata_t metadataB
);
310 * @function sec_protocol_metadata_challenge_parameters_are_equal
313 * Compare challenge-relevant information for two `sec_protocol_metadata` instances.
315 * This comparison includes all information relevant to a challenge request, including:
316 * distinguished names, signature algorithms, and supported certificate types.
317 * See Section 7.4.4 of RFC5246 for more details.
320 * A `sec_protocol_metadata_t` instance.
323 * A `sec_protocol_metadata_t` instance.
325 * @return Returns true if both metadata values have the same challenge parameters.
327 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
329 sec_protocol_metadata_challenge_parameters_are_equal(sec_protocol_metadata_t metadataA
, sec_protocol_metadata_t metadataB
);
332 * @function sec_protocol_metadata_create_secret
335 * Export a secret, e.g., a cryptographic key, derived from the protocol metadata using a label string.
338 * A `sec_protocol_metadata_t` instance.
341 * Length of the KDF label string.
346 * @param exporter_length
347 * Length of the secret to be exported.
349 * @return Returns a dispatch_data_t object carrying the exported secret.
351 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
352 SEC_RETURNS_RETAINED _Nullable dispatch_data_t
353 sec_protocol_metadata_create_secret(sec_protocol_metadata_t metadata
, size_t label_len
,
354 const char *label
, size_t exporter_length
);
357 * @function sec_protocol_metadata_create_secret_with_context
360 * Export a secret, e.g., a cryptographic key, derived from the protocol metadata using a label and context string.
363 * A `sec_protocol_metadata_t` instance.
366 * Length of the KDF label string.
372 * Length of the KDF context string.
375 * Constant opaque context value
377 * @param exporter_length
378 * Length of the secret to be exported.
380 * @return Returns a dispatch_data_t object carrying the exported secret.
382 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
383 SEC_RETURNS_RETAINED _Nullable dispatch_data_t
384 sec_protocol_metadata_create_secret_with_context(sec_protocol_metadata_t metadata
, size_t label_len
,
385 const char *label
, size_t context_len
,
386 const uint8_t *context
, size_t exporter_length
);
388 SEC_ASSUME_NONNULL_END
392 #endif // SecProtocolMetadata_h