2 * Copyright (c) 1999-2002,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 * 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 /***********************
72 *** Common typedefs ***
73 ***********************/
75 /* Opaque reference to an SSL session context */
77 typedef struct SSLContext
*SSLContextRef
;
79 /* Opaque reference to an I/O connection (socket, endpoint, etc.) */
80 typedef const void * SSLConnectionRef
;
82 /* SSL Protocol version */
84 kSSLProtocolUnknown
= 0, /* no protocol negotiated/specified; use default */
85 kSSLProtocol3
= 2, /* SSL 3.0 */
86 kTLSProtocol1
= 4, /* TLS 1.0 */
87 kTLSProtocol11
= 7, /* TLS 1.1 */
88 kTLSProtocol12
= 8, /* TLS 1.2 */
89 kDTLSProtocol1
= 9, /* DTLS 1.0 */
91 /* DEPRECATED on iOS */
92 kSSLProtocol2
= 1, /* SSL 2.0 */
93 kSSLProtocol3Only
= 3, /* SSL 3.0 Only */
94 kTLSProtocol1Only
= 5, /* TLS 1.0 Only */
95 kSSLProtocolAll
= 6, /* All TLS supported protocols */
99 /* SSL session options */
102 * Set this option to enable returning from SSLHandshake (with a result of
103 * errSSLServerAuthCompleted) when the server authentication portion of the
104 * handshake is complete. This disable certificate verification and
105 * provides an opportunity to perform application-specific server
106 * verification before deciding to continue.
108 kSSLSessionOptionBreakOnServerAuth
,
110 * Set this option to enable returning from SSLHandshake (with a result of
111 * errSSLClientCertRequested) when the server requests a client certificate.
113 kSSLSessionOptionBreakOnCertRequested
,
115 * This option is the same as kSSLSessionOptionBreakOnServerAuth but applies
116 * to the case where SecureTransport is the server and the client has presented
117 * its certificates allowing the server to verify whether these should be
118 * allowed to authenticate.
120 kSSLSessionOptionBreakOnClientAuth
,
122 * Enable/Disable TLS False Start
123 * When enabled, False Start will only be performed if a adequate cipher-suite is
126 kSSLSessionOptionFalseStart
,
128 * Enable/Disable 1/n-1 record splitting for BEAST attack mitigation.
129 * When enabled, record splitting will only be performed for TLS 1.0 connections
130 * using a block cipher.
132 kSSLSessionOptionSendOneByteRecord
,
136 /* State of an SSLSession */
138 kSSLIdle
, /* no I/O performed yet */
139 kSSLHandshake
, /* SSL handshake in progress */
140 kSSLConnected
, /* Handshake complete, ready for normal I/O */
141 kSSLClosed
, /* connection closed normally */
142 kSSLAborted
/* connection aborted */
146 * Status of client certificate exchange (which is optional
147 * for both server and client).
150 /* Server hasn't asked for a cert. Client hasn't sent one. */
152 /* Server has asked for a cert, but client didn't send it. */
153 kSSLClientCertRequested
,
155 * Server side: We asked for a cert, client sent one, we validated
156 * it OK. App can inspect the cert via
157 * SSLGetPeerCertificates().
158 * Client side: server asked for one, we sent it.
162 * Client sent a cert but failed validation. Server side only.
163 * Server app can inspect the cert via SSLGetPeerCertificates().
165 kSSLClientCertRejected
166 } SSLClientCertificateState
;
169 * R/W functions. The application using this library provides
170 * these functions via SSLSetIOFuncs().
172 * Data's memory is allocated by caller; on entry to these two functions
173 * the *length argument indicates both the size of the available data and the
174 * requested byte count. Number of bytes actually transferred is returned in
177 * The application may configure the underlying connection to operate
178 * in a non-blocking manner; in such a case, a read operation may
179 * well return errSSLWouldBlock, indicating "I transferred less data than
180 * you requested (maybe even zero bytes), nothing is wrong, except
181 * requested I/O hasn't completed". This will be returned back up to
182 * the application as a return from SSLRead(), SSLWrite(), SSLHandshake(),
186 (*SSLReadFunc
) (SSLConnectionRef connection
,
187 void *data
, /* owned by
190 size_t *dataLength
); /* IN/OUT */
192 (*SSLWriteFunc
) (SSLConnectionRef connection
,
194 size_t *dataLength
); /* IN/OUT */
197 /*************************************************
198 *** OSStatus values unique to SecureTransport ***
199 *************************************************/
202 Note: the comments that appear after these errors are used to create SecErrorMessages.strings.
203 The comments must not be multi-line, and should be in a form meaningful to an end user. If
204 a different or additional comment is needed, it can be put in the header doc format, or on a
205 line that does not start with errZZZ.
209 errSSLProtocol
= -9800, /* SSL protocol error */
210 errSSLNegotiation
= -9801, /* Cipher Suite negotiation failure */
211 errSSLFatalAlert
= -9802, /* Fatal alert */
212 errSSLWouldBlock
= -9803, /* I/O would block (not fatal) */
213 errSSLSessionNotFound
= -9804, /* attempt to restore an unknown session */
214 errSSLClosedGraceful
= -9805, /* connection closed gracefully */
215 errSSLClosedAbort
= -9806, /* connection closed via error */
216 errSSLXCertChainInvalid
= -9807, /* invalid certificate chain */
217 errSSLBadCert
= -9808, /* bad certificate format */
218 errSSLCrypto
= -9809, /* underlying cryptographic error */
219 errSSLInternal
= -9810, /* Internal error */
220 errSSLModuleAttach
= -9811, /* module attach failure */
221 errSSLUnknownRootCert
= -9812, /* valid cert chain, untrusted root */
222 errSSLNoRootCert
= -9813, /* cert chain not verified by root */
223 errSSLCertExpired
= -9814, /* chain had an expired cert */
224 errSSLCertNotYetValid
= -9815, /* chain had a cert not yet valid */
225 errSSLClosedNoNotify
= -9816, /* server closed session with no notification */
226 errSSLBufferOverflow
= -9817, /* insufficient buffer provided */
227 errSSLBadCipherSuite
= -9818, /* bad SSLCipherSuite */
229 /* fatal errors detected by peer */
230 errSSLPeerUnexpectedMsg
= -9819, /* unexpected message received */
231 errSSLPeerBadRecordMac
= -9820, /* bad MAC */
232 errSSLPeerDecryptionFail
= -9821, /* decryption failed */
233 errSSLPeerRecordOverflow
= -9822, /* record overflow */
234 errSSLPeerDecompressFail
= -9823, /* decompression failure */
235 errSSLPeerHandshakeFail
= -9824, /* handshake failure */
236 errSSLPeerBadCert
= -9825, /* misc. bad certificate */
237 errSSLPeerUnsupportedCert
= -9826, /* bad unsupported cert format */
238 errSSLPeerCertRevoked
= -9827, /* certificate revoked */
239 errSSLPeerCertExpired
= -9828, /* certificate expired */
240 errSSLPeerCertUnknown
= -9829, /* unknown certificate */
241 errSSLIllegalParam
= -9830, /* illegal parameter */
242 errSSLPeerUnknownCA
= -9831, /* unknown Cert Authority */
243 errSSLPeerAccessDenied
= -9832, /* access denied */
244 errSSLPeerDecodeError
= -9833, /* decoding error */
245 errSSLPeerDecryptError
= -9834, /* decryption error */
246 errSSLPeerExportRestriction
= -9835, /* export restriction */
247 errSSLPeerProtocolVersion
= -9836, /* bad protocol version */
248 errSSLPeerInsufficientSecurity
= -9837, /* insufficient security */
249 errSSLPeerInternalError
= -9838, /* internal error */
250 errSSLPeerUserCancelled
= -9839, /* user canceled */
251 errSSLPeerNoRenegotiation
= -9840, /* no renegotiation allowed */
253 /* non-fatal result codes */
254 errSSLPeerAuthCompleted
= -9841, /* peer cert is valid, or was ignored if verification disabled */
255 errSSLClientCertRequested
= -9842, /* server has requested a client cert */
257 /* more errors detected by us */
258 errSSLHostNameMismatch
= -9843, /* peer host name mismatch */
259 errSSLConnectionRefused
= -9844, /* peer dropped connection before responding */
260 errSSLDecryptionFail
= -9845, /* decryption failure */
261 errSSLBadRecordMac
= -9846, /* bad MAC */
262 errSSLRecordOverflow
= -9847, /* record overflow */
263 errSSLBadConfiguration
= -9848, /* configuration error */
264 errSSLUnexpectedRecord
= -9849, /* unexpected (skipped) record in DTLS */
267 /* DEPRECATED aliases for errSSLPeerAuthCompleted */
268 #define errSSLServerAuthCompleted errSSLPeerAuthCompleted
269 #define errSSLClientAuthCompleted errSSLPeerAuthCompleted
271 /* DEPRECATED alias for the end of the error range */
272 #define errSSLLast errSSLUnexpectedRecord
291 * Secure Transport APIs require a SSLContextRef, which is an opaque
292 * reference to the SSL session and its parameters. On Mac OS X 10.7
293 * and earlier versions, a new context is created using SSLNewContext,
294 * and is disposed by calling SSLDisposeContext.
296 * On i0S 5.0 and later, as well as Mac OS X versions after 10.7, the
297 * SSLContextRef is a true CFType object with retain-release semantics.
298 * New code should create a new context using SSLCreateContext (instead
299 * of SSLNewContext), and dispose the context by calling CFRelease
300 * (instead of SSLDisposeContext) when finished with it.
304 * Return the CFTypeID for SSLContext objects.
307 SSLContextGetTypeID(void)
308 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
311 * Create a new instance of an SSLContextRef using the specified allocator.
314 SSLCreateContext(CFAllocatorRef alloc
, SSLProtocolSide protocolSide
, SSLConnectionType connectionType
)
315 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
318 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
320 * Create a new session context.
322 * ==========================
323 * MAC OS X ONLY (DEPRECATED)
324 * ==========================
325 * NOTE: this function is not available on iOS, and should be considered
326 * deprecated on Mac OS X. Your code should use SSLCreateContext instead.
329 SSLNewContext (Boolean isServer
,
330 SSLContextRef
*contextPtr
) /* RETURNED */
331 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
334 * Dispose of a session context.
336 * ==========================
337 * MAC OS X ONLY (DEPRECATED)
338 * ==========================
339 * NOTE: this function is not available on iOS, and should be considered
340 * deprecated on Mac OS X. Your code should use CFRelease to dispose a session
341 * created with SSLCreateContext.
344 SSLDisposeContext (SSLContextRef context
)
345 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
347 #endif /* MAC OS X */
350 * Determine the state of an SSL/DTLS session.
353 SSLGetSessionState (SSLContextRef context
,
354 SSLSessionState
*state
) /* RETURNED */
355 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
358 * Set options for an SSL session. Must be called prior to SSLHandshake();
359 * subsequently cannot be called while session is active.
362 SSLSetSessionOption (SSLContextRef context
,
363 SSLSessionOption option
,
365 __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_5_0
);
368 * Determine current value for the specified option in a given SSL session.
371 SSLGetSessionOption (SSLContextRef context
,
372 SSLSessionOption option
,
374 __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_5_0
);
376 /********************************************************************
377 *** Session context configuration, common to client and servers. ***
378 ********************************************************************/
381 * Specify functions which do the network I/O. Must be called prior
382 * to SSLHandshake(); subsequently cannot be called while a session is
386 SSLSetIOFuncs (SSLContextRef context
,
387 SSLReadFunc readFunc
,
388 SSLWriteFunc writeFunc
)
389 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
392 * Set the minimum SSL protocol version allowed. Optional.
393 * The default is the lower supported protocol.
395 * This can only be called when no session is active.
397 * For TLS contexts, legal values for minVersion are :
403 * For DTLS contexts, legal values for minVersion are :
407 SSLSetProtocolVersionMin (SSLContextRef context
,
408 SSLProtocol minVersion
)
409 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
412 * Get minimum protocol version allowed
415 SSLGetProtocolVersionMin (SSLContextRef context
,
416 SSLProtocol
*minVersion
)
417 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
420 * Set the maximum SSL protocol version allowed. Optional.
421 * The default is the highest supported protocol.
423 * This can only be called when no session is active.
425 * For TLS contexts, legal values for minVersion are :
431 * For DTLS contexts, legal values for minVersion are :
435 SSLSetProtocolVersionMax (SSLContextRef context
,
436 SSLProtocol maxVersion
)
437 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
440 * Get maximum protocol version allowed
443 SSLGetProtocolVersionMax (SSLContextRef context
,
444 SSLProtocol
*maxVersion
)
445 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
448 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
450 * Set allowed SSL protocol versions. Optional.
451 * Specifying kSSLProtocolAll for SSLSetProtocolVersionEnabled results in
452 * specified 'enable' boolean to be applied to all supported protocols.
453 * The default is "all supported protocols are enabled".
454 * This can only be called when no session is active.
456 * Legal values for protocol are :
462 * ==========================
463 * MAC OS X ONLY (DEPRECATED)
464 * ==========================
465 * NOTE: this function is not available on iOS, and should be considered
466 * deprecated on Mac OS X. You can use SSLSetProtocolVersionMin and/or
467 * SSLSetProtocolVersionMax to specify which protocols are enabled.
470 SSLSetProtocolVersionEnabled (SSLContextRef context
,
471 SSLProtocol protocol
,
473 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
476 * Obtain a value specified in SSLSetProtocolVersionEnabled.
478 * ==========================
479 * MAC OS X ONLY (DEPRECATED)
480 * ==========================
481 * NOTE: this function is not available on iOS, and should be considered
482 * deprecated on Mac OS X. You can use SSLGetProtocolVersionMin and/or
483 * SSLGetProtocolVersionMax to check whether a protocol is enabled.
486 SSLGetProtocolVersionEnabled(SSLContextRef context
,
487 SSLProtocol protocol
,
488 Boolean
*enable
) /* RETURNED */
489 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
492 * Get/set SSL protocol version; optional. Default is kSSLProtocolUnknown,
493 * in which case the highest possible version is attempted, but a lower
494 * version is accepted if the peer requires it.
495 * SSLSetProtocolVersion cannot be called when a session is active.
497 * ==========================
498 * MAC OS X ONLY (DEPRECATED)
499 * ==========================
500 * NOTE: this function is not available on iOS, and deprecated on Mac OS X 10.8.
501 * Use SSLSetProtocolVersionMin and/or SSLSetProtocolVersionMax to specify
502 * which protocols are enabled.
505 SSLSetProtocolVersion (SSLContextRef context
,
507 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_8
,__IPHONE_NA
,__IPHONE_NA
);
510 * Obtain the protocol version specified in SSLSetProtocolVersion.
511 * If SSLSetProtocolVersionEnabled() has been called for this session,
512 * SSLGetProtocolVersion() may return errSecParam if the protocol enable
513 * state can not be represented by the SSLProtocol enums (e.g.,
514 * SSL2 and TLS1 enabled, SSL3 disabled).
516 * ==========================
517 * MAC OS X ONLY (DEPRECATED)
518 * ==========================
519 * NOTE: this function is not available on iOS, and deprecated on Mac OS X 10.8.
520 * Use SSLGetProtocolVersionMin and/or SSLGetProtocolVersionMax to check
521 * whether a protocol is enabled.
524 SSLGetProtocolVersion (SSLContextRef context
,
525 SSLProtocol
*protocol
) /* RETURNED */
526 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_8
,__IPHONE_NA
,__IPHONE_NA
);
528 #endif /* MAC OS X */
531 * Specify this connection's certificate(s). This is mandatory for
532 * server connections, optional for clients. Specifying a certificate
533 * for a client enables SSL client-side authentication. The end-entity
534 * cert is in certRefs[0]. Specifying a root cert is optional; if it's
535 * not specified, the root cert which verifies the cert chain specified
536 * here must be present in the system-wide set of trusted anchor certs.
538 * The certRefs argument is a CFArray containing SecCertificateRefs,
539 * except for certRefs[0], which is a SecIdentityRef.
541 * Must be called prior to SSLHandshake(), or immediately after
542 * SSLHandshake has returned errSSLClientCertRequested (i.e. before the
543 * handshake is resumed by calling SSLHandshake again.)
545 * SecureTransport assumes the following:
547 * -- The certRef references remain valid for the lifetime of the session.
548 * -- The certificate specified in certRefs[0] is capable of signing.
549 * -- The required capabilities of the certRef[0], and of the optional cert
550 * specified in SSLSetEncryptionCertificate (see below), are highly
551 * dependent on the application. For example, to work as a server with
552 * Netscape clients, the cert specified here must be capable of both
553 * signing and encrypting.
556 SSLSetCertificate (SSLContextRef context
,
558 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
561 * Specify I/O connection - a socket, endpoint, etc., which is
562 * managed by caller. On the client side, it's assumed that communication
563 * has been established with the desired server on this connection.
564 * On the server side, it's assumed that an incoming client request
565 * has been established.
567 * Must be called prior to SSLHandshake(); subsequently can only be
568 * called when no session is active.
571 SSLSetConnection (SSLContextRef context
,
572 SSLConnectionRef connection
)
573 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
576 SSLGetConnection (SSLContextRef context
,
577 SSLConnectionRef
*connection
)
578 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
581 * Specify the fully qualified doman name of the peer, e.g., "store.apple.com."
582 * Optional; used to verify the common name field in peer's certificate.
583 * Name is in the form of a C string; NULL termination optional, i.e.,
584 * peerName[peerNameLen+1] may or may not have a NULL. In any case peerNameLen
585 * is the number of bytes of the peer domain name.
588 SSLSetPeerDomainName (SSLContextRef context
,
589 const char *peerName
,
591 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
594 * Determine the buffer size needed for SSLGetPeerDomainName().
597 SSLGetPeerDomainNameLength (SSLContextRef context
,
598 size_t *peerNameLen
) // RETURNED
599 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
602 * Obtain the value specified in SSLSetPeerDomainName().
605 SSLGetPeerDomainName (SSLContextRef context
,
606 char *peerName
, // returned here
607 size_t *peerNameLen
) // IN/OUT
608 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
611 * Specify the Datagram TLS Hello Cookie.
612 * This is to be called for server side only and is optional.
613 * The default is a zero len cookie. The maximum cookieLen is 32 bytes.
616 SSLSetDatagramHelloCookie (SSLContextRef dtlsContext
,
619 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
622 * Specify the maximum record size, including all DTLS record headers.
623 * This should be set appropriately to avoid fragmentation
624 * of Datagrams during handshake, as fragmented datagrams may
625 * be dropped by some network.
626 * This is for Datagram TLS only
629 SSLSetMaxDatagramRecordSize (SSLContextRef dtlsContext
,
631 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
634 * Get the maximum record size, including all Datagram TLS record headers.
635 * This is for Datagram TLS only
638 SSLGetMaxDatagramRecordSize (SSLContextRef dtlsContext
,
640 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
643 * Obtain the actual negotiated protocol version of the active
644 * session, which may be different that the value specified in
645 * SSLSetProtocolVersion(). Returns kSSLProtocolUnknown if no
646 * SSL session is in progress.
649 SSLGetNegotiatedProtocolVersion (SSLContextRef context
,
650 SSLProtocol
*protocol
) /* RETURNED */
651 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
654 * Determine number and values of all of the SSLCipherSuites we support.
655 * Caller allocates output buffer for SSLGetSupportedCiphers() and passes in
656 * its size in *numCiphers. If supplied buffer is too small, errSSLBufferOverflow
660 SSLGetNumberSupportedCiphers (SSLContextRef context
,
662 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
665 SSLGetSupportedCiphers (SSLContextRef context
,
666 SSLCipherSuite
*ciphers
, /* RETURNED */
667 size_t *numCiphers
) /* IN/OUT */
668 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
671 * Specify a (typically) restricted set of SSLCipherSuites to be enabled by
672 * the current SSLContext. Can only be called when no session is active. Default
673 * set of enabled SSLCipherSuites is the same as the complete set of supported
674 * SSLCipherSuites as obtained by SSLGetSupportedCiphers().
677 SSLSetEnabledCiphers (SSLContextRef context
,
678 const SSLCipherSuite
*ciphers
,
680 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
683 * Determine number and values of all of the SSLCipherSuites currently enabled.
684 * Caller allocates output buffer for SSLGetEnabledCiphers() and passes in
685 * its size in *numCiphers. If supplied buffer is too small, errSSLBufferOverflow
689 SSLGetNumberEnabledCiphers (SSLContextRef context
,
691 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
694 SSLGetEnabledCiphers (SSLContextRef context
,
695 SSLCipherSuite
*ciphers
, /* RETURNED */
696 size_t *numCiphers
) /* IN/OUT */
697 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
700 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
702 * Enable/disable peer certificate chain validation. Default is enabled.
703 * If caller disables, it is the caller's responsibility to call
704 * SSLCopyPeerCertificates() upon successful completion of the handshake
705 * and then to perform external validation of the peer certificate
706 * chain before proceeding with data transfer.
708 * ==========================
709 * MAC OS X ONLY (DEPRECATED)
710 * ==========================
711 * NOTE: this function is not available on iOS, and should be considered
712 * deprecated on Mac OS X. To disable peer certificate chain validation, you
713 * can instead use SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth
714 * to true. This will disable verification and cause SSLHandshake to return with
715 * an errSSLServerAuthCompleted result when the peer certificates have been
716 * received; at that time, you can choose to evaluate peer trust yourself, or
717 * simply call SSLHandshake again to proceed with the handshake.
720 SSLSetEnableCertVerify (SSLContextRef context
,
721 Boolean enableVerify
)
722 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
725 * Check whether peer certificate chain validation is enabled.
727 * ==========================
728 * MAC OS X ONLY (DEPRECATED)
729 * ==========================
730 * NOTE: this function is not available on iOS, and should be considered
731 * deprecated on Mac OS X. To check whether peer certificate chain validation
732 * is enabled in a context, call SSLGetSessionOption to obtain the value of
733 * the kSSLSessionOptionBreakOnServerAuth session option flag. If the value
734 * of this option flag is true, then verification is disabled.
737 SSLGetEnableCertVerify (SSLContextRef context
,
738 Boolean
*enableVerify
) /* RETURNED */
739 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
742 * Specify the option of ignoring certificates' "expired" times.
743 * This is a common failure in the real SSL world. Default setting for this
744 * flag is false, meaning expired certs result in an errSSLCertExpired error.
746 * ==========================
747 * MAC OS X ONLY (DEPRECATED)
748 * ==========================
749 * NOTE: this function is not available on iOS, and should be considered
750 * deprecated on Mac OS X. To ignore expired certificate errors, first disable
751 * Secure Transport's automatic verification of peer certificates by calling
752 * SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth to true. When
753 * SSLHandshake subsequently returns an errSSLServerAuthCompleted result,
754 * your code should obtain the SecTrustRef for the peer's certificates and
755 * perform a custom trust evaluation with SecTrust APIs (see SecTrust.h).
756 * The SecTrustSetOptions function allows you to specify that the expiration
757 * status of certificates should be ignored for this evaluation.
761 * status = SSLSetSessionOption(ctx, kSSLSessionOptionBreakOnServerAuth, true);
763 * status = SSLHandshake(ctx);
765 * if (status == errSSLServerAuthCompleted) {
766 * SecTrustRef peerTrust = NULL;
767 * status = SSLCopyPeerTrust(ctx, &peerTrust);
768 * if (status == errSecSuccess) {
769 * SecTrustResultType trustResult;
770 * // set flag to allow expired certificates
771 * SecTrustSetOptions(peerTrust, kSecTrustOptionAllowExpired);
772 * status = SecTrustEvaluate(peerTrust, &trustResult);
773 * if (status == errSecSuccess) {
774 * // A "proceed" result means the cert is explicitly trusted,
775 * // e.g. "Always Trust" was clicked;
776 * // "Unspecified" means the cert has no explicit trust settings,
777 * // but is implicitly OK since it chains back to a trusted root.
778 * // Any other result means the cert is not trusted.
780 * if (trustResult == kSecTrustResultProceed ||
781 * trustResult == kSecTrustResultUnspecified) {
782 * // certificate is trusted
783 * status = errSSLWouldBlock; // so we call SSLHandshake again
784 * } else if (trustResult == kSecTrustResultRecoverableTrustFailure) {
785 * // not trusted, for some reason other than being expired;
786 * // could ask the user whether to allow the connection here
788 * status = errSSLXCertChainInvalid;
790 * // cannot use this certificate (fatal)
791 * status = errSSLBadCert;
795 * CFRelease(peerTrust);
798 * } // errSSLServerAuthCompleted
800 * } while (status == errSSLWouldBlock);
804 SSLSetAllowsExpiredCerts (SSLContextRef context
,
805 Boolean allowsExpired
)
806 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
809 * Obtain the current value of an SSLContext's "allowExpiredCerts" flag.
811 * ==========================
812 * MAC OS X ONLY (DEPRECATED)
813 * ==========================
814 * NOTE: this function is not available on iOS, and should be considered
815 * deprecated on Mac OS X.
818 SSLGetAllowsExpiredCerts (SSLContextRef context
,
819 Boolean
*allowsExpired
) /* RETURNED */
820 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
823 * Similar to SSLSetAllowsExpiredCerts, SSLSetAllowsExpiredRoots allows the
824 * option of ignoring "expired" status for root certificates only.
825 * Default setting is false, i.e., expired root certs result in an
826 * errSSLCertExpired error.
828 * ==========================
829 * MAC OS X ONLY (DEPRECATED)
830 * ==========================
831 * NOTE: this function is not available on iOS, and should be considered
832 * deprecated on Mac OS X. To ignore expired certificate errors, first disable
833 * Secure Transport's automatic verification of peer certificates by calling
834 * SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth to true. When
835 * SSLHandshake subsequently returns an errSSLServerAuthCompleted result,
836 * your code should obtain the SecTrustRef for the peer's certificates and
837 * perform a custom trust evaluation with SecTrust APIs (see SecTrust.h).
838 * The SecTrustSetOptions function allows you to specify that the expiration
839 * status of certificates should be ignored for this evaluation.
841 * See the description of the SSLSetAllowsExpiredCerts function (above)
842 * for a code example. The kSecTrustOptionAllowExpiredRoot option can be used
843 * instead of kSecTrustOptionAllowExpired to allow expired roots only.
846 SSLSetAllowsExpiredRoots (SSLContextRef context
,
847 Boolean allowsExpired
)
848 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
851 * Obtain the current value of an SSLContext's "allow expired roots" flag.
853 * ==========================
854 * MAC OS X ONLY (DEPRECATED)
855 * ==========================
856 * NOTE: this function is not available on iOS, and should be considered
857 * deprecated on Mac OS X.
860 SSLGetAllowsExpiredRoots (SSLContextRef context
,
861 Boolean
*allowsExpired
) /* RETURNED */
862 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
865 * Specify option of allowing for an unknown root cert, i.e., one which
866 * this software can not verify as one of a list of known good root certs.
867 * Default for this flag is false, in which case one of the following two
869 * -- The peer returns a cert chain with a root cert, and the chain
870 * verifies to that root, but the root is not one of our trusted
871 * roots. This results in errSSLUnknownRootCert on handshake.
872 * -- The peer returns a cert chain which does not contain a root cert,
873 * and we can't verify the chain to one of our trusted roots. This
874 * results in errSSLNoRootCert on handshake.
876 * Both of these error conditions are ignored when the AllowAnyRoot flag is
877 * true, allowing connection to a totally untrusted peer.
879 * ==========================
880 * MAC OS X ONLY (DEPRECATED)
881 * ==========================
882 * NOTE: this function is not available on iOS, and should be considered
883 * deprecated on Mac OS X. To ignore unknown root cert errors, first disable
884 * Secure Transport's automatic verification of peer certificates by calling
885 * SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth to true. When
886 * SSLHandshake subsequently returns an errSSLServerAuthCompleted result,
887 * your code should obtain the SecTrustRef for the peer's certificates and
888 * perform a custom trust evaluation with SecTrust APIs (see SecTrust.h).
890 * See the description of the SSLSetAllowsExpiredCerts function (above)
891 * for a code example. Note that an unknown root certificate will cause
892 * SecTrustEvaluate to report kSecTrustResultRecoverableTrustFailure as the
896 SSLSetAllowsAnyRoot (SSLContextRef context
,
898 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
901 * Obtain the current value of an SSLContext's "allow any root" flag.
903 * ==========================
904 * MAC OS X ONLY (DEPRECATED)
905 * ==========================
906 * NOTE: this function is not available on iOS, and should be considered
907 * deprecated on Mac OS X.
910 SSLGetAllowsAnyRoot (SSLContextRef context
,
911 Boolean
*anyRoot
) /* RETURNED */
912 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
915 * Augment or replace the system's default trusted root certificate set
916 * for this session. If replaceExisting is true, the specified roots will
917 * be the only roots which are trusted during this session. If replaceExisting
918 * is false, the specified roots will be added to the current set of trusted
919 * root certs. If this function has never been called, the current trusted
920 * root set is the same as the system's default trusted root set.
921 * Successive calls with replaceExisting false result in accumulation
922 * of additional root certs.
924 * The trustedRoots array contains SecCertificateRefs.
926 * ==========================
927 * MAC OS X ONLY (DEPRECATED)
928 * ==========================
929 * NOTE: this function is not available on iOS, and should be considered
930 * deprecated on Mac OS X. To trust specific roots in a session, first disable
931 * Secure Transport's automatic verification of peer certificates by calling
932 * SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth to true. When
933 * SSLHandshake subsequently returns an errSSLServerAuthCompleted result,
934 * your code should obtain the SecTrustRef for the peer's certificates and
935 * perform a custom trust evaluation with SecTrust APIs (see SecTrust.h).
937 * See the description of the SSLSetAllowsExpiredCerts function (above)
938 * for a code example. You can call SecTrustSetAnchorCertificates to
939 * augment the system's trusted root set, or SecTrustSetAnchorCertificatesOnly
940 * to make these the only trusted roots, prior to calling SecTrustEvaluate.
943 SSLSetTrustedRoots (SSLContextRef context
,
944 CFArrayRef trustedRoots
,
945 Boolean replaceExisting
)
946 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
949 * Obtain an array of SecCertificateRefs representing the current
950 * set of trusted roots. If SSLSetTrustedRoots() has never been called
951 * for this session, this returns the system's default root set.
953 * Caller must CFRelease the returned CFArray.
955 * ==========================
956 * MAC OS X ONLY (DEPRECATED)
957 * ==========================
958 * NOTE: this function is not available on iOS, and should be considered
959 * deprecated on Mac OS X. To get the current set of trusted roots, call the
960 * SSLCopyPeerTrust function to obtain the SecTrustRef for the peer certificate
961 * chain, then SecTrustCopyCustomAnchorCertificates (see SecTrust.h).
964 SSLCopyTrustedRoots (SSLContextRef context
,
965 CFArrayRef
*trustedRoots
) /* RETURNED */
966 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
969 * Request peer certificates. Valid anytime, subsequent to a handshake attempt.
971 * The certs argument is a CFArray containing SecCertificateRefs.
972 * Caller must CFRelease the returned array.
974 * The cert at index 0 of the returned array is the subject (end
975 * entity) cert; the root cert (or the closest cert to it) is at
976 * the end of the returned array.
978 * ==========================
979 * MAC OS X ONLY (DEPRECATED)
980 * ==========================
981 * NOTE: this function is not available on iOS, and should be considered
982 * deprecated on Mac OS X. To get peer certificates, call SSLCopyPeerTrust
983 * to obtain the SecTrustRef for the peer certificate chain, then use the
984 * SecTrustGetCertificateCount and SecTrustGetCertificateAtIndex functions
985 * to retrieve individual certificates in the chain (see SecTrust.h).
988 SSLCopyPeerCertificates (SSLContextRef context
,
989 CFArrayRef
*certs
) /* RETURNED */
990 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
992 #endif /* MAC OS X */
995 * Obtain a SecTrustRef representing peer certificates. Valid anytime,
996 * subsequent to a handshake attempt. Caller must CFRelease the returned
999 * The returned trust reference will have already been evaluated for you,
1000 * unless one of the following is true:
1001 * - Your code has disabled automatic certificate verification, by calling
1002 * SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth to true.
1003 * - Your code has called SSLSetPeerID, and this session has been resumed
1004 * from an earlier cached session.
1006 * In these cases, your code should call SecTrustEvaluate prior to
1007 * examining the peer certificate chain or trust results (see SecTrust.h).
1009 * NOTE: if you have not called SSLHandshake at least once prior to
1010 * calling this function, the returned trust reference will be NULL.
1013 SSLCopyPeerTrust (SSLContextRef context
,
1014 SecTrustRef
*trust
) /* RETURNED */
1015 __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_5_0
);
1018 * Specify some data, opaque to this library, which is sufficient
1019 * to uniquely identify the peer of the current session. An example
1020 * would be IP address and port, stored in some caller-private manner.
1021 * To be optionally called prior to SSLHandshake for the current
1022 * session. This is mandatory if this session is to be resumable.
1024 * SecureTransport allocates its own copy of the incoming peerID. The
1025 * data provided in *peerID, while opaque to SecureTransport, is used
1026 * in a byte-for-byte compare to other previous peerID values set by the
1027 * current application. Matching peerID blobs result in SecureTransport
1028 * attempting to resume an SSL session with the same parameters as used
1029 * in the previous session which specified the same peerID bytes.
1032 SSLSetPeerID (SSLContextRef context
,
1035 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1038 * Obtain current PeerID. Returns NULL pointer, zero length if
1039 * SSLSetPeerID has not been called for this context.
1042 SSLGetPeerID (SSLContextRef context
,
1043 const void **peerID
,
1045 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1048 * Obtain the SSLCipherSuite (e.g., SSL_RSA_WITH_DES_CBC_SHA) negotiated
1049 * for this session. Only valid when a session is active.
1052 SSLGetNegotiatedCipher (SSLContextRef context
,
1053 SSLCipherSuite
*cipherSuite
)
1054 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1057 /********************************************************
1058 *** Session context configuration, server side only. ***
1059 ********************************************************/
1062 * Specify this connection's encryption certificate(s). This is
1063 * used in one of the following cases:
1065 * -- The end-entity certificate specified in SSLSetCertificate() is
1066 * not capable of encryption.
1068 * -- The end-entity certificate specified in SSLSetCertificate()
1069 * contains a key which is too large (i.e., too strong) for legal
1070 * encryption in this session. In this case a weaker cert is
1071 * specified here and is used for server-initiated key exchange.
1073 * The certRefs argument is a CFArray containing SecCertificateRefs,
1074 * except for certRefs[0], which is a SecIdentityRef.
1076 * The following assumptions are made:
1078 * -- The certRefs references remains valid for the lifetime of the
1080 * -- The specified certRefs[0] is capable of encryption.
1082 * Can only be called when no session is active.
1087 * -- SSL servers which enforce the SSL3 spec to the letter will
1088 * not accept encryption certs with RSA keys larger than 512
1089 * bits for exportable ciphers. Apps which wish to use encryption
1090 * certs with key sizes larger than 512 bits should disable the
1091 * use of exportable ciphers via the SSLSetEnabledCiphers() call.
1094 SSLSetEncryptionCertificate (SSLContextRef context
,
1095 CFArrayRef certRefs
)
1096 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1099 * Specify requirements for client-side authentication.
1100 * Optional; Default is kNeverAuthenticate.
1102 * Can only be called when no session is active.
1105 kNeverAuthenticate
, /* skip client authentication */
1106 kAlwaysAuthenticate
, /* require it */
1107 kTryAuthenticate
/* try to authenticate, but not an error
1108 * if client doesn't have a cert */
1112 SSLSetClientSideAuthenticate (SSLContextRef context
,
1113 SSLAuthenticate auth
)
1114 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1117 * Add a DER-encoded distinguished name to list of acceptable names
1118 * to be specified in requests for client certificates.
1121 SSLAddDistinguishedName (SSLContextRef context
,
1124 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_5_0
);
1127 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
1129 * Add a SecCertificateRef, or a CFArray of them, to a server's list
1130 * of acceptable Certificate Authorities (CAs) to present to the client
1131 * when client authentication is performed.
1133 * If replaceExisting is true, the specified certificate(s) will replace
1134 * a possible existing list of acceptable CAs. If replaceExisting is
1135 * false, the specified certificate(s) will be appended to the existing
1136 * list of acceptable CAs, if any.
1138 * Returns errSecParam if this is called on a SSLContextRef which
1139 * is configured as a client, or when a session is active.
1141 * NOTE: this function is currently not available on iOS.
1144 SSLSetCertificateAuthorities(SSLContextRef context
,
1145 CFTypeRef certificateOrArray
,
1146 Boolean replaceExisting
)
1147 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_NA
);
1150 * Obtain the certificates specified in SSLSetCertificateAuthorities(),
1151 * if any. Returns a NULL array if SSLSetCertificateAuthorities() has not
1153 * Caller must CFRelease the returned array.
1155 * NOTE: this function is currently not available on iOS.
1158 SSLCopyCertificateAuthorities(SSLContextRef context
,
1159 CFArrayRef
*certificates
) /* RETURNED */
1160 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_NA
);
1162 #endif /* MAC OS X */
1165 * Obtain the list of acceptable distinguished names as provided by
1166 * a server (if the SSLContextRef is configured as a client), or as
1167 * specified by SSLSetCertificateAuthorities (if the SSLContextRef
1168 * is configured as a server).
1169 * The returned array contains CFDataRefs, each of which represents
1170 * one DER-encoded RDN.
1172 * Caller must CFRelease the returned array.
1175 SSLCopyDistinguishedNames (SSLContextRef context
,
1177 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_5_0
);
1180 * Obtain client certificate exchange status. Can be called
1181 * any time. Reflects the *last* client certificate state change;
1182 * subsequent to a renegotiation attempt by either peer, the state
1183 * is reset to kSSLClientCertNone.
1186 SSLGetClientCertificateState (SSLContextRef context
,
1187 SSLClientCertificateState
*clientState
)
1188 __OSX_AVAILABLE_STARTING(__MAC_10_3
, __IPHONE_5_0
);
1191 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
1193 * Specify Diffie-Hellman parameters. Optional; if we are configured to allow
1194 * for D-H ciphers and a D-H cipher is negotiated, and this function has not
1195 * been called, a set of process-wide parameters will be calculated. However
1196 * that can take a long time (30 seconds).
1198 * NOTE: this function is currently not available on iOS.
1200 OSStatus
SSLSetDiffieHellmanParams (SSLContextRef context
,
1201 const void *dhParams
,
1203 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_NA
);
1206 * Return parameter block specified in SSLSetDiffieHellmanParams.
1207 * Returned data is not copied and belongs to the SSLContextRef.
1209 * NOTE: this function is currently not available on iOS.
1211 OSStatus
SSLGetDiffieHellmanParams (SSLContextRef context
,
1212 const void **dhParams
,
1213 size_t *dhParamsLen
)
1214 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_NA
);
1217 * Enable/Disable RSA blinding. This feature thwarts a known timing
1218 * attack to which RSA keys are vulnerable; enabling it is a tradeoff
1219 * between performance and security. The default for RSA blinding is
1222 * ==========================
1223 * MAC OS X ONLY (DEPRECATED)
1224 * ==========================
1225 * NOTE: this function is not available on iOS, and should be considered
1226 * deprecated on Mac OS X. RSA blinding is enabled unconditionally, as
1227 * it prevents a known way for an attacker to recover the private key,
1228 * and the performance gain of disabling it is negligible.
1230 OSStatus
SSLSetRsaBlinding (SSLContextRef context
,
1232 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
1234 OSStatus
SSLGetRsaBlinding (SSLContextRef context
,
1236 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
,__MAC_10_9
,__IPHONE_NA
,__IPHONE_NA
);
1238 #endif /* MAC OS X */
1240 /*******************************
1241 ******** I/O Functions ********
1242 *******************************/
1245 * Note: depending on the configuration of the underlying I/O
1246 * connection, all SSL I/O functions can return errSSLWouldBlock,
1247 * indicating "not complete, nothing is wrong, except required
1248 * I/O hasn't completed". Caller may need to repeat I/Os as necessary
1249 * if the underlying connection has been configured to behave in
1250 * a non-blocking manner.
1254 * Perform the SSL handshake. On successful return, session is
1255 * ready for normal secure application I/O via SSLWrite and SSLRead.
1257 * Interesting error returns:
1259 * errSSLUnknownRootCert: Peer had a valid cert chain, but the root of
1260 * the chain is unknown.
1262 * errSSLNoRootCert: Peer had a cert chain which did not end in a root.
1264 * errSSLCertExpired: Peer's cert chain had one or more expired certs.
1266 * errSSLXCertChainInvalid: Peer had an invalid cert chain (i.e.,
1267 * signature verification within the chain failed, or no certs
1270 * In all of the above errors, the handshake was aborted; the peer's
1271 * cert chain is available via SSLCopyPeerTrust or SSLCopyPeerCertificates.
1273 * Other interesting result codes:
1275 * errSSLPeerAuthCompleted: Peer's cert chain is valid, or was ignored if
1276 * cert verification was disabled via SSLSetEnableCertVerify. The application
1277 * may decide to continue with the handshake (by calling SSLHandshake
1278 * again), or close the connection at this point.
1280 * errSSLClientCertRequested: The server has requested a client certificate.
1281 * The client may choose to examine the server's certificate and
1282 * distinguished name list, then optionally call SSLSetCertificate prior
1283 * to resuming the handshake by calling SSLHandshake again.
1285 * A return value of errSSLWouldBlock indicates that SSLHandshake has to be
1286 * called again (and again and again until something else is returned).
1289 SSLHandshake (SSLContextRef context
)
1290 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1293 * Normal application-level read/write. On both of these, a errSSLWouldBlock
1294 * return and a partially completed transfer - or even zero bytes transferred -
1295 * are NOT mutually exclusive.
1298 SSLWrite (SSLContextRef context
,
1301 size_t *processed
) /* RETURNED */
1302 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1305 * data is mallocd by caller; available size specified in
1306 * dataLength; actual number of bytes read returned in
1310 SSLRead (SSLContextRef context
,
1311 void * data
, /* RETURNED */
1313 size_t *processed
) /* RETURNED */
1314 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1317 * Determine how much data the client can be guaranteed to
1318 * obtain via SSLRead() without blocking or causing any low-level
1319 * read operations to occur.
1322 SSLGetBufferedReadSize (SSLContextRef context
,
1323 size_t *bufSize
) /* RETURNED */
1324 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1327 * Determine how much data the application can be guaranteed to write
1328 * with SSLWrite() without causing fragmentation. The value is based on
1329 * the maximum Datagram Record size defined by the application with
1330 * SSLSetMaxDatagramRecordSize(), minus the DTLS Record header size.
1333 SSLGetDatagramWriteSize (SSLContextRef dtlsContext
,
1335 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_5_0
);
1338 * Terminate current SSL session.
1341 SSLClose (SSLContextRef context
)
1342 __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_5_0
);
1348 #endif /* !_SECURITY_SECURETRANSPORT_H_ */