2  * Copyright (c) 1999-2001,2005-2014 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  * sslContext.h - Private SSL typedefs: SSLContext and its components 
  28 #ifndef _SSLCONTEXT_H_ 
  29 #define _SSLCONTEXT_H_ 1 
  31 #include "SecureTransport.h" 
  32 #include "sslBuildFlags.h" 
  34 #include <tls_handshake.h> 
  35 #include <tls_record.h> 
  36 #include <tls_stream_parser.h> 
  37 #include <tls_cache.h> 
  41 #include <Security/SecDH.h> 
  42 #include <Security/SecKeyInternal.h> 
  44 #include "../sec/Security/SecDH.h"  // hack to get SecDH. 
  45 // typedef struct OpaqueSecDHContext *SecDHContext; 
  47 #include <corecrypto/ccec.h> 
  49 #include <CoreFoundation/CFRuntime.h> 
  50 #include <AssertMacros.h> 
  53 #include "sslRecord.h" 
  54 #include "cipherSpecs.h" 
  56 #include <dispatch/dispatch.h> 
  65     SSLConnectionRef    ioRef
; 
  68 //FIXME should not need this. 
  71     SSL_HdskStateUninit 
= 0,                    /* No Handshake yet */ 
  72     SSL_HdskStatePending
,               /* Handshake in Progress */ 
  73     SSL_HdskStateReady
,                 /* Handshake is done */ 
  74     SSL_HdskStateGracefulClose
, 
  75     SSL_HdskStateErrorClose
, 
  76     SSL_HdskStateNoNotifyClose
,                 /* server disconnected with no 
  80 #define SSLChangeHdskState(ctx, newState) { ctx->state=newState; } 
  87     const struct SSLRecordFuncs 
*recFuncs
; 
  88     SSLRecordContextRef recCtx
; 
  93     int writeCipher_ready
; 
  95     SSLHandshakeState   state
; 
  98          * Prior to successful protocol negotiation, negProtocolVersion 
  99          * is SSL_Version_Undetermined. Subsequent to successful 
 100          * negotiation, negProtocolVersion contains the actual over-the-wire 
 103          * The Boolean versionEnable flags are set by 
 104          * SSLSetProtocolVersionEnabled or SSLSetProtocolVersion and 
 105          * remain invariant once negotiation has started. If there 
 106          * were a large number of these and/or we were adding new 
 107          * protocol versions on a regular basis, we'd probably want 
 108          * to implement these as a word of flags. For now, in the 
 109          * real world, this is the most straightforward implementation. 
 111     tls_protocol_version  negProtocolVersion
;   /* negotiated */ 
 112     tls_protocol_version  clientReqProtocol
;    /* requested by client in hello msg */ 
 113     tls_protocol_version  minProtocolVersion
; 
 114     tls_protocol_version  maxProtocolVersion
; 
 115     Boolean             isDTLS
;             /* if this is a Datagram Context */ 
 116     SSLProtocolSide     protocolSide
;           /* ConnectionEnd enum { server, client } in rfc5246. */ 
 118     SSLBuffer           dtlsCookie
;         /* DTLS ClientHello cookie */ 
 121     uint16_t            selectedCipher
;         /* currently selected */ 
 123     /* Server DH Parameters */ 
 124     SSLBuffer                   dhParamsEncoded
;        /* PKCS3 encoded blob - prime + generator */ 
 127          * The arrays we are given via SSLSetCertificate() and SSLSetEncryptionCertificate(). 
 128          * We keep them here, refcounted, solely for the associated getter. 
 130     CFArrayRef                  localCertArray
; 
 131     CFArrayRef                  encryptCertArray
; 
 133         /* peer certs as SecTrustRef */ 
 134         SecTrustRef                     peerSecTrust
; 
 136     CFMutableArrayRef   trustedCerts
; 
 137     Boolean             trustedCertsOnly
; 
 139 #if !TARGET_OS_IPHONE 
 141      * trusted leaf certs as specified in SSLSetTrustedLeafCertificates() 
 143     CFArrayRef                  trustedLeafCerts
; 
 146         Boolean                                 allowExpiredCerts
; 
 147         Boolean                                 allowExpiredRoots
; 
 148         Boolean                                 enableCertVerify
; 
 152     SSLBuffer                   resumableSession
;       /* We keep a copy for now - but eventually this should go away if we get refcounted SSLBuffers */ 
 154     uint16_t            *ecdhCurves
