1 |
/* |
/* |
2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
RDP licensing negotiation |
RDP licensing negotiation |
4 |
Copyright (C) Matthew Chapman 1999-2002 |
Copyright (C) Matthew Chapman 1999-2005 |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
7 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
19 |
*/ |
*/ |
20 |
|
|
21 |
#include "rdesktop.h" |
#include "rdesktop.h" |
|
|
|
|
#ifdef WITH_OPENSSL |
|
22 |
#include <openssl/rc4.h> |
#include <openssl/rc4.h> |
|
#else |
|
|
#include "crypto/rc4.h" |
|
|
#endif |
|
23 |
|
|
24 |
extern char g_username[16]; |
extern char g_username[64]; |
25 |
extern char hostname[16]; |
extern char g_hostname[16]; |
26 |
|
|
27 |
static uint8 g_licence_key[16]; |
static uint8 g_licence_key[16]; |
28 |
static uint8 g_licence_sign_key[16]; |
static uint8 g_licence_sign_key[16]; |
31 |
|
|
32 |
/* Generate a session key and RC4 keys, given client and server randoms */ |
/* Generate a session key and RC4 keys, given client and server randoms */ |
33 |
static void |
static void |
34 |
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) |
35 |
{ |
{ |
36 |
uint8 session_key[48]; |
uint8 master_secret[48]; |
37 |
uint8 temp_hash[48]; |
uint8 key_block[48]; |
38 |
|
|
39 |
/* Generate session key - two rounds of sec_hash_48 */ |
/* Generate master secret and then key material */ |
40 |
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'); |
41 |
sec_hash_48(session_key, temp_hash, server_key, client_key, 65); |
sec_hash_48(key_block, master_secret, server_random, client_random, 'A'); |
42 |
|
|
43 |
/* Store first 16 bytes of session key, for generating signatures */ |
/* Store first 16 bytes of session key as MAC secret */ |
44 |
memcpy(g_licence_sign_key, session_key, 16); |
memcpy(g_licence_sign_key, key_block, 16); |
45 |
|
|
46 |
/* Generate RC4 key */ |
/* Generate RC4 key from next 16 bytes */ |
47 |
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); |
48 |
} |
} |
49 |
|
|
50 |
static void |
static void |
51 |
licence_generate_hwid(uint8 * hwid) |
licence_generate_hwid(uint8 * hwid) |
52 |
{ |
{ |
53 |
buf_out_uint32(hwid, 2); |
buf_out_uint32(hwid, 2); |
54 |
strncpy((char *) (hwid + 4), hostname, LICENCE_HWID_SIZE - 4); |
strncpy((char *) (hwid + 4), g_hostname, LICENCE_HWID_SIZE - 4); |
55 |
} |
} |
56 |
|
|
57 |
/* Present an existing licence to the server */ |
/* Present an existing licence to the server */ |
169 |
return; |
return; |
170 |
} |
} |
171 |
|
|
172 |
licence_send_request(null_data, null_data, g_username, hostname); |
licence_send_request(null_data, null_data, g_username, g_hostname); |
173 |
} |
} |
174 |
|
|
175 |
/* Send an authentication response packet */ |
/* Send an authentication response packet */ |