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, based on Netscape SSLRef 3.0
26 Copyright: (c) 1999 by Apple Computer, Inc., all rights reserved.
30 /* *********************************************************************
33 SSLRef 3.0 Final -- 11/19/96
35 Copyright (c)1996 by Netscape Communications Corp.
37 By retrieving this software you are bound by the licensing terms
38 disclosed in the file "LICENSE.txt". Please read it, and if you don't
39 accept the terms, delete this software.
41 SSLRef 3.0 was developed by Netscape Communications Corp. of Mountain
42 View, California <http://home.netscape.com/> and Consensus Development
43 Corporation of Berkeley, California <http://www.consensus.com/>.
45 *********************************************************************
47 File: sslctx.h Internal state of an SSL connection
49 Contains the SSLContext structure which encapsulates the state of the
50 connection at any time. Whenever SSLREF might have to return (mostly
51 when I/O is done), this structure must completely represent the
54 ****************************************************************** */
59 #include <Security/SecureTransport.h>
60 #include "sslBuildFlags.h"
61 #include <Security/cssmtype.h>
70 SSLConnectionRef ioRef
;
76 * This struct is a remnant of the original SSLRef implementation; it
77 * held things like caller-provided memory allocator callbacks.
78 * We'll keep the struct (and an instance of it in SSLContext, below)
79 * around in case we want to use it in SSLAllocBuffer and its siblings.
84 typedef struct SystemContext SystemContext
;
87 * A carryover from original SSLRef 3.0 - we'll store the DER-encoded
88 * certs in an SSLCertificate this way for now; there's a lot of code
89 * which munges these lists.
91 typedef struct SSLCertificate
93 struct SSLCertificate
*next
;
97 #include "cryptType.h"
100 * An SSLContext contains four of these - one for each of {read,write} and for
101 * {current, pending}.
106 const HashHmacReference
*macRef
; /* HMAC (TLS) or digest (SSL) */
107 const SSLSymmetricCipher
*symCipher
;
109 /* this is a context which is reused once per record */
110 HashHmacContext macCtx
;
113 * symKey is obtained from the CSP at cspHand. Normally this
114 * cspHand is the same as ctx->cspHand; some day they might differ.
115 * Code which deals with this struct doesn't ever have to
116 * attach or detach from cspHand - that's taken care of at the
120 CSSM_CSP_HANDLE cspHand
;
121 CSSM_CC_HANDLE ccHand
;
123 /* needed in CDSASymmInit */
126 sslUint64 sequenceNum
;
129 /* in SSL2 mode, the macSecret is the same size as the
130 * cipher key - which is 24 bytes in the 3DES case. */
131 uint8 macSecret
[MAX_SYMKEY_SIZE
];
133 /* typedef in cryptType.h */
135 #include "sslhdshk.h"
137 typedef struct WaitingRecord
138 { struct WaitingRecord
*next
;
143 typedef struct DNListElem
144 { struct DNListElem
*next
;
151 * For Apple CDSA version, SystemContext is empty; we'll leave it in for now
152 * because it gets passed around so often for SSLAllocBuffer().
154 SystemContext sysCtx
;
158 * For the first two, SSL_Version_Undetermined means "get the best we
159 * can, up to macProtocolVersion".
161 SSLProtocolVersion reqProtocolVersion
; /* requested by app */
162 SSLProtocolVersion negProtocolVersion
; /* negotiated */
163 SSLProtocolVersion maxProtocolVersion
; /* max allowed by app */
164 SSLProtocolSide protocolSide
;
165 const struct _SslTlsCallouts
*sslTslCalls
; /* selects between SSLv3 and TLSv1 */
167 /* crypto state in CDSA-centric terms */
169 CSSM_KEY_PTR signingPrivKey
;/* our private signing key */
170 CSSM_KEY_PTR signingPubKey
; /* our public signing key */
171 CSSM_CSP_HANDLE signingKeyCsp
; /* associated DL/CSP */
172 #if ST_KEYCHAIN_ENABLE
173 #if ST_KC_KEYS_NEED_REF
174 SecKeychainRef signingKeyRef
; /* for signingPrivKey */
176 void *signingKeyRef
; /* TBD */
177 #endif /* ST_KC_KEYS_NEED_REF */
180 /* this stuff should probably be #if ST_SERVER_MODE_ENABLE.... */
181 CSSM_KEY_PTR encryptPrivKey
;/* our private encrypt key, for
182 * server-initiated key exchange */
183 CSSM_KEY_PTR encryptPubKey
; /* public version of above */
184 CSSM_CSP_HANDLE encryptKeyCsp
;
185 #if ST_KEYCHAIN_ENABLE
186 #if ST_KC_KEYS_NEED_REF
187 SecKeychainRef encryptKeyRef
; /* for signingPrivKey */
189 void *encryptKeyRef
; /* TBD */
190 #endif /* ST_KC_KEYS_NEED_REF */
191 #endif /* ST_KEYCHAIN_ENABLE */
193 CSSM_KEY_PTR peerPubKey
;
194 CSSM_CSP_HANDLE peerPubKeyCsp
; /* may not be needed, we figure this
195 * one out by trial&error, right? */
198 * Various cert chains stored in an SSLRef-centric way for now
199 * (see comments above re: SSLCertificate).
200 * For all three, the root is the first in the chain.
202 SSLCertificate
*localCert
;
203 SSLCertificate
*encryptCert
;
204 SSLCertificate
*peerCert
;
207 * trusted root certs; specific to this implementation, we'll store
208 * them conveniently...these will be used as AnchorCerts in a TP
211 UInt32 numTrustedCerts
;
212 CSSM_DATA_PTR trustedCerts
;
215 * Keychain to which newly encountered root certs are attempted
216 * to be added. AccessCreds untyped for now.
218 #if ST_KEYCHAIN_ENABLE && ST_MANAGES_TRUSTED_ROOTS
219 SecKeychainRef newRootCertKc
;
221 #endif /* ST_KEYCHAIN_ENABLE && ST_MANAGES_TRUSTED_ROOTS */
223 /* for symmetric cipher and RNG */
224 CSSM_CSP_HANDLE cspHand
;
226 /* session-wide handles for Apple TP, CL */
227 CSSM_TP_HANDLE tpHand
;
228 CSSM_CL_HANDLE clHand
;
230 #if ST_FAKE_KEYCHAIN || ST_FAKE_GET_CSPDL_HANDLE
231 /* we manually attach to this for now; eventually we get it from KC */
232 CSSM_CSP_HANDLE cspDlHand
;
235 /* FIXME - how will we represent this? */
239 Boolean allowExpiredCerts
;
243 SSLBuffer dhPeerPublic
;
244 SSLBuffer dhExchangePublic
;
248 SSLBuffer resumableSession
;
250 char *peerDomainName
;
251 UInt32 peerDomainNameLen
;
253 CipherContext readCipher
;
254 CipherContext writeCipher
;
255 CipherContext readPending
;
256 CipherContext writePending
;
258 uint16 selectedCipher
; /* currently selected */
259 const SSLCipherSpec
*selectedCipherSpec
; /* ditto */
260 SSLCipherSpec
*validCipherSpecs
; /* context's valid specs */
261 unsigned numValidCipherSpecs
; /* size of validCipherSpecs */
262 SSLHandshakeState state
;
264 #if ST_SERVER_MODE_ENABLE
265 SSLAuthenticate clientAuth
; /* kNeverAuthenticate, etc. */
266 Boolean tryClientAuth
;
267 #endif /* ST_SERVER_MODE_ENABLE */
272 DNListElem
*acceptableDNList
;
274 uint8 clientRandom
[SSL_CLIENT_SRVR_RAND_SIZE
];
275 uint8 serverRandom
[SSL_CLIENT_SRVR_RAND_SIZE
];
276 SSLBuffer preMasterSecret
;
277 uint8 masterSecret
[48];
279 /* running digests of all handshake messages */
280 SSLBuffer shaState
, md5State
;
282 SSLBuffer fragmentedMessageCache
;
284 int ssl2ChallengeLength
;
285 int ssl2ConnectionIDLength
;
286 int ssl2SessionMatch
;
288 /* Record layer fields */
289 SSLBuffer partialReadBuffer
;
292 /* Transport layer fields */
293 WaitingRecord
*recordWriteQueue
;
294 SSLBuffer receivedDataBuffer
;
295 uint32 receivedDataPos
;
297 Boolean allowAnyRoot
; // don't require known roots
299 char *rootCertName
; // if non-null, write root cert here
300 #endif /* SSL_DEBUG */
304 #endif /* _SSLCTX_H_ */