]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_ssl/lib/SecureTransport.h
Security-57336.1.9.tar.gz
[apple/security.git] / OSX / libsecurity_ssl / lib / SecureTransport.h
1 /*
2 * Copyright (c) 1999-2002,2005-2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*
25 * SecureTransport.h - Public API for Apple SSL/TLS Implementation
26 */
27
28 #ifndef _SECURITY_SECURETRANSPORT_H_
29 #define _SECURITY_SECURETRANSPORT_H_
30
31 /*
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
35 *
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.
43 *
44 * Some terminology:
45 *
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.
48 *
49 * A "server" is an entity which accepts requests for SSL sessions made
50 * by clients. E.g., a secure web server.
51
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.
55 *
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.
59 */
60
61 #include <CoreFoundation/CFArray.h>
62 #include <Security/CipherSuite.h>
63 #include <Security/SecTrust.h>
64 #include <sys/types.h>
65 #include <Availability.h>
66
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70
71 CF_ASSUME_NONNULL_BEGIN
72 CF_IMPLICIT_BRIDGING_ENABLED
73
74 /***********************
75 *** Common typedefs ***
76 ***********************/
77
78 /* Opaque reference to an SSL session context */
79 struct SSLContext;
80 typedef struct CF_BRIDGED_TYPE(id) SSLContext *SSLContextRef;
81
82 /* Opaque reference to an I/O connection (socket, endpoint, etc.) */
83 typedef const void * SSLConnectionRef;
84
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 */
93
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 */
99
100 };
101
102 /* SSL session options */
103 typedef CF_ENUM(int, SSLSessionOption) {
104 /*
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.
110 */
111 kSSLSessionOptionBreakOnServerAuth = 0,
112 /*
113 * Set this option to enable returning from SSLHandshake (with a result of
114 * errSSLClientCertRequested) when the server requests a client certificate.
115 */
116 kSSLSessionOptionBreakOnCertRequested = 1,
117 /*
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.
122 */
123 kSSLSessionOptionBreakOnClientAuth = 2,
124 /*
125 * Enable/Disable TLS False Start
126 * When enabled, False Start will only be performed if a adequate cipher-suite is
127 * negotiated.
128 */
129 kSSLSessionOptionFalseStart = 3,
130 /*
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.
134 */
135 kSSLSessionOptionSendOneByteRecord = 4,
136 /*
137 * Allow/Disallow server identity change on renegotiation. Disallow by default
138 * to avoid Triple Handshake attack.
139 */
140 kSSLSessionOptionAllowServerIdentityChange = 5,
141 /*
142 * Enable fallback countermeasures. Use this option when retyring a SSL connection
143 * with a lower protocol version because of failure to connect.
144 */
145 kSSLSessionOptionFallback = 6,
146 /*
147 * Set this option to break from a client hello in order to check for SNI
148 */
149 kSSLSessionOptionBreakOnClientHello = 7,
150
151 };
152
153 /* State of an SSLSession */
154 typedef CF_ENUM(int, SSLSessionState) {
155 kSSLIdle, /* no I/O performed yet */
156 kSSLHandshake, /* SSL handshake in progress */
157 kSSLConnected, /* Handshake complete, ready for normal I/O */
158 kSSLClosed, /* connection closed normally */
159 kSSLAborted /* connection aborted */
160 };
161
162 /*
163 * Status of client certificate exchange (which is optional
164 * for both server and client).
165 */
166 typedef CF_ENUM(int, SSLClientCertificateState) {
167 /* Server hasn't asked for a cert. Client hasn't sent one. */
168 kSSLClientCertNone,
169 /* Server has asked for a cert, but client didn't send it. */
170 kSSLClientCertRequested,
171 /*
172 * Server side: We asked for a cert, client sent one, we validated
173 * it OK. App can inspect the cert via
174 * SSLGetPeerCertificates().
175 * Client side: server asked for one, we sent it.
176 */
177 kSSLClientCertSent,
178 /*
179 * Client sent a cert but failed validation. Server side only.
180 * Server app can inspect the cert via SSLGetPeerCertificates().
181 */
182 kSSLClientCertRejected
183 } ;
184
185 /*
186 * R/W functions. The application using this library provides
187 * these functions via SSLSetIOFuncs().
188 *
189 * Data's memory is allocated by caller; on entry to these two functions
190 * the *length argument indicates both the size of the available data and the
191 * requested byte count. Number of bytes actually transferred is returned in
192 * *length.
193 *
194 * The application may configure the underlying connection to operate
195 * in a non-blocking manner; in such a case, a read operation may
196 * well return errSSLWouldBlock, indicating "I transferred less data than
197 * you requested (maybe even zero bytes), nothing is wrong, except
198 * requested I/O hasn't completed". This will be returned back up to
199 * the application as a return from SSLRead(), SSLWrite(), SSLHandshake(),
200 * etc.
201 */
202 typedef OSStatus
203 (*SSLReadFunc) (SSLConnectionRef connection,
204 void *data, /* owned by
205 * caller, data
206 * RETURNED */
207 size_t *dataLength); /* IN/OUT */
208 typedef OSStatus
209 (*SSLWriteFunc) (SSLConnectionRef connection,
210 const void *data,
211 size_t *dataLength); /* IN/OUT */
212
213 /*************************************************
214 *** OSStatus values unique to SecureTransport ***
215 *************************************************/
216
217 /*
218 Note: the comments that appear after these errors are used to create SecErrorMessages.strings.
219 The comments must not be multi-line, and should be in a form meaningful to an end user. If
220 a different or additional comment is needed, it can be put in the header doc format, or on a
221 line that does not start with errZZZ.
222 */
223
224 CF_ENUM(OSStatus) {
225 errSSLProtocol = -9800, /* SSL protocol error */
226 errSSLNegotiation = -9801, /* Cipher Suite negotiation failure */
227 errSSLFatalAlert = -9802, /* Fatal alert */
228 errSSLWouldBlock = -9803, /* I/O would block (not fatal) */
229 errSSLSessionNotFound = -9804, /* attempt to restore an unknown session */
230 errSSLClosedGraceful = -9805, /* connection closed gracefully */
231 errSSLClosedAbort = -9806, /* connection closed via error */
232 errSSLXCertChainInvalid = -9807, /* invalid certificate chain */
233 errSSLBadCert = -9808, /* bad certificate format */
234 errSSLCrypto = -9809, /* underlying cryptographic error */
235 errSSLInternal = -9810, /* Internal error */
236 errSSLModuleAttach = -9811, /* module attach failure */
237 errSSLUnknownRootCert = -9812, /* valid cert chain, untrusted root */
238 errSSLNoRootCert = -9813, /* cert chain not verified by root */
239 errSSLCertExpired = -9814, /* chain had an expired cert */
240 errSSLCertNotYetValid = -9815, /* chain had a cert not yet valid */
241 errSSLClosedNoNotify = -9816, /* server closed session with no notification */
242 errSSLBufferOverflow = -9817, /* insufficient buffer provided */
243 errSSLBadCipherSuite = -9818, /* bad SSLCipherSuite */
244
245 /* fatal errors detected by peer */
246 errSSLPeerUnexpectedMsg = -9819, /* unexpected message received */
247 errSSLPeerBadRecordMac = -9820, /* bad MAC */
248 errSSLPeerDecryptionFail = -9821, /* decryption failed */
249 errSSLPeerRecordOverflow = -9822, /* record overflow */
250 errSSLPeerDecompressFail = -9823, /* decompression failure */
251 errSSLPeerHandshakeFail = -9824, /* handshake failure */
252 errSSLPeerBadCert = -9825, /* misc. bad certificate */
253 errSSLPeerUnsupportedCert = -9826, /* bad unsupported cert format */
254 errSSLPeerCertRevoked = -9827, /* certificate revoked */
255 errSSLPeerCertExpired = -9828, /* certificate expired */
256 errSSLPeerCertUnknown = -9829, /* unknown certificate */
257 errSSLIllegalParam = -9830, /* illegal parameter */
258 errSSLPeerUnknownCA = -9831, /* unknown Cert Authority */
259 errSSLPeerAccessDenied = -9832, /* access denied */
260 errSSLPeerDecodeError = -9833, /* decoding error */
261 errSSLPeerDecryptError = -9834, /* decryption error */
262 errSSLPeerExportRestriction = -9835, /* export restriction */
263 errSSLPeerProtocolVersion = -9836, /* bad protocol version */
264 errSSLPeerInsufficientSecurity = -9837, /* insufficient security */
265 errSSLPeerInternalError = -9838, /* internal error */
266 errSSLPeerUserCancelled = -9839, /* user canceled */
267 errSSLPeerNoRenegotiation = -9840, /* no renegotiation allowed */
268
269 /* non-fatal result codes */
270 errSSLPeerAuthCompleted = -9841, /* peer cert is valid, or was ignored if verification disabled */
271 errSSLClientCertRequested = -9842, /* server has requested a client cert */
272
273 /* more errors detected by us */
274 errSSLHostNameMismatch = -9843, /* peer host name mismatch */
275 errSSLConnectionRefused = -9844, /* peer dropped connection before responding */
276 errSSLDecryptionFail = -9845, /* decryption failure */
277 errSSLBadRecordMac = -9846, /* bad MAC */
278 errSSLRecordOverflow = -9847, /* record overflow */
279 errSSLBadConfiguration = -9848, /* configuration error */
280 errSSLUnexpectedRecord = -9849, /* unexpected (skipped) record in DTLS */
281 errSSLWeakPeerEphemeralDHKey = -9850, /* weak ephemeral dh key */
282
283 /* non-fatal result codes */
284 errSSLClientHelloReceived = -9851, /* SNI */
285 };
286
287 /* DEPRECATED aliases for errSSLPeerAuthCompleted */
288 #define errSSLServerAuthCompleted errSSLPeerAuthCompleted
289 #define errSSLClientAuthCompleted errSSLPeerAuthCompleted
290
291 /* DEPRECATED alias for the end of the error range */
292 #define errSSLLast errSSLUnexpectedRecord
293
294 typedef CF_ENUM(int, SSLProtocolSide)
295 {
296 kSSLServerSide,
297 kSSLClientSide
298 };
299
300 typedef CF_ENUM(int, SSLConnectionType)
301 {
302 kSSLStreamType,
303 kSSLDatagramType
304 };
305
306 typedef CF_ENUM(int, SSLSessionStrengthPolicy)
307 {
308 kSSLSessionStrengthPolicyDefault,
309 kSSLSessionStrengthPolicyATSv1
310 };
311
312 /******************
313 *** Public API ***
314 ******************/
315
316 /*
317 * Secure Transport APIs require a SSLContextRef, which is an opaque
318 * reference to the SSL session and its parameters. On Mac OS X 10.7
319 * and earlier versions, a new context is created using SSLNewContext,
320 * and is disposed by calling SSLDisposeContext.
321 *
322 * On i0S 5.0 and later, as well as Mac OS X versions after 10.7, the
323 * SSLContextRef is a true CFType object with retain-release semantics.
324 * New code should create a new context using SSLCreateContext (instead
325 * of SSLNewContext), and dispose the context by calling CFRelease
326 * (instead of SSLDisposeContext) when finished with it.
327 */
328
329 /*
330 * Return the CFTypeID for SSLContext objects.
331 */
332 CFTypeID
333 SSLContextGetTypeID(void)
334 __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_5_0);
335
336 /*
337 * Create a new instance of an SSLContextRef using the specified allocator.
338 */
339 __nullable
340 SSLContextRef
341 SSLCreateContext(CFAllocatorRef __nullable alloc, SSLProtocolSide protocolSide, SSLConnectionType connectionType)
342 __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_5_0);
343
344
345 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
346 /*
347 * Create a new session context.
348 *
349 * ==========================
350 * MAC OS X ONLY (DEPRECATED)
351 * ==========================
352 * NOTE: this function is not available on iOS, and should be considered
353 * deprecated on Mac OS X. Your code should use SSLCreateContext instead.
354 */
355 OSStatus
356 SSLNewContext (Boolean isServer,
357 SSLContextRef * __nonnull CF_RETURNS_RETAINED contextPtr) /* RETURNED */
358 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_9,__IPHONE_NA,__IPHONE_NA);
359
360 /*
361 * Dispose of a session context.
362 *
363 * ==========================
364 * MAC OS X ONLY (DEPRECATED)
365 * ==========================
366 * NOTE: this function is not available on iOS, and should be considered
367 * deprecated on Mac OS X. Your code should use CFRelease to dispose a session
368 * created with SSLCreateContext.
369 */
370 OSStatus
371 SSLDisposeContext (SSLContextRef context)
372 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_9,__IPHONE_NA,__IPHONE_NA);
373
374 #endif /* MAC OS X */
375
376 /*
377 * Determine the state of an SSL/DTLS session.
378 */
379 OSStatus
380 SSLGetSessionState (SSLContextRef context,
381 SSLSessionState *state) /* RETURNED */
382 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
383
384 /*
385 * Set options for an SSL session. Must be called prior to SSLHandshake();
386 * subsequently cannot be called while session is active.
387 */
388 OSStatus
389 SSLSetSessionOption (SSLContextRef context,
390 SSLSessionOption option,
391 Boolean value)
392 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_5_0);
393
394 /*
395 * Determine current value for the specified option in a given SSL session.
396 */
397 OSStatus
398 SSLGetSessionOption (SSLContextRef context,
399 SSLSessionOption option,
400 Boolean *value)
401 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_5_0);
402
403 /********************************************************************
404 *** Session context configuration, common to client and servers. ***
405 ********************************************************************/
406
407 /*
408 * Specify functions which do the network I/O. Must be called prior
409 * to SSLHandshake(); subsequently cannot be called while a session is
410 * active.
411 */
412 OSStatus
413 SSLSetIOFuncs (SSLContextRef context,
414 SSLReadFunc readFunc,
415 SSLWriteFunc writeFunc)
416 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
417
418 /*
419 * Set the minimum SSL protocol version allowed. Optional.
420 * The default is the lower supported protocol.
421 *
422 * This can only be called when no session is active.
423 *
424 * For TLS contexts, legal values for minVersion are :
425 * kSSLProtocol3
426 * kTLSProtocol1
427 * kTLSProtocol11
428 * kTLSProtocol12
429 *
430 * For DTLS contexts, legal values for minVersion are :
431 * kDTLSProtocol1
432 */
433 OSStatus
434 SSLSetProtocolVersionMin (SSLContextRef context,
435 SSLProtocol minVersion)
436 __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_5_0);
437
438 /*
439 * Get minimum protocol version allowed
440 */
441 OSStatus
442 SSLGetProtocolVersionMin (SSLContextRef context,
443 SSLProtocol *minVersion)
444 __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_5_0);
445
446 /*
447 * Set the maximum SSL protocol version allowed. Optional.
448 * The default is the highest supported protocol.
449 *
450 * This can only be called when no session is active.
451 *
452 * For TLS contexts, legal values for minVersion are :
453 * kSSLProtocol3
454 * kTLSProtocol1
455 * kTLSProtocol11
456 * kTLSProtocol12
457 *
458 * For DTLS contexts, legal values for minVersion are :
459 * kDTLSProtocol1
460 */
461 OSStatus
462 SSLSetProtocolVersionMax (SSLContextRef context,
463 SSLProtocol maxVersion)
464 __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_5_0);
465
466 /*
467 * Get maximum protocol version allowed
468 */
469 OSStatus
470 SSLGetProtocolVersionMax (SSLContextRef context,
471 SSLProtocol *maxVersion)
472 __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_5_0);
473
474
475 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
476 /*
477 * Set allowed SSL protocol versions. Optional.
478 * Specifying kSSLProtocolAll for SSLSetProtocolVersionEnabled results in
479 * specified 'enable' boolean to be applied to all supported protocols.
480 * The default is "all supported protocols are enabled".
481 * This can only be called when no session is active.
482 *
483 * Legal values for protocol are :
484 * kSSLProtocol2
485 * kSSLProtocol3
486 * kTLSProtocol1
487 * kSSLProtocolAll
488 *
489 * ==========================
490 * MAC OS X ONLY (DEPRECATED)
491 * ==========================
492 * NOTE: this function is not available on iOS, and should be considered
493 * deprecated on Mac OS X. You can use SSLSetProtocolVersionMin and/or
494 * SSLSetProtocolVersionMax to specify which protocols are enabled.
495 */
496 OSStatus
497 SSLSetProtocolVersionEnabled (SSLContextRef context,
498 SSLProtocol protocol,
499 Boolean enable)
500 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_9,__IPHONE_NA,__IPHONE_NA);
501
502 /*
503 * Obtain a value specified in SSLSetProtocolVersionEnabled.
504 *
505 * ==========================
506 * MAC OS X ONLY (DEPRECATED)
507 * ==========================
508 * NOTE: this function is not available on iOS, and should be considered
509 * deprecated on Mac OS X. You can use SSLGetProtocolVersionMin and/or
510 * SSLGetProtocolVersionMax to check whether a protocol is enabled.
511 */
512 OSStatus
513 SSLGetProtocolVersionEnabled(SSLContextRef context,
514 SSLProtocol protocol,
515 Boolean *enable) /* RETURNED */
516 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_9,__IPHONE_NA,__IPHONE_NA);
517
518 /*
519 * Get/set SSL protocol version; optional. Default is kSSLProtocolUnknown,
520 * in which case the highest possible version is attempted, but a lower
521 * version is accepted if the peer requires it.
522 * SSLSetProtocolVersion cannot be called when a session is active.
523 *
524 * ==========================
525 * MAC OS X ONLY (DEPRECATED)
526 * ==========================
527 * NOTE: this function is not available on iOS, and deprecated on Mac OS X 10.8.
528 * Use SSLSetProtocolVersionMin and/or SSLSetProtocolVersionMax to specify
529 * which protocols are enabled.
530 */
531 OSStatus
532 SSLSetProtocolVersion (SSLContextRef context,
533 SSLProtocol version)
534 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_8,__IPHONE_NA,__IPHONE_NA);
535
536 /*
537 * Obtain the protocol version specified in SSLSetProtocolVersion.
538 * If SSLSetProtocolVersionEnabled() has been called for this session,
539 * SSLGetProtocolVersion() may return errSecParam if the protocol enable
540 * state can not be represented by the SSLProtocol enums (e.g.,
541 * SSL2 and TLS1 enabled, SSL3 disabled).
542 *
543 * ==========================
544 * MAC OS X ONLY (DEPRECATED)
545 * ==========================
546 * NOTE: this function is not available on iOS, and deprecated on Mac OS X 10.8.
547 * Use SSLGetProtocolVersionMin and/or SSLGetProtocolVersionMax to check
548 * whether a protocol is enabled.
549 */
550 OSStatus
551 SSLGetProtocolVersion (SSLContextRef context,
552 SSLProtocol *protocol) /* RETURNED */
553 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_8,__IPHONE_NA,__IPHONE_NA);
554
555 #endif /* MAC OS X */
556
557 /*
558 * Specify this connection's certificate(s). This is mandatory for
559 * server connections, optional for clients. Specifying a certificate
560 * for a client enables SSL client-side authentication. The end-entity
561 * cert is in certRefs[0]. Specifying a root cert is optional; if it's
562 * not specified, the root cert which verifies the cert chain specified
563 * here must be present in the system-wide set of trusted anchor certs.
564 *
565 * The certRefs argument is a CFArray containing SecCertificateRefs,
566 * except for certRefs[0], which is a SecIdentityRef.
567 *
568 * Must be called prior to SSLHandshake(), or immediately after
569 * SSLHandshake has returned errSSLClientCertRequested (i.e. before the
570 * handshake is resumed by calling SSLHandshake again.)
571 *
572 * SecureTransport assumes the following:
573 *
574 * -- The certRef references remain valid for the lifetime of the session.
575 * -- The certificate specified in certRefs[0] is capable of signing.
576 * -- The required capabilities of the certRef[0], and of the optional cert
577 * specified in SSLSetEncryptionCertificate (see below), are highly
578 * dependent on the application. For example, to work as a server with
579 * Netscape clients, the cert specified here must be capable of both
580 * signing and encrypting.
581 */
582 OSStatus
583 SSLSetCertificate (SSLContextRef context,
584 CFArrayRef certRefs)
585 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
586
587 /*
588 * Specify I/O connection - a socket, endpoint, etc., which is
589 * managed by caller. On the client side, it's assumed that communication
590 * has been established with the desired server on this connection.
591 * On the server side, it's assumed that an incoming client request
592 * has been established.
593 *
594 * Must be called prior to SSLHandshake(); subsequently can only be
595 * called when no session is active.
596 */
597 OSStatus
598 SSLSetConnection (SSLContextRef context,
599 SSLConnectionRef __nullable connection)
600 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
601
602 OSStatus
603 SSLGetConnection (SSLContextRef context,
604 SSLConnectionRef * __nonnull CF_RETURNS_NOT_RETAINED connection)
605 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
606
607 /*
608 * Specify the fully qualified doman name of the peer, e.g., "store.apple.com."
609 * Optional; used to verify the common name field in peer's certificate.
610 * Name is in the form of a C string; NULL termination optional, i.e.,
611 * peerName[peerNameLen+1] may or may not have a NULL. In any case peerNameLen
612 * is the number of bytes of the peer domain name.
613 */
614 OSStatus
615 SSLSetPeerDomainName (SSLContextRef context,
616 const char * __nullable peerName,
617 size_t peerNameLen)
618 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
619
620 /*
621 * Determine the buffer size needed for SSLGetPeerDomainName().
622 */
623 OSStatus
624 SSLGetPeerDomainNameLength (SSLContextRef context,
625 size_t *peerNameLen) // RETURNED
626 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
627
628 /*
629 * Obtain the value specified in SSLSetPeerDomainName().
630 */
631 OSStatus
632 SSLGetPeerDomainName (SSLContextRef context,
633 char *peerName, // returned here
634 size_t *peerNameLen) // IN/OUT
635 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
636
637 /*
638 * Specify the Datagram TLS Hello Cookie.
639 * This is to be called for server side only and is optional.
640 * The default is a zero len cookie. The maximum cookieLen is 32 bytes.
641 */
642 OSStatus
643 SSLSetDatagramHelloCookie (SSLContextRef dtlsContext,
644 const void * __nullable cookie,
645 size_t cookieLen)
646 __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_5_0);
647
648 /*
649 * Specify the maximum record size, including all DTLS record headers.
650 * This should be set appropriately to avoid fragmentation
651 * of Datagrams during handshake, as fragmented datagrams may
652 * be dropped by some network.
653 * This is for Datagram TLS only
654 */
655 OSStatus
656 SSLSetMaxDatagramRecordSize (SSLContextRef dtlsContext,
657 size_t maxSize)
658 __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_5_0);
659
660 /*
661 * Get the maximum record size, including all Datagram TLS record headers.
662 * This is for Datagram TLS only
663 */
664 OSStatus
665 SSLGetMaxDatagramRecordSize (SSLContextRef dtlsContext,
666 size_t *maxSize)
667 __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_5_0);
668
669 /*
670 * Obtain the actual negotiated protocol version of the active
671 * session, which may be different that the value specified in
672 * SSLSetProtocolVersion(). Returns kSSLProtocolUnknown if no
673 * SSL session is in progress.
674 */
675 OSStatus
676 SSLGetNegotiatedProtocolVersion (SSLContextRef context,
677 SSLProtocol *protocol) /* RETURNED */
678 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
679
680 /*
681 * Determine number and values of all of the SSLCipherSuites we support.
682 * Caller allocates output buffer for SSLGetSupportedCiphers() and passes in
683 * its size in *numCiphers. If supplied buffer is too small, errSSLBufferOverflow
684 * will be returned.
685 */
686 OSStatus
687 SSLGetNumberSupportedCiphers (SSLContextRef context,
688 size_t *numCiphers)
689 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
690
691 OSStatus
692 SSLGetSupportedCiphers (SSLContextRef context,
693 SSLCipherSuite *ciphers, /* RETURNED */
694 size_t *numCiphers) /* IN/OUT */
695 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
696
697 /*
698 * Specify a (typically) restricted set of SSLCipherSuites to be enabled by
699 * the current SSLContext. Can only be called when no session is active. Default
700 * set of enabled SSLCipherSuites is the same as the complete set of supported
701 * SSLCipherSuites as obtained by SSLGetSupportedCiphers().
702 */
703 OSStatus
704 SSLSetEnabledCiphers (SSLContextRef context,
705 const SSLCipherSuite *ciphers,
706 size_t numCiphers)
707 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
708
709 /*
710 * Determine number and values of all of the SSLCipherSuites currently enabled.
711 * Caller allocates output buffer for SSLGetEnabledCiphers() and passes in
712 * its size in *numCiphers. If supplied buffer is too small, errSSLBufferOverflow
713 * will be returned.
714 */
715 OSStatus
716 SSLGetNumberEnabledCiphers (SSLContextRef context,
717 size_t *numCiphers)
718 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
719
720 OSStatus
721 SSLGetEnabledCiphers (SSLContextRef context,
722 SSLCipherSuite *ciphers, /* RETURNED */
723 size_t *numCiphers) /* IN/OUT */
724 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
725
726
727 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
728 /*
729 * Enable/disable peer certificate chain validation. Default is enabled.
730 * If caller disables, it is the caller's responsibility to call
731 * SSLCopyPeerCertificates() upon successful completion of the handshake
732 * and then to perform external validation of the peer certificate
733 * chain before proceeding with data transfer.
734 *
735 * ==========================
736 * MAC OS X ONLY (DEPRECATED)
737 * ==========================
738 * NOTE: this function is not available on iOS, and should be considered
739 * deprecated on Mac OS X. To disable peer certificate chain validation, you
740 * can instead use SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth
741 * to true. This will disable verification and cause SSLHandshake to return with
742 * an errSSLServerAuthCompleted result when the peer certificates have been
743 * received; at that time, you can choose to evaluate peer trust yourself, or
744 * simply call SSLHandshake again to proceed with the handshake.
745 */
746 OSStatus
747 SSLSetEnableCertVerify (SSLContextRef context,
748 Boolean enableVerify)
749 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_9,__IPHONE_NA,__IPHONE_NA);
750
751 /*
752 * Check whether peer certificate chain validation is enabled.
753 *
754 * ==========================
755 * MAC OS X ONLY (DEPRECATED)
756 * ==========================
757 * NOTE: this function is not available on iOS, and should be considered
758 * deprecated on Mac OS X. To check whether peer certificate chain validation
759 * is enabled in a context, call SSLGetSessionOption to obtain the value of
760 * the kSSLSessionOptionBreakOnServerAuth session option flag. If the value
761 * of this option flag is true, then verification is disabled.
762 */
763 OSStatus
764 SSLGetEnableCertVerify (SSLContextRef context,
765 Boolean *enableVerify) /* RETURNED */
766 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_9,__IPHONE_NA,__IPHONE_NA);
767
768 /*
769 * Specify the option of ignoring certificates' "expired" times.
770 * This is a common failure in the real SSL world. Default setting for this
771 * flag is false, meaning expired certs result in an errSSLCertExpired error.
772 *
773 * ==========================
774 * MAC OS X ONLY (DEPRECATED)
775 * ==========================
776 * NOTE: this function is not available on iOS, and should be considered
777 * deprecated on Mac OS X. To ignore expired certificate errors, first disable
778 * Secure Transport's automatic verification of peer certificates by calling
779 * SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth to true. When
780 * SSLHandshake subsequently returns an errSSLServerAuthCompleted result,
781 * your code should obtain the SecTrustRef for the peer's certificates and
782 * perform a custom trust evaluation with SecTrust APIs (see SecTrust.h).
783 * The SecTrustSetOptions function allows you to specify that the expiration
784 * status of certificates should be ignored for this evaluation.
785 *
786 * Example:
787 *
788 * status = SSLSetSessionOption(ctx, kSSLSessionOptionBreakOnServerAuth, true);
789 * do {
790 * status = SSLHandshake(ctx);
791 *
792 * if (status == errSSLServerAuthCompleted) {
793 * SecTrustRef peerTrust = NULL;
794 * status = SSLCopyPeerTrust(ctx, &peerTrust);
795 * if (status == errSecSuccess) {
796 * SecTrustResultType trustResult;
797 * // set flag to allow expired certificates
798 * SecTrustSetOptions(peerTrust, kSecTrustOptionAllowExpired);
799 * status = SecTrustEvaluate(peerTrust, &trustResult);
800 * if (status == errSecSuccess) {
801 * // A "proceed" result means the cert is explicitly trusted,
802 * // e.g. "Always Trust" was clicked;
803 * // "Unspecified" means the cert has no explicit trust settings,
804 * // but is implicitly OK since it chains back to a trusted root.
805 * // Any other result means the cert is not trusted.
806 * //
807 * if (trustResult == kSecTrustResultProceed ||
808 * trustResult == kSecTrustResultUnspecified) {
809 * // certificate is trusted
810 * status = errSSLWouldBlock; // so we call SSLHandshake again
811 * } else if (trustResult == kSecTrustResultRecoverableTrustFailure) {
812 * // not trusted, for some reason other than being expired;
813 * // could ask the user whether to allow the connection here
814 * //
815 * status = errSSLXCertChainInvalid;
816 * } else {
817 * // cannot use this certificate (fatal)
818 * status = errSSLBadCert;
819 * }
820 * }
821 * if (peerTrust) {
822 * CFRelease(peerTrust);
823 * }
824 * }
825 * } // errSSLServerAuthCompleted
826 *
827 * } while (status == errSSLWouldBlock);
828 *
829 */
830 OSStatus
831 SSLSetAllowsExpiredCerts (SSLContextRef context,
832 Boolean allowsExpired)
833 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_9,__IPHONE_NA,__IPHONE_NA);
834
835 /*
836 * Obtain the current value of an SSLContext's "allowExpiredCerts" flag.
837 *
838 * ==========================
839 * MAC OS X ONLY (DEPRECATED)
840 * ==========================
841 * NOTE: this function is not available on iOS, and should be considered
842 * deprecated on Mac OS X.
843 */
844 OSStatus
845 SSLGetAllowsExpiredCerts (SSLContextRef context,
846 Boolean *allowsExpired) /* RETURNED */
847 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_9,__IPHONE_NA,__IPHONE_NA);
848
849 /*
850 * Similar to SSLSetAllowsExpiredCerts, SSLSetAllowsExpiredRoots allows the
851 * option of ignoring "expired" status for root certificates only.
852 * Default setting is false, i.e., expired root certs result in an
853 * errSSLCertExpired error.
854 *
855 * ==========================
856 * MAC OS X ONLY (DEPRECATED)
857 * ==========================
858 * NOTE: this function is not available on iOS, and should be considered
859 * deprecated on Mac OS X. To ignore expired certificate errors, first disable
860 * Secure Transport's automatic verification of peer certificates by calling
861 * SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth to true. When
862 * SSLHandshake subsequently returns an errSSLServerAuthCompleted result,
863 * your code should obtain the SecTrustRef for the peer's certificates and
864 * perform a custom trust evaluation with SecTrust APIs (see SecTrust.h).
865 * The SecTrustSetOptions function allows you to specify that the expiration
866 * status of certificates should be ignored for this evaluation.
867 *
868 * See the description of the SSLSetAllowsExpiredCerts function (above)
869 * for a code example. The kSecTrustOptionAllowExpiredRoot option can be used
870 * instead of kSecTrustOptionAllowExpired to allow expired roots only.
871 */
872 OSStatus
873 SSLSetAllowsExpiredRoots (SSLContextRef context,
874 Boolean allowsExpired)
875 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_9,__IPHONE_NA,__IPHONE_NA);
876
877 /*
878 * Obtain the current value of an SSLContext's "allow expired roots" flag.
879 *
880 * ==========================
881 * MAC OS X ONLY (DEPRECATED)
882 * ==========================
883 * NOTE: this function is not available on iOS, and should be considered
884 * deprecated on Mac OS X.
885 */
886 OSStatus
887 SSLGetAllowsExpiredRoots (SSLContextRef context,
888 Boolean *allowsExpired) /* RETURNED */
889 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_9,__IPHONE_NA,__IPHONE_NA);
890
891 /*
892 * Specify option of allowing for an unknown root cert, i.e., one which
893 * this software can not verify as one of a list of known good root certs.
894 * Default for this flag is false, in which case one of the following two
895 * errors may occur:
896 * -- The peer returns a cert chain with a root cert, and the chain
897 * verifies to that root, but the root is not one of our trusted
898 * roots. This results in errSSLUnknownRootCert on handshake.
899 * -- The peer returns a cert chain which does not contain a root cert,
900 * and we can't verify the chain to one of our trusted roots. This
901 * results in errSSLNoRootCert on handshake.
902 *
903 * Both of these error conditions are ignored when the AllowAnyRoot flag is
904 * true, allowing connection to a totally untrusted peer.
905 *
906 * ==========================
907 * MAC OS X ONLY (DEPRECATED)
908 * ==========================
909 * NOTE: this function is not available on iOS, and should be considered
910 * deprecated on Mac OS X. To ignore unknown root cert errors, first disable
911 * Secure Transport's automatic verification of peer certificates by calling
912 * SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth to true. When
913 * SSLHandshake subsequently returns an errSSLServerAuthCompleted result,
914 * your code should obtain the SecTrustRef for the peer's certificates and
915 * perform a custom trust evaluation with SecTrust APIs (see SecTrust.h).
916 *
917 * See the description of the SSLSetAllowsExpiredCerts function (above)
918 * for a code example. Note that an unknown root certificate will cause
919 * SecTrustEvaluate to report kSecTrustResultRecoverableTrustFailure as the
920 * trust result.
921 */
922 OSStatus
923 SSLSetAllowsAnyRoot (SSLContextRef context,
924 Boolean anyRoot)
925 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_9,__IPHONE_NA,__IPHONE_NA);
926
927 /*
928 * Obtain the current value of an SSLContext's "allow any root" flag.
929 *
930 * ==========================
931 * MAC OS X ONLY (DEPRECATED)
932 * ==========================
933 * NOTE: this function is not available on iOS, and should be considered
934 * deprecated on Mac OS X.
935 */
936 OSStatus
937 SSLGetAllowsAnyRoot (SSLContextRef context,
938 Boolean *anyRoot) /* RETURNED */
939 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_9,__IPHONE_NA,__IPHONE_NA);
940
941 /*
942 * Augment or replace the system's default trusted root certificate set
943 * for this session. If replaceExisting is true, the specified roots will
944 * be the only roots which are trusted during this session. If replaceExisting
945 * is false, the specified roots will be added to the current set of trusted
946 * root certs. If this function has never been called, the current trusted
947 * root set is the same as the system's default trusted root set.
948 * Successive calls with replaceExisting false result in accumulation
949 * of additional root certs.
950 *
951 * The trustedRoots array contains SecCertificateRefs.
952 *
953 * ==========================
954 * MAC OS X ONLY (DEPRECATED)
955 * ==========================
956 * NOTE: this function is not available on iOS, and should be considered
957 * deprecated on Mac OS X. To trust specific roots in a session, first disable
958 * Secure Transport's automatic verification of peer certificates by calling
959 * SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth to true. When
960 * SSLHandshake subsequently returns an errSSLServerAuthCompleted result,
961 * your code should obtain the SecTrustRef for the peer's certificates and
962 * perform a custom trust evaluation with SecTrust APIs (see SecTrust.h).
963 *
964 * See the description of the SSLSetAllowsExpiredCerts function (above)
965 * for a code example. You can call SecTrustSetAnchorCertificates to
966 * augment the system's trusted root set, or SecTrustSetAnchorCertificatesOnly
967 * to make these the only trusted roots, prior to calling SecTrustEvaluate.
968 */
969 OSStatus
970 SSLSetTrustedRoots (SSLContextRef context,
971 CFArrayRef trustedRoots,
972 Boolean replaceExisting)
973 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_9,__IPHONE_NA,__IPHONE_NA);
974
975 /*
976 * Obtain an array of SecCertificateRefs representing the current
977 * set of trusted roots. If SSLSetTrustedRoots() has never been called
978 * for this session, this returns the system's default root set.
979 *
980 * Caller must CFRelease the returned CFArray.
981 *
982 * ==========================
983 * MAC OS X ONLY (DEPRECATED)
984 * ==========================
985 * NOTE: this function is not available on iOS, and should be considered
986 * deprecated on Mac OS X. To get the current set of trusted roots, call the
987 * SSLCopyPeerTrust function to obtain the SecTrustRef for the peer certificate
988 * chain, then SecTrustCopyCustomAnchorCertificates (see SecTrust.h).
989 */
990 OSStatus
991 SSLCopyTrustedRoots (SSLContextRef context,
992 CFArrayRef * __nonnull CF_RETURNS_RETAINED trustedRoots) /* RETURNED */
993 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5,__MAC_10_9,__IPHONE_NA,__IPHONE_NA);
994
995 /*
996 * Request peer certificates. Valid anytime, subsequent to a handshake attempt.
997 *
998 * The certs argument is a CFArray containing SecCertificateRefs.
999 * Caller must CFRelease the returned array.
1000 *
1001 * The cert at index 0 of the returned array is the subject (end
1002 * entity) cert; the root cert (or the closest cert to it) is at
1003 * the end of the returned array.
1004 *
1005 * ==========================
1006 * MAC OS X ONLY (DEPRECATED)
1007 * ==========================
1008 * NOTE: this function is not available on iOS, and should be considered
1009 * deprecated on Mac OS X. To get peer certificates, call SSLCopyPeerTrust
1010 * to obtain the SecTrustRef for the peer certificate chain, then use the
1011 * SecTrustGetCertificateCount and SecTrustGetCertificateAtIndex functions
1012 * to retrieve individual certificates in the chain (see SecTrust.h).
1013 */
1014 OSStatus
1015 SSLCopyPeerCertificates (SSLContextRef context,
1016 CFArrayRef * __nonnull CF_RETURNS_RETAINED certs) /* RETURNED */
1017 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5,__MAC_10_9,__IPHONE_NA,__IPHONE_NA);
1018
1019 #endif /* MAC OS X */
1020
1021 /*
1022 * Obtain a SecTrustRef representing peer certificates. Valid anytime,
1023 * subsequent to a handshake attempt. Caller must CFRelease the returned
1024 * trust reference.
1025 *
1026 * The returned trust reference will have already been evaluated for you,
1027 * unless one of the following is true:
1028 * - Your code has disabled automatic certificate verification, by calling
1029 * SSLSetSessionOption to set kSSLSessionOptionBreakOnServerAuth to true.
1030 * - Your code has called SSLSetPeerID, and this session has been resumed
1031 * from an earlier cached session.
1032 *
1033 * In these cases, your code should call SecTrustEvaluate prior to
1034 * examining the peer certificate chain or trust results (see SecTrust.h).
1035 *
1036 * NOTE: if you have not called SSLHandshake at least once prior to
1037 * calling this function, the returned trust reference will be NULL.
1038 */
1039 OSStatus
1040 SSLCopyPeerTrust (SSLContextRef context,
1041 SecTrustRef * __nonnull CF_RETURNS_RETAINED trust) /* RETURNED */
1042 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_5_0);
1043
1044 /*
1045 * Specify some data, opaque to this library, which is sufficient
1046 * to uniquely identify the peer of the current session. An example
1047 * would be IP address and port, stored in some caller-private manner.
1048 * To be optionally called prior to SSLHandshake for the current
1049 * session. This is mandatory if this session is to be resumable.
1050 *
1051 * SecureTransport allocates its own copy of the incoming peerID. The
1052 * data provided in *peerID, while opaque to SecureTransport, is used
1053 * in a byte-for-byte compare to other previous peerID values set by the
1054 * current application. Matching peerID blobs result in SecureTransport
1055 * attempting to resume an SSL session with the same parameters as used
1056 * in the previous session which specified the same peerID bytes.
1057 */
1058 OSStatus
1059 SSLSetPeerID (SSLContextRef context,
1060 const void * __nullable peerID,
1061 size_t peerIDLen)
1062 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
1063
1064 /*
1065 * Obtain current PeerID. Returns NULL pointer, zero length if
1066 * SSLSetPeerID has not been called for this context.
1067 */
1068 OSStatus
1069 SSLGetPeerID (SSLContextRef context,
1070 const void * __nullable * __nonnull peerID,
1071 size_t *peerIDLen)
1072 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
1073
1074 /*
1075 * Obtain the SSLCipherSuite (e.g., SSL_RSA_WITH_DES_CBC_SHA) negotiated
1076 * for this session. Only valid when a session is active.
1077 */
1078 OSStatus
1079 SSLGetNegotiatedCipher (SSLContextRef context,
1080 SSLCipherSuite *cipherSuite)
1081 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
1082
1083
1084 /********************************************************
1085 *** Session context configuration, server side only. ***
1086 ********************************************************/
1087
1088 /*
1089 * This function is deprecated in OSX 10.11 and iOS 9.0 and
1090 * has no effect on the TLS handshake since OSX 10.10 and
1091 * iOS 8.0. Using separate RSA certificates for encryption
1092 * and signing is no longer supported.
1093 */
1094 OSStatus
1095 SSLSetEncryptionCertificate (SSLContextRef context,
1096 CFArrayRef certRefs)
1097 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2, __MAC_10_11, __IPHONE_5_0, __IPHONE_9_0);
1098
1099 /*
1100 * Specify requirements for client-side authentication.
1101 * Optional; Default is kNeverAuthenticate.
1102 *
1103 * Can only be called when no session is active.
1104 */
1105 typedef CF_ENUM(int, SSLAuthenticate) {
1106 kNeverAuthenticate, /* skip client authentication */
1107 kAlwaysAuthenticate, /* require it */
1108 kTryAuthenticate /* try to authenticate, but not an error
1109 * if client doesn't have a cert */
1110 };
1111
1112 OSStatus
1113 SSLSetClientSideAuthenticate (SSLContextRef context,
1114 SSLAuthenticate auth)
1115 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
1116
1117 /*
1118 * Add a DER-encoded distinguished name to list of acceptable names
1119 * to be specified in requests for client certificates.
1120 */
1121 OSStatus
1122 SSLAddDistinguishedName (SSLContextRef context,
1123 const void * __nullable derDN,
1124 size_t derDNLen)
1125 __OSX_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_5_0);
1126
1127
1128 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
1129 /*
1130 * Add a SecCertificateRef, or a CFArray of them, to a server's list
1131 * of acceptable Certificate Authorities (CAs) to present to the client
1132 * when client authentication is performed.
1133 *
1134 * If replaceExisting is true, the specified certificate(s) will replace
1135 * a possible existing list of acceptable CAs. If replaceExisting is
1136 * false, the specified certificate(s) will be appended to the existing
1137 * list of acceptable CAs, if any.
1138 *
1139 * Returns errSecParam if this is called on a SSLContextRef which
1140 * is configured as a client, or when a session is active.
1141 *
1142 * NOTE: this function is currently not available on iOS.
1143 */
1144 OSStatus
1145 SSLSetCertificateAuthorities(SSLContextRef context,
1146 CFTypeRef certificateOrArray,
1147 Boolean replaceExisting)
1148 __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_NA);
1149
1150 /*
1151 * Obtain the certificates specified in SSLSetCertificateAuthorities(),
1152 * if any. Returns a NULL array if SSLSetCertificateAuthorities() has not
1153 * been called.
1154 * Caller must CFRelease the returned array.
1155 *
1156 * NOTE: this function is currently not available on iOS.
1157 */
1158 OSStatus
1159 SSLCopyCertificateAuthorities(SSLContextRef context,
1160 CFArrayRef * __nonnull CF_RETURNS_RETAINED certificates) /* RETURNED */
1161 __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_NA);
1162
1163 #endif /* MAC OS X */
1164
1165 /*
1166 * Obtain the list of acceptable distinguished names as provided by
1167 * a server (if the SSLContextRef is configured as a client), or as
1168 * specified by SSLSetCertificateAuthorities (if the SSLContextRef
1169 * is configured as a server).
1170 * The returned array contains CFDataRefs, each of which represents
1171 * one DER-encoded RDN.
1172 *
1173 * Caller must CFRelease the returned array.
1174 */
1175 OSStatus
1176 SSLCopyDistinguishedNames (SSLContextRef context,
1177 CFArrayRef * __nonnull CF_RETURNS_RETAINED names)
1178 __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_5_0);
1179
1180 /*
1181 * Obtain client certificate exchange status. Can be called
1182 * any time. Reflects the *last* client certificate state change;
1183 * subsequent to a renegotiation attempt by either peer, the state
1184 * is reset to kSSLClientCertNone.
1185 */
1186 OSStatus
1187 SSLGetClientCertificateState (SSLContextRef context,
1188 SSLClientCertificateState *clientState)
1189 __OSX_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_5_0);
1190
1191
1192 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
1193 /*
1194 * Specify Diffie-Hellman parameters. Optional; if we are configured to allow
1195 * for D-H ciphers and a D-H cipher is negotiated, and this function has not
1196 * been called, a set of process-wide parameters will be calculated. However
1197 * that can take a long time (30 seconds).
1198 *
1199 * NOTE: this function is currently not available on iOS.
1200 */
1201 OSStatus SSLSetDiffieHellmanParams (SSLContextRef context,
1202 const void * __nullable dhParams,
1203 size_t dhParamsLen)
1204 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_NA);
1205
1206 /*
1207 * Return parameter block specified in SSLSetDiffieHellmanParams.
1208 * Returned data is not copied and belongs to the SSLContextRef.
1209 *
1210 * NOTE: this function is currently not available on iOS.
1211 */
1212 OSStatus SSLGetDiffieHellmanParams (SSLContextRef context,
1213 const void * __nullable * __nonnull dhParams,
1214 size_t *dhParamsLen)
1215 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_NA);
1216
1217 /*
1218 * Enable/Disable RSA blinding. This feature thwarts a known timing
1219 * attack to which RSA keys are vulnerable; enabling it is a tradeoff
1220 * between performance and security. The default for RSA blinding is
1221 * enabled.
1222 *
1223 * ==========================
1224 * MAC OS X ONLY (DEPRECATED)
1225 * ==========================
1226 * NOTE: this function is not available on iOS, and should be considered
1227 * deprecated on Mac OS X. RSA blinding is enabled unconditionally, as
1228 * it prevents a known way for an attacker to recover the private key,
1229 * and the performance gain of disabling it is negligible.
1230 */
1231 OSStatus SSLSetRsaBlinding (SSLContextRef context,
1232 Boolean blinding)
1233 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_9,__IPHONE_NA,__IPHONE_NA);
1234
1235 OSStatus SSLGetRsaBlinding (SSLContextRef context,
1236 Boolean *blinding)
1237 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_9,__IPHONE_NA,__IPHONE_NA);
1238
1239 #endif /* MAC OS X */
1240
1241 /*******************************
1242 ******** I/O Functions ********
1243 *******************************/
1244
1245 /*
1246 * Note: depending on the configuration of the underlying I/O
1247 * connection, all SSL I/O functions can return errSSLWouldBlock,
1248 * indicating "not complete, nothing is wrong, except required
1249 * I/O hasn't completed". Caller may need to repeat I/Os as necessary
1250 * if the underlying connection has been configured to behave in
1251 * a non-blocking manner.
1252 */
1253
1254 /*
1255 * Perform the SSL handshake. On successful return, session is
1256 * ready for normal secure application I/O via SSLWrite and SSLRead.
1257 *
1258 * Interesting error returns:
1259 *
1260 * errSSLUnknownRootCert: Peer had a valid cert chain, but the root of
1261 * the chain is unknown.
1262 *
1263 * errSSLNoRootCert: Peer had a cert chain which did not end in a root.
1264 *
1265 * errSSLCertExpired: Peer's cert chain had one or more expired certs.
1266 *
1267 * errSSLXCertChainInvalid: Peer had an invalid cert chain (i.e.,
1268 * signature verification within the chain failed, or no certs
1269 * were found).
1270 *
1271 * In all of the above errors, the handshake was aborted; the peer's
1272 * cert chain is available via SSLCopyPeerTrust or SSLCopyPeerCertificates.
1273 *
1274 * Other interesting result codes:
1275 *
1276 * errSSLPeerAuthCompleted: Peer's cert chain is valid, or was ignored if
1277 * cert verification was disabled via SSLSetEnableCertVerify. The application
1278 * may decide to continue with the handshake (by calling SSLHandshake
1279 * again), or close the connection at this point.
1280 *
1281 * errSSLClientCertRequested: The server has requested a client certificate.
1282 * The client may choose to examine the server's certificate and
1283 * distinguished name list, then optionally call SSLSetCertificate prior
1284 * to resuming the handshake by calling SSLHandshake again.
1285 *
1286 * A return value of errSSLWouldBlock indicates that SSLHandshake has to be
1287 * called again (and again and again until something else is returned).
1288 */
1289 OSStatus
1290 SSLHandshake (SSLContextRef context)
1291 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
1292
1293 /*
1294 * Normal application-level read/write. On both of these, a errSSLWouldBlock
1295 * return and a partially completed transfer - or even zero bytes transferred -
1296 * are NOT mutually exclusive.
1297 */
1298 OSStatus
1299 SSLWrite (SSLContextRef context,
1300 const void * __nullable data,
1301 size_t dataLength,
1302 size_t *processed) /* RETURNED */
1303 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
1304
1305 /*
1306 * data is mallocd by caller; available size specified in
1307 * dataLength; actual number of bytes read returned in
1308 * *processed.
1309 */
1310 OSStatus
1311 SSLRead (SSLContextRef context,
1312 void * data, /* RETURNED */
1313 size_t dataLength,
1314 size_t *processed) /* RETURNED */
1315 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
1316
1317 /*
1318 * Determine how much data the client can be guaranteed to
1319 * obtain via SSLRead() without blocking or causing any low-level
1320 * read operations to occur.
1321 */
1322 OSStatus
1323 SSLGetBufferedReadSize (SSLContextRef context,
1324 size_t *bufSize) /* RETURNED */
1325 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
1326
1327 /*
1328 * Determine how much data the application can be guaranteed to write
1329 * with SSLWrite() without causing fragmentation. The value is based on
1330 * the maximum Datagram Record size defined by the application with
1331 * SSLSetMaxDatagramRecordSize(), minus the DTLS Record header size.
1332 */
1333 OSStatus
1334 SSLGetDatagramWriteSize (SSLContextRef dtlsContext,
1335 size_t *bufSize)
1336 __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_5_0);
1337
1338 /*
1339 * Terminate current SSL session.
1340 */
1341 OSStatus
1342 SSLClose (SSLContextRef context)
1343 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_5_0);
1344
1345 /*
1346 * Set the minimum acceptable strength of policy to be negotiated for an
1347 * ATS session
1348 */
1349 OSStatus
1350 SSLSetSessionStrengthPolicy(SSLContextRef context,
1351 SSLSessionStrengthPolicy policyStrength);
1352
1353 CF_IMPLICIT_BRIDGING_DISABLED
1354 CF_ASSUME_NONNULL_END
1355
1356 #ifdef __cplusplus
1357 }
1358 #endif
1359
1360 #endif /* !_SECURITY_SECURETRANSPORT_H_ */