|
@@ -1,4 +1,6 @@
|
1
|
1
|
// Note: This file still needs some work.
|
|
2
|
+// Note: I had to redefine the enums to a set of const values,
|
|
3
|
+// so that the size of the variable would be correct.
|
2
|
4
|
|
3
|
5
|
// Typedefs
|
4
|
6
|
// (As defined by the SSL v3.0 RFC Draft)
|
|
@@ -14,15 +16,13 @@ typedef struct _ProtocolVersion{
|
14
|
16
|
uint8 major, minor;
|
15
|
17
|
} ProtocolVersion;
|
16
|
18
|
|
17
|
|
-ProtocolVersion version = { 3, 0 };
|
|
19
|
+const ProtocolVersion version = { 3, 0 };
|
18
|
20
|
|
19
|
|
-typedef enum _ContentType{
|
20
|
|
- content_type_change_cipher_spec_type=20,
|
21
|
|
- content_type_alert=21,
|
22
|
|
- content_type_handshake=22,
|
23
|
|
- content_type_application_data=23,
|
24
|
|
- content_type_size=255 // to force size
|
25
|
|
-} ContentType;
|
|
21
|
+typedef uint8 ContentType;
|
|
22
|
+const ContentType content_type_change_cipher_spec_type = 20;
|
|
23
|
+const ContentType content_type_alert = 21;
|
|
24
|
+const ContentType content_type_handshake = 22;
|
|
25
|
+const ContentType content_type_application_data = 23;
|
26
|
26
|
|
27
|
27
|
typedef struct _SSLPlaintext{
|
28
|
28
|
ContentType type;
|
|
@@ -38,6 +38,14 @@ typedef struct _SSLCompressed{
|
38
|
38
|
uint8 fragment[17408]; // SSLCompressed.length
|
39
|
39
|
} SSLCompressed;
|
40
|
40
|
|
|
41
|
+typedef struct _SSLCiphertext{
|
|
42
|
+ ContentType type;
|
|
43
|
+ ProtocolVersion version;
|
|
44
|
+ uint16 length;
|
|
45
|
+ uint8 fragment; // so we have a pointer to the data, and don't have to do math
|
|
46
|
+ // fragment; type GenericStreamCipher or GenericBlockCipher
|
|
47
|
+} SSLCiphertext; // recast to get fragment
|
|
48
|
+
|
41
|
49
|
typedef struct _GenericStreamCipher{
|
42
|
50
|
uint8 content[17408]; // SSLCompressed.length
|
43
|
51
|
uint8 MAC[]; // CipherSpec.hash_size
|
|
@@ -72,27 +80,23 @@ typedef struct _ChangeCipherSpec{
|
72
|
80
|
} ChangeCipherSpec;
|
73
|
81
|
|
74
|
82
|
// Alert messages
|
75
|
|
-typedef enum _AlertLevel{
|
76
|
|
- alert_level_warning=1,
|
77
|
|
- alert_level_fatal=2,
|
78
|
|
- alert_level_size=255
|
79
|
|
-} AlertLevel;
|
80
|
|
-
|
81
|
|
-typedef enum _AlertDescription{
|
82
|
|
- alert_description_close_notify=0,
|
83
|
|
- alert_description_unexpected_message=10,
|
84
|
|
- alert_description_bad_record_mac=20,
|
85
|
|
- alert_description_decompression_failure=30,
|
86
|
|
- alert_description_handshake_failure=40,
|
87
|
|
- alert_description_no_certificate=41,
|
88
|
|
- alert_description_bad_certificate=42,
|
89
|
|
- alert_description_unsupported_certificate=43,
|
90
|
|
- alert_description_certificate_revoked=44,
|
91
|
|
- alert_description_certificate_expired=45,
|
92
|
|
- alert_description_certificate_unknown=46,
|
93
|
|
- alert_description_illegal_parameter=47,
|
94
|
|
- alert_description_size=255
|
95
|
|
-} AlertDescription;
|
|
83
|
+typedef uint8 AlertLevel;
|
|
84
|
+const AlertLevel alert_level_warning = 1;
|
|
85
|
+const AlertLevel alert_level_fatal=2;
|
|
86
|
+
|
|
87
|
+typedef uint8 AlertDescription;
|
|
88
|
+const AlertDescription alert_description_close_notify = 0;
|
|
89
|
+const AlertDescription alert_description_unexpected_message = 10;
|
|
90
|
+const AlertDescription alert_description_bad_record_mac = 20;
|
|
91
|
+const AlertDescription alert_description_decompression_failure = 30;
|
|
92
|
+const AlertDescription alert_description_handshake_failure = 40;
|
|
93
|
+const AlertDescription alert_description_no_certificate = 41;
|
|
94
|
+const AlertDescription alert_description_bad_certificate = 42;
|
|
95
|
+const AlertDescription alert_description_unsupported_certificate = 43;
|
|
96
|
+const AlertDescription alert_description_certificate_revoked = 44;
|
|
97
|
+const AlertDescription alert_description_certificate_expired = 45;
|
|
98
|
+const AlertDescription alert_description_certificate_unknown = 46;
|
|
99
|
+const AlertDescription alert_description_illegal_parameter = 47;
|
96
|
100
|
|
97
|
101
|
typedef struct _Alert{
|
98
|
102
|
AlertLevel level;
|
|
@@ -101,23 +105,22 @@ typedef struct _Alert{
|
101
|
105
|
|
102
|
106
|
// Handshake protocol
|
103
|
107
|
// What is the best way to have a generic pointer to the body struct??
|
104
|
|
-typedef enum _HandshakeType{
|
105
|
|
- handshake_type_hello_request=0,
|
106
|
|
- handshake_type_client_hello=1,
|
107
|
|
- handshake_type_server_hello=2,
|
108
|
|
- handshake_type_certificate=11,
|
109
|
|
- handshake_type_server_key_exchange=12,
|
110
|
|
- handshake_type_certificate_request=13,
|
111
|
|
- handshake_type_server_done=14,
|
112
|
|
- handshake_type_certificate_verify=15,
|
113
|
|
- handshake_type_client_key_exchange=16,
|
114
|
|
- handshake_type_finished=20,
|
115
|
|
- handshake_type_size=255
|
116
|
|
-} HandshakeType;
|
|
108
|
+typedef uint8 HandshakeType;
|
|
109
|
+const HandshakeType handshake_type_hello_request = 0;
|
|
110
|
+const HandshakeType handshake_type_client_hello = 1;
|
|
111
|
+const HandshakeType handshake_type_server_hello = 2;
|
|
112
|
+const HandshakeType handshake_type_certificate = 11;
|
|
113
|
+const HandshakeType handshake_type_server_key_exchange = 12;
|
|
114
|
+const HandshakeType handshake_type_certificate_request = 13;
|
|
115
|
+const HandshakeType handshake_type_server_done = 14;
|
|
116
|
+const HandshakeType handshake_type_certificate_verify = 15;
|
|
117
|
+const HandshakeType handshake_type_client_key_exchange = 16;
|
|
118
|
+const HandshakeType handshake_type_finished = 20;
|
117
|
119
|
|
118
|
120
|
typedef struct _Handshake{
|
119
|
121
|
HandshakeType msg_type;
|
120
|
122
|
uint24 length;
|
|
123
|
+ // body; // one of HandshakeType structs
|
121
|
124
|
} Handshake; // generic Handshake, need to recast to get body
|
122
|
125
|
|
123
|
126
|
// Hello messages
|
|
@@ -134,21 +137,38 @@ typedef struct _Random{
|
134
|
137
|
uint8 random_bytes[28];
|
135
|
138
|
} Random;
|
136
|
139
|
|
137
|
|
-typedef uint8 SessionID[32]; // <0..32>
|
|
140
|
+//typedef uint8 SessionID[32]; // <0..32>
|
|
141
|
+typedef uint8 SessionIDLength;
|
|
142
|
+typedef uint8 SessionID;
|
|
143
|
+
|
|
144
|
+typedef uint16 CipherSuiteLength;
|
138
|
145
|
typedef uint8 CipherSuite[2];
|
139
|
146
|
|
140
|
|
-typedef enum _CompressionMethod{ compression_method_null=0, compression_method_size=255 } CompressionMethod;
|
|
147
|
+typedef uint8 CompressionMethodLength;
|
|
148
|
+typedef uint8 CompressionMethod;
|
|
149
|
+const CompressionMethod compression_method_null = 0;
|
|
150
|
+
|
141
|
151
|
|
142
|
152
|
typedef struct _ClientHello{
|
143
|
153
|
ProtocolVersion client_version;
|
144
|
154
|
Random random;
|
145
|
|
- SessionID session_id;
|
146
|
|
- CipherSuite cipher_suites[32768]; // <2..2^16-1> = 65,536 bytes and CipherSuite is 2 bytes
|
147
|
|
- CompressionMethod compression_methods[256]; // <0..2^8-1> = 256 bytes and CompressionMethod is 1 byte
|
|
155
|
+ SessionIDLength session_id_length;
|
|
156
|
+ SessionID *session_id;
|
|
157
|
+ SessionID *session_id_end;
|
|
158
|
+ CipherSuiteLength *cipher_suites_length;
|
|
159
|
+ CipherSuite *cipher_suites; // min size is one entry
|
|
160
|
+ CipherSuite *cipher_suites_end;
|
|
161
|
+ //CipherSuite cipher_suites[32768]; // <2..2^16-1> = 65,536 bytes and CipherSuite is 2 bytes
|
|
162
|
+ CompressionMethodLength *compression_methods_length;
|
|
163
|
+ CompressionMethod *compression_methods;
|
|
164
|
+ CompressionMethod *compression_methods_end;
|
|
165
|
+ //CompressionMethod *compression_methods; // min size is zero
|
|
166
|
+ //CompressionMethod compression_methods[256]; // <0..2^8-1> = 256 bytes and CompressionMethod is 1 byte
|
148
|
167
|
} ClientHello;
|
149
|
168
|
|
150
|
169
|
typedef struct _ClientHelloHandshake{
|
151
|
|
- HandshakeType msg_type;
|
|
170
|
+ //HandshakeType msg_type;
|
|
171
|
+ uint8 msg_type;
|
152
|
172
|
uint24 length;
|
153
|
173
|
ClientHello body;
|
154
|
174
|
} ClientHelloHandshake;
|
|
@@ -175,11 +195,10 @@ typedef struct _Certificate{
|
175
|
195
|
// for some reason the size of certificate_list and ASN1Cert is the same, so only one certificate in the list
|
176
|
196
|
} Certificate;
|
177
|
197
|
|
178
|
|
-typedef enum _KeyExchangeAlgorithm{
|
179
|
|
- key_exchange_algorithm_rsa,
|
180
|
|
- key_exchange_algorithm_diffie_hellman,
|
181
|
|
- key_exchange_algorithm_fortezza_kea
|
182
|
|
-} KeyExchangeAlgorithm;
|
|
198
|
+typedef uint8 KeyExchangeAlgorithm;
|
|
199
|
+const KeyExchangeAlgorithm key_exchange_algorithm_rsa = 0;
|
|
200
|
+const KeyExchangeAlgorithm key_exchange_algorithm_diffie_hellman = 1;
|
|
201
|
+const KeyExchangeAlgorithm key_exchange_algorithm_fortezza_kea = 2;
|
183
|
202
|
|
184
|
203
|
typedef struct _AnonSignature{
|
185
|
204
|
struct {};
|
|
@@ -218,22 +237,19 @@ typedef struct _ServerRSAKeyExchange{
|
218
|
237
|
Signature signed_params;
|
219
|
238
|
} ServerRSAKeyExchange;
|
220
|
239
|
|
221
|
|
-typedef enum _SignatureAlgorithm{
|
222
|
|
- signature_algorithm_anonymous,
|
223
|
|
- signature_algorithm_rsa,
|
224
|
|
- signature_algorithm_dsa
|
225
|
|
-} SignatureAlgorithm;
|
226
|
|
-
|
227
|
|
-typedef enum _CertificateType{
|
228
|
|
- certificate_type_RSA_sign=1,
|
229
|
|
- certificate_type_DSS_sign=2,
|
230
|
|
- certificate_type_RSA_fixed_DH=3,
|
231
|
|
- certificate_type_DSS_fixed_DH=4,
|
232
|
|
- certificate_type_RSA_ephemeral_DH=5,
|
233
|
|
- certificate_type_DSS_ephemeral_DH=6,
|
234
|
|
- certificate_type_FORTEZZA_MISSI=20,
|
235
|
|
- certificate_type_size=255
|
236
|
|
-} CertificateType;
|
|
240
|
+typedef uint8 SignatureAlgorithm;
|
|
241
|
+const SignatureAlgorithm signature_algorithm_anonymous = 0;
|
|
242
|
+const SignatureAlgorithm signature_algorithm_rsa = 1;
|
|
243
|
+const SignatureAlgorithm signature_algorithm_dsa = 2;
|
|
244
|
+
|
|
245
|
+typedef uint8 CertificateType;
|
|
246
|
+const CertificateType certificate_type_RSA_sign = 1;
|
|
247
|
+const CertificateType certificate_type_DSS_sign = 2;
|
|
248
|
+const CertificateType certificate_type_RSA_fixed_DH = 3;
|
|
249
|
+const CertificateType certificate_type_DSS_fixed_DH = 4;
|
|
250
|
+const CertificateType certificate_type_RSA_ephemeral_DH = 5;
|
|
251
|
+const CertificateType certificate_type_DSS_ephemeral_DH = 6;
|
|
252
|
+const CertificateType certificate_type_FORTEZZA_MISSI = 20;
|
237
|
253
|
|
238
|
254
|
typedef uint8 DistinguishedName[65536]; // <1..2^16-1> = 65,536
|
239
|
255
|
|
|
@@ -259,7 +275,9 @@ typedef struct _RSAClientKeyExchange{
|
259
|
275
|
EncryptedPreMasterSecret exchange_keys;
|
260
|
276
|
} RSAClientKeyExchange;
|
261
|
277
|
|
262
|
|
-typedef enum _PublicValueEncoding{ public_value_encoding_implicit, public_value_encoding_explicit } PublicValueEncoding;
|
|
278
|
+typedef uint8 PublicValueEncoding;
|
|
279
|
+const PublicValueEncoding public_value_encoding_implicit = 0;
|
|
280
|
+const PublicValueEncoding public_value_encoding_explicit = 1;
|
263
|
281
|
|
264
|
282
|
typedef struct _ClientDiffieHellmanPublic{
|
265
|
283
|
// This is a select on PublicValueEncoding, and I chose the larger size
|
|
@@ -281,25 +299,35 @@ typedef struct _Finished{
|
281
|
299
|
} Finished;
|
282
|
300
|
|
283
|
301
|
// The CipherSuite
|
284
|
|
-CipherSuite SSL_NULL_WITH_NULL_NULL = { 0x00, 0x00 };
|
|
302
|
+CipherSuite SSL_NULL_WITH_NULL_NULL = { 0x00, 0x13 };
|
285
|
303
|
CipherSuite SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA = { 0x00, 0x0B };
|
286
|
304
|
CipherSuite SSL_DH_DSS_WITH_DES_CBC_SHA = { 0x00, 0x0C };
|
|
305
|
+CipherSuite SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA = { 0x00, 0x11 };
|
287
|
306
|
CipherSuite SSL_DH_anon_EXPORT_WITH_RC4_40_MD5 = { 0x00, 0x17 };
|
288
|
307
|
CipherSuite SSL_DH_anon_WITH_RC4_128_MD5 = { 0x00, 0x18 };
|
289
|
308
|
|
290
|
309
|
// The CipherSpec
|
291
|
|
-typedef enum _CipherType{ cipher_type_stream, cipher_type_block } CipherType;
|
292
|
|
-typedef enum _IsExportable{ is_exportable_true, is_exportable_false } IsExportable;
|
293
|
|
-typedef enum _BulkCipherAlgorithm{
|
294
|
|
- bulk_cipher_algorithm_null,
|
295
|
|
- bulk_cipher_algorithm_rc4,
|
296
|
|
- bulk_cipher_algorithm_rc2,
|
297
|
|
- bulk_cipher_algorithm_des,
|
298
|
|
- bulk_cipher_algorithm_3des,
|
299
|
|
- bulk_cipher_algorithm_des40,
|
300
|
|
- bulk_cipher_algorithm_fortezza
|
301
|
|
-} BulkCipherAlgorithm;
|
302
|
|
-typedef enum _MACAlgorithm{ mac_algorithm_null, mac_algorithm_md5, mac_algorithm_sha } MACAlgorithm;
|
|
310
|
+typedef uint8 CipherType;
|
|
311
|
+const CipherType cipher_type_stream = 0;
|
|
312
|
+const CipherType cipher_type_block = 1;
|
|
313
|
+
|
|
314
|
+typedef uint8 IsExportable;
|
|
315
|
+const IsExportable is_exportable_true = 0;
|
|
316
|
+const IsExportable is_exportable_false = 1;
|
|
317
|
+
|
|
318
|
+typedef uint8 BulkCipherAlgorithm;
|
|
319
|
+const BulkCipherAlgorithm bulk_cipher_algorithm_null = 0;
|
|
320
|
+const BulkCipherAlgorithm bulk_cipher_algorithm_rc4 = 1;
|
|
321
|
+const BulkCipherAlgorithm bulk_cipher_algorithm_rc2 = 2;
|
|
322
|
+const BulkCipherAlgorithm bulk_cipher_algorithm_des = 3;
|
|
323
|
+const BulkCipherAlgorithm bulk_cipher_algorithm_3des = 4;
|
|
324
|
+const BulkCipherAlgorithm bulk_cipher_algorithm_des40 = 5;
|
|
325
|
+const BulkCipherAlgorithm bulk_cipher_algorithm_fortezza = 6;
|
|
326
|
+
|
|
327
|
+typedef uint8 MACAlgorithm;
|
|
328
|
+const MACAlgorithm mac_algorithm_null = 0;
|
|
329
|
+const MACAlgorithm mac_algorithm_md5 = 1;
|
|
330
|
+const MACAlgorithm mac_algorithm_sha = 2;
|
303
|
331
|
|
304
|
332
|
typedef struct _CipherSpec{
|
305
|
333
|
BulkCipherAlgorithm bulk_cipher_algorithm;
|