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"
64 #include <Security/cssmtype.h>
66 #if ST_KEYCHAIN_ENABLE
68 #endif /* ST_KEYCHAIN_ENABLE */
70 #endif /* _APPLE_CDSA_ */
81 * These were originally in ssl.h; they're not exposed as client-specified
85 typedef SSLErr (*SSLRandomFunc
) (
88 typedef SSLErr (*SSLTimeFunc
) (
91 typedef SSLErr (*SSLConvertTimeFunc
) (
94 typedef SSLErr (*SSLAddSessionFunc
) (
96 SSLBuffer sessionData
,
98 typedef SSLErr (*SSLGetSessionFunc
) (
100 SSLBuffer
*sessionData
,
102 typedef SSLErr (*SSLDeleteSessionFunc
) (
103 SSLBuffer sessionKey
,
105 typedef SSLErr (*SSLCheckCertificateFunc
) (
108 void *checkCertificateRef
);
109 #endif /* _APPLE_CDSA_ */
114 SSLConnectionRef ioRef
;
119 /* FIXME - this probably goes away; we keep it as a struct due
120 * to its pervasive use in calls to SSLAllocBuffer. We have to
121 * have *an* element in it for compiler reasons.
128 SSLReallocFunc realloc
;
131 SSLConvertTimeFunc convertTime
;
133 SSLRandomFunc random
;
135 #endif /* _APPLE_CDSA_ */
138 typedef struct SystemContext SystemContext
;
143 /* these functions are hard-coded */
144 SSLAddSessionFunc addSession
;
145 SSLGetSessionFunc getSession
;
146 SSLDeleteSessionFunc deleteSession
;
152 /* not used, cert functions via CDSA */
154 { SSLCheckCertificateFunc checkCertFunc
;
156 } CertificateContext
;
160 * A carryover from original SSLRef 3.0 - we'll store the DER-encoded
161 * certs in an SSLCertificate this way for now; there's a lot of code
162 * which munges these lists.
164 typedef struct SSLCertificate
166 struct SSLCertificate
*next
;
169 /* but not decoded...we never do that! */
171 #endif /* _APPLE_CDSA_ */
174 #include "cryptType.h"
177 { const HashReference
*hash
;
178 const SSLSymmetricCipher
*symCipher
;
183 * symKey is obtained from the CSP at cspHand. Normally this
184 * cspHand is the same as ctx->cspHand; some day they might differ.
185 * Code which deals with this struct doesn't ever have to
186 * attach or detach from cspHand - that's taken care of at the
190 CSSM_CSP_HANDLE cspHand
;
191 CSSM_CC_HANDLE ccHand
;
193 /* needed in CDSASymmInit */
197 void *symCipherState
;
198 #endif /* _APPLE_CDSA_*/
199 sslUint64 sequenceNum
;
202 /* in SSL2 mode, the macSecret is the same size as the
203 * cipher key - which is 24 bytes in the 3DDES case. */
204 uint8 macSecret
[MAX_SYMKEY_SIZE
];
206 uint8 macSecret
[MAX_DIGEST_SIZE
];
207 #endif /* __APPLE__ */
209 /* typedef in cryptType.h */
211 #include "sslhdshk.h"
213 typedef struct WaitingRecord
214 { struct WaitingRecord
*next
;
219 typedef struct DNListElem
220 { struct DNListElem
*next
;
227 * For _APPLE_CDSA_, SystemContext is empty; we'll leave it in for now
228 * 'cause it gets passed around so often for SSLAllocBuffer().
230 SystemContext sysCtx
;
232 SessionContext sessionCtx
;
234 CertificateContext certCtx
;
237 SSLProtocolVersion reqProtocolVersion
; /* requested by app */
238 SSLProtocolVersion negProtocolVersion
; /* negotiated */
239 SSLProtocolSide protocolSide
;
243 /* crypto state in CDSA-centric terms */
245 CSSM_KEY_PTR signingPrivKey
; /* our private signing key */
246 CSSM_KEY_PTR signingPubKey
; /* our public signing key */
247 CSSM_CSP_HANDLE signingKeyCsp
; /* associated DL/CSP */
248 #if ST_KEYCHAIN_ENABLE
249 KCItemRef signingKeyRef
; /* for signingPrivKey */
252 /* this stuff should probably be #if ST_SERVER_MODE_ENABLE.... */
253 CSSM_KEY_PTR encryptPrivKey
; /* our private encrypt key, for
254 * server-initiated key exchange */
255 CSSM_KEY_PTR encryptPubKey
; /* public version of above */
256 CSSM_CSP_HANDLE encryptKeyCsp
;
257 #if ST_KEYCHAIN_ENABLE
258 /* but we'll just do this so we can compile it */
259 KCItemRef encryptKeyRef
; /* for encryptPrivKey */
260 #endif /* ST_KEYCHAIN_ENABLE */
262 CSSM_KEY_PTR peerPubKey
;
263 CSSM_CSP_HANDLE peerPubKeyCsp
; /* may not be needed, we figure this
264 * one out by trial&error, right? */
267 * Various cert chains stored in an SSLRef-centric way for now
268 * (see comments above re: SSLCertificate).
269 * For all three, the root is the first in the chain.
271 SSLCertificate
*localCert
;
272 SSLCertificate
*encryptCert
;
273 SSLCertificate
*peerCert
;
276 * trusted root certs; specific to this implementation, we'll store
277 * them conveniently...these will be used as AnchorCerts in a TP
280 UInt32 numTrustedCerts
;
281 CSSM_DATA_PTR trustedCerts
;
284 * Keychain to which newly encountered root certs are attempted
285 * to be added. AccessCreds untyped for now.
287 #if ST_KEYCHAIN_ENABLE
290 #endif /* ST_KEYCHAIN_ENABLE */
292 /* for symmetric cipher and RNG */
293 CSSM_CSP_HANDLE cspHand
;
295 /* session-wide handles for Apple TP, CL */
296 CSSM_TP_HANDLE tpHand
;
297 CSSM_CL_HANDLE clHand
;
299 /* FIXME - how will we represent this? */
303 /* context and allocator for CF */
304 CFAllocatorRef cfAllocatorRef
;
305 CFAllocatorContext lCFAllocatorContext
;
307 Boolean allowExpiredCerts
;
310 /* from SSLRef 3.0 */
311 SSLRSAPrivateKey localKey
;
312 SSLRSAPrivateKey exportKey
;
313 SSLCertificate
*localCert
;
314 SSLCertificate
*peerCert
;
315 SSLRSAPublicKey peerKey
;
316 SSLDHParams dhAnonParams
;
317 SSLDHParams peerDHParams
;
322 SSLBuffer dhPeerPublic
;
323 SSLBuffer dhExchangePublic
;
327 SSLBuffer resumableSession
;
329 CipherContext readCipher
;
330 CipherContext writeCipher
;
331 CipherContext readPending
;
332 CipherContext writePending
;
334 uint16 selectedCipher
; /* currently selected */
335 const SSLCipherSpec
*selectedCipherSpec
; /* ditto */
336 SSLCipherSpec
*validCipherSpecs
; /* context's valid specs */
337 unsigned numValidCipherSpecs
; /* size of validCipherSpecs */
338 SSLHandshakeState state
;
341 #if ST_SERVER_MODE_ENABLE
342 SSLAuthenticate clientAuth
; /* kNeverAuthenticate, etc. */
343 Boolean tryClientAuth
;
344 #endif /* ST_SERVER_MODE_ENABLE */
346 int requestClientCert
;
352 DNListElem
*acceptableDNList
;
354 uint8 clientRandom
[32];
355 uint8 serverRandom
[32];
356 SSLBuffer preMasterSecret
;
357 uint8 masterSecret
[48];
359 SSLBuffer shaState
, md5State
;
361 SSLBuffer fragmentedMessageCache
;
363 int ssl2ChallengeLength
;
364 int ssl2ConnectionIDLength
;
365 int ssl2SessionMatch
;
367 /* Record layer fields */
368 SSLBuffer partialReadBuffer
;
371 /* Transport layer fields */
372 WaitingRecord
*recordWriteQueue
;
373 SSLBuffer receivedDataBuffer
;
374 uint32 receivedDataPos
;
377 Boolean allowAnyRoot
; // don't require known roots
379 char *rootCertName
; // if non-null, write root cert here
380 #endif /* SSL_DEBUG */
381 #endif /* _APPLE_CDSA_ */
385 #endif /* _SSLCTX_H_ */