]> git.saurik.com Git - apple/security.git/blob - SecureTransport/privateInc/sslContext.h
7126fb902cc7cbe61c846e33588ab0b0b39beb51
[apple/security.git] / SecureTransport / privateInc / sslContext.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
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
8 * using this file.
9 *
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.
16 */
17
18
19 /*
20 File: sslContext.h
21
22 Contains: Private SSL typedefs: SSLContext and its components
23
24 Written by: Doug Mitchell
25
26 Copyright: (c) 1999 by Apple Computer, Inc., all rights reserved.
27
28 */
29
30 #ifndef _SSLCONTEXT_H_
31 #define _SSLCONTEXT_H_ 1
32
33 #include <Security/SecureTransport.h>
34 #include "sslBuildFlags.h"
35 #include <Security/cssmtype.h>
36
37 #include "sslPriv.h"
38 #include "tls_ssl.h"
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 typedef struct
45 { SSLReadFunc read;
46 SSLWriteFunc write;
47 SSLConnectionRef ioRef;
48 } IOContext;
49
50 /*
51 * An element in a certificate chain.
52 */
53 typedef struct SSLCertificate
54 {
55 struct SSLCertificate *next;
56 SSLBuffer derCert;
57 } SSLCertificate;
58
59 #include "cryptType.h"
60
61 /*
62 * An SSLContext contains four of these - one for each of {read,write} and for
63 * {current, pending}.
64 */
65 struct CipherContext
66 {
67
68 const HashHmacReference *macRef; /* HMAC (TLS) or digest (SSL) */
69 const SSLSymmetricCipher *symCipher;
70
71 /* this is a context which is reused once per record */
72 HashHmacContext macCtx;
73
74 /*
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
79 * SSLContext level.
80 */
81 CSSM_KEY_PTR symKey;
82 CSSM_CSP_HANDLE cspHand;
83 CSSM_CC_HANDLE ccHand;
84
85 /* needed in CDSASymmInit */
86 uint8 encrypting;
87
88 sslUint64 sequenceNum;
89 uint8 ready;
90
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];
94 };
95 /* typedef in cryptType.h */
96
97 #include "sslHandshake.h"
98
99 typedef struct WaitingRecord
100 { struct WaitingRecord *next;
101 SSLBuffer data;
102 uint32 sent;
103 } WaitingRecord;
104
105 typedef struct DNListElem
106 { struct DNListElem *next;
107 SSLBuffer derDN;
108 } DNListElem;
109
110 struct SSLContext
111 {
112 IOContext ioCtx;
113
114 /*
115 * Prior to successful protocol negotiation, negProtocolVersion
116 * is SSL_Version_Undetermined. Subsequent to successful
117 * negotiation, negProtocolVersion contains the actual over-the-wire
118 * protocol value.
119 *
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.
127 */
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;
134
135 const struct _SslTlsCallouts *sslTslCalls; /* selects between SSLv3 and TLSv1 */
136
137 /* crypto state in CDSA-centric terms */
138
139 CSSM_KEY_PTR signingPrivKey; /* our private signing key */
140 CSSM_KEY_PTR signingPubKey; /* our public signing key */
141 CSSM_CSP_HANDLE signingKeyCsp; /* associated DL/CSP */
142
143 CSSM_KEY_PTR encryptPrivKey; /* our private encrypt key, for
144 * server-initiated key exchange */
145 CSSM_KEY_PTR encryptPubKey; /* public version of above */
146 CSSM_CSP_HANDLE encryptKeyCsp;
147
148 CSSM_KEY_PTR peerPubKey;
149 CSSM_CSP_HANDLE peerPubKeyCsp; /* may not be needed, we figure this
150 * one out by trial&error, right? */
151
152 /*
153 * Various cert chains.
154 * For all three, the root is the first in the chain.
155 */
156 SSLCertificate *localCert;
157 SSLCertificate *encryptCert;
158 SSLCertificate *peerCert;
159
160 /* peer certs as SecTrustRef */
161 SecTrustRef peerSecTrust;
162
163 /*
164 * trusted root certs; specific to this implementation, we'll store
165 * them conveniently...these will be used as AnchorCerts in a TP
166 * call.
167 */
168 uint32 numTrustedCerts;
169 CSSM_DATA_PTR trustedCerts;
170
171 /* for symmetric cipher and RNG */
172 CSSM_CSP_HANDLE cspHand;
173
174 /* session-wide handles for Apple TP, CL */
175 CSSM_TP_HANDLE tpHand;
176 CSSM_CL_HANDLE clHand;
177
178 #if APPLE_DH
179 SSLBuffer dhParamsPrime;
180 SSLBuffer dhParamsGenerator;
181 SSLBuffer dhParamsEncoded; /* prime + generator */
182 SSLBuffer dhPeerPublic;
183 SSLBuffer dhExchangePublic;
184 CSSM_KEY_PTR dhPrivate;
185 #endif /* APPLE_DH */
186
187 Boolean allowExpiredCerts;
188 Boolean allowExpiredRoots;
189 Boolean enableCertVerify;
190
191 SSLBuffer sessionID;
192
193 SSLBuffer peerID;
194 SSLBuffer resumableSession;
195
196 char *peerDomainName;
197 UInt32 peerDomainNameLen;
198
199 CipherContext readCipher;
200 CipherContext writeCipher;
201 CipherContext readPending;
202 CipherContext writePending;
203
204 uint16 selectedCipher; /* currently selected */
205 const SSLCipherSpec *selectedCipherSpec; /* ditto */
206 SSLCipherSpec *validCipherSpecs; /* context's valid specs */
207 unsigned numValidCipherSpecs; /* size of validCipherSpecs */
208 SSLHandshakeState state;
209
210 /* server-side only */
211 SSLAuthenticate clientAuth; /* kNeverAuthenticate, etc. */
212 Boolean tryClientAuth;
213
214 /* client and server */
215 SSLClientCertificateState clientCertState;
216
217 DNListElem *acceptableDNList;
218
219 int certRequested;
220 int certSent;
221 int certReceived;
222 int x509Requested;
223
224 uint8 clientRandom[SSL_CLIENT_SRVR_RAND_SIZE];
225 uint8 serverRandom[SSL_CLIENT_SRVR_RAND_SIZE];
226 SSLBuffer preMasterSecret;
227 uint8 masterSecret[SSL_MASTER_SECRET_SIZE];
228
229 /* running digests of all handshake messages */
230 SSLBuffer shaState, md5State;
231
232 SSLBuffer fragmentedMessageCache;
233
234 unsigned ssl2ChallengeLength;
235 unsigned ssl2ConnectionIDLength;
236 unsigned sessionMatch;
237
238 /* Record layer fields */
239 SSLBuffer partialReadBuffer;
240 uint32 amountRead;
241
242 /* Transport layer fields */
243 WaitingRecord *recordWriteQueue;
244 SSLBuffer receivedDataBuffer;
245 uint32 receivedDataPos;
246
247 Boolean allowAnyRoot; // don't require known roots
248 Boolean sentFatalAlert; // this session terminated by fatal alert
249 Boolean rsaBlindingEnable;
250 };
251
252 #ifdef __cplusplus
253 }
254 #endif
255
256 #endif /* _SSLCONTEXT_H_ */