26 |
#include "crypto/rc4.h" |
#include "crypto/rc4.h" |
27 |
#endif |
#endif |
28 |
|
|
29 |
extern char username[16]; |
extern char g_username[16]; |
30 |
extern char hostname[16]; |
extern char hostname[16]; |
31 |
|
|
32 |
static uint8 g_licence_key[16]; |
static uint8 g_licence_key[16]; |
36 |
|
|
37 |
/* Generate a session key and RC4 keys, given client and server randoms */ |
/* Generate a session key and RC4 keys, given client and server randoms */ |
38 |
static void |
static void |
39 |
licence_generate_keys(uint8 * client_key, uint8 * server_key, uint8 * client_rsa) |
licence_generate_keys(uint8 * client_random, uint8 * server_random, uint8 * pre_master_secret) |
40 |
{ |
{ |
41 |
uint8 session_key[48]; |
uint8 master_secret[48]; |
42 |
uint8 temp_hash[48]; |
uint8 key_block[48]; |
43 |
|
|
44 |
/* Generate session key - two rounds of sec_hash_48 */ |
/* Generate master secret and then key material */ |
45 |
sec_hash_48(temp_hash, client_rsa, client_key, server_key, 65); |
sec_hash_48(master_secret, pre_master_secret, client_random, server_random, 'A'); |
46 |
sec_hash_48(session_key, temp_hash, server_key, client_key, 65); |
sec_hash_48(key_block, master_secret, server_random, client_random, 'A'); |
47 |
|
|
48 |
/* Store first 16 bytes of session key, for generating signatures */ |
/* Store first 16 bytes of session key as MAC secret */ |
49 |
memcpy(g_licence_sign_key, session_key, 16); |
memcpy(g_licence_sign_key, key_block, 16); |
50 |
|
|
51 |
/* Generate RC4 key */ |
/* Generate RC4 key from next 16 bytes */ |
52 |
sec_hash_16(g_licence_key, &session_key[16], client_key, server_key); |
sec_hash_16(g_licence_key, &key_block[16], client_random, server_random); |
53 |
} |
} |
54 |
|
|
55 |
static void |
static void |
73 |
s = sec_init(sec_flags, length + 4); |
s = sec_init(sec_flags, length + 4); |
74 |
|
|
75 |
out_uint8(s, LICENCE_TAG_PRESENT); |
out_uint8(s, LICENCE_TAG_PRESENT); |
76 |
out_uint8(s, 2); /* version */ |
out_uint8(s, 2); /* version */ |
77 |
out_uint16_le(s, length); |
out_uint16_le(s, length); |
78 |
|
|
79 |
out_uint32_le(s, 1); |
out_uint32_le(s, 1); |
113 |
s = sec_init(sec_flags, length + 2); |
s = sec_init(sec_flags, length + 2); |
114 |
|
|
115 |
out_uint8(s, LICENCE_TAG_REQUEST); |
out_uint8(s, LICENCE_TAG_REQUEST); |
116 |
out_uint8(s, 2); /* version */ |
out_uint8(s, 2); /* version */ |
117 |
out_uint16_le(s, length); |
out_uint16_le(s, length); |
118 |
|
|
119 |
out_uint32_le(s, 1); |
out_uint32_le(s, 1); |
174 |
return; |
return; |
175 |
} |
} |
176 |
|
|
177 |
licence_send_request(null_data, null_data, username, hostname); |
licence_send_request(null_data, null_data, g_username, hostname); |
178 |
} |
} |
179 |
|
|
180 |
/* Send an authentication response packet */ |
/* Send an authentication response packet */ |
188 |
s = sec_init(sec_flags, length + 2); |
s = sec_init(sec_flags, length + 2); |
189 |
|
|
190 |
out_uint8(s, LICENCE_TAG_AUTHRESP); |
out_uint8(s, LICENCE_TAG_AUTHRESP); |
191 |
out_uint8(s, 2); /* version */ |
out_uint8(s, 2); /* version */ |
192 |
out_uint16_le(s, length); |
out_uint16_le(s, length); |
193 |
|
|
194 |
out_uint16_le(s, 1); |
out_uint16_le(s, 1); |