127 |
memcpy(sec_sign_key, session_key, 16); |
memcpy(sec_sign_key, session_key, 16); |
128 |
|
|
129 |
/* Generate RC4 keys */ |
/* Generate RC4 keys */ |
130 |
sec_hash_16(sec_decrypt_key, &session_key[16], client_key, |
sec_hash_16(sec_decrypt_key, &session_key[16], client_key, server_key); |
131 |
server_key); |
sec_hash_16(sec_encrypt_key, &session_key[32], client_key, server_key); |
|
sec_hash_16(sec_encrypt_key, &session_key[32], client_key, |
|
|
server_key); |
|
132 |
|
|
133 |
if (rc4_key_size == 1) |
if (rc4_key_size == 1) |
134 |
{ |
{ |
179 |
|
|
180 |
/* Generate a signature hash, using a combination of SHA1 and MD5 */ |
/* Generate a signature hash, using a combination of SHA1 and MD5 */ |
181 |
void |
void |
182 |
sec_sign(uint8 * signature, int siglen, uint8 * session_key, int keylen, |
sec_sign(uint8 * signature, int siglen, uint8 * session_key, int keylen, uint8 * data, int datalen) |
|
uint8 * data, int datalen) |
|
183 |
{ |
{ |
184 |
uint8 shasig[20]; |
uint8 shasig[20]; |
185 |
uint8 md5sig[16]; |
uint8 md5sig[16]; |
283 |
|
|
284 |
/* Perform an RSA public key encryption operation */ |
/* Perform an RSA public key encryption operation */ |
285 |
static void |
static void |
286 |
sec_rsa_encrypt(uint8 * out, uint8 * in, int len, |
sec_rsa_encrypt(uint8 * out, uint8 * in, int len, uint8 * modulus, uint8 * exponent) |
|
uint8 * modulus, uint8 * exponent) |
|
287 |
{ |
{ |
288 |
BN_CTX ctx; |
BN_CTX ctx; |
289 |
BIGNUM mod, exp, x, y; |
BIGNUM mod, exp, x, y; |
354 |
hexdump(s->p + 8, datalen); |
hexdump(s->p + 8, datalen); |
355 |
#endif |
#endif |
356 |
|
|
357 |
sec_sign(s->p, 8, sec_sign_key, rc4_key_len, s->p + 8, |
sec_sign(s->p, 8, sec_sign_key, rc4_key_len, s->p + 8, datalen); |
|
datalen); |
|
358 |
sec_encrypt(s->p + 8, datalen); |
sec_encrypt(s->p + 8, datalen); |
359 |
} |
} |
360 |
|
|
385 |
{ |
{ |
386 |
int hostlen = 2 * strlen(hostname); |
int hostlen = 2 * strlen(hostname); |
387 |
|
|
388 |
|
if (hostlen > 30) |
389 |
|
hostlen = 30; |
390 |
|
|
391 |
out_uint16_be(s, 5); /* unknown */ |
out_uint16_be(s, 5); /* unknown */ |
392 |
out_uint16_be(s, 0x14); |
out_uint16_be(s, 0x14); |
393 |
out_uint8(s, 0x7c); |
out_uint8(s, 0x7c); |
466 |
/* Parse a crypto information structure */ |
/* Parse a crypto information structure */ |
467 |
static BOOL |
static BOOL |
468 |
sec_parse_crypt_info(STREAM s, uint32 * rc4_key_size, |
sec_parse_crypt_info(STREAM s, uint32 * rc4_key_size, |
469 |
uint8 ** server_random, uint8 ** modulus, |
uint8 ** server_random, uint8 ** modulus, uint8 ** exponent) |
|
uint8 ** exponent) |
|
470 |
{ |
{ |
471 |
uint32 crypt_level, random_len, rsa_info_len; |
uint32 crypt_level, random_len, rsa_info_len; |
472 |
uint16 tag, length; |
uint16 tag, length; |
474 |
|
|
475 |
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 */ |
476 |
in_uint32_le(s, crypt_level); /* 1 = low, 2 = medium, 3 = high */ |
in_uint32_le(s, crypt_level); /* 1 = low, 2 = medium, 3 = high */ |
477 |
|
if (crypt_level == 0) /* no encryptation */ |
478 |
|
return False; |
479 |
in_uint32_le(s, random_len); |
in_uint32_le(s, random_len); |
480 |
in_uint32_le(s, rsa_info_len); |
in_uint32_le(s, rsa_info_len); |
481 |
|
|
504 |
switch (tag) |
switch (tag) |
505 |
{ |
{ |
506 |
case SEC_TAG_PUBKEY: |
case SEC_TAG_PUBKEY: |
507 |
if (!sec_parse_public_key |
if (!sec_parse_public_key(s, modulus, exponent)) |
|
(s, modulus, exponent)) |
|
508 |
return False; |
return False; |
509 |
|
|
510 |
break; |
break; |
532 |
uint8 client_random[SEC_RANDOM_SIZE]; |
uint8 client_random[SEC_RANDOM_SIZE]; |
533 |
uint32 rc4_key_size; |
uint32 rc4_key_size; |
534 |
|
|
535 |
if (!sec_parse_crypt_info(s, &rc4_key_size, &server_random, |
if (!sec_parse_crypt_info(s, &rc4_key_size, &server_random, &modulus, &exponent)) |
|
&modulus, &exponent)) |
|
536 |
return; |
return; |
537 |
|
|
538 |
/* Generate a client random, and hence determine encryption keys */ |
/* Generate a client random, and hence determine encryption keys */ |
539 |
generate_random(client_random); |
generate_random(client_random); |
540 |
sec_rsa_encrypt(sec_crypted_random, client_random, |
sec_rsa_encrypt(sec_crypted_random, client_random, SEC_RANDOM_SIZE, modulus, exponent); |
|
SEC_RANDOM_SIZE, modulus, exponent); |
|
541 |
sec_generate_keys(client_random, server_random, rc4_key_size); |
sec_generate_keys(client_random, server_random, rc4_key_size); |
542 |
} |
} |
543 |
|
|
547 |
{ |
{ |
548 |
uint16 tag, length; |
uint16 tag, length; |
549 |
uint8 *next_tag; |
uint8 *next_tag; |
550 |
|
uint8 len; |
551 |
|
|
552 |
in_uint8s(s, 23); /* header */ |
in_uint8s(s, 21); /* header */ |
553 |
|
in_uint8(s, len); |
554 |
|
if (len & 0x80) |
555 |
|
in_uint8(s, len); |
556 |
|
|
557 |
while (s->p < s->end) |
while (s->p < s->end) |
558 |
{ |
{ |