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-2000 |
Copyright (C) Matthew Chapman 1999-2001 |
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 |
28 |
static uint8 licence_key[16]; |
static uint8 licence_key[16]; |
29 |
static uint8 licence_sign_key[16]; |
static uint8 licence_sign_key[16]; |
30 |
|
|
31 |
|
BOOL licence_issued = False; |
32 |
|
|
33 |
/* Generate a session key and RC4 keys, given client and server randoms */ |
/* Generate a session key and RC4 keys, given client and server randoms */ |
34 |
void licence_generate_keys(uint8 *client_key, uint8 *server_key, |
void |
35 |
uint8 *client_rsa) |
licence_generate_keys(uint8 *client_key, uint8 *server_key, uint8 *client_rsa) |
36 |
{ |
{ |
37 |
uint8 session_key[48]; |
uint8 session_key[48]; |
38 |
uint8 temp_hash[48]; |
uint8 temp_hash[48]; |
39 |
|
|
40 |
/* Generate session key - two rounds of sec_hash_48 */ |
/* Generate session key - two rounds of sec_hash_48 */ |
41 |
sec_hash_48(temp_hash, client_rsa, client_key, server_key, 65); |
sec_hash_48(temp_hash, client_rsa, client_key, server_key, 65); |
42 |
sec_hash_48(session_key, temp_hash, server_key, client_key, 65); |
sec_hash_48(session_key, temp_hash, server_key, client_key, 65); |
43 |
|
|
44 |
/* Store first 16 bytes of session key, for generating signatures */ |
/* Store first 16 bytes of session key, for generating signatures */ |
45 |
memcpy(licence_sign_key, session_key, 16); |
memcpy(licence_sign_key, session_key, 16); |
46 |
|
|
47 |
/* Generate RC4 key */ |
/* Generate RC4 key */ |
48 |
sec_hash_16(licence_key, &session_key[16], client_key, server_key); |
sec_hash_16(licence_key, &session_key[16], client_key, server_key); |
49 |
} |
} |
50 |
|
|
51 |
/* Send a licence request packet */ |
/* Send a licence request packet */ |
52 |
static void licence_send_request(uint8 *client_random, uint8 *rsa_data, |
static void |
53 |
char *user, char *host) |
licence_send_request(uint8 *client_random, uint8 *rsa_data, |
54 |
|
char *user, char *host) |
55 |
{ |
{ |
56 |
uint32 sec_flags = SEC_LICENCE_NEG; |
uint32 sec_flags = SEC_LICENCE_NEG; |
57 |
uint16 userlen = strlen(user) + 1; |
uint16 userlen = strlen(user) + 1; |
86 |
} |
} |
87 |
|
|
88 |
/* Process a licence demand packet */ |
/* Process a licence demand packet */ |
89 |
static void licence_process_demand(STREAM s) |
static void |
90 |
|
licence_process_demand(STREAM s) |
91 |
{ |
{ |
92 |
uint8 null_data[SEC_MODULUS_SIZE]; |
uint8 null_data[SEC_MODULUS_SIZE]; |
93 |
uint8 *server_random; |
uint8 *server_random; |
105 |
} |
} |
106 |
|
|
107 |
/* Send an authentication response packet */ |
/* Send an authentication response packet */ |
108 |
static void licence_send_authresp(uint8 *token, uint8 *crypt_hwid, |
static void |
109 |
uint8 *signature) |
licence_send_authresp(uint8 *token, uint8 *crypt_hwid, uint8 *signature) |
110 |
{ |
{ |
111 |
uint32 sec_flags = SEC_LICENCE_NEG; |
uint32 sec_flags = SEC_LICENCE_NEG; |
112 |
uint16 length = 58; |
uint16 length = 58; |
132 |
} |
} |
133 |
|
|
134 |
/* Parse an authentication request packet */ |
/* Parse an authentication request packet */ |
135 |
static BOOL licence_parse_authreq(STREAM s, uint8 **token, uint8 **signature) |
static BOOL |
136 |
|
licence_parse_authreq(STREAM s, uint8 **token, uint8 **signature) |
137 |
{ |
{ |
138 |
uint16 tokenlen; |
uint16 tokenlen; |
139 |
|
|
140 |
in_uint8s(s, 6); /* unknown: f8 3d 15 00 04 f6 */ |
in_uint8s(s, 6); /* unknown: f8 3d 15 00 04 f6 */ |
141 |
|
|
142 |
in_uint16_le(s, tokenlen); |
in_uint16_le(s, tokenlen); |
143 |
if (tokenlen != LICENCE_TOKEN_SIZE) |
if (tokenlen != LICENCE_TOKEN_SIZE) |
144 |
{ |
{ |
145 |
ERROR("token len %d\n", tokenlen); |
error("token len %d\n", tokenlen); |
146 |
return False; |
return False; |
147 |
} |
} |
148 |
|
|
153 |
} |
} |
154 |
|
|
155 |
/* Process an authentication request packet */ |
/* Process an authentication request packet */ |
156 |
static void licence_process_authreq(STREAM s) |
static void |
157 |
|
licence_process_authreq(STREAM s) |
158 |
{ |
{ |
159 |
uint8 *in_token, *in_sig; |
uint8 *in_token, *in_sig; |
160 |
uint8 out_token[LICENCE_TOKEN_SIZE], decrypt_token[LICENCE_TOKEN_SIZE]; |
uint8 out_token[LICENCE_TOKEN_SIZE], |
161 |
|
decrypt_token[LICENCE_TOKEN_SIZE]; |
162 |
uint8 hwid[LICENCE_HWID_SIZE], crypt_hwid[LICENCE_HWID_SIZE]; |
uint8 hwid[LICENCE_HWID_SIZE], crypt_hwid[LICENCE_HWID_SIZE]; |
163 |
uint8 sealed_buffer[LICENCE_TOKEN_SIZE + LICENCE_HWID_SIZE]; |
uint8 sealed_buffer[LICENCE_TOKEN_SIZE + LICENCE_HWID_SIZE]; |
164 |
uint8 out_sig[LICENCE_SIGNATURE_SIZE]; |
uint8 out_sig[LICENCE_SIGNATURE_SIZE]; |
180 |
memcpy(sealed_buffer, decrypt_token, LICENCE_TOKEN_SIZE); |
memcpy(sealed_buffer, decrypt_token, LICENCE_TOKEN_SIZE); |
181 |
memcpy(sealed_buffer + LICENCE_TOKEN_SIZE, hwid, LICENCE_HWID_SIZE); |
memcpy(sealed_buffer + LICENCE_TOKEN_SIZE, hwid, LICENCE_HWID_SIZE); |
182 |
sec_sign(out_sig, licence_sign_key, 16, |
sec_sign(out_sig, licence_sign_key, 16, |
183 |
sealed_buffer, sizeof(sealed_buffer)); |
sealed_buffer, sizeof(sealed_buffer)); |
184 |
|
|
185 |
/* Deliberately break signature if licencing disabled */ |
/* Deliberately break signature if licencing disabled */ |
186 |
if (!licence) |
if (!licence) |
194 |
} |
} |
195 |
|
|
196 |
/* Process an licence issue packet */ |
/* Process an licence issue packet */ |
197 |
static void licence_process_issue(STREAM s) |
static void |
198 |
|
licence_process_issue(STREAM s) |
199 |
{ |
{ |
200 |
RC4_KEY crypt_key; |
RC4_KEY crypt_key; |
201 |
uint32 length; |
uint32 length; |
202 |
uint16 check; |
uint16 check; |
203 |
|
|
204 |
in_uint8s(s, 2); /* 3d 45 - unknown */ |
in_uint8s(s, 2); /* 3d 45 - unknown */ |
205 |
in_uint16_le(s, length); |
in_uint16_le(s, length); |
206 |
if (!s_check_rem(s, length)) |
if (!s_check_rem(s, length)) |
207 |
return; |
return; |
213 |
if (check != 0) |
if (check != 0) |
214 |
return; |
return; |
215 |
|
|
216 |
|
licence_issued = True; |
217 |
|
|
218 |
/* We should save the licence here */ |
/* We should save the licence here */ |
|
STATUS("Server issued licence.\n"); |
|
219 |
} |
} |
220 |
|
|
221 |
/* Process a licence packet */ |
/* Process a licence packet */ |
222 |
void licence_process(STREAM s) |
void |
223 |
|
licence_process(STREAM s) |
224 |
{ |
{ |
225 |
uint16 tag; |
uint16 tag; |
226 |
|
|
227 |
in_uint16_le(s, tag); |
in_uint16_le(s, tag); |
228 |
in_uint8s(s, 2); /* length */ |
in_uint8s(s, 2); /* length */ |
229 |
|
|
230 |
switch (tag) |
switch (tag) |
231 |
{ |
{ |
245 |
break; |
break; |
246 |
|
|
247 |
default: |
default: |
248 |
NOTIMP("licence tag 0x%x\n", tag); |
unimpl("licence tag 0x%x\n", tag); |
249 |
} |
} |
250 |
} |
} |