28 |
extern int width; |
extern int width; |
29 |
extern int height; |
extern int height; |
30 |
extern int keylayout; |
extern int keylayout; |
31 |
|
extern BOOL use_encryption; |
32 |
|
extern BOOL licence_issued; |
33 |
|
|
34 |
static int rc4_key_len; |
static int rc4_key_len; |
35 |
static RC4_KEY rc4_decrypt_key; |
static RC4_KEY rc4_decrypt_key; |
47 |
* a client and server salt) and a global salt value used for padding. |
* a client and server salt) and a global salt value used for padding. |
48 |
* Both SHA1 and MD5 algorithms are used. |
* Both SHA1 and MD5 algorithms are used. |
49 |
*/ |
*/ |
50 |
void sec_hash_48(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2, uint8 salt) |
void |
51 |
|
sec_hash_48(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2, uint8 salt) |
52 |
{ |
{ |
53 |
uint8 shasig[20]; |
uint8 shasig[20]; |
54 |
uint8 pad[4]; |
uint8 pad[4]; |
58 |
|
|
59 |
for (i = 0; i < 3; i++) |
for (i = 0; i < 3; i++) |
60 |
{ |
{ |
61 |
memset(pad, salt+i, i+1); |
memset(pad, salt + i, i + 1); |
62 |
|
|
63 |
SHA1_Init(&sha); |
SHA1_Init(&sha); |
64 |
SHA1_Update(&sha, pad, i+1); |
SHA1_Update(&sha, pad, i + 1); |
65 |
SHA1_Update(&sha, in, 48); |
SHA1_Update(&sha, in, 48); |
66 |
SHA1_Update(&sha, salt1, 32); |
SHA1_Update(&sha, salt1, 32); |
67 |
SHA1_Update(&sha, salt2, 32); |
SHA1_Update(&sha, salt2, 32); |
70 |
MD5_Init(&md5); |
MD5_Init(&md5); |
71 |
MD5_Update(&md5, in, 48); |
MD5_Update(&md5, in, 48); |
72 |
MD5_Update(&md5, shasig, 20); |
MD5_Update(&md5, shasig, 20); |
73 |
MD5_Final(&out[i*16], &md5); |
MD5_Final(&out[i * 16], &md5); |
74 |
} |
} |
75 |
} |
} |
76 |
|
|
78 |
* Weaker 16-byte transformation, also using two 32-byte salts, but |
* Weaker 16-byte transformation, also using two 32-byte salts, but |
79 |
* only using a single round of MD5. |
* only using a single round of MD5. |
80 |
*/ |
*/ |
81 |
void sec_hash_16(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2) |
void |
82 |
|
sec_hash_16(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2) |
83 |
{ |
{ |
84 |
MD5_CTX md5; |
MD5_CTX md5; |
85 |
|
|
91 |
} |
} |
92 |
|
|
93 |
/* Reduce key entropy from 64 to 40 bits */ |
/* Reduce key entropy from 64 to 40 bits */ |
94 |
static void sec_make_40bit(uint8 *key) |
static void |
95 |
|
sec_make_40bit(uint8 *key) |
96 |
{ |
{ |
97 |
key[0] = 0xd1; |
key[0] = 0xd1; |
98 |
key[1] = 0x26; |
key[1] = 0x26; |
100 |
} |
} |
101 |
|
|
102 |
/* Generate a session key and RC4 keys, given client and server randoms */ |
/* Generate a session key and RC4 keys, given client and server randoms */ |
103 |
static void sec_generate_keys(uint8 *client_key, uint8 *server_key, |
static void |
104 |
int rc4_key_size) |
sec_generate_keys(uint8 *client_key, uint8 *server_key, int rc4_key_size) |
105 |
{ |
{ |
106 |
uint8 session_key[48]; |
uint8 session_key[48]; |
107 |
uint8 temp_hash[48]; |
uint8 temp_hash[48]; |
108 |
uint8 input[48]; |
uint8 input[48]; |
109 |
|
|
110 |
/* Construct input data to hash */ |
/* Construct input data to hash */ |
111 |
memcpy(input, client_key, 24); |
memcpy(input, client_key, 24); |
112 |
memcpy(input+24, server_key, 24); |
memcpy(input + 24, server_key, 24); |
113 |
|
|
114 |
/* Generate session key - two rounds of sec_hash_48 */ |
/* Generate session key - two rounds of sec_hash_48 */ |
115 |
sec_hash_48(temp_hash, input, client_key, server_key, 65); |
sec_hash_48(temp_hash, input, client_key, server_key, 65); |
116 |
sec_hash_48(session_key, temp_hash, client_key, server_key, 88); |
sec_hash_48(session_key, temp_hash, client_key, server_key, 88); |
117 |
|
|
118 |
/* Store first 8 bytes of session key, for generating signatures */ |
/* Store first 8 bytes of session key, for generating signatures */ |
119 |
memcpy(sec_sign_key, session_key, 8); |
memcpy(sec_sign_key, session_key, 8); |
120 |
|
|
121 |
/* Generate RC4 keys */ |
/* Generate RC4 keys */ |
122 |
sec_hash_16(sec_decrypt_key, &session_key[16], client_key, server_key); |
sec_hash_16(sec_decrypt_key, &session_key[16], client_key, |
123 |
sec_hash_16(sec_encrypt_key, &session_key[32], client_key, server_key); |
server_key); |
124 |
|
sec_hash_16(sec_encrypt_key, &session_key[32], client_key, |
125 |
|
server_key); |
126 |
|
|
127 |
if (rc4_key_size == 1) |
if (rc4_key_size == 1) |
128 |
{ |
{ |
147 |
RC4_set_key(&rc4_encrypt_key, rc4_key_len, sec_encrypt_key); |
RC4_set_key(&rc4_encrypt_key, rc4_key_len, sec_encrypt_key); |
148 |
} |
} |
149 |
|
|
150 |
static uint8 pad_54[40] = |
static uint8 pad_54[40] = { |
151 |
{ |
54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, |
152 |
54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54, |
54, 54, 54, |
153 |
54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54 |
54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, |
154 |
|
54, 54, 54 |
155 |
}; |
}; |
156 |
|
|
157 |
static uint8 pad_92[48] = |
static uint8 pad_92[48] = { |
158 |
{ |
92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, |
159 |
92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92, |
92, 92, 92, 92, 92, 92, 92, |
160 |
92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92 |
92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, |
161 |
|
92, 92, 92, 92, 92, 92, 92 |
162 |
}; |
}; |
163 |
|
|
164 |
/* Output a uint32 into a buffer (little-endian) */ |
/* Output a uint32 into a buffer (little-endian) */ |
165 |
void buf_out_uint32(uint8 *buffer, uint32 value) |
void |
166 |
|
buf_out_uint32(uint8 *buffer, uint32 value) |
167 |
{ |
{ |
168 |
buffer[0] = (value) & 0xff; |
buffer[0] = (value) & 0xff; |
169 |
buffer[1] = (value >> 8) & 0xff; |
buffer[1] = (value >> 8) & 0xff; |
172 |
} |
} |
173 |
|
|
174 |
/* Generate a signature hash, using a combination of SHA1 and MD5 */ |
/* Generate a signature hash, using a combination of SHA1 and MD5 */ |
175 |
void sec_sign(uint8 *signature, uint8 *session_key, int length, |
void |
176 |
uint8 *data, int datalen) |
sec_sign(uint8 *signature, uint8 *session_key, int length, |
177 |
|
uint8 *data, int datalen) |
178 |
{ |
{ |
179 |
uint8 shasig[20]; |
uint8 shasig[20]; |
180 |
uint8 md5sig[16]; |
uint8 md5sig[16]; |
182 |
SHA_CTX sha; |
SHA_CTX sha; |
183 |
MD5_CTX md5; |
MD5_CTX md5; |
184 |
|
|
185 |
buf_out_uint32(lenhdr, datalen); |
buf_out_uint32(lenhdr, datalen); |
186 |
|
|
187 |
SHA1_Init(&sha); |
SHA1_Init(&sha); |
188 |
SHA1_Update(&sha, session_key, length); |
SHA1_Update(&sha, session_key, length); |
201 |
} |
} |
202 |
|
|
203 |
/* Update an encryption key - similar to the signing process */ |
/* Update an encryption key - similar to the signing process */ |
204 |
static void sec_update(uint8 *key, uint8 *update_key) |
static void |
205 |
|
sec_update(uint8 *key, uint8 *update_key) |
206 |
{ |
{ |
207 |
uint8 shasig[20]; |
uint8 shasig[20]; |
208 |
SHA_CTX sha; |
SHA_CTX sha; |
229 |
} |
} |
230 |
|
|
231 |
/* Encrypt data using RC4 */ |
/* Encrypt data using RC4 */ |
232 |
static void sec_encrypt(uint8 *data, int length) |
static void |
233 |
|
sec_encrypt(uint8 *data, int length) |
234 |
{ |
{ |
235 |
static int use_count; |
static int use_count; |
236 |
|
|
246 |
} |
} |
247 |
|
|
248 |
/* Decrypt data using RC4 */ |
/* Decrypt data using RC4 */ |
249 |
static void sec_decrypt(uint8 *data, int length) |
static void |
250 |
|
sec_decrypt(uint8 *data, int length) |
251 |
{ |
{ |
252 |
static int use_count; |
static int use_count; |
253 |
|
|
263 |
} |
} |
264 |
|
|
265 |
/* Read in a NUMBER from a buffer */ |
/* Read in a NUMBER from a buffer */ |
266 |
static void sec_read_number(NUMBER *num, uint8 *buffer, int len) |
static void |
267 |
|
sec_read_number(NUMBER * num, uint8 *buffer, int len) |
268 |
{ |
{ |
269 |
INT *data = num->n_part; |
INT *data = num->n_part; |
270 |
int i, j; |
int i, j; |
271 |
|
|
272 |
for (i = 0, j = 0; j < len; i++, j += 2) |
for (i = 0, j = 0; j < len; i++, j += 2) |
273 |
data[i] = buffer[j] | (buffer[j+1] << 8); |
data[i] = buffer[j] | (buffer[j + 1] << 8); |
274 |
|
|
275 |
num->n_len = i; |
num->n_len = i; |
276 |
} |
} |
277 |
|
|
278 |
/* Write a NUMBER to a buffer */ |
/* Write a NUMBER to a buffer */ |
279 |
static void sec_write_number(NUMBER *num, uint8 *buffer, int len) |
static void |
280 |
|
sec_write_number(NUMBER * num, uint8 *buffer, int len) |
281 |
{ |
{ |
282 |
INT *data = num->n_part; |
INT *data = num->n_part; |
283 |
int i, j; |
int i, j; |
285 |
for (i = 0, j = 0; j < len; i++, j += 2) |
for (i = 0, j = 0; j < len; i++, j += 2) |
286 |
{ |
{ |
287 |
buffer[j] = data[i] & 0xff; |
buffer[j] = data[i] & 0xff; |
288 |
buffer[j+1] = data[i] >> 8; |
buffer[j + 1] = data[i] >> 8; |
289 |
} |
} |
290 |
} |
} |
291 |
|
|
292 |
/* Perform an RSA public key encryption operation */ |
/* Perform an RSA public key encryption operation */ |
293 |
static void sec_rsa_encrypt(uint8 *out, uint8 *in, int len, |
static void |
294 |
uint8 *modulus, uint8 *exponent) |
sec_rsa_encrypt(uint8 *out, uint8 *in, int len, |
295 |
|
uint8 *modulus, uint8 *exponent) |
296 |
{ |
{ |
297 |
NUMBER data, key; |
NUMBER data, key; |
298 |
|
|
308 |
} |
} |
309 |
|
|
310 |
/* Initialise secure transport packet */ |
/* Initialise secure transport packet */ |
311 |
STREAM sec_init(uint32 flags, int maxlen) |
STREAM |
312 |
|
sec_init(uint32 flags, int maxlen) |
313 |
{ |
{ |
314 |
int hdrlen; |
int hdrlen; |
315 |
STREAM s; |
STREAM s; |
316 |
|
|
317 |
hdrlen = (flags & SEC_ENCRYPT) ? 12 : 4; |
if (!licence_issued) |
318 |
s = mcs_init(maxlen + hdrlen); |
hdrlen = (flags & SEC_ENCRYPT) ? 12 : 4; |
319 |
|
else |
320 |
|
hdrlen = (flags & SEC_ENCRYPT) ? 12 : 0; |
321 |
|
s = mcs_init(maxlen + hdrlen); |
322 |
s_push_layer(s, sec_hdr, hdrlen); |
s_push_layer(s, sec_hdr, hdrlen); |
323 |
|
|
324 |
return s; |
return s; |
325 |
} |
} |
326 |
|
|
327 |
/* Transmit secure transport packet */ |
/* Transmit secure transport packet */ |
328 |
void sec_send(STREAM s, uint32 flags) |
void |
329 |
|
sec_send(STREAM s, uint32 flags) |
330 |
{ |
{ |
331 |
int datalen; |
int datalen; |
332 |
|
|
333 |
s_pop_layer(s, sec_hdr); |
s_pop_layer(s, sec_hdr); |
334 |
out_uint32_le(s, flags); |
if (!licence_issued || (flags & SEC_ENCRYPT)) |
335 |
|
out_uint32_le(s, flags); |
336 |
|
|
337 |
if (flags & SEC_ENCRYPT) |
if (flags & SEC_ENCRYPT) |
338 |
{ |
{ |
341 |
|
|
342 |
#if RDP_DEBUG |
#if RDP_DEBUG |
343 |
DEBUG("Sending encrypted packet:\n"); |
DEBUG("Sending encrypted packet:\n"); |
344 |
hexdump(s->p+8, datalen); |
hexdump(s->p + 8, datalen); |
345 |
#endif |
#endif |
346 |
|
|
347 |
sec_sign(s->p, sec_sign_key, 8, s->p+8, datalen); |
sec_sign(s->p, sec_sign_key, 8, s->p + 8, datalen); |
348 |
sec_encrypt(s->p+8, datalen); |
sec_encrypt(s->p + 8, datalen); |
349 |
} |
} |
350 |
|
|
351 |
mcs_send(s); |
mcs_send(s); |
352 |
} |
} |
353 |
|
|
354 |
/* Transfer the client random to the server */ |
/* Transfer the client random to the server */ |
355 |
static void sec_establish_key() |
static void |
356 |
|
sec_establish_key() |
357 |
{ |
{ |
358 |
uint32 length = SEC_MODULUS_SIZE + SEC_PADDING_SIZE; |
uint32 length = SEC_MODULUS_SIZE + SEC_PADDING_SIZE; |
359 |
uint32 flags = SEC_CLIENT_RANDOM; |
uint32 flags = SEC_CLIENT_RANDOM; |
370 |
} |
} |
371 |
|
|
372 |
/* Output connect initial data blob */ |
/* Output connect initial data blob */ |
373 |
static void sec_out_mcs_data(STREAM s) |
static void |
374 |
|
sec_out_mcs_data(STREAM s) |
375 |
{ |
{ |
376 |
int hostlen = 2 * strlen(hostname); |
int hostlen = 2 * strlen(hostname); |
377 |
|
|
380 |
out_uint8(s, 0x7c); |
out_uint8(s, 0x7c); |
381 |
out_uint16_be(s, 1); |
out_uint16_be(s, 1); |
382 |
|
|
383 |
out_uint16_be(s, (158 | 0x8000)); /* remaining length */ |
out_uint16_be(s, (158 | 0x8000)); /* remaining length */ |
384 |
|
|
385 |
out_uint16_be(s, 8); /* length? */ |
out_uint16_be(s, 8); /* length? */ |
386 |
out_uint16_be(s, 16); |
out_uint16_be(s, 16); |
388 |
out_uint16_le(s, 0xc001); |
out_uint16_le(s, 0xc001); |
389 |
out_uint8(s, 0); |
out_uint8(s, 0); |
390 |
|
|
391 |
out_uint32_le(s, 0x61637544); /* "Duca" ?! */ |
out_uint32_le(s, 0x61637544); /* "Duca" ?! */ |
392 |
out_uint16_be(s, (144 | 0x8000)); /* remaining length */ |
out_uint16_be(s, (144 | 0x8000)); /* remaining length */ |
393 |
|
|
394 |
/* Client information */ |
/* Client information */ |
395 |
out_uint16_le(s, SEC_TAG_CLI_INFO); |
out_uint16_le(s, SEC_TAG_CLI_INFO); |
401 |
out_uint16_le(s, 0xca01); |
out_uint16_le(s, 0xca01); |
402 |
out_uint16_le(s, 0xaa03); |
out_uint16_le(s, 0xaa03); |
403 |
out_uint32_le(s, keylayout); |
out_uint32_le(s, keylayout); |
404 |
out_uint32_le(s, 419); /* client build? we are 419 compatible :-) */ |
out_uint32_le(s, 419); /* client build? we are 419 compatible :-) */ |
405 |
|
|
406 |
/* Unicode name of client, padded to 32 bytes */ |
/* Unicode name of client, padded to 32 bytes */ |
407 |
rdp_out_unistr(s, hostname, hostlen); |
rdp_out_unistr(s, hostname, hostlen); |
408 |
out_uint8s(s, 30-hostlen); |
out_uint8s(s, 30 - hostlen); |
409 |
|
|
410 |
out_uint32_le(s, 4); |
out_uint32_le(s, 4); |
411 |
out_uint32(s, 0); |
out_uint32(s, 0); |
412 |
out_uint32_le(s, 12); |
out_uint32_le(s, 12); |
413 |
out_uint8s(s, 64); /* reserved? 4 + 12 doublewords */ |
out_uint8s(s, 64); /* reserved? 4 + 12 doublewords */ |
414 |
|
|
415 |
out_uint16(s, 0xca01); |
out_uint16(s, 0xca01); |
416 |
out_uint16(s, 0); |
out_uint16(s, 0); |
418 |
/* Client encryption settings */ |
/* Client encryption settings */ |
419 |
out_uint16_le(s, SEC_TAG_CLI_CRYPT); |
out_uint16_le(s, SEC_TAG_CLI_CRYPT); |
420 |
out_uint16(s, 8); /* length */ |
out_uint16(s, 8); /* length */ |
421 |
out_uint32_le(s, 1); /* encryption enabled */ |
out_uint32_le(s, use_encryption ? 1 : 0); /* encryption enabled */ |
422 |
s_mark_end(s); |
s_mark_end(s); |
423 |
} |
} |
424 |
|
|
425 |
/* Parse a public key structure */ |
/* Parse a public key structure */ |
426 |
static BOOL sec_parse_public_key(STREAM s, uint8 **modulus, uint8 **exponent) |
static BOOL |
427 |
|
sec_parse_public_key(STREAM s, uint8 **modulus, uint8 **exponent) |
428 |
{ |
{ |
429 |
uint32 magic, modulus_len; |
uint32 magic, modulus_len; |
430 |
|
|
442 |
return False; |
return False; |
443 |
} |
} |
444 |
|
|
445 |
in_uint8s(s, 8); /* modulus_bits, unknown */ |
in_uint8s(s, 8); /* modulus_bits, unknown */ |
446 |
in_uint8p(s, *exponent, SEC_EXPONENT_SIZE); |
in_uint8p(s, *exponent, SEC_EXPONENT_SIZE); |
447 |
in_uint8p(s, *modulus, SEC_MODULUS_SIZE); |
in_uint8p(s, *modulus, SEC_MODULUS_SIZE); |
448 |
in_uint8s(s, SEC_PADDING_SIZE); |
in_uint8s(s, SEC_PADDING_SIZE); |
451 |
} |
} |
452 |
|
|
453 |
/* Parse a crypto information structure */ |
/* Parse a crypto information structure */ |
454 |
static BOOL sec_parse_crypt_info(STREAM s, uint32 *rc4_key_size, |
static BOOL |
455 |
uint8 **server_random, uint8 **modulus, uint8 **exponent) |
sec_parse_crypt_info(STREAM s, uint32 *rc4_key_size, |
456 |
|
uint8 **server_random, uint8 **modulus, uint8 **exponent) |
457 |
{ |
{ |
458 |
uint32 crypt_level, random_len, rsa_info_len; |
uint32 crypt_level, random_len, rsa_info_len; |
459 |
uint16 tag, length; |
uint16 tag, length; |
460 |
uint8 *next_tag, *end; |
uint8 *next_tag, *end; |
461 |
|
|
462 |
in_uint32_le(s, *rc4_key_size); /* 1 = 40-bit, 2 = 128-bit */ |
in_uint32_le(s, *rc4_key_size); /* 1 = 40-bit, 2 = 128-bit */ |
463 |
in_uint32_le(s, crypt_level); /* 1 = low, 2 = medium, 3 = high */ |
in_uint32_le(s, crypt_level); /* 1 = low, 2 = medium, 3 = high */ |
464 |
in_uint32_le(s, random_len); |
in_uint32_le(s, random_len); |
465 |
in_uint32_le(s, rsa_info_len); |
in_uint32_le(s, rsa_info_len); |
466 |
|
|
477 |
if (end > s->end) |
if (end > s->end) |
478 |
return False; |
return False; |
479 |
|
|
480 |
in_uint8s(s, 12); /* unknown */ |
in_uint8s(s, 12); /* unknown */ |
481 |
|
|
482 |
while (s->p < end) |
while (s->p < end) |
483 |
{ |
{ |
489 |
switch (tag) |
switch (tag) |
490 |
{ |
{ |
491 |
case SEC_TAG_PUBKEY: |
case SEC_TAG_PUBKEY: |
492 |
if (!sec_parse_public_key(s, modulus, exponent)) |
if (!sec_parse_public_key |
493 |
|
(s, modulus, exponent)) |
494 |
return False; |
return False; |
495 |
|
|
496 |
break; |
break; |
511 |
} |
} |
512 |
|
|
513 |
/* Process crypto information blob */ |
/* Process crypto information blob */ |
514 |
static void sec_process_crypt_info(STREAM s) |
static void |
515 |
|
sec_process_crypt_info(STREAM s) |
516 |
{ |
{ |
517 |
uint8 *server_random, *modulus, *exponent; |
uint8 *server_random, *modulus, *exponent; |
518 |
uint8 client_random[SEC_RANDOM_SIZE]; |
uint8 client_random[SEC_RANDOM_SIZE]; |
519 |
uint32 rc4_key_size; |
uint32 rc4_key_size; |
520 |
|
|
521 |
if (!sec_parse_crypt_info(s, &rc4_key_size, &server_random, |
if (!sec_parse_crypt_info(s, &rc4_key_size, &server_random, |
522 |
&modulus, &exponent)) |
&modulus, &exponent)) |
523 |
return; |
return; |
524 |
|
|
525 |
/* Generate a client random, and hence determine encryption keys */ |
/* Generate a client random, and hence determine encryption keys */ |
526 |
generate_random(client_random); |
generate_random(client_random); |
527 |
sec_rsa_encrypt(sec_crypted_random, client_random, |
sec_rsa_encrypt(sec_crypted_random, client_random, |
528 |
SEC_RANDOM_SIZE, modulus, exponent); |
SEC_RANDOM_SIZE, modulus, exponent); |
529 |
sec_generate_keys(client_random, server_random, rc4_key_size); |
sec_generate_keys(client_random, server_random, rc4_key_size); |
530 |
} |
} |
531 |
|
|
532 |
/* Process connect response data blob */ |
/* Process connect response data blob */ |
533 |
static void sec_process_mcs_data(STREAM s) |
static void |
534 |
|
sec_process_mcs_data(STREAM s) |
535 |
{ |
{ |
536 |
uint16 tag, length; |
uint16 tag, length; |
537 |
uint8 *next_tag; |
uint8 *next_tag; |
538 |
|
|
539 |
in_uint8s(s, 23); /* header */ |
in_uint8s(s, 23); /* header */ |
540 |
|
|
541 |
while (s->p < s->end) |
while (s->p < s->end) |
542 |
{ |
{ |
567 |
} |
} |
568 |
|
|
569 |
/* Receive secure transport packet */ |
/* Receive secure transport packet */ |
570 |
STREAM sec_recv() |
STREAM |
571 |
|
sec_recv() |
572 |
{ |
{ |
573 |
uint32 sec_flags; |
uint32 sec_flags; |
574 |
STREAM s; |
STREAM s; |
575 |
|
|
576 |
while ((s = mcs_recv()) != NULL) |
while ((s = mcs_recv()) != NULL) |
577 |
{ |
{ |
578 |
in_uint32_le(s, sec_flags); |
if (use_encryption || !licence_issued) |
|
|
|
|
if (sec_flags & SEC_LICENCE_NEG) |
|
579 |
{ |
{ |
580 |
licence_process(s); |
in_uint32_le(s, sec_flags); |
|
continue; |
|
|
} |
|
581 |
|
|
582 |
if (sec_flags & SEC_ENCRYPT) |
if (sec_flags & SEC_LICENCE_NEG) |
583 |
{ |
{ |
584 |
in_uint8s(s, 8); /* signature */ |
licence_process(s); |
585 |
sec_decrypt(s->p, s->end - s->p); |
continue; |
586 |
|
} |
587 |
|
|
588 |
|
if (sec_flags & SEC_ENCRYPT) |
589 |
|
{ |
590 |
|
in_uint8s(s, 8); /* signature */ |
591 |
|
sec_decrypt(s->p, s->end - s->p); |
592 |
|
} |
593 |
} |
} |
594 |
|
|
595 |
return s; |
return s; |
599 |
} |
} |
600 |
|
|
601 |
/* Establish a secure connection */ |
/* Establish a secure connection */ |
602 |
BOOL sec_connect(char *server) |
BOOL |
603 |
|
sec_connect(char *server) |
604 |
{ |
{ |
605 |
struct stream mcs_data; |
struct stream mcs_data; |
606 |
|
|
613 |
return False; |
return False; |
614 |
|
|
615 |
sec_process_mcs_data(&mcs_data); |
sec_process_mcs_data(&mcs_data); |
616 |
sec_establish_key(); |
if (use_encryption) |
617 |
|
sec_establish_key(); |
618 |
return True; |
return True; |
619 |
} |
} |
620 |
|
|
621 |
/* Disconnect a connection */ |
/* Disconnect a connection */ |
622 |
void sec_disconnect() |
void |
623 |
|
sec_disconnect() |
624 |
{ |
{ |
625 |
mcs_disconnect(); |
mcs_disconnect(); |
626 |
} |
} |