; 
 155     unsigned            ecdhNumCurves
; 
 157         /* server-side only */ 
 158     SSLAuthenticate             clientAuth
;                             /* kNeverAuthenticate, etc. */ 
 160         /* client and server */ 
 161         SSLClientCertificateState       clientCertState
; 
 163     DNListElem          
*acceptableDNList
;              /* client and server */ 
 164         CFMutableArrayRef       acceptableCAs
;                  /* server only - SecCertificateRefs */ 
 171     unsigned            sessionMatch
; 
 174         /* Transport layer fields */ 
 175     SSLBuffer                   receivedDataBuffer
; 
 176     size_t              receivedDataPos
; 
 178         Boolean                         allowAnyRoot
;           // don't require known roots 
 179         Boolean                         sentFatalAlert
;         // this session terminated by fatal alert 
 180         Boolean                         rsaBlindingEnable
; 
 181         Boolean                         oneByteRecordEnable
;    /* enable 1/n-1 data splitting for TLSv1 and SSLv3 */ 
 183         /* optional session cache timeout (in seconds) override - 0 means default */ 
 184         uint32_t                        sessionCacheTimeout
; 
 186         /* optional SessionTicket */ 
 187         SSLBuffer                       sessionTicket
; 
 189         /* optional callback to obtain master secret, with its opaque arg */ 
 190         SSLInternalMasterSecretFunction masterSecretCallback
; 
 191         const void                      *masterSecretArg
; 
 193         #if     SSL_PAC_SERVER_ENABLE 
 194         /* server PAC resume sets serverRandom early to allow for secret acquisition */ 
 195         uint8_t                         serverRandomValid
; 
 198         Boolean                         anonCipherEnable
; 
 200         /* optional switches to enable additional returns from SSLHandshake */ 
 201     Boolean             breakOnServerAuth
; 
 202     Boolean             breakOnCertRequest
; 
 203     Boolean             breakOnClientAuth
; 
 204     Boolean             signalServerAuth
; 
 205     Boolean             signalCertRequest
; 
 206     Boolean             signalClientAuth
; 
 207     Boolean             breakOnClientHello
; 
 209     /* List of peer-specified supported_signature_algorithms */ 
 210         unsigned                                         numPeerSigAlgs
; 
 211         const tls_signature_and_hash_algorithm 
*peerSigAlgs
; 
 213         /* List of server-specified client auth types */ 
 214         unsigned                                        numAuthTypes
; 
 215         const tls_client_auth_type 
*clientAuthTypes
; 
 217     /* Timeout for DTLS retransmit */ 
 218     CFAbsoluteTime      timeout_deadline
; 
 219     CFAbsoluteTime      timeout_duration
; 
 222     /* RFC 5746: Secure renegotiation */ 
 223     Boolean             secure_renegotiation
; 
 224     Boolean             secure_renegotiation_received
; 
 225     SSLBuffer           ownVerifyData
; 
 226     SSLBuffer           peerVerifyData
; 
 228     /* RFC 4279: TLS PSK */ 
 229     SSLBuffer           pskSharedSecret
; 
 230     SSLBuffer           pskIdentity
; 
 232     /* TLS False Start */ 
 233     Boolean             falseStartEnabled
; //FalseStart enabled (by API call) 
 234     /* Fallback behavior */ 
 235     Boolean             fallbackEnabled
; // Fallback behavior enabled. 
 241     SSLALPNFunc     alpnFunc
; 
 244     /* Enable DHE or not */ 
 247     /* For early failure reporting */ 
 248     bool    serverHelloReceived
; 
 251 OSStatus 
SSLUpdateNegotiatedClientAuthType(SSLContextRef ctx
); 
 253 Boolean 
sslIsSessionActive(const SSLContext 
*ctx
); 
 255 static inline bool sslVersionIsLikeTls12(SSLContext 
*ctx
) 
 257     check(ctx
->negProtocolVersion
!=SSL_Version_Undetermined
); 
 258     return ctx
->isDTLS 
? ctx
->negProtocolVersion 
> DTLS_Version_1_0 
: ctx
->negProtocolVersion 
>= TLS_Version_1_2
; 
 261 /* This is implemented in tls_callbacks.c */ 
 262     int sslGetSessionID(SSLContext 
*myCtx
, SSLBuffer 
*sessionID
); 
 268 #endif /* _SSLCONTEXT_H_ */