19 |
*/ |
*/ |
20 |
|
|
21 |
#include "rdesktop.h" |
#include "rdesktop.h" |
22 |
#include <openssl/rc4.h> |
#include "ssl.h" |
23 |
|
|
24 |
extern char g_username[64]; |
extern char g_username[64]; |
25 |
extern char g_hostname[16]; |
extern char g_hostname[16]; |
143 |
uint8 hwid[LICENCE_HWID_SIZE]; |
uint8 hwid[LICENCE_HWID_SIZE]; |
144 |
uint8 *licence_data; |
uint8 *licence_data; |
145 |
int licence_size; |
int licence_size; |
146 |
RC4_KEY crypt_key; |
SSL_RC4 crypt_key; |
147 |
|
|
148 |
/* Retrieve the server random from the incoming packet */ |
/* Retrieve the server random from the incoming packet */ |
149 |
in_uint8p(s, server_random, SEC_RANDOM_SIZE); |
in_uint8p(s, server_random, SEC_RANDOM_SIZE); |
161 |
sec_sign(signature, 16, g_licence_sign_key, 16, hwid, sizeof(hwid)); |
sec_sign(signature, 16, g_licence_sign_key, 16, hwid, sizeof(hwid)); |
162 |
|
|
163 |
/* Now encrypt the HWID */ |
/* Now encrypt the HWID */ |
164 |
RC4_set_key(&crypt_key, 16, g_licence_key); |
ssl_rc4_set_key(&crypt_key, g_licence_key, 16); |
165 |
RC4(&crypt_key, sizeof(hwid), hwid, hwid); |
ssl_rc4_crypt(&crypt_key, hwid, hwid, sizeof(hwid)); |
166 |
|
|
167 |
licence_present(null_data, null_data, licence_data, licence_size, hwid, signature); |
licence_present(null_data, null_data, licence_data, licence_size, hwid, signature); |
168 |
xfree(licence_data); |
xfree(licence_data); |
230 |
uint8 hwid[LICENCE_HWID_SIZE], crypt_hwid[LICENCE_HWID_SIZE]; |
uint8 hwid[LICENCE_HWID_SIZE], crypt_hwid[LICENCE_HWID_SIZE]; |
231 |
uint8 sealed_buffer[LICENCE_TOKEN_SIZE + LICENCE_HWID_SIZE]; |
uint8 sealed_buffer[LICENCE_TOKEN_SIZE + LICENCE_HWID_SIZE]; |
232 |
uint8 out_sig[LICENCE_SIGNATURE_SIZE]; |
uint8 out_sig[LICENCE_SIGNATURE_SIZE]; |
233 |
RC4_KEY crypt_key; |
SSL_RC4 crypt_key; |
234 |
|
|
235 |
/* Parse incoming packet and save the encrypted token */ |
/* Parse incoming packet and save the encrypted token */ |
236 |
licence_parse_authreq(s, &in_token, &in_sig); |
licence_parse_authreq(s, &in_token, &in_sig); |
237 |
memcpy(out_token, in_token, LICENCE_TOKEN_SIZE); |
memcpy(out_token, in_token, LICENCE_TOKEN_SIZE); |
238 |
|
|
239 |
/* Decrypt the token. It should read TEST in Unicode. */ |
/* Decrypt the token. It should read TEST in Unicode. */ |
240 |
RC4_set_key(&crypt_key, 16, g_licence_key); |
ssl_rc4_set_key(&crypt_key, g_licence_key, 16); |
241 |
RC4(&crypt_key, LICENCE_TOKEN_SIZE, in_token, decrypt_token); |
ssl_rc4_crypt(&crypt_key, in_token, decrypt_token, LICENCE_TOKEN_SIZE); |
242 |
|
|
243 |
/* Generate a signature for a buffer of token and HWID */ |
/* Generate a signature for a buffer of token and HWID */ |
244 |
licence_generate_hwid(hwid); |
licence_generate_hwid(hwid); |
247 |
sec_sign(out_sig, 16, g_licence_sign_key, 16, sealed_buffer, sizeof(sealed_buffer)); |
sec_sign(out_sig, 16, g_licence_sign_key, 16, sealed_buffer, sizeof(sealed_buffer)); |
248 |
|
|
249 |
/* Now encrypt the HWID */ |
/* Now encrypt the HWID */ |
250 |
RC4_set_key(&crypt_key, 16, g_licence_key); |
ssl_rc4_set_key(&crypt_key, g_licence_key, 16); |
251 |
RC4(&crypt_key, LICENCE_HWID_SIZE, hwid, crypt_hwid); |
ssl_rc4_crypt(&crypt_key, hwid, crypt_hwid, LICENCE_HWID_SIZE); |
252 |
|
|
253 |
licence_send_authresp(out_token, crypt_hwid, out_sig); |
licence_send_authresp(out_token, crypt_hwid, out_sig); |
254 |
} |
} |
257 |
static void |
static void |
258 |
licence_process_issue(STREAM s) |
licence_process_issue(STREAM s) |
259 |
{ |
{ |
260 |
RC4_KEY crypt_key; |
SSL_RC4 crypt_key; |
261 |
uint32 length; |
uint32 length; |
262 |
uint16 check; |
uint16 check; |
263 |
int i; |
int i; |
267 |
if (!s_check_rem(s, length)) |
if (!s_check_rem(s, length)) |
268 |
return; |
return; |
269 |
|
|
270 |
RC4_set_key(&crypt_key, 16, g_licence_key); |
ssl_rc4_set_key(&crypt_key, g_licence_key, 16); |
271 |
RC4(&crypt_key, length, s->p, s->p); |
ssl_rc4_crypt(&crypt_key, s->p, s->p, length); |
272 |
|
|
273 |
in_uint16(s, check); |
in_uint16(s, check); |
274 |
if (check != 0) |
if (check != 0) |