1 // Note: This file still needs some work.
4 // (As defined by the SSL v3.0 RFC Draft)
5 // URL: http://wp.netscape.com/eng/ssl3/draft302.txt
6 typedef unsigned char uint8;
7 typedef uint8 uint16[2];
8 typedef uint8 uint24[3];
9 typedef uint8 uint32[4];
10 typedef uint8 uint64[8];
13 typedef struct _ProtocolVersion{
17 ProtocolVersion version = { 3, 0 };
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
27 typedef struct _SSLPlaintext{
29 ProtocolVersion version;
30 uint16 length; // can not exceed 2^14 bytes
31 uint8 fragment[16384]; // 2^14 = 16,384 bytes
34 typedef struct _SSLCompressed{
36 ProtocolVersion version;
37 uint16 length; // can not exceed 2^14 + 1024
38 uint8 fragment[17408]; // SSLCompressed.length
41 typedef struct _GenericStreamCipher{
42 uint8 content[17408]; // SSLCompressed.length
43 uint8 MAC[]; // CipherSpec.hash_size
44 } GenericStreamCipher;
46 typedef struct _SSLStreamCiphertext{
48 ProtocolVersion version;
49 uint16 length; // can not exceed 2^14 + 2048 = 18,456
50 GenericStreamCipher fragment;
51 } SSLStreamCiphertext;
53 typedef struct _GenericBlockCipher{
54 uint8 content[17408]; // SSLConpressed.length
55 uint8 MAC[0]; // CipherSpec.hash_size
56 // padding is used to bring the plaintext to
57 // a multiple of the block cipher's block length.
58 uint8 padding[0]; // GenericBlockCipher.padding_length
62 typedef struct _SSLBlockCiphertext{
64 ProtocolVersion version;
65 uint16 length; // can not exceed 2^14 + 2048 = 18,456
66 GenericBlockCipher fragment;
69 // Change cipher specs message
70 typedef struct _ChangeCipherSpec{
71 enum { type_change_cipher_spec=1, type_size=255 } type;
75 typedef enum _AlertLevel{
76 alert_level_warning=1,
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
97 typedef struct _Alert{
99 AlertDescription description;
102 // Handshake protocol
103 // 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
118 typedef struct _Handshake{
119 HandshakeType msg_type;
121 } Handshake; // generic Handshake, need to recast to get body
124 typedef struct _HelloRequest{} HelloRequest;
126 typedef struct _HelloRequestHandshake{
127 HandshakeType msg_type;
130 } HelloRequestHandshake;
132 typedef struct _Random{
133 uint32 gmt_unix_time;
134 uint8 random_bytes[28];
137 typedef uint8 SessionID[32]; // <0..32>
138 typedef uint8 CipherSuite[2];
140 typedef enum _CompressionMethod{ compression_method_null=0, compression_method_size=255 } CompressionMethod;
142 typedef struct _ClientHello{
143 ProtocolVersion client_version;
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
150 typedef struct _ClientHelloHandshake{
151 HandshakeType msg_type;
154 } ClientHelloHandshake;
156 typedef struct _ServerHello{
157 ProtocolVersion server_version;
159 SessionID session_id;
160 CipherSuite cipher_suite;
161 CompressionMethod compression_method;
164 typedef struct _ServerHelloHandshake{
165 HandshakeType msg_type;
168 } ServerHelloHandshake;
170 // Server authentication and key exchange messages
171 typedef uint8 ASN1Cert[16777216]; // <1..2^24-1> = 16,777,216 bytes
173 typedef struct _Certificate{
174 ASN1Cert certificate_list[1]; // <1..2^24-1> / ANS1Cert = 1
175 // for some reason the size of certificate_list and ASN1Cert is the same, so only one certificate in the list
178 typedef enum _KeyExchangeAlgorithm{
179 key_exchange_algorithm_rsa,
180 key_exchange_algorithm_diffie_hellman,
181 key_exchange_algorithm_fortezza_kea
182 } KeyExchangeAlgorithm;
184 typedef struct _AnonSignature{
188 typedef struct _RSASignature{
193 typedef struct _DSASignature{
197 // use union??, make a mess to reference, but easy to make Signature type.
198 typedef union _Signature{ AnonSignature anon; RSASignature rsa; DSASignature dsa; } Signature;
200 typedef struct _ServerRSAParams{
201 uint8 RSA_modulus[65536]; // <1..2^16-1> = 65,536
202 uint8 RSA_exponent[65536]; // <1..2^16-1> = 65,536
205 typedef struct _ServerDHParams{
206 uint8 DH_p[65536]; // <1..2^16-1>
207 uint8 DH_g[65536]; // <1..2^16-1>
208 uint8 DH_Ys[65536]; // <1..2^16-1>
211 typedef struct _ServerDHKeyExchange{
212 ServerDHParams params;
213 Signature signed_params;
214 } ServerDHKeyExchange;
216 typedef struct _ServerRSAKeyExchange{
217 ServerRSAParams params;
218 Signature signed_params;
219 } ServerRSAKeyExchange;
221 typedef enum _SignatureAlgorithm{
222 signature_algorithm_anonymous,
223 signature_algorithm_rsa,
224 signature_algorithm_dsa
225 } SignatureAlgorithm;
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
238 typedef uint8 DistinguishedName[65536]; // <1..2^16-1> = 65,536
240 typedef struct _CertificateRequest{
241 CertificateType certificate_types[256]; // <1..2^8-1>
242 DistinguishedName certificate_authorities[1]; // <3...2^16-1> / DistinguishedName
243 // this is another one that is odd with a list size of 1
244 } CertificateRequest;
246 typedef struct _ServerHelloDone{} ServerHelloDone;
248 // Client authentication and key exchange messages
249 typedef struct _PreMasterSecret{
250 ProtocolVersion client_version;
254 typedef struct _EncryptedPreMasterSecret{
255 PreMasterSecret pre_master_secret;
256 } EncryptedPreMasterSecret;
258 typedef struct _RSAClientKeyExchange{
259 EncryptedPreMasterSecret exchange_keys;
260 } RSAClientKeyExchange;
262 typedef enum _PublicValueEncoding{ public_value_encoding_implicit, public_value_encoding_explicit } PublicValueEncoding;
264 typedef struct _ClientDiffieHellmanPublic{
265 // This is a select on PublicValueEncoding, and I chose the larger size
266 uint8 dh_public[65536]; // DH_Yc<1..2^16-1>, the dh public value
267 } ClientDiffieHellmanPublic;
269 typedef struct _DHClientKeyExhange{
270 ClientDiffieHellmanPublic exchange_keys;
271 } DHClientKeyExchange;
273 typedef struct _CertificateVerify{
277 // Handshake finalization message
278 typedef struct _Finished{
284 CipherSuite SSL_NULL_WITH_NULL_NULL = { 0x00, 0x00 };
285 CipherSuite SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA = { 0x00, 0x0B };
286 CipherSuite SSL_DH_DSS_WITH_DES_CBC_SHA = { 0x00, 0x0C };
287 CipherSuite SSL_DH_anon_EXPORT_WITH_RC4_40_MD5 = { 0x00, 0x17 };
288 CipherSuite SSL_DH_anon_WITH_RC4_128_MD5 = { 0x00, 0x18 };
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;
304 typedef struct _CipherSpec{
305 BulkCipherAlgorithm bulk_cipher_algorithm;
306 MACAlgorithm mac_algorithm;
307 CipherType cipher_type;
308 IsExportable is_exportable;