2 * Copyright (c) 1999-2001,2005-2012 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@
25 * SecureTransportPriv.h - Apple-private exported routines
28 #ifndef _SECURE_TRANSPORT_PRIV_H_
29 #define _SECURE_TRANSPORT_PRIV_H_ 1
31 #include <Security/SecureTransport.h>
32 #include <Security/SecTrust.h>
38 /* The size of of client- and server-generated random numbers in hello messages. */
39 #define SSL_CLIENT_SRVR_RAND_SIZE 32
41 /* The size of the pre-master and master secrets. */
42 #define SSL_RSA_PREMASTER_SECRET_SIZE 48
43 #define SSL_MASTER_SECRET_SIZE 48
46 * For the following three functions, *size is the available
47 * buffer size on entry and the actual size of the data returned
48 * on return. The above consts are for convenience.
50 OSStatus
SSLInternalMasterSecret(
51 SSLContextRef context
,
52 void *secret
, // mallocd by caller, SSL_MASTER_SECRET_SIZE
53 size_t *secretSize
); // in/out
55 OSStatus
SSLInternalServerRandom(
56 SSLContextRef context
,
57 void *randBuf
, // mallocd by caller, SSL_CLIENT_SRVR_RAND_SIZE
58 size_t *randSize
); // in/out
60 OSStatus
SSLInternalClientRandom(
61 SSLContextRef context
,
62 void *randBuf
, // mallocd by caller, SSL_CLIENT_SRVR_RAND_SIZE
63 size_t *randSize
); // in/out
66 * Obtain the sizes of the currently negotiated HMAC digest, session
67 * key, and session key IV.
69 OSStatus
SSLGetCipherSizes(
70 SSLContextRef context
,
72 size_t *symmetricKeySize
,
75 OSStatus
SSLInternal_PRF(
76 SSLContextRef context
,
83 void *out
, // mallocd by caller, length >= outLen
87 * Obtain a SecTrustRef representing peer certificates. Valid anytime,
88 * subsequent to a handshake attempt. The returned SecTrustRef is valid
89 * only as long as the SSLContextRef is.
92 SSLGetPeerSecTrust (SSLContextRef context
,
93 SecTrustRef
*secTrust
); /* RETURNED */
96 * Obtain resumable session info. Can be called anytime subsequent to
99 * if sessionWasResumed is True on return, the session is indeed a
100 * resumed session; the sessionID (an opaque blob generated by the
101 * server) is returned in *sessionID. The length of the sessionID
102 * is returned in *sessionIDLength. Caller must allocate the
103 * sessionID buffer; it max size is MAX_SESSION_ID_LENGTH bytes.
105 #define MAX_SESSION_ID_LENGTH 32
108 SSLGetResumableSessionInfo (
109 SSLContextRef context
,
110 Boolean
*sessionWasResumed
, // RETURNED
111 void *sessionID
, // RETURNED, mallocd by caller
112 size_t *sessionIDLength
); // IN/OUT
115 * Getters for SSLSetCertificate() and SSLSetEncryptionCertificate()
119 SSLContextRef context
,
120 CFArrayRef
*certRefs
); // RETURNED, *not* retained
123 SSLGetEncryptionCertificate (
124 SSLContextRef context
,
125 CFArrayRef
*certRefs
); // RETURNED, *not* retained
128 * Getter for SSLSetClientSideAuthenticate()
131 SSLGetClientSideAuthenticate (
132 SSLContextRef context
,
133 SSLAuthenticate
*auth
); // RETURNED
136 * Get/set array of trusted leaf certificates.
138 * If none have been set previously with SSLSetTrustedLeafCertificates(),
139 * then SSLCopyTrustedLeafCertificates() will return NULL with noErr.
142 SSLSetTrustedLeafCertificates (
143 SSLContextRef context
,
144 CFArrayRef certRefs
);
147 SSLCopyTrustedLeafCertificates (
148 SSLContextRef context
,
149 CFArrayRef
*certRefs
); // RETURNED, caller must release
152 * Get/set enable of anonymous ciphers. Default is enabled.
154 * SSLSetAllowAnonymousCiphers() returns badReqErr if SSLSetEnabledCiphers()
155 * has already been called.
157 * The enable state set by SSLSetAllowAnonymousCiphers() is ignored if
158 * SSLSetEnabledCiphers() is called after SSLSetAllowAnonymousCiphers() is
159 * called, i.e., SSLSetEnabledCiphers() overrides SSLSetAllowAnonymousCiphers().
161 * NOTE: "Anonymous" ciphers include those ciphers that perform no encryption,
162 * as well as ciphers that perform no authentication, since neither are secure.
165 SSLSetAllowAnonymousCiphers(
166 SSLContextRef context
,
170 SSLGetAllowAnonymousCiphers(
171 SSLContextRef context
,
175 * Override the default session cache timeout for a cache entry created for
176 * the current session.
179 SSLSetSessionCacheTimeout(
180 SSLContextRef context
,
181 uint32_t timeoutInSeconds
);
184 * Callback function for EAP-style PAC-based session resumption.
185 * This function is called by SecureTransport to obtain the
188 typedef void (*SSLInternalMasterSecretFunction
)(
190 const void *arg
, /* opaque to SecureTransport; app-specific */
191 void *secret
, /* mallocd by caller, SSL_MASTER_SECRET_SIZE */
192 size_t *secretLength
); /* in/out */
195 * Register a callback for obtaining the master_secret when performing
196 * PAC-based session resumption. At the time the callback is called,
197 * the following are guaranteed to be valid:
199 * -- serverRandom (via SSLInternalServerRandom())
200 * -- clientRandom (via SSLInternalClientRandom())
201 * -- negotiated protocol version (via SSLGetNegotiatedProtocolVersion())
202 * -- negotiated CipherSuite (via SSLGetNegotiatedCipher())
204 * Currently, PAC-based session resumption is only implemented on
205 * the client side for Deployment builds.
207 * On the client side, this callback occurs if/when the server sends a
208 * ChangeCipherSpec message immediately following its ServerHello
209 * message (i.e., it's skipped the entire Key Exchange phase of
212 * On the server side (Development builds only) this callback occurs
213 * immediately upon receipt of the Client Hello message, before we send
217 SSLInternalSetMasterSecretFunction(
219 SSLInternalMasterSecretFunction mFunc
,
220 const void *arg
); /* opaque to SecureTransport; app-specific */
223 * Provide an opaque SessionTicket for use in PAC-based session
224 * resumption. Client side only. The provided ticket is sent in
225 * the ClientHello message as a SessionTicket extension.
226 * The maximum ticketLength is 2**16-1.
228 OSStatus
SSLInternalSetSessionTicket(
231 size_t ticketLength
);
234 * Support for specifying and obtaining ECC curves, used with the ECDH-based
239 * These are the named curves from RFC 4492
240 * section 5.1.1, with the exception of SSL_Curve_None which means
241 * "ECDSA not negotiated".
247 SSL_Curve_sect163k1
= 1,
248 SSL_Curve_sect163r1
= 2,
249 SSL_Curve_sect163r2
= 3,
250 SSL_Curve_sect193r1
= 4,
251 SSL_Curve_sect193r2
= 5,
252 SSL_Curve_sect233k1
= 6,
253 SSL_Curve_sect233r1
= 7,
254 SSL_Curve_sect239k1
= 8,
255 SSL_Curve_sect283k1
= 9,
256 SSL_Curve_sect283r1
= 10,
257 SSL_Curve_sect409k1
= 11,
258 SSL_Curve_sect409r1
= 12,
259 SSL_Curve_sect571k1
= 13,
260 SSL_Curve_sect571r1
= 14,
261 SSL_Curve_secp160k1
= 15,
262 SSL_Curve_secp160r1
= 16,
263 SSL_Curve_secp160r2
= 17,
264 SSL_Curve_secp192k1
= 18,
265 SSL_Curve_secp192r1
= 19,
266 SSL_Curve_secp224k1
= 20,
267 SSL_Curve_secp224r1
= 21,
268 SSL_Curve_secp256k1
= 22,
270 /* These are the ones we actually support */
271 SSL_Curve_secp256r1
= 23,
272 SSL_Curve_secp384r1
= 24,
273 SSL_Curve_secp521r1
= 25
274 } SSL_ECDSA_NamedCurve
;
277 * Obtain the SSL_ECDSA_NamedCurve negotiated during a handshake.
278 * Returns paramErr if no ECDH-related ciphersuite was negotiated.
280 extern OSStatus
SSLGetNegotiatedCurve(
282 SSL_ECDSA_NamedCurve
*namedCurve
); /* RETURNED */
285 * Obtain the number of currently enabled SSL_ECDSA_NamedCurves.
287 extern OSStatus
SSLGetNumberOfECDSACurves(
289 unsigned *numCurves
); /* RETURNED */
292 * Obtain the ordered list of currently enabled SSL_ECDSA_NamedCurves.
293 * Caller allocates returned array and specifies its size (in
294 * SSL_ECDSA_NamedCurves) in *numCurves on entry; *numCurves
295 * is the actual size of the returned array on successful return.
297 extern OSStatus
SSLGetECDSACurves(
299 SSL_ECDSA_NamedCurve
*namedCurves
, /* RETURNED */
300 unsigned *numCurves
); /* IN/OUT */
303 * Specify ordered list of allowable named curves.
305 extern OSStatus
SSLSetECDSACurves(
307 const SSL_ECDSA_NamedCurve
*namedCurves
,
311 * Server-specified client authentication mechanisms.
314 /* doesn't appear on the wire */
315 SSLClientAuthNone
= -1,
317 SSLClientAuth_RSASign
= 1,
318 SSLClientAuth_DSSSign
= 2,
319 SSLClientAuth_RSAFixedDH
= 3,
320 SSLClientAuth_DSS_FixedDH
= 4,
322 SSLClientAuth_ECDSASign
= 64,
323 SSLClientAuth_RSAFixedECDH
= 65,
324 SSLClientAuth_ECDSAFixedECDH
= 66
325 } SSLClientAuthenticationType
;
327 /* TLS 1.2 Signature Algorithms extension values for hash field. */
329 SSL_HashAlgorithmNone
= 0,
330 SSL_HashAlgorithmMD5
= 1,
331 SSL_HashAlgorithmSHA1
= 2,
332 SSL_HashAlgorithmSHA224
= 3,
333 SSL_HashAlgorithmSHA256
= 4,
334 SSL_HashAlgorithmSHA384
= 5,
335 SSL_HashAlgorithmSHA512
= 6
338 /* TLS 1.2 Signature Algorithms extension values for signature field. */
340 SSL_SignatureAlgorithmAnonymous
= 0,
341 SSL_SignatureAlgorithmRSA
= 1,
342 SSL_SignatureAlgorithmDSA
= 2,
343 SSL_SignatureAlgorithmECDSA
= 3
344 } SSL_SignatureAlgorithm
;
347 SSL_HashAlgorithm hash
;
348 SSL_SignatureAlgorithm signature
;
349 } SSLSignatureAndHashAlgorithm
;
352 * Obtain the number of client authentication mechanisms specified by
353 * the server in its Certificate Request message.
354 * Returns paramErr if server hasn't sent a Certificate Request message
355 * (i.e., client certificate state is kSSLClientCertNone).
357 extern OSStatus
SSLGetNumberOfClientAuthTypes(
362 * Obtain the client authentication mechanisms specified by
363 * the server in its Certificate Request message.
364 * Caller allocates returned array and specifies its size (in
365 * SSLClientAuthenticationTypes) in *numType on entry; *numTypes
366 * is the actual size of the returned array on successful return.
368 extern OSStatus
SSLGetClientAuthTypes(
370 SSLClientAuthenticationType
*authTypes
, /* RETURNED */
371 unsigned *numTypes
); /* IN/OUT */
374 * Obtain the SSLClientAuthenticationType actually performed.
375 * Only valid if client certificate state is kSSLClientCertSent
376 * or kSSLClientCertRejected; SSLClientAuthNone is returned as
377 * the negotiated auth type otherwise.
379 extern OSStatus
SSLGetNegotiatedClientAuthType(
381 SSLClientAuthenticationType
*authType
); /* RETURNED */
384 * Obtain the number of supported_signature_algorithms specified by
385 * the server in its Certificate Request message.
386 * Returns paramErr if server hasn't sent a Certificate Request message
387 * (i.e., client certificate state is kSSLClientCertNone).
389 extern OSStatus
SSLGetNumberOfSignatureAlgorithms(
391 unsigned *numSigAlgs
);
394 * Obtain the supported_signature_algorithms specified by
395 * the server in its Certificate Request message.
396 * Caller allocates returned array and specifies its size (in
397 * SSLClientAuthenticationTypes) in *numType on entry; *numTypes
398 * is the actual size of the returned array on successful return.
400 extern OSStatus
SSLGetSignatureAlgorithms(
402 SSLSignatureAndHashAlgorithm
*sigAlgs
, /* RETURNED */
403 unsigned *numSigAlgs
); /* IN/OUT */
406 * Create a new Datagram TLS session context.
407 * Use in place of SSLNewContext to create a DTLS session.
408 * Deprecated: please use the allocator based functions, when available.
411 SSLNewDatagramContext (Boolean isServer
,
412 SSLContextRef
*dtlsContextPtr
); /* RETURNED */
416 /* Private SSL session options */
419 * This option can be used to enable sending the first byte
420 * of application data in its own SSL record in order to
421 * mitigate a known-IV weakness, a.k.a. the BEAST attack.
423 kSSLSessionOptionSendOneByteRecord
= -1
424 } SSLPrivateSessionOption
;
430 #endif /* _SECURE_TRANSPORT_PRIV_H_ */