xref: /reactos/base/applications/mstsc/licence.c (revision c2c66aff)
1*c2c66affSColin Finck /* -*- c-basic-offset: 8 -*-
2*c2c66affSColin Finck    rdesktop: A Remote Desktop Protocol client.
3*c2c66affSColin Finck    RDP licensing negotiation
4*c2c66affSColin Finck    Copyright (C) Matthew Chapman <matthewc.unsw.edu.au> 1999-2008
5*c2c66affSColin Finck    Copyright (C) Thomas Uhle <thomas.uhle@mailbox.tu-dresden.de> 2011
6*c2c66affSColin Finck    Copyright (C) Henrik Andersson <henrik.andersson@cendio.com> 2014
7*c2c66affSColin Finck 
8*c2c66affSColin Finck 
9*c2c66affSColin Finck    This program is free software: you can redistribute it and/or modify
10*c2c66affSColin Finck    it under the terms of the GNU General Public License as published by
11*c2c66affSColin Finck    the Free Software Foundation, either version 3 of the License, or
12*c2c66affSColin Finck    (at your option) any later version.
13*c2c66affSColin Finck 
14*c2c66affSColin Finck    This program is distributed in the hope that it will be useful,
15*c2c66affSColin Finck    but WITHOUT ANY WARRANTY; without even the implied warranty of
16*c2c66affSColin Finck    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*c2c66affSColin Finck    GNU General Public License for more details.
18*c2c66affSColin Finck 
19*c2c66affSColin Finck    You should have received a copy of the GNU General Public License
20*c2c66affSColin Finck    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21*c2c66affSColin Finck */
22*c2c66affSColin Finck 
23*c2c66affSColin Finck #include "precomp.h"
24*c2c66affSColin Finck 
25*c2c66affSColin Finck void *
26*c2c66affSColin Finck rdssl_rc4_info_create(void);
27*c2c66affSColin Finck void
28*c2c66affSColin Finck rdssl_rc4_info_delete(void * rc4_info);
29*c2c66affSColin Finck void
30*c2c66affSColin Finck rdssl_rc4_set_key(void * rc4_info, char * key, int len);
31*c2c66affSColin Finck void
32*c2c66affSColin Finck rdssl_rc4_crypt(void * rc4_info, char * in_data, char * out_data, int len);
33*c2c66affSColin Finck int
34*c2c66affSColin Finck rdssl_mod_exp(char* out, int out_len, char* in, int in_len,
35*c2c66affSColin Finck               char* mod, int mod_len, char* exp, int exp_len);
36*c2c66affSColin Finck 
37*c2c66affSColin Finck extern char g_username[256];
38*c2c66affSColin Finck extern char g_hostname[256];
39*c2c66affSColin Finck extern RDP_VERSION g_rdp_version;
40*c2c66affSColin Finck 
41*c2c66affSColin Finck static uint8 g_licence_key[16];
42*c2c66affSColin Finck static uint8 g_licence_sign_key[16];
43*c2c66affSColin Finck 
44*c2c66affSColin Finck RD_BOOL g_licence_issued = False;
45*c2c66affSColin Finck RD_BOOL g_licence_error_result = False;
46*c2c66affSColin Finck 
47*c2c66affSColin Finck /* Generate a session key and RC4 keys, given client and server randoms */
48*c2c66affSColin Finck static void
licence_generate_keys(uint8 * client_random,uint8 * server_random,uint8 * pre_master_secret)49*c2c66affSColin Finck licence_generate_keys(uint8 * client_random, uint8 * server_random, uint8 * pre_master_secret)
50*c2c66affSColin Finck {
51*c2c66affSColin Finck 	uint8 master_secret[48];
52*c2c66affSColin Finck 	uint8 key_block[48];
53*c2c66affSColin Finck 
54*c2c66affSColin Finck 	/* Generate master secret and then key material */
55*c2c66affSColin Finck 	sec_hash_48(master_secret, pre_master_secret, client_random, server_random, 'A');
56*c2c66affSColin Finck 	sec_hash_48(key_block, master_secret, server_random, client_random, 'A');
57*c2c66affSColin Finck 
58*c2c66affSColin Finck 	/* Store first 16 bytes of session key as MAC secret */
59*c2c66affSColin Finck 	memcpy(g_licence_sign_key, key_block, 16);
60*c2c66affSColin Finck 
61*c2c66affSColin Finck 	/* Generate RC4 key from next 16 bytes */
62*c2c66affSColin Finck 	sec_hash_16(g_licence_key, &key_block[16], client_random, server_random);
63*c2c66affSColin Finck }
64*c2c66affSColin Finck 
65*c2c66affSColin Finck static void
licence_generate_hwid(uint8 * hwid)66*c2c66affSColin Finck licence_generate_hwid(uint8 * hwid)
67*c2c66affSColin Finck {
68*c2c66affSColin Finck 	buf_out_uint32(hwid, 2);
69*c2c66affSColin Finck 	strncpy((char *) (hwid + 4), g_hostname, LICENCE_HWID_SIZE - 4);
70*c2c66affSColin Finck }
71*c2c66affSColin Finck 
72*c2c66affSColin Finck /* Send a lincece info packet to server */
73*c2c66affSColin Finck static void
licence_info(uint8 * client_random,uint8 * rsa_data,uint8 * licence_data,int licence_size,uint8 * hwid,uint8 * signature)74*c2c66affSColin Finck licence_info(uint8 * client_random, uint8 * rsa_data,
75*c2c66affSColin Finck 	     uint8 * licence_data, int licence_size, uint8 * hwid, uint8 * signature)
76*c2c66affSColin Finck {
77*c2c66affSColin Finck 	uint32 sec_flags = SEC_LICENSE_PKT;
78*c2c66affSColin Finck 	uint16 length =
79*c2c66affSColin Finck 		24 + SEC_RANDOM_SIZE + SEC_MODULUS_SIZE + SEC_PADDING_SIZE +
80*c2c66affSColin Finck 		licence_size + LICENCE_HWID_SIZE + LICENCE_SIGNATURE_SIZE;
81*c2c66affSColin Finck 	STREAM s;
82*c2c66affSColin Finck 
83*c2c66affSColin Finck 	s = sec_init(sec_flags, length + 2);
84*c2c66affSColin Finck 
85*c2c66affSColin Finck 	out_uint8(s, LICENCE_TAG_LICENCE_INFO);
86*c2c66affSColin Finck 	out_uint8(s, ((g_rdp_version >= RDP_V5) ? 3 : 2));	/* version */
87*c2c66affSColin Finck 	out_uint16_le(s, length);
88*c2c66affSColin Finck 
89*c2c66affSColin Finck 	out_uint32_le(s, 1);
90*c2c66affSColin Finck 	out_uint16(s, 0);
91*c2c66affSColin Finck 	out_uint16_le(s, 0x0201);
92*c2c66affSColin Finck 
93*c2c66affSColin Finck 	out_uint8p(s, client_random, SEC_RANDOM_SIZE);
94*c2c66affSColin Finck 	out_uint16_le(s, 2);
95*c2c66affSColin Finck 	out_uint16_le(s, (SEC_MODULUS_SIZE + SEC_PADDING_SIZE));
96*c2c66affSColin Finck 	out_uint8p(s, rsa_data, SEC_MODULUS_SIZE);
97*c2c66affSColin Finck 	out_uint8s(s, SEC_PADDING_SIZE);
98*c2c66affSColin Finck 
99*c2c66affSColin Finck 	out_uint16_le(s, 1);
100*c2c66affSColin Finck 	out_uint16_le(s, licence_size);
101*c2c66affSColin Finck 	out_uint8p(s, licence_data, licence_size);
102*c2c66affSColin Finck 
103*c2c66affSColin Finck 	out_uint16_le(s, 1);
104*c2c66affSColin Finck 	out_uint16_le(s, LICENCE_HWID_SIZE);
105*c2c66affSColin Finck 	out_uint8p(s, hwid, LICENCE_HWID_SIZE);
106*c2c66affSColin Finck 
107*c2c66affSColin Finck 	out_uint8p(s, signature, LICENCE_SIGNATURE_SIZE);
108*c2c66affSColin Finck 
109*c2c66affSColin Finck 	s_mark_end(s);
110*c2c66affSColin Finck 	sec_send(s, sec_flags);
111*c2c66affSColin Finck }
112*c2c66affSColin Finck 
113*c2c66affSColin Finck /* Send a new licence request packet */
114*c2c66affSColin Finck static void
licence_send_new_licence_request(uint8 * client_random,uint8 * rsa_data,char * user,char * host)115*c2c66affSColin Finck licence_send_new_licence_request(uint8 * client_random, uint8 * rsa_data, char *user, char *host)
116*c2c66affSColin Finck {
117*c2c66affSColin Finck 	uint32 sec_flags = SEC_LICENSE_PKT;
118*c2c66affSColin Finck 	uint16 userlen = strlen(user) + 1;
119*c2c66affSColin Finck 	uint16 hostlen = strlen(host) + 1;
120*c2c66affSColin Finck 	uint16 length =
121*c2c66affSColin Finck 		24 + SEC_RANDOM_SIZE + SEC_MODULUS_SIZE + SEC_PADDING_SIZE + userlen + hostlen;
122*c2c66affSColin Finck 	STREAM s;
123*c2c66affSColin Finck 
124*c2c66affSColin Finck 	s = sec_init(sec_flags, length + 2);
125*c2c66affSColin Finck 
126*c2c66affSColin Finck 	out_uint8(s, LICENCE_TAG_NEW_LICENCE_REQUEST);
127*c2c66affSColin Finck 	out_uint8(s, ((g_rdp_version >= RDP_V5) ? 3 : 2));	/* version */
128*c2c66affSColin Finck 	out_uint16_le(s, length);
129*c2c66affSColin Finck 
130*c2c66affSColin Finck 	out_uint32_le(s, 1);	// KEY_EXCHANGE_ALG_RSA
131*c2c66affSColin Finck 	out_uint16(s, 0);
132*c2c66affSColin Finck 	out_uint16_le(s, 0xff01);
133*c2c66affSColin Finck 
134*c2c66affSColin Finck 	out_uint8p(s, client_random, SEC_RANDOM_SIZE);
135*c2c66affSColin Finck 	out_uint16_le(s, 2);
136*c2c66affSColin Finck 	out_uint16_le(s, (SEC_MODULUS_SIZE + SEC_PADDING_SIZE));
137*c2c66affSColin Finck 	out_uint8p(s, rsa_data, SEC_MODULUS_SIZE);
138*c2c66affSColin Finck 	out_uint8s(s, SEC_PADDING_SIZE);
139*c2c66affSColin Finck 
140*c2c66affSColin Finck 	/* Username LICENSE_BINARY_BLOB */
141*c2c66affSColin Finck 	out_uint16_le(s, BB_CLIENT_USER_NAME_BLOB);
142*c2c66affSColin Finck 	out_uint16_le(s, userlen);
143*c2c66affSColin Finck 	out_uint8p(s, user, userlen);
144*c2c66affSColin Finck 
145*c2c66affSColin Finck 	/* Machinename LICENSE_BINARY_BLOB */
146*c2c66affSColin Finck 	out_uint16_le(s, BB_CLIENT_MACHINE_NAME_BLOB);
147*c2c66affSColin Finck 	out_uint16_le(s, hostlen);
148*c2c66affSColin Finck 	out_uint8p(s, host, hostlen);
149*c2c66affSColin Finck 
150*c2c66affSColin Finck 	s_mark_end(s);
151*c2c66affSColin Finck 	sec_send(s, sec_flags);
152*c2c66affSColin Finck }
153*c2c66affSColin Finck 
154*c2c66affSColin Finck /* Process a licence request packet */
155*c2c66affSColin Finck static void
licence_process_request(STREAM s)156*c2c66affSColin Finck licence_process_request(STREAM s)
157*c2c66affSColin Finck {
158*c2c66affSColin Finck 	uint8 null_data[SEC_MODULUS_SIZE];
159*c2c66affSColin Finck 	uint8 *server_random;
160*c2c66affSColin Finck 	uint8 signature[LICENCE_SIGNATURE_SIZE];
161*c2c66affSColin Finck 	uint8 hwid[LICENCE_HWID_SIZE];
162*c2c66affSColin Finck 	uint8 *licence_data;
163*c2c66affSColin Finck 	int licence_size;
164*c2c66affSColin Finck 	void * crypt_key;
165*c2c66affSColin Finck 
166*c2c66affSColin Finck 	/* Retrieve the server random from the incoming packet */
167*c2c66affSColin Finck 	in_uint8p(s, server_random, SEC_RANDOM_SIZE);
168*c2c66affSColin Finck 
169*c2c66affSColin Finck 	/* We currently use null client keys. This is a bit naughty but, hey,
170*c2c66affSColin Finck 	   the security of licence negotiation isn't exactly paramount. */
171*c2c66affSColin Finck 	memset(null_data, 0, sizeof(null_data));
172*c2c66affSColin Finck 	licence_generate_keys(null_data, server_random, null_data);
173*c2c66affSColin Finck 
174*c2c66affSColin Finck 	licence_size = load_licence(&licence_data);
175*c2c66affSColin Finck 	if (licence_size > 0)
176*c2c66affSColin Finck 	{
177*c2c66affSColin Finck 		/* Generate a signature for the HWID buffer */
178*c2c66affSColin Finck 		licence_generate_hwid(hwid);
179*c2c66affSColin Finck 		sec_sign(signature, 16, g_licence_sign_key, 16, hwid, sizeof(hwid));
180*c2c66affSColin Finck 
181*c2c66affSColin Finck 		/* Now encrypt the HWID */
182*c2c66affSColin Finck 		crypt_key = rdssl_rc4_info_create();
183*c2c66affSColin Finck 		rdssl_rc4_set_key(crypt_key, (char *)g_licence_key, 16);
184*c2c66affSColin Finck 		rdssl_rc4_crypt(crypt_key, (char *)hwid, (char *)hwid, sizeof(hwid));
185*c2c66affSColin Finck 		rdssl_rc4_info_delete(crypt_key);
186*c2c66affSColin Finck 
187*c2c66affSColin Finck #if WITH_DEBUG
188*c2c66affSColin Finck 		DEBUG(("Sending licensing PDU (message type 0x%02x)\n", LICENCE_TAG_LICENCE_INFO));
189*c2c66affSColin Finck #endif
190*c2c66affSColin Finck 		licence_info(null_data, null_data, licence_data, licence_size, hwid, signature);
191*c2c66affSColin Finck 
192*c2c66affSColin Finck 		xfree(licence_data);
193*c2c66affSColin Finck 		return;
194*c2c66affSColin Finck 	}
195*c2c66affSColin Finck 
196*c2c66affSColin Finck #if WITH_DEBUG
197*c2c66affSColin Finck 	DEBUG(("Sending licensing PDU (message type 0x%02x)\n", LICENCE_TAG_NEW_LICENCE_REQUEST));
198*c2c66affSColin Finck #endif
199*c2c66affSColin Finck 	licence_send_new_licence_request(null_data, null_data, g_username, g_hostname);
200*c2c66affSColin Finck }
201*c2c66affSColin Finck 
202*c2c66affSColin Finck /* Send a platform challenge response packet */
203*c2c66affSColin Finck static void
licence_send_platform_challenge_response(uint8 * token,uint8 * crypt_hwid,uint8 * signature)204*c2c66affSColin Finck licence_send_platform_challenge_response(uint8 * token, uint8 * crypt_hwid, uint8 * signature)
205*c2c66affSColin Finck {
206*c2c66affSColin Finck 	uint32 sec_flags = SEC_LICENSE_PKT;
207*c2c66affSColin Finck 	uint16 length = 58;
208*c2c66affSColin Finck 	STREAM s;
209*c2c66affSColin Finck 
210*c2c66affSColin Finck 	s = sec_init(sec_flags, length + 2);
211*c2c66affSColin Finck 
212*c2c66affSColin Finck 	out_uint8(s, LICENCE_TAG_PLATFORM_CHALLANGE_RESPONSE);
213*c2c66affSColin Finck 	out_uint8(s, ((g_rdp_version >= RDP_V5) ? 3 : 2));	/* version */
214*c2c66affSColin Finck 	out_uint16_le(s, length);
215*c2c66affSColin Finck 
216*c2c66affSColin Finck 	out_uint16_le(s, 1);
217*c2c66affSColin Finck 	out_uint16_le(s, LICENCE_TOKEN_SIZE);
218*c2c66affSColin Finck 	out_uint8p(s, token, LICENCE_TOKEN_SIZE);
219*c2c66affSColin Finck 
220*c2c66affSColin Finck 	out_uint16_le(s, 1);
221*c2c66affSColin Finck 	out_uint16_le(s, LICENCE_HWID_SIZE);
222*c2c66affSColin Finck 	out_uint8p(s, crypt_hwid, LICENCE_HWID_SIZE);
223*c2c66affSColin Finck 
224*c2c66affSColin Finck 	out_uint8p(s, signature, LICENCE_SIGNATURE_SIZE);
225*c2c66affSColin Finck 
226*c2c66affSColin Finck 	s_mark_end(s);
227*c2c66affSColin Finck 	sec_send(s, sec_flags);
228*c2c66affSColin Finck }
229*c2c66affSColin Finck 
230*c2c66affSColin Finck /* Parse a platform challenge request packet */
231*c2c66affSColin Finck static RD_BOOL
licence_parse_platform_challenge(STREAM s,uint8 ** token,uint8 ** signature)232*c2c66affSColin Finck licence_parse_platform_challenge(STREAM s, uint8 ** token, uint8 ** signature)
233*c2c66affSColin Finck {
234*c2c66affSColin Finck 	uint16 tokenlen;
235*c2c66affSColin Finck 
236*c2c66affSColin Finck 	in_uint8s(s, 6);	/* unknown: f8 3d 15 00 04 f6 */
237*c2c66affSColin Finck 
238*c2c66affSColin Finck 	in_uint16_le(s, tokenlen);
239*c2c66affSColin Finck 	if (tokenlen != LICENCE_TOKEN_SIZE)
240*c2c66affSColin Finck 	{
241*c2c66affSColin Finck 		error("token len %d\n", tokenlen);
242*c2c66affSColin Finck 		return False;
243*c2c66affSColin Finck 	}
244*c2c66affSColin Finck 
245*c2c66affSColin Finck 	in_uint8p(s, *token, tokenlen);
246*c2c66affSColin Finck 	in_uint8p(s, *signature, LICENCE_SIGNATURE_SIZE);
247*c2c66affSColin Finck 
248*c2c66affSColin Finck 	return s_check_end(s);
249*c2c66affSColin Finck }
250*c2c66affSColin Finck 
251*c2c66affSColin Finck /* Process a platform challenge packet */
252*c2c66affSColin Finck static void
licence_process_platform_challenge(STREAM s)253*c2c66affSColin Finck licence_process_platform_challenge(STREAM s)
254*c2c66affSColin Finck {
255*c2c66affSColin Finck 	uint8 *in_token = NULL, *in_sig;
256*c2c66affSColin Finck 	uint8 out_token[LICENCE_TOKEN_SIZE], decrypt_token[LICENCE_TOKEN_SIZE];
257*c2c66affSColin Finck 	uint8 hwid[LICENCE_HWID_SIZE], crypt_hwid[LICENCE_HWID_SIZE];
258*c2c66affSColin Finck 	uint8 sealed_buffer[LICENCE_TOKEN_SIZE + LICENCE_HWID_SIZE];
259*c2c66affSColin Finck 	uint8 out_sig[LICENCE_SIGNATURE_SIZE];
260*c2c66affSColin Finck 	void * crypt_key;
261*c2c66affSColin Finck 
262*c2c66affSColin Finck 	/* Parse incoming packet and save the encrypted token */
263*c2c66affSColin Finck 	licence_parse_platform_challenge(s, &in_token, &in_sig);
264*c2c66affSColin Finck 	memcpy(out_token, in_token, LICENCE_TOKEN_SIZE);
265*c2c66affSColin Finck 
266*c2c66affSColin Finck 	/* Decrypt the token. It should read TEST in Unicode. */
267*c2c66affSColin Finck 	crypt_key = rdssl_rc4_info_create();
268*c2c66affSColin Finck 	rdssl_rc4_set_key(crypt_key, (char *)g_licence_key, 16);
269*c2c66affSColin Finck 	rdssl_rc4_crypt(crypt_key, (char *)in_token, (char *)decrypt_token, LICENCE_TOKEN_SIZE);
270*c2c66affSColin Finck 	rdssl_rc4_info_delete(crypt_key);
271*c2c66affSColin Finck 
272*c2c66affSColin Finck 	/* Generate a signature for a buffer of token and HWID */
273*c2c66affSColin Finck 	licence_generate_hwid(hwid);
274*c2c66affSColin Finck 	memcpy(sealed_buffer, decrypt_token, LICENCE_TOKEN_SIZE);
275*c2c66affSColin Finck 	memcpy(sealed_buffer + LICENCE_TOKEN_SIZE, hwid, LICENCE_HWID_SIZE);
276*c2c66affSColin Finck 	sec_sign(out_sig, 16, g_licence_sign_key, 16, sealed_buffer, sizeof(sealed_buffer));
277*c2c66affSColin Finck 
278*c2c66affSColin Finck 	/* Now encrypt the HWID */
279*c2c66affSColin Finck 	crypt_key = rdssl_rc4_info_create();
280*c2c66affSColin Finck 	rdssl_rc4_set_key(crypt_key, (char *)g_licence_key, 16);
281*c2c66affSColin Finck 	rdssl_rc4_crypt(crypt_key, (char *)hwid, (char *)crypt_hwid, LICENCE_HWID_SIZE);
282*c2c66affSColin Finck 
283*c2c66affSColin Finck 	licence_send_platform_challenge_response(out_token, crypt_hwid, out_sig);
284*c2c66affSColin Finck }
285*c2c66affSColin Finck 
286*c2c66affSColin Finck /* Process a new licence packet */
287*c2c66affSColin Finck static void
licence_process_new_license(STREAM s)288*c2c66affSColin Finck licence_process_new_license(STREAM s)
289*c2c66affSColin Finck {
290*c2c66affSColin Finck 	void * crypt_key;
291*c2c66affSColin Finck 	uint32 length;
292*c2c66affSColin Finck 	int i;
293*c2c66affSColin Finck 
294*c2c66affSColin Finck 	in_uint8s(s, 2);	// Skip license binary blob type
295*c2c66affSColin Finck 	in_uint16_le(s, length);
296*c2c66affSColin Finck 	if (!s_check_rem(s, length))
297*c2c66affSColin Finck 		return;
298*c2c66affSColin Finck 
299*c2c66affSColin Finck 	crypt_key = rdssl_rc4_info_create();
300*c2c66affSColin Finck 	rdssl_rc4_set_key(crypt_key, (char *)g_licence_key, 16);
301*c2c66affSColin Finck 	rdssl_rc4_crypt(crypt_key, (char *)s->p, (char *)s->p, length);
302*c2c66affSColin Finck 	rdssl_rc4_info_delete(crypt_key);
303*c2c66affSColin Finck 
304*c2c66affSColin Finck 	/* Parse NEW_LICENSE_INFO block */
305*c2c66affSColin Finck 	in_uint8s(s, 4);	// skip dwVersion
306*c2c66affSColin Finck 
307*c2c66affSColin Finck 	/* Skip strings, Scope, CompanyName and ProductId to get
308*c2c66affSColin Finck 	   to the LicenseInfo which we store in license blob. */
309*c2c66affSColin Finck 	length = 0;
310*c2c66affSColin Finck 	for (i = 0; i < 4; i++)
311*c2c66affSColin Finck 	{
312*c2c66affSColin Finck 		in_uint8s(s, length);
313*c2c66affSColin Finck 		in_uint32_le(s, length);
314*c2c66affSColin Finck 		if (!s_check_rem(s, length))
315*c2c66affSColin Finck 			return;
316*c2c66affSColin Finck 	}
317*c2c66affSColin Finck 
318*c2c66affSColin Finck 	g_licence_issued = True;
319*c2c66affSColin Finck 	save_licence(s->p, length);
320*c2c66affSColin Finck }
321*c2c66affSColin Finck 
322*c2c66affSColin Finck /* process a licence error alert packet */
323*c2c66affSColin Finck void
licence_process_error_alert(STREAM s)324*c2c66affSColin Finck licence_process_error_alert(STREAM s)
325*c2c66affSColin Finck {
326*c2c66affSColin Finck 	uint32 error_code;
327*c2c66affSColin Finck 	uint32 state_transition;
328*c2c66affSColin Finck 	uint32 error_info;
329*c2c66affSColin Finck 	in_uint32(s, error_code);
330*c2c66affSColin Finck 	in_uint32(s, state_transition);
331*c2c66affSColin Finck 	in_uint32(s, error_info);
332*c2c66affSColin Finck 
333*c2c66affSColin Finck 	/* There is a special case in the error alert handling, when licensing is all good
334*c2c66affSColin Finck 	   and the server is not sending a license to client, a "Server License Error PDU -
335*c2c66affSColin Finck 	   Valid Client" packet is sent which means, every thing is ok.
336*c2c66affSColin Finck 
337*c2c66affSColin Finck 	   Therefor we should flag that everything is ok with license here.
338*c2c66affSColin Finck 	 */
339*c2c66affSColin Finck 	if (error_code == 0x07)
340*c2c66affSColin Finck 	{
341*c2c66affSColin Finck 		g_licence_issued = True;
342*c2c66affSColin Finck 		return;
343*c2c66affSColin Finck 	}
344*c2c66affSColin Finck 
345*c2c66affSColin Finck 	/* handle error codes, for now, just report them */
346*c2c66affSColin Finck 	switch (error_code)
347*c2c66affSColin Finck 	{
348*c2c66affSColin Finck 		case 0x6:	// ERR_NO_LICENSE_SERVER
349*c2c66affSColin Finck 			warning("License error alert from server: No license server\n");
350*c2c66affSColin Finck 			break;
351*c2c66affSColin Finck 
352*c2c66affSColin Finck 		case 0x8:	// ERR_INVALID_CLIENT
353*c2c66affSColin Finck 			warning("License error alert from server: Invalid client\n");
354*c2c66affSColin Finck 			break;
355*c2c66affSColin Finck 
356*c2c66affSColin Finck 		case 0x4:	// ERR_INVALID_SCOPE
357*c2c66affSColin Finck 		case 0xb:	// ERR_INVALID_PRODUCTID
358*c2c66affSColin Finck 		case 0xc:	// ERR_INVALID_MESSAGE_LENGTH
359*c2c66affSColin Finck 		default:
360*c2c66affSColin Finck 			warning("License error alert from server: code %u, state transition %u\n",
361*c2c66affSColin Finck 				error_code, state_transition);
362*c2c66affSColin Finck 			break;
363*c2c66affSColin Finck 	}
364*c2c66affSColin Finck 
365*c2c66affSColin Finck 	/* handle error codes, for now, just report them */
366*c2c66affSColin Finck 	switch (error_info)
367*c2c66affSColin Finck 	{
368*c2c66affSColin Finck 		default:
369*c2c66affSColin Finck 			break;
370*c2c66affSColin Finck 	}
371*c2c66affSColin Finck 
372*c2c66affSColin Finck 	g_licence_error_result = True;
373*c2c66affSColin Finck }
374*c2c66affSColin Finck 
375*c2c66affSColin Finck 
376*c2c66affSColin Finck /* Process a licence packet */
377*c2c66affSColin Finck void
licence_process(STREAM s)378*c2c66affSColin Finck licence_process(STREAM s)
379*c2c66affSColin Finck {
380*c2c66affSColin Finck 	uint8 tag;
381*c2c66affSColin Finck 
382*c2c66affSColin Finck 	in_uint8(s, tag);
383*c2c66affSColin Finck 	in_uint8s(s, 3);	/* version, length */
384*c2c66affSColin Finck 
385*c2c66affSColin Finck #if WITH_DEBUG
386*c2c66affSColin Finck 	DEBUG(("Received licensing PDU (message type 0x%02x)\n", tag));
387*c2c66affSColin Finck #endif
388*c2c66affSColin Finck 
389*c2c66affSColin Finck 	switch (tag)
390*c2c66affSColin Finck 	{
391*c2c66affSColin Finck 		case LICENCE_TAG_REQUEST:
392*c2c66affSColin Finck 			licence_process_request(s);
393*c2c66affSColin Finck 			break;
394*c2c66affSColin Finck 
395*c2c66affSColin Finck 		case LICENCE_TAG_PLATFORM_CHALLANGE:
396*c2c66affSColin Finck 			licence_process_platform_challenge(s);
397*c2c66affSColin Finck 			break;
398*c2c66affSColin Finck 
399*c2c66affSColin Finck 		case LICENCE_TAG_NEW_LICENCE:
400*c2c66affSColin Finck 		case LICENCE_TAG_UPGRADE_LICENCE:
401*c2c66affSColin Finck 			/* we can handle new and upgrades of licences the same way. */
402*c2c66affSColin Finck 			licence_process_new_license(s);
403*c2c66affSColin Finck 			break;
404*c2c66affSColin Finck 
405*c2c66affSColin Finck 		case LICENCE_TAG_ERROR_ALERT:
406*c2c66affSColin Finck 			licence_process_error_alert(s);
407*c2c66affSColin Finck 			break;
408*c2c66affSColin Finck 
409*c2c66affSColin Finck 		default:
410*c2c66affSColin Finck 			unimpl("licence tag 0x%02x\n", tag);
411*c2c66affSColin Finck 	}
412*c2c66affSColin Finck }
413