summaryrefslogtreecommitdiff
path: root/module/ssl3.m
blob: 32c47bd79fde876f833c3d109887d66f5c760779 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#
# ssl 3.0 protocol
#

SSL3: module {

	PATH: con "/dis/lib/crypt/ssl3.dis";

	init: fn(): string;

	# SSL cipher suites

	NULL_WITH_NULL_NULL,
	RSA_WITH_NULL_MD5,
	RSA_WITH_NULL_SHA,
	RSA_EXPORT_WITH_RC4_40_MD5,
	RSA_WITH_RC4_128_MD5,
	RSA_WITH_RC4_128_SHA,
	RSA_EXPORT_WITH_RC2_CBC_40_MD5,
	RSA_WITH_IDEA_CBC_SHA,
	RSA_EXPORT_WITH_DES40_CBC_SHA,
	RSA_WITH_DES_CBC_SHA,
	RSA_WITH_3DES_EDE_CBC_SHA,
	DH_DSS_EXPORT_WITH_DES40_CBC_SHA,
	DH_DSS_WITH_DES_CBC_SHA,
	DH_DSS_WITH_3DES_EDE_CBC_SHA,
	DH_RSA_EXPORT_WITH_DES40_CBC_SHA,
	DH_RSA_WITH_DES_CBC_SHA,
	DH_RSA_WITH_3DES_EDE_CBC_SHA,
	DHE_DSS_EXPORT_WITH_DES40_CBC_SHA,
	DHE_DSS_WITH_DES_CBC_SHA,
	DHE_DSS_WITH_3DES_EDE_CBC_SHA,
	DHE_RSA_EXPORT_WITH_DES40_CBC_SHA,
	DHE_RSA_WITH_DES_CBC_SHA,
	DHE_RSA_WITH_3DES_EDE_CBC_SHA,
	DH_anon_EXPORT_WITH_RC4_40_MD5,
	DH_anon_WITH_RC4_128_MD5,
	DH_anon_EXPORT_WITH_DES40_CBC_SHA,
	DH_anon_WITH_DES_CBC_SHA,
	DH_anon_WITH_3DES_EDE_CBC_SHA,
	FORTEZZA_KEA_WITH_NULL_SHA,
	FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA,
	FORTEZZA_KEA_WITH_RC4_128_SHA 		: con iota;

	Authinfo: adt {
		suites: array of byte; # [2] x
		comprs: array of byte; # [1] x

		sk: ref PrivateKey; # for user certs 
		root_type: int; # root type of certs
		certs: list of array of byte; # x509 cert chain

		types: array of byte; # acceptable cert types
		dns: list of array of byte; # acceptable cert authorities
	};

	PrivateKey: adt {
		pick {
		RSA =>
			sk			: ref PKCS->RSAKey;
		DSS =>
			sk			: ref PKCS->DSSPrivateKey;
		DH =>
			sk			: ref PKCS->DHPrivateKey;
		}
	};

	Record: adt {
		content_type			: int;
		version			 	: array of byte; # [2]		
		data				: array of byte;
	};

	# key exchange algorithms

	KeyExAlg: adt {
		pick {
		NULL =>
		DH =>
			params			: ref PKCS->DHParams;
			sk			: ref PKCS->DHPrivateKey;			
			peer_params		: ref PKCS->DHParams;
			peer_pk			: ref PKCS->DHPublicKey;
			exch_pk			: ref PKCS->DHPublicKey;
		RSA =>
			sk	 		: ref PKCS->RSAKey; # for RSA key exchange
			export_key 		: ref PKCS->RSAKey; # server RSA temp key
			peer_pk			: ref PKCS->RSAKey; # temp key from server
		FORTEZZA_KEA =>	
			# not supported yet
		}
	};

	SigAlg: adt {
		pick {
		anon =>
		RSA =>
			sk	 		: ref PKCS->RSAKey; # for sign
			peer_pk			: ref PKCS->RSAKey; # for verify from peer cert
		DSS =>
			sk	 		: ref PKCS->DSSPrivateKey; # for sign
			peer_pk			: ref PKCS->DSSPublicKey; # for verify from peer cert
		FORTEZZA_KEA =>	# not supported yet
		}
	};

	CipherSpec: adt {
		is_exportable			: int;
	
		bulk_cipher_algorithm		: int;
		cipher_type			: int;
		key_material			: int;
		IV_size				: int;

		mac_algorithm			: int;
		hash_size			: int;		
	};

	# record format queue

	RecordQueue: adt {
		macState			: ref MacState;
		cipherState			: ref CipherState;

		length				: int;
		sequence_numbers		: array of int;
	
		data				: list of ref Record;
		fragment			: int;
		b, e				: int;

		new: fn(): ref RecordQueue;
		read: fn(q: self ref RecordQueue, ctx: ref Context, fd: ref Sys->FD): string;
		write: fn(q: self ref RecordQueue, ctx: ref Context, fd: ref Sys->FD, r: ref Record): string;
		calcmac: fn(q: self ref RecordQueue, ctx: ref Context, cntype: int, a: array of byte, ofs, n: int) : array of byte;
	};

	MacState: adt {
		hash_size			: int;
		pick {
		null =>
		md5 =>
			ds			: array of ref Keyring->DigestState;
		sha =>
			ds			: array of ref Keyring->DigestState;
		}
	};

	CipherState: adt {
		block_size			: int;
		pick {
		null =>
		rc4 =>
			es			: ref Keyring->RC4state;
		descbc =>
			es			: ref Keyring->DESstate;
		ideacbc =>
			es			: ref Keyring->IDEAstate;
		}
	};

	# context for processing both v2 and v3 protocols.

	Context: adt {
		c				: ref Sys->Connection;
		session				: ref SSLsession->Session;

		sel_keyx			: ref KeyExAlg;
		sel_sign			: ref SigAlg;
		sel_ciph			: ref CipherSpec;
		sel_cmpr			: int;

		local_info			: ref Authinfo;

		client_random			: array of byte; # [32]
		server_random			: array of byte; # [32]
		
		sha_state			: ref Keyring->DigestState;
		md5_state			: ref Keyring->DigestState;

		cw_mac				: array of byte;
		sw_mac				: array of byte;
		cw_key				: array of byte;
		sw_key				: array of byte;
		cw_IV				: array of byte;
		sw_IV				: array of byte;

		in_queue			: ref RecordQueue;
		out_queue			: ref RecordQueue;

		status				: int;
		state				: int;


		new: fn(): ref Context;
		client: fn(ctx: self ref Context, fd: ref Sys->FD, peer: string, ver: int, info: ref Authinfo): (string, int);
		server: fn(ctx: self ref Context, fd: ref Sys->FD, info: ref Authinfo, client_auth: int): string;
		use_devssl: fn(ctx: self ref Context);
		set_version: fn(ctx: self ref Context, vers: int): string;
		connect: fn(ctx: self ref Context, fd: ref Sys->FD): string;
		read: fn(ctx: self ref Context, a: array of byte, n: int): int;
		write: fn(ctx: self ref Context, a: array of byte, n: int): int;
	};
};