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.15), ios(13.0), watchos(6.0), tvos(13.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), macCatalyst(13.0, 13.0))
156 sec_protocol_metadata_get_negotiated_ciphersuite(sec_protocol_metadata_t metadata
);
159 * @function sec_protocol_metadata_get_early_data_accepted
162 * Determine if early data was accepted by the peer.
165 * A `sec_protocol_metadata_t` instance.
167 * @return A bool indicating if early data was accepted.
169 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
171 sec_protocol_metadata_get_early_data_accepted(sec_protocol_metadata_t metadata
);
175 * @function sec_protocol_metadata_access_peer_certificate_chain
178 * Get the certificate chain of the protocol instance peer.
181 * A `sec_protocol_metadata_t` instance.
184 * A block to invoke one or more times with sec_certificate_t objects
186 * @return Returns true if the peer certificates were accessible, false otherwise.
188 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
190 sec_protocol_metadata_access_peer_certificate_chain(sec_protocol_metadata_t metadata
,
191 void (^handler
)(sec_certificate_t certificate
));
194 * @function sec_protocol_metadata_copy_ocsp_response
197 * Get the OCSP response from the protocol instance peer.
200 * A `sec_protocol_metadata_t` instance.
203 * A block to invoke one or more times with OCSP data
205 * @return Returns true if the OSCP response was accessible, false otherwise.
207 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
209 sec_protocol_metadata_access_ocsp_response(sec_protocol_metadata_t metadata
,
210 void (^handler
)(dispatch_data_t ocsp_data
));
213 * @function sec_protocol_metadata_access_supported_signature_algorithms
216 * Get the signature algorithms supported by the peer. Clients may call this
217 * in response to a challenge block.
220 * A `sec_protocol_metadata_t` instance.
223 * A block to invoke one or more times with OCSP data
225 * @return Returns true if the supported signature list was accessible, false otherwise.
227 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
229 sec_protocol_metadata_access_supported_signature_algorithms(sec_protocol_metadata_t metadata
,
230 void (^handler
)(uint16_t signature_algorithm
));
233 * @function sec_protocol_metadata_access_distinguished_names
236 * Get the X.509 Distinguished Names from the protocol instance peer.
239 * A `sec_protocol_metadata_t` instance.
242 * A block to invoke one or more times with distinguished_name data
244 * @return Returns true if the distinguished names were accessible, false otherwise.
246 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
248 sec_protocol_metadata_access_distinguished_names(sec_protocol_metadata_t metadata
,
249 void (^handler
)(dispatch_data_t distinguished_name
));
252 * @function sec_protocol_metadata_access_pre_shared_keys
255 * Get the PSKs supported by the local instance.
258 * A `sec_protocol_metadata_t` instance.
261 * A block to invoke one or more times with tuples of dispatch_data_t objects carrying PSKs and their corresponding identities.
263 * @return Returns true if the PSKs were accessible, false otherwise.
265 API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
267 sec_protocol_metadata_access_pre_shared_keys(sec_protocol_metadata_t metadata
, void (^handler
)(dispatch_data_t psk
, dispatch_data_t psk_identity
));
272 * @function sec_protocol_metadata_get_server_name
275 * Obtain the server name offered by a client or server during
276 * connection establishmet. This is the value commonly carried
277 * in the TLS SNI extesion.
280 * A `sec_protocol_metadata_t` instance.
282 * @return Returns A NULL-terminated string carrying the server name, or NULL
283 * if none was provided.
285 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
286 const char * _Nullable
287 sec_protocol_metadata_get_server_name(sec_protocol_metadata_t metadata
);
290 * @function sec_protocol_metadata_peers_are_equal
293 * Compare peer information for two `sec_protocol_metadata` instances.
294 * This comparison does not include protocol configuration options, e.g., ciphersuites.
297 * A `sec_protocol_metadata_t` instance.
300 * A `sec_protocol_metadata_t` instance.
302 * @return Returns true if both metadata values refer to the same peer, and false otherwise.
304 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
306 sec_protocol_metadata_peers_are_equal(sec_protocol_metadata_t metadataA
, sec_protocol_metadata_t metadataB
);
309 * @function sec_protocol_metadata_challenge_parameters_are_equal
312 * Compare challenge-relevant information for two `sec_protocol_metadata` instances.
314 * This comparison includes all information relevant to a challenge request, including:
315 * distinguished names, signature algorithms, and supported certificate types.
316 * See Section 7.4.4 of RFC5246 for more details.
319 * A `sec_protocol_metadata_t` instance.
322 * A `sec_protocol_metadata_t` instance.
324 * @return Returns true if both metadata values have the same challenge parameters.
326 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
328 sec_protocol_metadata_challenge_parameters_are_equal(sec_protocol_metadata_t metadataA
, sec_protocol_metadata_t metadataB
);
331 * @function sec_protocol_metadata_create_secret
334 * Export a secret, e.g., a cryptographic key, derived from the protocol metadata using a label string.
337 * A `sec_protocol_metadata_t` instance.
340 * Length of the KDF label string.
345 * @param exporter_length
346 * Length of the secret to be exported.
348 * @return Returns a dispatch_data_t object carrying the exported secret.
350 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
351 SEC_RETURNS_RETAINED _Nullable dispatch_data_t
352 sec_protocol_metadata_create_secret(sec_protocol_metadata_t metadata
, size_t label_len
,
353 const char *label
, size_t exporter_length
);
356 * @function sec_protocol_metadata_create_secret_with_context
359 * Export a secret, e.g., a cryptographic key, derived from the protocol metadata using a label and context string.
362 * A `sec_protocol_metadata_t` instance.
365 * Length of the KDF label string.
371 * Length of the KDF context string.
374 * Constant opaque context value
376 * @param exporter_length
377 * Length of the secret to be exported.
379 * @return Returns a dispatch_data_t object carrying the exported secret.
381 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
382 SEC_RETURNS_RETAINED _Nullable dispatch_data_t
383 sec_protocol_metadata_create_secret_with_context(sec_protocol_metadata_t metadata
, size_t label_len
,
384 const char *label
, size_t context_len
,
385 const uint8_t *context
, size_t exporter_length
);
387 SEC_ASSUME_NONNULL_END
391 #endif // SecProtocolMetadata_h