2 * Copyright (c) 1999-2002,2005-2016 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 * SecureTransport.h - Public API for Apple SSL/TLS Implementation
28 #ifndef _SECURITY_SECURETRANSPORT_H_
29 #define _SECURITY_SECURETRANSPORT_H_
32 * This file describes the public API for an implementation of the
33 * Secure Socket Layer, V. 3.0, Transport Layer Security, V. 1.0 to V. 1.2
34 * and Datagram Transport Layer Security V. 1.0
36 * There are no transport layer dependencies in this library;
37 * it can be used with sockets, Open Transport, etc. Applications using
38 * this library provide callback functions which do the actual I/O
39 * on underlying network connections. Applications are also responsible
40 * for setting up raw network connections; the application passes in
41 * an opaque reference to the underlying (connected) entity at the
42 * start of an SSL session in the form of an SSLConnectionRef.
46 * A "client" is the initiator of an SSL Session. The canonical example
47 * of a client is a web browser, when it's talking to an https URL.
49 * A "server" is an entity which accepts requests for SSL sessions made
50 * by clients. E.g., a secure web server.
52 * An "SSL Session", or "session", is bounded by calls to SSLHandshake()
53 * and SSLClose(). An "Active session" is in some state between these
54 * two calls, inclusive.
56 * An SSL Session Context, or SSLContextRef, is an opaque reference in this
57 * library to the state associated with one session. A SSLContextRef cannot
58 * be reused for multiple sessions.
61 #include <CoreFoundation/CFArray.h>
62 #include <Security/CipherSuite.h>
63 #include <Security/SecTrust.h>
64 #include <sys/types.h>
65 #include <Availability.h>
71 CF_ASSUME_NONNULL_BEGIN
72 CF_IMPLICIT_BRIDGING_ENABLED
74 /***********************
75 *** Common typedefs ***
76 ***********************/
78 /* Opaque reference to an SSL session context */
80 typedef struct CF_BRIDGED_TYPE(id
) SSLContext
*SSLContextRef
;
82 /* Opaque reference to an I/O connection (socket, endpoint, etc.) */
83 typedef const void * SSLConnectionRef
;
85 /* SSL Protocol version */
86 typedef CF_ENUM(int, SSLProtocol
) {
87 kSSLProtocolUnknown
= 0, /* no protocol negotiated/specified; use default */
88 kSSLProtocol3
= 2, /* SSL 3.0 */
89 kTLSProtocol1
= 4, /* TLS 1.0 */
90 kTLSProtocol11
= 7, /* TLS 1.1 */
91 kTLSProtocol12
= 8, /* TLS 1.2 */
92 kDTLSProtocol1
= 9, /* DTLS 1.0 */
94 /* DEPRECATED on iOS */
95 kSSLProtocol2
= 1, /* SSL 2.0 */
96 kSSLProtocol3Only
= 3, /* SSL 3.0 Only */
97 kTLSProtocol1Only
= 5, /* TLS 1.0 Only */
98 kSSLProtocolAll
= 6, /* All TLS supported protocols */
102 /* SSL session options */
103 typedef CF_ENUM(int, SSLSessionOption
) {
105 * Set this option to enable returning from SSLHandshake (with a result of
106 * errSSLServerAuthCompleted) when the server authentication portion of the
107 * handshake is complete. This disable certificate verification and
108 * provides an opportunity to perform application-specific server
109 * verification before deciding to continue.
111 kSSLSessionOptionBreakOnServerAuth
= 0,
113 * Set this option to enable returning from SSLHandshake (with a result of
114 * errSSLClientCertRequested) when the server requests a client certificate.
116 kSSLSessionOptionBreakOnCertRequested
= 1,
118 * This option is the same as kSSLSessionOptionBreakOnServerAuth but applies
119 * to the case where SecureTransport is the server and the client has presented
120 * its certificates allowing the server to verify whether these should be
121 * allowed to authenticate.
123 kSSLSessionOptionBreakOnClientAuth
= 2,
125 * Enable/Disable TLS False Start
126 * When enabled, False Start will only be performed if a adequate cipher-suite is
129 kSSLSessionOptionFalseStart
= 3,
131 * Enable/Disable 1/n-1 record splitting for BEAST attack mitigation.
132 * When enabled, record splitting will only be performed for TLS 1.0 connections
133 * using a block cipher.
135 kSSLSessionOptionSendOneByteRecord
= 4,
137 * Allow/Disallow server identity change on renegotiation. Disallow by default
138 * to avoid Triple Handshake attack.
140 kSSLSessionOptionAllowServerIdentityChange
= 5,
142 * Enable fallback countermeasures. Use this option when retyring a SSL connection
143 * with a lower protocol version because of failure to connect.
145 kSSLSessionOptionFallback
= 6,
147 * Set this option to break from a client hello in order to check for SNI
149 kSSLSessionOptionBreakOnClientHello
= 7,
151 * Set this option to Allow renegotations. False by default.
153 kSSLSessionOptionAllowRenegotiation
= 8,
157 /* State of an SSLSession */
158 typedef CF_ENUM(int, SSLSessionState
) {
159 kSSLIdle
, /* no I/O performed yet */
160 kSSLHandshake
, /* SSL handshake in progress */
161 kSSLConnected
, /* Handshake complete, ready for normal I/O */
162 kSSLClosed
, /* connection closed normally */
163 kSSLAborted
/* connection aborted */
167 * Status of client certificate exchange (which is optional
168 * for both server and client).
170 typedef CF_ENUM(int, SSLClientCertificateState
) {
171 /* Server hasn't asked for a cert. Client hasn't sent one. */
173 /* Server has asked for a cert, but client didn't send it. */
174 kSSLClientCertRequested
,
176 * Server side: We asked for a cert, client sent one, we validated
177 * it OK. App can inspect the cert via
178 * SSLCopyPeerCertificates().
179 * Client side: server asked for one, we sent it.
183 * Client sent a cert but failed validation. Server side only.
184 * Server app can inspect the cert via SSLCopyPeerCertificates().
186 kSSLClientCertRejected
190 * R/W functions. The application using this library provides
191 * these functions via SSLSetIOFuncs().
193 * Data's memory is allocated by caller; on entry to these two functions
194 * the *length argument indicates both the size of the available data and the
195 * requested byte count. Number of bytes actually transferred is returned in
198 * The application may configure the underlying connection to operate
199 * in a non-blocking manner; in such a case, a read operation may
200 * well return errSSLWouldBlock, indicating "I transferred less data than
201 * you requested (maybe even zero bytes), nothing is wrong, except
202 * requested I/O hasn't completed". This will be returned back up to
203 * the application as a return from SSLRead(), SSLWrite(), SSLHandshake(),
207 (*SSLReadFunc
) (SSLConnectionRef connection
,
208 void *data
, /* owned by
211 size_t *dataLength
); /* IN/OUT */
213 (*SSLWriteFunc
) (SSLConnectionRef connection
,
215 size_t *dataLength
); /* IN/OUT */
217 /*************************************************
218 *** OSStatus values unique to SecureTransport ***
219 *************************************************/
222 Note: the comments that appear after these errors are used to create SecErrorMessages.strings.
223 The comments must not be multi-line, and should be in a form meaningful to an end user. If
224 a different or additional comment is needed, it can be put in the header doc format, or on a
225 line that does not start with errZZZ.
229 errSSLProtocol
= -9800, /* SSL protocol error */
230 errSSLNegotiation
= -9801, /* Cipher Suite negotiation failure */
231 errSSLFatalAlert
= -9802, /* Fatal alert */
232 errSSLWouldBlock
= -9803, /* I/O would block (not fatal) */
233 errSSLSessionNotFound
= -9804, /* attempt to restore an unknown session */
234 errSSLClosedGraceful
= -9805, /* connection closed gracefully */
235 errSSLClosedAbort
= -9806, /* connection closed via error */
236 errSSLXCertChainInvalid
= -9807, /* invalid certificate chain */
237 errSSLBadCert
= -9808, /* bad certificate format */
238 errSSLCrypto
= -9809, /* underlying cryptographic error */
239 errSSLInternal
= -9810, /* Internal error */
240 errSSLModuleAttach
= -9811, /* module attach failure */
241 errSSLUnknownRootCert
= -9812, /* valid cert chain, untrusted root */
242 errSSLNoRootCert
= -9813, /* cert chain not verified by root */
243 errSSLCertExpired
= -9814, /* chain had an expired cert */
244 errSSLCertNotYetValid
= -9815, /* chain had a cert not yet valid */
245 errSSLClosedNoNotify
= -9816, /* server closed session with no notification */
246 errSSLBufferOverflow
= -9817, /* insufficient buffer provided */
247 errSSLBadCipherSuite
= -9818, /* bad SSLCipherSuite */
249 /* fatal errors detected by peer */
250 errSSLPeerUnexpectedMsg
= -9819, /* unexpected message received */
251 errSSLPeerBadRecordMac
= -9820, /* bad MAC */
252 errSSLPeerDecryptionFail
= -9821, /* decryption failed */
253 errSSLPeerRecordOverflow
= -9822, /* record overflow */
254 errSSLPeerDecompressFail
= -9823, /* decompression failure */
255 errSSLPeerHandshakeFail
= -9824, /* handshake failure */
256 errSSLPeerBadCert
= -9825, /* misc. bad certificate */
257 errSSLPeerUnsupportedCert
= -9826, /* bad unsupported cert format */
258 errSSLPeerCertRevoked
= -9827, /* certificate revoked */
259 errSSLPeerCertExpired
= -9828, /* certificate expired */
260 errSSLPeerCertUnknown
= -9829, /* unknown certificate */
261 errSSLIllegalParam
= -9830, /* illegal parameter */
262 errSSLPeerUnknownCA
= -9831, /* unknown Cert Authority */
263 errSSLPeerAccessDenied
= -9832, /* access denied */
264 errSSLPeerDecodeError
= -9833, /* decoding error */
265 errSSLPeerDecryptError
= -9834, /* decryption error */
266 errSSLPeerExportRestriction
= -9835, /* export restriction */
267 errSSLPeerProtocolVersion
= -9836, /* bad protocol version */
268 errSSLPeerInsufficientSecurity
= -9837, /* insufficient security */
269 errSSLPeerInternalError
= -9838, /* internal error */
270 errSSLPeerUserCancelled
= -9839, /* user canceled */
271 errSSLPeerNoRenegotiation
= -9840, /* no renegotiation allowed */
273 /* non-fatal result codes */
274 errSSLPeerAuthCompleted
= -9841, /* peer cert is valid, or was ignored if verification disabled */
275 errSSLClientCertRequested
= -9842, /* server has requested a client cert */
277 /* more errors detected by us */
278 errSSLHostNameMismatch
= -9843, /* peer host name mismatch */
279 errSSLConnectionRefused
= -9844, /* peer dropped connection before responding */
280 errSSLDecryptionFail
= -9845, /* decryption failure */
281 errSSLBadRecordMac
= -9846, /* bad MAC */
282 errSSLRecordOverflow
= -9847, /* record overflow */
283 errSSLBadConfiguration
= -9848, /* configuration error */
284 errSSLUnexpectedRecord
= -9849, /* unexpected (skipped) record in DTLS */
285 errSSLWeakPeerEphemeralDHKey
= -9850, /* weak ephemeral dh key */
287 /* non-fatal result codes */
288 errSSLClientHelloReceived
= -9851, /* SNI */
291 /* DEPRECATED aliases for errSSLPeerAuthCompleted */
292 #define errSSLServerAuthCompleted errSSLPeerAuthCompleted
293 #define errSSLClientAuthCompleted errSSLPeerAuthCompleted
295 /* DEPRECATED alias for the end of the error range */
296 #define errSSLLast errSSLUnexpectedRecord
298 typedef CF_ENUM(int, SSLProtocolSide
)
304 typedef CF_ENUM(int, SSLConnectionType
)
311 * Predefined TLS configurations constants
314 /* Default configuration (has 3DES, no RC4) */
315 extern const CFStringRef kSSLSessionConfig_default
;
316 /* ATS v1 Config: TLS v1.2, only PFS ciphersuites */
317 extern const CFStringRef kSSLSessionConfig_ATSv1
;
318 /* ATS v1 Config without PFS: TLS v1.2, include non PFS ciphersuites */
319 extern const CFStringRef kSSLSessionConfig_ATSv1_noPFS
;
320 /* TLS v1.2 to TLS v1.0, with default ciphersuites (no 3DES, no RC4) */
321 extern const CFStringRef kSSLSessionConfig_standard
;
322 /* TLS v1.2 to TLS v1.0, with default ciphersuites + RC4 + 3DES */
323 extern const CFStringRef kSSLSessionConfig_RC4_fallback
;
324 /* TLS v1.0 only, with default ciphersuites + fallback SCSV */
325 extern const CFStringRef kSSLSessionConfig_TLSv1_fallback
;
326 /* TLS v1.0, with default ciphersuites + RC4 + 3DES + fallback SCSV */
327 extern const CFStringRef kSSLSessionConfig_TLSv1_RC4_fallback
;
328 /* TLS v1.2 to TLS v1.0, defaults + RC4 + DHE ciphersuites */
329 extern const CFStringRef kSSLSessionConfig_legacy
;
330 /* TLS v1.2 to TLS v1.0, default + RC4 + DHE ciphersuites */
331 extern const CFStringRef kSSLSessionConfig_legacy_DHE
;
332 /* TLS v1.2, anonymous ciphersuites only */
333 extern const CFStringRef kSSLSessionConfig_anonymous
;
334 /* TLS v1.2 to TLS v1.0, has 3DES, no RC4 */
335 extern const CFStringRef kSSLSessionConfig_3DES_fallback
;
336 /* TLS v1.0, with default ciphersuites + 3DES, no RC4 */
337 extern const CFStringRef kSSLSessionConfig_TLSv1_3DES_fallback
;
345 * Secure Transport APIs require a SSLContextRef, which is an opaque
346 * reference to the SSL session and its parameters. On Mac OS X 10.7
347 * and earlier versions, a new context is created using SSLNewContext,
348 * and is disposed by calling SSLDisposeContext.
350 * On i0S 5.0 and later, as well as Mac OS X versions after 10.7, the
351 * SSLContextRef is a true CFType object with retain-release semantics.
352 * New code should create a new context using SSLCreateContext (instead
353 * of SSLNewContext), and dispose the context by calling CFRelease
354 * (instead of SSLDisposeContext) when finished with it.
358 * Return the CFTypeID for SSLContext objects.
361 SSLContextGetTypeID(void)
362 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
365 * Create a new instance of an SSLContextRef using the specified allocator.
369 SSLCreateContext(CFAllocatorRef __nullable alloc
, SSLProtocolSide protocolSide
, SSLConnectionType connectionType
)
370 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
373 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
375 * Create a new session context.
377 * ==========================
378 * MAC OS X ONLY (DEPRECATED)
379 * ==========================
380 * NOTE: this function is not available on iOS, and should be considered
381 * deprecated on Mac OS X. Your code should use SSLCreateContext instead.
384 SSLNewContext (Boolean isServer
,
385 SSLContextRef
* __nonnull CF_RETURNS_RETAINED contextPtr
) /* RETURNED */
386 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
389 * Dispose of a session context.
391 * ==========================
392 * MAC OS X ONLY (DEPRECATED)
393 * ==========================
394 * NOTE: this function is not available on iOS, and should be considered
395 * deprecated on Mac OS X. Your code should use CFRelease to dispose a session
396 * created with SSLCreateContext.
399 SSLDisposeContext (SSLContextRef context
)
400 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
402 #endif /* MAC OS X */
405 * Determine the state of an SSL/DTLS session.
408 SSLGetSessionState (SSLContextRef context
,
409 SSLSessionState
*state
) /* RETURNED */
410 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
413 * Set options for an SSL session. Must be called prior to SSLHandshake();
414 * subsequently cannot be called while session is active.
417 SSLSetSessionOption (SSLContextRef context
,
418 SSLSessionOption option
,
420 __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_5_0
);
423 * Determine current value for the specified option in a given SSL session.
426 SSLGetSessionOption (SSLContextRef context
,
427 SSLSessionOption option
,
429 __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_5_0
);
431 /********************************************************************
432 *** Session context configuration, common to client and servers. ***
433 ********************************************************************/
436 * Specify functions which do the network I/O. Must be called prior
437 * to SSLHandshake(); subsequently cannot be called while a session is
441 SSLSetIOFuncs (SSLContextRef context
,
442 SSLReadFunc readFunc
,
443 SSLWriteFunc writeFunc
)
444 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
448 * Set a predefined configuration for the SSL Session
450 * This currently affect enabled protocol versions,
451 * enabled ciphersuites, and the kSSLSessionOptionFallback
455 SSLSetSessionConfig(SSLContextRef context
,
457 __OSX_AVAILABLE_STARTING(__MAC_10_12
, __IPHONE_10_0
);
460 * Set the minimum SSL protocol version allowed. Optional.
461 * The default is the lower supported protocol.
463 * This can only be called when no session is active.
465 * For TLS contexts, legal values for minVersion are :
471 * For DTLS contexts, legal values for minVersion are :
475 SSLSetProtocolVersionMin (SSLContextRef context
,
476 SSLProtocol minVersion
)
477 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
480 * Get minimum protocol version allowed
483 SSLGetProtocolVersionMin (SSLContextRef context
,
484 SSLProtocol
*minVersion
)
485 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
488 * Set the maximum SSL protocol version allowed. Optional.
489 * The default is the highest supported protocol.
491 * This can only be called when no session is active.
493 * For TLS contexts, legal values for maxVersion are :
499 * For DTLS contexts, legal values for maxVersion are :
503 SSLSetProtocolVersionMax (SSLContextRef context
,
504 SSLProtocol maxVersion
)
505 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
508 * Get maximum protocol version allowed
511 SSLGetProtocolVersionMax (SSLContextRef context
,
512 SSLProtocol
*maxVersion
)
513 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
516 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
518 * Set allowed SSL protocol versions. Optional.
519 * Specifying kSSLProtocolAll for SSLSetProtocolVersionEnabled results in
520 * specified 'enable' boolean to be applied to all supported protocols.
521 * The default is "all supported protocols are enabled".
522 * This can only be called when no session is active.
524 * Legal values for protocol are :
530 * ==========================
531 * MAC OS X ONLY (DEPRECATED)
532 * ==========================
533 * NOTE: this function is not available on iOS, and should be considered
534 * deprecated on Mac OS X. You can use SSLSetProtocolVersionMin and/or
535 * SSLSetProtocolVersionMax to specify which protocols are enabled.
538 SSLSetProtocolVersionEnabled (SSLContextRef context
,
539 SSLProtocol protocol
,
541 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
544 * Obtain a value specified in SSLSetProtocolVersionEnabled.
546 * ==========================
547 * MAC OS X ONLY (DEPRECATED)
548 * ==========================
549 * NOTE: this function is not available on iOS, and should be considered
550 * deprecated on Mac OS X. You can use SSLGetProtocolVersionMin and/or
551 * SSLGetProtocolVersionMax to check whether a protocol is enabled.
554 SSLGetProtocolVersionEnabled(SSLContextRef context
,
555 SSLProtocol protocol
,
556 Boolean
*enable
) /* RETURNED */
557 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
560 * Get/set SSL protocol version; optional. Default is kSSLProtocolUnknown,
561 * in which case the highest possible version is attempted, but a lower
562 * version is accepted if the peer requires it.
563 * SSLSetProtocolVersion cannot be called when a session is active.
565 * ==========================
566 * MAC OS X ONLY (DEPRECATED)
567 * ==========================
568 * NOTE: this function is not available on iOS, and deprecated on Mac OS X 10.8.
569 * Use SSLSetProtocolVersionMin and/or SSLSetProtocolVersionMax to specify
570 * which protocols are enabled.
573 SSLSetProtocolVersion (SSLContextRef context
,
575 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_8
,__IPHONE_NA
,__IPHONE_NA
);
578 * Obtain the protocol version specified in SSLSetProtocolVersion.
579 * If SSLSetProtocolVersionEnabled() has been called for this session,
580 * SSLGetProtocolVersion() may return errSecParam if the protocol enable
581 * state can not be represented by the SSLProtocol enums (e.g.,
582 * SSL2 and TLS1 enabled, SSL3 disabled).
584 * ==========================
585 * MAC OS X ONLY (DEPRECATED)
586 * ==========================
587 * NOTE: this function is not available on iOS, and deprecated on Mac OS X 10.8.
588 * Use SSLGetProtocolVersionMin and/or SSLGetProtocolVersionMax to check
589 * whether a protocol is enabled.
592 SSLGetProtocolVersion (SSLContextRef context
,
593 SSLProtocol
*protocol
) /* RETURNED */
594 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_8
,__IPHONE_NA
,__IPHONE_NA
);
596 #endif /* MAC OS X */
599 * Specify this connection's certificate(s). This is mandatory for
600 * server connections, optional for clients. Specifying a certificate
601 * for a client enables SSL client-side authentication. The end-entity
602 * cert is in certRefs[0]. Specifying a root cert is optional; if it's
603 * not specified, the root cert which verifies the cert chain specified
604 * here must be present in the system-wide set of trusted anchor certs.
606 * The certRefs argument is a CFArray containing SecCertificateRefs,
607 * except for certRefs[0], which is a SecIdentityRef.
609 * Must be called prior to SSLHandshake(), or immediately after
610 * SSLHandshake has returned errSSLClientCertRequested (i.e. before the
611 * handshake is resumed by calling SSLHandshake again.)
613 * SecureTransport assumes the following:
615 * -- The certRef references remain valid for the lifetime of the session.
616 * -- The certificate specified in certRefs[0] is capable of signing.
617 * -- The required capabilities of the certRef[0], and of the optional cert
618 * specified in SSLSetEncryptionCertificate (see below), are highly
619 * dependent on the application. For example, to work as a server with
620 * Netscape clients, the cert specified here must be capable of both
621 * signing and encrypting.
624 SSLSetCertificate (SSLContextRef context
,
625 CFArrayRef _Nullable certRefs
)
626 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
629 * Specify I/O connection - a socket, endpoint, etc., which is
630 * managed by caller. On the client side, it's assumed that communication
631 * has been established with the desired server on this connection.
632 * On the server side, it's assumed that an incoming client request
633 * has been established.
635 * Must be called prior to SSLHandshake(); subsequently can only be
636 * called when no session is active.
639 SSLSetConnection (SSLContextRef context
,
640 SSLConnectionRef __nullable connection
)
641 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
644 SSLGetConnection (SSLContextRef context
,
645 SSLConnectionRef
* __nonnull CF_RETURNS_NOT_RETAINED connection
)
646 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
649 * Specify the fully qualified doman name of the peer, e.g., "store.apple.com."
650 * Optional; used to verify the common name field in peer's certificate.
651 * Name is in the form of a C string; NULL termination optional, i.e.,
652 * peerName[peerNameLen+1] may or may not have a NULL. In any case peerNameLen
653 * is the number of bytes of the peer domain name.
656 SSLSetPeerDomainName (SSLContextRef context
,
657 const char * __nullable peerName
,
659 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
662 * Determine the buffer size needed for SSLGetPeerDomainName().
665 SSLGetPeerDomainNameLength (SSLContextRef context
,
666 size_t *peerNameLen
) // RETURNED
667 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
670 * Obtain the value specified in SSLSetPeerDomainName().
673 SSLGetPeerDomainName (SSLContextRef context
,
674 char *peerName
, // returned here
675 size_t *peerNameLen
) // IN/OUT
676 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
680 * Determine the buffer size needed for SSLCopyRequestedPeerNameLength().
683 SSLCopyRequestedPeerName (SSLContextRef context
,
686 __OSX_AVAILABLE_STARTING(__MAC_10_11
, __IPHONE_9_0
);
689 * Server Only: obtain the hostname specified by the client in the ServerName extension (SNI)
692 SSLCopyRequestedPeerNameLength (SSLContextRef ctx
,
694 __OSX_AVAILABLE_STARTING(__MAC_10_11
, __IPHONE_9_0
);
698 * Specify the Datagram TLS Hello Cookie.
699 * This is to be called for server side only and is optional.
700 * The default is a zero len cookie. The maximum cookieLen is 32 bytes.
703 SSLSetDatagramHelloCookie (SSLContextRef dtlsContext
,
704 const void * __nullable cookie
,
706 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
709 * Specify the maximum record size, including all DTLS record headers.
710 * This should be set appropriately to avoid fragmentation
711 * of Datagrams during handshake, as fragmented datagrams may
712 * be dropped by some network.
713 * This is for Datagram TLS only
716 SSLSetMaxDatagramRecordSize (SSLContextRef dtlsContext
,
718 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
721 * Get the maximum record size, including all Datagram TLS record headers.
722 * This is for Datagram TLS only
725 SSLGetMaxDatagramRecordSize (SSLContextRef dtlsContext
,
727 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
730 * Obtain the actual negotiated protocol version of the active
731 * session, which may be different that the value specified in
732 * SSLSetProtocolVersion(). Returns kSSLProtocolUnknown if no
733 * SSL session is in progress.
736 SSLGetNegotiatedProtocolVersion (SSLContextRef context
,
737 SSLProtocol
*protocol
) /* RETURNED */
738 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
741 * Determine number and values of all of the SSLCipherSuites we support.
742 * Caller allocates output buffer for SSLGetSupportedCiphers() and passes in
743 * its size in *numCiphers. If supplied buffer is too small, errSSLBufferOverflow
747 SSLGetNumberSupportedCiphers (SSLContextRef context
,
749 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
752 SSLGetSupportedCiphers (SSLContextRef context
,
753 SSLCipherSuite
*ciphers
, /* RETURNED */
754 size_t *numCiphers
) /* IN/OUT */
755 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
758 * Specify a (typically) restricted set of SSLCipherSuites to be enabled by
759 * the current SSLContext. Can only be called when no session is active. Default
760 * set of enabled SSLCipherSuites is the same as the complete set of supported
761 * SSLCipherSuites as obtained by SSLGetSupportedCiphers().
764 SSLSetEnabledCiphers (SSLContextRef context
,
765 const SSLCipherSuite
*ciphers
,
767 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
770 * Determine number and values of all of the SSLCipherSuites currently enabled.
771 * Caller allocates output buffer for SSLGetEnabledCiphers() and passes in
772 * its size in *numCiphers. If supplied buffer is too small, errSSLBufferOverflow
776 SSLGetNumberEnabledCiphers (SSLContextRef context
,
778 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
781 SSLGetEnabledCiphers (SSLContextRef context
,
782 SSLCipherSuite
*ciphers
, /* RETURNED */
783 size_t *numCiphers
) /* IN/OUT */
784 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
787 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
789 * Enable/disable peer certificate chain validation. Default is enabled.
790 * If caller disables, it is the caller's responsibility to call
791 * SSLCopyPeerCertificates() upon successful completion of the handshake
792 * and then to perform external validation of the peer certificate
793 * chain before proceeding with data transfer.
795 * ==========================
796 * MAC OS X ONLY (DEPRECATED)
797 * ==========================
798 * NOTE: this function is not available on iOS, and should be considered
799 * deprecated on Mac OS X. To disable peer certificate chain validation, you
800 * can instead use SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth
801 * to true. This will disable verification and cause SSLHandshake to return with
802 * an errSSLServerAuthCompleted result when the peer certificates have been
803 * received; at that time, you can choose to evaluate peer trust yourself, or
804 * simply call SSLHandshake again to proceed with the handshake.
807 SSLSetEnableCertVerify (SSLContextRef context
,
808 Boolean enableVerify
)
809 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
812 * Check whether peer certificate chain validation is enabled.
814 * ==========================
815 * MAC OS X ONLY (DEPRECATED)
816 * ==========================
817 * NOTE: this function is not available on iOS, and should be considered
818 * deprecated on Mac OS X. To check whether peer certificate chain validation
819 * is enabled in a context, call SSLGetSessionOption to obtain the value of
820 * the kSSLSessionOptionBreakOnServerAuth session option flag. If the value
821 * of this option flag is true, then verification is disabled.
824 SSLGetEnableCertVerify (SSLContextRef context
,
825 Boolean
*enableVerify
) /* RETURNED */
826 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
829 * Specify the option of ignoring certificates' "expired" times.
830 * This is a common failure in the real SSL world. Default setting for this
831 * flag is false, meaning expired certs result in an errSSLCertExpired error.
833 * ==========================
834 * MAC OS X ONLY (DEPRECATED)
835 * ==========================
836 * NOTE: this function is not available on iOS, and should be considered
837 * deprecated on Mac OS X. To ignore expired certificate errors, first disable
838 * Secure Transport's automatic verification of peer certificates by calling
839 * SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth to true. When
840 * SSLHandshake subsequently returns an errSSLServerAuthCompleted result,
841 * your code should obtain the SecTrustRef for the peer's certificates and
842 * perform a custom trust evaluation with SecTrust APIs (see SecTrust.h).
843 * The SecTrustSetOptions function allows you to specify that the expiration
844 * status of certificates should be ignored for this evaluation.
848 * status = SSLSetSessionOption(ctx, kSSLSessionOptionBreakOnServerAuth, true);
850 * status = SSLHandshake(ctx);
852 * if (status == errSSLServerAuthCompleted) {
853 * SecTrustRef peerTrust = NULL;
854 * status = SSLCopyPeerTrust(ctx, &peerTrust);
855 * if (status == errSecSuccess) {
856 * SecTrustResultType trustResult;
857 * // set flag to allow expired certificates
858 * SecTrustSetOptions(peerTrust, kSecTrustOptionAllowExpired);
859 * status = SecTrustEvaluate(peerTrust, &trustResult);
860 * if (status == errSecSuccess) {
861 * // A "proceed" result means the cert is explicitly trusted,
862 * // e.g. "Always Trust" was clicked;
863 * // "Unspecified" means the cert has no explicit trust settings,
864 * // but is implicitly OK since it chains back to a trusted root.
865 * // Any other result means the cert is not trusted.
867 * if (trustResult == kSecTrustResultProceed ||
868 * trustResult == kSecTrustResultUnspecified) {
869 * // certificate is trusted
870 * status = errSSLWouldBlock; // so we call SSLHandshake again
871 * } else if (trustResult == kSecTrustResultRecoverableTrustFailure) {
872 * // not trusted, for some reason other than being expired;
873 * // could ask the user whether to allow the connection here
875 * status = errSSLXCertChainInvalid;
877 * // cannot use this certificate (fatal)
878 * status = errSSLBadCert;
882 * CFRelease(peerTrust);
885 * } // errSSLServerAuthCompleted
887 * } while (status == errSSLWouldBlock);
891 SSLSetAllowsExpiredCerts (SSLContextRef context
,
892 Boolean allowsExpired
)
893 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
896 * Obtain the current value of an SSLContext's "allowExpiredCerts" flag.
898 * ==========================
899 * MAC OS X ONLY (DEPRECATED)
900 * ==========================
901 * NOTE: this function is not available on iOS, and should be considered
902 * deprecated on Mac OS X.
905 SSLGetAllowsExpiredCerts (SSLContextRef context
,
906 Boolean
*allowsExpired
) /* RETURNED */
907 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
910 * Similar to SSLSetAllowsExpiredCerts, SSLSetAllowsExpiredRoots allows the
911 * option of ignoring "expired" status for root certificates only.
912 * Default setting is false, i.e., expired root certs result in an
913 * errSSLCertExpired error.
915 * ==========================
916 * MAC OS X ONLY (DEPRECATED)
917 * ==========================
918 * NOTE: this function is not available on iOS, and should be considered
919 * deprecated on Mac OS X. To ignore expired certificate errors, first disable
920 * Secure Transport's automatic verification of peer certificates by calling
921 * SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth to true. When
922 * SSLHandshake subsequently returns an errSSLServerAuthCompleted result,
923 * your code should obtain the SecTrustRef for the peer's certificates and
924 * perform a custom trust evaluation with SecTrust APIs (see SecTrust.h).
925 * The SecTrustSetOptions function allows you to specify that the expiration
926 * status of certificates should be ignored for this evaluation.
928 * See the description of the SSLSetAllowsExpiredCerts function (above)
929 * for a code example. The kSecTrustOptionAllowExpiredRoot option can be used
930 * instead of kSecTrustOptionAllowExpired to allow expired roots only.
933 SSLSetAllowsExpiredRoots (SSLContextRef context
,
934 Boolean allowsExpired
)
935 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
938 * Obtain the current value of an SSLContext's "allow expired roots" flag.
940 * ==========================
941 * MAC OS X ONLY (DEPRECATED)
942 * ==========================
943 * NOTE: this function is not available on iOS, and should be considered
944 * deprecated on Mac OS X.
947 SSLGetAllowsExpiredRoots (SSLContextRef context
,
948 Boolean
*allowsExpired
) /* RETURNED */
949 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
952 * Specify option of allowing for an unknown root cert, i.e., one which
953 * this software can not verify as one of a list of known good root certs.
954 * Default for this flag is false, in which case one of the following two
956 * -- The peer returns a cert chain with a root cert, and the chain
957 * verifies to that root, but the root is not one of our trusted
958 * roots. This results in errSSLUnknownRootCert on handshake.
959 * -- The peer returns a cert chain which does not contain a root cert,
960 * and we can't verify the chain to one of our trusted roots. This
961 * results in errSSLNoRootCert on handshake.
963 * Both of these error conditions are ignored when the AllowAnyRoot flag is
964 * true, allowing connection to a totally untrusted peer.
966 * ==========================
967 * MAC OS X ONLY (DEPRECATED)
968 * ==========================
969 * NOTE: this function is not available on iOS, and should be considered
970 * deprecated on Mac OS X. To ignore unknown root cert errors, first disable
971 * Secure Transport's automatic verification of peer certificates by calling
972 * SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth to true. When
973 * SSLHandshake subsequently returns an errSSLServerAuthCompleted result,
974 * your code should obtain the SecTrustRef for the peer's certificates and
975 * perform a custom trust evaluation with SecTrust APIs (see SecTrust.h).
977 * See the description of the SSLSetAllowsExpiredCerts function (above)
978 * for a code example. Note that an unknown root certificate will cause
979 * SecTrustEvaluate to report kSecTrustResultRecoverableTrustFailure as the
983 SSLSetAllowsAnyRoot (SSLContextRef context
,
985 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
988 * Obtain the current value of an SSLContext's "allow any root" flag.
990 * ==========================
991 * MAC OS X ONLY (DEPRECATED)
992 * ==========================
993 * NOTE: this function is not available on iOS, and should be considered
994 * deprecated on Mac OS X.
997 SSLGetAllowsAnyRoot (SSLContextRef context
,
998 Boolean
*anyRoot
) /* RETURNED */
999 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
1002 * Augment or replace the system's default trusted root certificate set
1003 * for this session. If replaceExisting is true, the specified roots will
1004 * be the only roots which are trusted during this session. If replaceExisting
1005 * is false, the specified roots will be added to the current set of trusted
1006 * root certs. If this function has never been called, the current trusted
1007 * root set is the same as the system's default trusted root set.
1008 * Successive calls with replaceExisting false result in accumulation
1009 * of additional root certs.
1011 * The trustedRoots array contains SecCertificateRefs.
1013 * ==========================
1014 * MAC OS X ONLY (DEPRECATED)
1015 * ==========================
1016 * NOTE: this function is not available on iOS, and should be considered
1017 * deprecated on Mac OS X. To trust specific roots in a session, first disable
1018 * Secure Transport's automatic verification of peer certificates by calling
1019 * SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth to true. When
1020 * SSLHandshake subsequently returns an errSSLServerAuthCompleted result,
1021 * your code should obtain the SecTrustRef for the peer's certificates and
1022 * perform a custom trust evaluation with SecTrust APIs (see SecTrust.h).
1024 * See the description of the SSLSetAllowsExpiredCerts function (above)
1025 * for a code example. You can call SecTrustSetAnchorCertificates to
1026 * augment the system's trusted root set, or SecTrustSetAnchorCertificatesOnly
1027 * to make these the only trusted roots, prior to calling SecTrustEvaluate.
1030 SSLSetTrustedRoots (SSLContextRef context
,
1031 CFArrayRef trustedRoots
,
1032 Boolean replaceExisting
)
1033 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
1036 * Obtain an array of SecCertificateRefs representing the current
1037 * set of trusted roots. If SSLSetTrustedRoots() has never been called
1038 * for this session, this returns the system's default root set.
1040 * Caller must CFRelease the returned CFArray.
1042 * ==========================
1043 * MAC OS X ONLY (DEPRECATED)
1044 * ==========================
1045 * NOTE: this function is not available on iOS, and should be considered
1046 * deprecated on Mac OS X. To get the current set of trusted roots, call the
1047 * SSLCopyPeerTrust function to obtain the SecTrustRef for the peer certificate
1048 * chain, then SecTrustCopyCustomAnchorCertificates (see SecTrust.h).
1051 SSLCopyTrustedRoots (SSLContextRef context
,
1052 CFArrayRef
* __nonnull CF_RETURNS_RETAINED trustedRoots
) /* RETURNED */
1053 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
1056 * Request peer certificates. Valid anytime, subsequent to a handshake attempt.
1058 * The certs argument is a CFArray containing SecCertificateRefs.
1059 * Caller must CFRelease the returned array.
1061 * The cert at index 0 of the returned array is the subject (end
1062 * entity) cert; the root cert (or the closest cert to it) is at
1063 * the end of the returned array.
1065 * ==========================
1066 * MAC OS X ONLY (DEPRECATED)
1067 * ==========================
1068 * NOTE: this function is not available on iOS, and should be considered
1069 * deprecated on Mac OS X. To get peer certificates, call SSLCopyPeerTrust
1070 * to obtain the SecTrustRef for the peer certificate chain, then use the
1071 * SecTrustGetCertificateCount and SecTrustGetCertificateAtIndex functions
1072 * to retrieve individual certificates in the chain (see SecTrust.h).
1075 SSLCopyPeerCertificates (SSLContextRef context
,
1076 CFArrayRef
* __nonnull CF_RETURNS_RETAINED certs
) /* RETURNED */
1077 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
1079 #endif /* MAC OS X */
1082 * Obtain a SecTrustRef representing peer certificates. Valid anytime,
1083 * subsequent to a handshake attempt. Caller must CFRelease the returned
1086 * The returned trust reference will have already been evaluated for you,
1087 * unless one of the following is true:
1088 * - Your code has disabled automatic certificate verification, by calling
1089 * SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth to true.
1090 * - Your code has called SSLSetPeerID, and this session has been resumed
1091 * from an earlier cached session.
1093 * In these cases, your code should call SecTrustEvaluate prior to
1094 * examining the peer certificate chain or trust results (see SecTrust.h).
1096 * NOTE: if you have not called SSLHandshake at least once prior to
1097 * calling this function, the returned trust reference will be NULL.
1100 SSLCopyPeerTrust (SSLContextRef context
,
1101 SecTrustRef
* __nonnull CF_RETURNS_RETAINED trust
) /* RETURNED */
1102 __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_5_0
);
1105 * Specify some data, opaque to this library, which is sufficient
1106 * to uniquely identify the peer of the current session. An example
1107 * would be IP address and port, stored in some caller-private manner.
1108 * To be optionally called prior to SSLHandshake for the current
1109 * session. This is mandatory if this session is to be resumable.
1111 * SecureTransport allocates its own copy of the incoming peerID. The
1112 * data provided in *peerID, while opaque to SecureTransport, is used
1113 * in a byte-for-byte compare to other previous peerID values set by the
1114 * current application. Matching peerID blobs result in SecureTransport
1115 * attempting to resume an SSL session with the same parameters as used
1116 * in the previous session which specified the same peerID bytes.
1119 SSLSetPeerID (SSLContextRef context
,
1120 const void * __nullable peerID
,
1122 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1125 * Obtain current PeerID. Returns NULL pointer, zero length if
1126 * SSLSetPeerID has not been called for this context.
1129 SSLGetPeerID (SSLContextRef context
,
1130 const void * __nullable
* __nonnull peerID
,
1132 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1135 * Obtain the SSLCipherSuite (e.g., SSL_RSA_WITH_DES_CBC_SHA) negotiated
1136 * for this session. Only valid when a session is active.
1139 SSLGetNegotiatedCipher (SSLContextRef context
,
1140 SSLCipherSuite
*cipherSuite
)
1141 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1144 /********************************************************
1145 *** Session context configuration, server side only. ***
1146 ********************************************************/
1149 * This function is deprecated in OSX 10.11 and iOS 9.0 and
1150 * has no effect on the TLS handshake since OSX 10.10 and
1151 * iOS 8.0. Using separate RSA certificates for encryption
1152 * and signing is no longer supported.
1155 SSLSetEncryptionCertificate (SSLContextRef context
,
1156 CFArrayRef certRefs
)
1157 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
, __MAC_10_11
, __IPHONE_5_0
, __IPHONE_9_0
);
1160 * Specify requirements for client-side authentication.
1161 * Optional; Default is kNeverAuthenticate.
1163 * Can only be called when no session is active.
1165 typedef CF_ENUM(int, SSLAuthenticate
) {
1166 kNeverAuthenticate
, /* skip client authentication */
1167 kAlwaysAuthenticate
, /* require it */
1168 kTryAuthenticate
/* try to authenticate, but not an error
1169 * if client doesn't have a cert */
1173 SSLSetClientSideAuthenticate (SSLContextRef context
,
1174 SSLAuthenticate auth
)
1175 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1178 * Add a DER-encoded distinguished name to list of acceptable names
1179 * to be specified in requests for client certificates.
1182 SSLAddDistinguishedName (SSLContextRef context
,
1183 const void * __nullable derDN
,
1185 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_5_0
);
1188 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
1190 * Add a SecCertificateRef, or a CFArray of them, to a server's list
1191 * of acceptable Certificate Authorities (CAs) to present to the client
1192 * when client authentication is performed.
1194 * If replaceExisting is true, the specified certificate(s) will replace
1195 * a possible existing list of acceptable CAs. If replaceExisting is
1196 * false, the specified certificate(s) will be appended to the existing
1197 * list of acceptable CAs, if any.
1199 * Returns errSecParam if this is called on a SSLContextRef which
1200 * is configured as a client, or when a session is active.
1202 * NOTE: this function is currently not available on iOS.
1205 SSLSetCertificateAuthorities(SSLContextRef context
,
1206 CFTypeRef certificateOrArray
,
1207 Boolean replaceExisting
)
1208 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_NA
);
1211 * Obtain the certificates specified in SSLSetCertificateAuthorities(),
1212 * if any. Returns a NULL array if SSLSetCertificateAuthorities() has not
1214 * Caller must CFRelease the returned array.
1216 * NOTE: this function is currently not available on iOS.
1219 SSLCopyCertificateAuthorities(SSLContextRef context
,
1220 CFArrayRef
* __nonnull CF_RETURNS_RETAINED certificates
) /* RETURNED */
1221 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_NA
);
1223 #endif /* MAC OS X */
1226 * Obtain the list of acceptable distinguished names as provided by
1227 * a server (if the SSLContextRef is configured as a client), or as
1228 * specified by SSLSetCertificateAuthorities (if the SSLContextRef
1229 * is configured as a server).
1230 * The returned array contains CFDataRefs, each of which represents
1231 * one DER-encoded RDN.
1233 * Caller must CFRelease the returned array.
1236 SSLCopyDistinguishedNames (SSLContextRef context
,
1237 CFArrayRef
* __nonnull CF_RETURNS_RETAINED names
)
1238 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_5_0
);
1241 * Obtain client certificate exchange status. Can be called
1242 * any time. Reflects the *last* client certificate state change;
1243 * subsequent to a renegotiation attempt by either peer, the state
1244 * is reset to kSSLClientCertNone.
1247 SSLGetClientCertificateState (SSLContextRef context
,
1248 SSLClientCertificateState
*clientState
)
1249 __OSX_AVAILABLE_STARTING(__MAC_10_3
, __IPHONE_5_0
);
1252 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
1254 * Specify Diffie-Hellman parameters. Optional; if we are configured to allow
1255 * for D-H ciphers and a D-H cipher is negotiated, and this function has not
1256 * been called, a set of process-wide parameters will be calculated. However
1257 * that can take a long time (30 seconds).
1259 * NOTE: this function is currently not available on iOS.
1261 OSStatus
SSLSetDiffieHellmanParams (SSLContextRef context
,
1262 const void * __nullable dhParams
,
1264 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_NA
);
1267 * Return parameter block specified in SSLSetDiffieHellmanParams.
1268 * Returned data is not copied and belongs to the SSLContextRef.
1270 * NOTE: this function is currently not available on iOS.
1272 OSStatus
SSLGetDiffieHellmanParams (SSLContextRef context
,
1273 const void * __nullable
* __nonnull dhParams
,
1274 size_t *dhParamsLen
)
1275 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_NA
);
1278 * Enable/Disable RSA blinding. This feature thwarts a known timing
1279 * attack to which RSA keys are vulnerable; enabling it is a tradeoff
1280 * between performance and security. The default for RSA blinding is
1283 * ==========================
1284 * MAC OS X ONLY (DEPRECATED)
1285 * ==========================
1286 * NOTE: this function is not available on iOS, and should be considered
1287 * deprecated on Mac OS X. RSA blinding is enabled unconditionally, as
1288 * it prevents a known way for an attacker to recover the private key,
1289 * and the performance gain of disabling it is negligible.
1291 OSStatus
SSLSetRsaBlinding (SSLContextRef context
,
1293 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
1295 OSStatus
SSLGetRsaBlinding (SSLContextRef context
,
1297 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
1299 #endif /* MAC OS X */
1301 /*******************************
1302 ******** I/O Functions ********
1303 *******************************/
1306 * Note: depending on the configuration of the underlying I/O
1307 * connection, all SSL I/O functions can return errSSLWouldBlock,
1308 * indicating "not complete, nothing is wrong, except required
1309 * I/O hasn't completed". Caller may need to repeat I/Os as necessary
1310 * if the underlying connection has been configured to behave in
1311 * a non-blocking manner.
1315 * Perform the SSL handshake. On successful return, session is
1316 * ready for normal secure application I/O via SSLWrite and SSLRead.
1318 * Interesting error returns:
1320 * errSSLUnknownRootCert: Peer had a valid cert chain, but the root of
1321 * the chain is unknown.
1323 * errSSLNoRootCert: Peer had a cert chain which did not end in a root.
1325 * errSSLCertExpired: Peer's cert chain had one or more expired certs.
1327 * errSSLXCertChainInvalid: Peer had an invalid cert chain (i.e.,
1328 * signature verification within the chain failed, or no certs
1331 * In all of the above errors, the handshake was aborted; the peer's
1332 * cert chain is available via SSLCopyPeerTrust or SSLCopyPeerCertificates.
1334 * Other interesting result codes:
1336 * errSSLPeerAuthCompleted: Peer's cert chain is valid, or was ignored if
1337 * cert verification was disabled via SSLSetEnableCertVerify. The application
1338 * may decide to continue with the handshake (by calling SSLHandshake
1339 * again), or close the connection at this point.
1341 * errSSLClientCertRequested: The server has requested a client certificate.
1342 * The client may choose to examine the server's certificate and
1343 * distinguished name list, then optionally call SSLSetCertificate prior
1344 * to resuming the handshake by calling SSLHandshake again.
1346 * A return value of errSSLWouldBlock indicates that SSLHandshake has to be
1347 * called again (and again and again until something else is returned).
1350 SSLHandshake (SSLContextRef context
)
1351 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1354 * Server Only: Request renegotation.
1355 * This will return an error if the server is already renegotiating, or if the session is closed.
1356 * After this return without error, the application should call SSLHandshake() and/or SSLRead() as
1357 * for the original handshake.
1360 SSLReHandshake (SSLContextRef context
)
1361 __OSX_AVAILABLE_STARTING(__MAC_10_12
, __IPHONE_10_0
);
1365 * Normal application-level read/write. On both of these, a errSSLWouldBlock
1366 * return and a partially completed transfer - or even zero bytes transferred -
1367 * are NOT mutually exclusive.
1370 SSLWrite (SSLContextRef context
,
1371 const void * __nullable data
,
1373 size_t *processed
) /* RETURNED */
1374 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1377 * data is mallocd by caller; available size specified in
1378 * dataLength; actual number of bytes read returned in
1382 SSLRead (SSLContextRef context
,
1383 void * data
, /* RETURNED */
1385 size_t *processed
) /* RETURNED */
1386 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1389 * Determine how much data the client can be guaranteed to
1390 * obtain via SSLRead() without blocking or causing any low-level
1391 * read operations to occur.
1394 SSLGetBufferedReadSize (SSLContextRef context
,
1395 size_t *bufSize
) /* RETURNED */
1396 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1399 * Determine how much data the application can be guaranteed to write
1400 * with SSLWrite() without causing fragmentation. The value is based on
1401 * the maximum Datagram Record size defined by the application with
1402 * SSLSetMaxDatagramRecordSize(), minus the DTLS Record header size.
1405 SSLGetDatagramWriteSize (SSLContextRef dtlsContext
,
1407 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
1410 * Terminate current SSL session.
1413 SSLClose (SSLContextRef context
)
1414 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1416 CF_IMPLICIT_BRIDGING_DISABLED
1417 CF_ASSUME_NONNULL_END
1423 #endif /* !_SECURITY_SECURETRANSPORT_H_ */