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/SecBase.h>
30 #include <Security/SecureTransport.h>
32 #include <dispatch/dispatch.h>
33 #include <os/object.h>
36 * The following diagram shows how clients interact with sec_protocol_options
37 * and sec_protocol_metadata when configuring and using network security protocols.
43 * +-------------+ +-------------+
45 * | options metadata |
46 * +-----\ /---------------+ +------------+----------+
47 * | sec_protocol_options | | sec_protocol_metadata |
48 * +-----------------------+ +-----------------------+
50 * Clients configure security protocols with `sec_protocol_options` instances.
51 * And they inspect protocol instances using `sec_protocol_metadata` instances.
54 #ifndef SEC_OBJECT_IMPL
56 * A `sec_protocol_metadata` instance conatins read-only properties of a connected and configured
57 * security protocol. Clients use this object to read information about a protocol instance. Properties
58 * include, for example, the negotiated TLS version, ciphersuite, and peer certificates.
60 SEC_OBJECT_DECL(sec_protocol_metadata
);
61 #endif // !SEC_OBJECT_IMPL
65 SEC_ASSUME_NONNULL_BEGIN
68 * @function sec_protocol_metadata_get_negotiated_protocol
71 * Get the application protocol negotiated, e.g., via the TLS ALPN extension.
74 * A `sec_protocol_metadata_t` instance.
76 * @return A NULL-terminated string carrying the negotiated protocol.
78 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
79 const char * _Nullable
80 sec_protocol_metadata_get_negotiated_protocol(sec_protocol_metadata_t metadata
);
83 * @function sec_protocol_metadata_copy_peer_public_key
86 * Get the protocol instance peer's public key.
89 * A `sec_protocol_metadata_t` instance.
91 * @return A `dispatch_data_t` containing the peer's raw public key.
93 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
94 SEC_RETURNS_RETAINED _Nullable dispatch_data_t
95 sec_protocol_metadata_copy_peer_public_key(sec_protocol_metadata_t metadata
);
98 * @function sec_protocol_metadata_get_negotiated_protocol_version
101 * Get the negotiated TLS version.
104 * A `sec_protocol_metadata_t` instance.
106 * @return A SSLProtocol enum of the TLS version.
108 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
110 sec_protocol_metadata_get_negotiated_protocol_version(sec_protocol_metadata_t metadata
);
113 * @function sec_protocol_metadata_get_negotiated_ciphersuite
116 * Get the negotiated TLS ciphersuite.
119 * A `sec_protocol_metadata_t` instance.
121 * @return A SSLCipherSuite.
123 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
125 sec_protocol_metadata_get_negotiated_ciphersuite(sec_protocol_metadata_t metadata
);
128 * @function sec_protocol_metadata_get_early_data_accepted
131 * Determine if early data was accepted by the peer.
134 * A `sec_protocol_metadata_t` instance.
136 * @return A bool indicating if early data was accepted.
138 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
140 sec_protocol_metadata_get_early_data_accepted(sec_protocol_metadata_t metadata
);
144 * @function sec_protocol_metadata_access_peer_certificate_chain
147 * Get the certificate chain of the protocol instance peer.
150 * A `sec_protocol_metadata_t` instance.
153 * A block to invoke one or more times with sec_certificate_t objects
155 * @return Returns true if the peer certificates were accessible, false otherwise.
157 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
159 sec_protocol_metadata_access_peer_certificate_chain(sec_protocol_metadata_t metadata
,
160 void (^handler
)(sec_certificate_t certificate
));
163 * @function sec_protocol_metadata_copy_ocsp_response
166 * Get the OCSP response from the protocol instance peer.
169 * A `sec_protocol_metadata_t` instance.
172 * A block to invoke one or more times with OCSP data
174 * @return Returns true if the OSCP response was accessible, false otherwise.
176 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
178 sec_protocol_metadata_access_ocsp_response(sec_protocol_metadata_t metadata
,
179 void (^handler
)(dispatch_data_t ocsp_data
));
182 * @function sec_protocol_metadata_access_supported_signature_algorithms
185 * Get the signature algorithms supported by the peer. Clients may call this
186 * in response to a challenge block.
189 * A `sec_protocol_metadata_t` instance.
192 * A block to invoke one or more times with OCSP data
194 * @return Returns true if the supported signature list was accessible, false otherwise.
196 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
198 sec_protocol_metadata_access_supported_signature_algorithms(sec_protocol_metadata_t metadata
,
199 void (^handler
)(uint16_t signature_algorithm
));
202 * @function sec_protocol_metadata_access_distinguished_names
205 * Get the X.509 Distinguished Names from the protocol instance peer.
208 * A `sec_protocol_metadata_t` instance.
211 * A block to invoke one or more times with distinguished_name data
213 * @return Returns true if the distinguished names were accessible, false otherwise.
215 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
217 sec_protocol_metadata_access_distinguished_names(sec_protocol_metadata_t metadata
,
218 void (^handler
)(dispatch_data_t distinguished_name
));
222 * @function sec_protocol_metadata_peers_are_equal
225 * Compare peer information for two `sec_protocol_metadata` instances.
226 * This comparison does not include protocol configuration options, e.g., ciphersuites.
229 * A `sec_protocol_metadata_t` instance.
232 * A `sec_protocol_metadata_t` instance.
234 * @return Returns true if both metadata values refer to the same peer, and false otherwise.
236 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
238 sec_protocol_metadata_peers_are_equal(sec_protocol_metadata_t metadataA
, sec_protocol_metadata_t metadataB
);
241 * @function sec_protocol_metadata_challenge_parameters_are_equal
244 * Compare challenge-relevant information for two `sec_protocol_metadata` instances.
246 * This comparison includes all information relevant to a challenge request, including:
247 * distinguished names, signature algorithms, and supported certificate types.
248 * See Section 7.4.4 of RFC5246 for more details.
251 * A `sec_protocol_metadata_t` instance.
254 * A `sec_protocol_metadata_t` instance.
256 * @return Returns true if both metadata values have the same challenge parameters.
258 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
260 sec_protocol_metadata_challenge_parameters_are_equal(sec_protocol_metadata_t metadataA
, sec_protocol_metadata_t metadataB
);
263 * @function sec_protocol_metadata_create_secret
266 * Export a secret, e.g., a cryptographic key, derived from the protocol metadata using a label string.
269 * A `sec_protocol_metadata_t` instance.
272 * Length of the KDF label string.
277 * @param exporter_length
278 * Length of the secret to be exported.
280 * @return Returns a dispatch_data_t object carrying the exported secret.
282 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
283 SEC_RETURNS_RETAINED _Nullable dispatch_data_t
284 sec_protocol_metadata_create_secret(sec_protocol_metadata_t metadata
, size_t label_len
,
285 const char *label
, size_t exporter_length
);
288 * @function sec_protocol_metadata_create_secret_with_context
291 * Export a secret, e.g., a cryptographic key, derived from the protocol metadata using a label and context string.
294 * A `sec_protocol_metadata_t` instance.
297 * Length of the KDF label string.
303 * Length of the KDF context string.
306 * Constant opaque context value
308 * @param exporter_length
309 * Length of the secret to be exported.
311 * @return Returns a dispatch_data_t object carrying the exported secret.
313 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
314 SEC_RETURNS_RETAINED _Nullable dispatch_data_t
315 sec_protocol_metadata_create_secret_with_context(sec_protocol_metadata_t metadata
, size_t label_len
,
316 const char *label
, size_t context_len
,
317 const uint8_t *context
, size_t exporter_length
);
319 SEC_ASSUME_NONNULL_END
323 #endif // SecProtocolMetadata_h