2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
22 Contains: Private SSL typedefs: SSLContext and its components
24 Written by: Doug Mitchell
26 Copyright: (c) 1999 by Apple Computer, Inc., all rights reserved.
30 #ifndef _SSLCONTEXT_H_
31 #define _SSLCONTEXT_H_ 1
33 #include <Security/SecureTransport.h>
34 #include "sslBuildFlags.h"
35 #include <Security/cssmtype.h>
47 SSLConnectionRef ioRef
;
51 * An element in a certificate chain.
53 typedef struct SSLCertificate
55 struct SSLCertificate
*next
;
59 #include "cryptType.h"
62 * An SSLContext contains four of these - one for each of {read,write} and for
68 const HashHmacReference
*macRef
; /* HMAC (TLS) or digest (SSL) */
69 const SSLSymmetricCipher
*symCipher
;
71 /* this is a context which is reused once per record */
72 HashHmacContext macCtx
;
75 * symKey is obtained from the CSP at cspHand. Normally this
76 * cspHand is the same as ctx->cspHand; some day they might differ.
77 * Code which deals with this struct doesn't ever have to
78 * attach or detach from cspHand - that's taken care of at the
82 CSSM_CSP_HANDLE cspHand
;
83 CSSM_CC_HANDLE ccHand
;
85 /* needed in CDSASymmInit */
88 sslUint64 sequenceNum
;
91 /* in SSL2 mode, the macSecret is the same size as the
92 * cipher key - which is 24 bytes in the 3DES case. */
93 uint8 macSecret
[MAX_SYMKEY_SIZE
];
95 /* typedef in cryptType.h */
97 #include "sslHandshake.h"
99 typedef struct WaitingRecord
100 { struct WaitingRecord
*next
;
105 typedef struct DNListElem
106 { struct DNListElem
*next
;
115 * Prior to successful protocol negotiation, negProtocolVersion
116 * is SSL_Version_Undetermined. Subsequent to successful
117 * negotiation, negProtocolVersion contains the actual over-the-wire
120 * The Boolean versionEnable flags are set by
121 * SSLSetProtocolVersionEnabled or SSLSetProtocolVersion and
122 * remain invariant once negotiation has started. If there
123 * were a large number of these and/or we were adding new
124 * protocol versions on a regular basis, we'd probably want
125 * to implement these as a word of flags. For now, in the
126 * real world, this is the most straightfoprward implementation.
128 SSLProtocolVersion negProtocolVersion
; /* negotiated */
129 SSLProtocolVersion clientReqProtocol
; /* requested by client in hello msg */
130 Boolean versionSsl2Enable
;
131 Boolean versionSsl3Enable
;
132 Boolean versionTls1Enable
;
133 SSLProtocolSide protocolSide
;
135 const struct _SslTlsCallouts
*sslTslCalls
; /* selects between SSLv3 and TLSv1 */
137 /* crypto state in CDSA-centric terms */
139 SecKeyRef signingPrivKeyRef
; /* our private signing key */
140 CSSM_KEY_PTR signingPubKey
; /* our public signing key */
142 SecKeyRef encryptPrivKeyRef
; /* our private encrypt key, for
143 * server-initiated key exchange */
144 CSSM_KEY_PTR encryptPubKey
; /* public version of above */
146 CSSM_KEY_PTR peerPubKey
;
147 CSSM_CSP_HANDLE peerPubKeyCsp
; /* may not be needed, we figure this
148 * one out by trial&error, right? */
151 * Various cert chains.
152 * For all three, the root is the first in the chain.
154 SSLCertificate
*localCert
;
155 SSLCertificate
*encryptCert
;
156 SSLCertificate
*peerCert
;
158 /* peer certs as SecTrustRef */
159 SecTrustRef peerSecTrust
;
162 * trusted root certs; specific to this implementation, we'll store
163 * them conveniently...these will be used as AnchorCerts in a TP
166 uint32 numTrustedCerts
;
167 CSSM_DATA_PTR trustedCerts
;
169 /* for symmetric cipher and RNG */
170 CSSM_CSP_HANDLE cspHand
;
172 /* session-wide handles for Apple TP, CL */
173 CSSM_TP_HANDLE tpHand
;
174 CSSM_CL_HANDLE clHand
;
177 SSLBuffer dhParamsPrime
;
178 SSLBuffer dhParamsGenerator
;
179 SSLBuffer dhParamsEncoded
; /* prime + generator */
180 SSLBuffer dhPeerPublic
;
181 SSLBuffer dhExchangePublic
;
182 CSSM_KEY_PTR dhPrivate
;
183 #endif /* APPLE_DH */
185 Boolean allowExpiredCerts
;
186 Boolean allowExpiredRoots
;
187 Boolean enableCertVerify
;
192 SSLBuffer resumableSession
;
194 char *peerDomainName
;
195 UInt32 peerDomainNameLen
;
197 CipherContext readCipher
;
198 CipherContext writeCipher
;
199 CipherContext readPending
;
200 CipherContext writePending
;
202 uint16 selectedCipher
; /* currently selected */
203 const SSLCipherSpec
*selectedCipherSpec
; /* ditto */
204 SSLCipherSpec
*validCipherSpecs
; /* context's valid specs */
205 unsigned numValidCipherSpecs
; /* size of validCipherSpecs */
206 SSLHandshakeState state
;
208 /* server-side only */
209 SSLAuthenticate clientAuth
; /* kNeverAuthenticate, etc. */
210 Boolean tryClientAuth
;
212 /* client and server */
213 SSLClientCertificateState clientCertState
;
215 DNListElem
*acceptableDNList
;
222 uint8 clientRandom
[SSL_CLIENT_SRVR_RAND_SIZE
];
223 uint8 serverRandom
[SSL_CLIENT_SRVR_RAND_SIZE
];
224 SSLBuffer preMasterSecret
;
225 uint8 masterSecret
[SSL_MASTER_SECRET_SIZE
];
227 /* running digests of all handshake messages */
228 SSLBuffer shaState
, md5State
;
230 SSLBuffer fragmentedMessageCache
;
232 unsigned ssl2ChallengeLength
;
233 unsigned ssl2ConnectionIDLength
;
234 unsigned sessionMatch
;
236 /* Record layer fields */
237 SSLBuffer partialReadBuffer
;
240 /* Transport layer fields */
241 WaitingRecord
*recordWriteQueue
;
242 SSLBuffer receivedDataBuffer
;
243 uint32 receivedDataPos
;
245 Boolean allowAnyRoot
; // don't require known roots
246 Boolean sentFatalAlert
; // this session terminated by fatal alert
247 Boolean rsaBlindingEnable
;
254 #endif /* _SSLCONTEXT_H_ */