ReactOS  0.4.12-dev-714-gfaac916
licence.c File Reference
#include "precomp.h"
Include dependency graph for licence.c:

Go to the source code of this file.

Functions

voidrdssl_rc4_info_create (void)
 
void rdssl_rc4_info_delete (void *rc4_info)
 
void rdssl_rc4_set_key (void *rc4_info, char *key, int len)
 
void rdssl_rc4_crypt (void *rc4_info, char *in_data, char *out_data, int len)
 
int rdssl_mod_exp (char *out, int out_len, char *in, int in_len, char *mod, int mod_len, char *exp, int exp_len)
 
static void licence_generate_keys (uint8 *client_random, uint8 *server_random, uint8 *pre_master_secret)
 
static void licence_generate_hwid (uint8 *hwid)
 
static void licence_info (uint8 *client_random, uint8 *rsa_data, uint8 *licence_data, int licence_size, uint8 *hwid, uint8 *signature)
 
static void licence_send_new_licence_request (uint8 *client_random, uint8 *rsa_data, char *user, char *host)
 
static void licence_process_request (STREAM s)
 
static void licence_send_platform_challenge_response (uint8 *token, uint8 *crypt_hwid, uint8 *signature)
 
static RD_BOOL licence_parse_platform_challenge (STREAM s, uint8 **token, uint8 **signature)
 
static void licence_process_platform_challenge (STREAM s)
 
static void licence_process_new_license (STREAM s)
 
void licence_process_error_alert (STREAM s)
 
void licence_process (STREAM s)
 

Variables

char g_username [256]
 
char g_hostname [256]
 
RDP_VERSION g_rdp_version
 
static uint8 g_licence_key [16]
 
static uint8 g_licence_sign_key [16]
 
RD_BOOL g_licence_issued = False
 
RD_BOOL g_licence_error_result = False
 

Function Documentation

◆ licence_generate_hwid()

static void licence_generate_hwid ( uint8 hwid)
static

Definition at line 66 of file licence.c.

67 {
68  buf_out_uint32(hwid, 2);
69  strncpy((char *) (hwid + 4), g_hostname, LICENCE_HWID_SIZE - 4);
70 }
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
void buf_out_uint32(uint8 *buffer, uint32 value)
Definition: secure.c:304
char g_hostname[256]
Definition: uimain.c:26
#define LICENCE_HWID_SIZE
Definition: constants.h:142

Referenced by licence_process_platform_challenge(), and licence_process_request().

◆ licence_generate_keys()

static void licence_generate_keys ( uint8 client_random,
uint8 server_random,
uint8 pre_master_secret 
)
static

Definition at line 49 of file licence.c.

50 {
51  uint8 master_secret[48];
52  uint8 key_block[48];
53 
54  /* Generate master secret and then key material */
55  sec_hash_48(master_secret, pre_master_secret, client_random, server_random, 'A');
56  sec_hash_48(key_block, master_secret, server_random, client_random, 'A');
57 
58  /* Store first 16 bytes of session key as MAC secret */
59  memcpy(g_licence_sign_key, key_block, 16);
60 
61  /* Generate RC4 key from next 16 bytes */
62  sec_hash_16(g_licence_key, &key_block[16], client_random, server_random);
63 }
void sec_hash_48(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2, uint8 salt)
Definition: secure.c:155
static uint8 g_licence_key[16]
Definition: licence.c:41
void sec_hash_16(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2)
Definition: secure.c:187
unsigned char uint8
Definition: types.h:28
static uint8 g_licence_sign_key[16]
Definition: licence.c:42
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

Referenced by licence_process_request().

◆ licence_info()

static void licence_info ( uint8 client_random,
uint8 rsa_data,
uint8 licence_data,
int  licence_size,
uint8 hwid,
uint8 signature 
)
static

Definition at line 74 of file licence.c.

76 {
77  uint32 sec_flags = SEC_LICENSE_PKT;
78  uint16 length =
81  STREAM s;
82 
83  s = sec_init(sec_flags, length + 2);
84 
86  out_uint8(s, ((g_rdp_version >= RDP_V5) ? 3 : 2)); /* version */
88 
89  out_uint32_le(s, 1);
90  out_uint16(s, 0);
91  out_uint16_le(s, 0x0201);
92 
93  out_uint8p(s, client_random, SEC_RANDOM_SIZE);
94  out_uint16_le(s, 2);
96  out_uint8p(s, rsa_data, SEC_MODULUS_SIZE);
98 
99  out_uint16_le(s, 1);
100  out_uint16_le(s, licence_size);
101  out_uint8p(s, licence_data, licence_size);
102 
103  out_uint16_le(s, 1);
106 
107  out_uint8p(s, signature, LICENCE_SIGNATURE_SIZE);
108 
109  s_mark_end(s);
110  sec_send(s, sec_flags);
111 }
#define out_uint16_le(s, v)
Definition: parse.h:58
#define out_uint8p(s, v, n)
Definition: parse.h:93
unsigned int uint32
Definition: types.h:32
STREAM sec_init(uint32 flags, int maxlen)
Definition: secure.c:419
#define out_uint32_le(s, v)
Definition: parse.h:59
#define out_uint16(s, v)
Definition: parse.h:84
RDP_VERSION g_rdp_version
Definition: uimain.c:74
#define LICENCE_SIGNATURE_SIZE
Definition: constants.h:143
#define out_uint8(s, v)
Definition: parse.h:92
#define SEC_LICENSE_PKT
Definition: constants.h:105
#define out_uint8s(s, n)
Definition: parse.h:95
#define SEC_MODULUS_SIZE
Definition: constants.h:92
Definition: types.h:44
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define SEC_RANDOM_SIZE
Definition: constants.h:91
#define LICENCE_TAG_LICENCE_INFO
Definition: constants.h:149
Definition: parse.h:22
#define SEC_PADDING_SIZE
Definition: constants.h:94
GLdouble s
Definition: gl.h:2039
void sec_send(STREAM s, uint32 flags)
Definition: secure.c:472
unsigned short uint16
Definition: types.h:30
#define LICENCE_HWID_SIZE
Definition: constants.h:142
#define s_mark_end(s)
Definition: parse.h:41

Referenced by licence_process_request().

◆ licence_parse_platform_challenge()

static RD_BOOL licence_parse_platform_challenge ( STREAM  s,
uint8 **  token,
uint8 **  signature 
)
static

Definition at line 232 of file licence.c.

233 {
234  uint16 tokenlen;
235 
236  in_uint8s(s, 6); /* unknown: f8 3d 15 00 04 f6 */
237 
238  in_uint16_le(s, tokenlen);
239  if (tokenlen != LICENCE_TOKEN_SIZE)
240  {
241  error("token len %d\n", tokenlen);
242  return False;
243  }
244 
245  in_uint8p(s, *token, tokenlen);
246  in_uint8p(s, *signature, LICENCE_SIGNATURE_SIZE);
247 
248  return s_check_end(s);
249 }
#define error(str)
Definition: mkdosfs.c:1605
#define in_uint8p(s, v, n)
Definition: parse.h:89
#define LICENCE_SIGNATURE_SIZE
Definition: constants.h:143
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
#define LICENCE_TOKEN_SIZE
Definition: constants.h:141
#define in_uint8s(s, n)
Definition: parse.h:91
#define s_check_end(s)
Definition: parse.h:44
#define False
Definition: types.h:25
GLdouble s
Definition: gl.h:2039
unsigned short uint16
Definition: types.h:30
#define in_uint16_le(s, v)
Definition: parse.h:55

Referenced by licence_process_platform_challenge().

◆ licence_process()

void licence_process ( STREAM  s)

Definition at line 378 of file licence.c.

379 {
380  uint8 tag;
381 
382  in_uint8(s, tag);
383  in_uint8s(s, 3); /* version, length */
384 
385 #if WITH_DEBUG
386  DEBUG(("Received licensing PDU (message type 0x%02x)\n", tag));
387 #endif
388 
389  switch (tag)
390  {
391  case LICENCE_TAG_REQUEST:
393  break;
394 
397  break;
398 
401  /* we can handle new and upgrades of licences the same way. */
403  break;
404 
407  break;
408 
409  default:
410  unimpl("licence tag 0x%02x\n", tag);
411  }
412 }
static void licence_process_new_license(STREAM s)
Definition: licence.c:288
#define LICENCE_TAG_NEW_LICENCE
Definition: constants.h:147
Definition: ecma_167.h:138
void licence_process_error_alert(STREAM s)
Definition: licence.c:324
#define in_uint8s(s, n)
Definition: parse.h:91
#define LICENCE_TAG_UPGRADE_LICENCE
Definition: constants.h:148
#define LICENCE_TAG_REQUEST
Definition: constants.h:145
#define LICENCE_TAG_PLATFORM_CHALLANGE
Definition: constants.h:146
unsigned char uint8
Definition: types.h:28
GLdouble s
Definition: gl.h:2039
static void licence_process_platform_challenge(STREAM s)
Definition: licence.c:253
#define in_uint8(s, v)
Definition: parse.h:88
static void licence_process_request(STREAM s)
Definition: licence.c:156
void unimpl(char *format,...)
Definition: uimain.c:801
#define DEBUG(args)
Definition: rdesktop.h:129
#define LICENCE_TAG_ERROR_ALERT
Definition: constants.h:152
char * tag
Definition: main.c:59

Referenced by sec_recv().

◆ licence_process_error_alert()

void licence_process_error_alert ( STREAM  s)

Definition at line 324 of file licence.c.

325 {
327  uint32 state_transition;
328  uint32 error_info;
330  in_uint32(s, state_transition);
331  in_uint32(s, error_info);
332 
333  /* There is a special case in the error alert handling, when licensing is all good
334  and the server is not sending a license to client, a "Server License Error PDU -
335  Valid Client" packet is sent which means, every thing is ok.
336 
337  Therefor we should flag that everything is ok with license here.
338  */
339  if (error_code == 0x07)
340  {
342  return;
343  }
344 
345  /* handle error codes, for now, just report them */
346  switch (error_code)
347  {
348  case 0x6: // ERR_NO_LICENSE_SERVER
349  warning("License error alert from server: No license server\n");
350  break;
351 
352  case 0x8: // ERR_INVALID_CLIENT
353  warning("License error alert from server: Invalid client\n");
354  break;
355 
356  case 0x4: // ERR_INVALID_SCOPE
357  case 0xb: // ERR_INVALID_PRODUCTID
358  case 0xc: // ERR_INVALID_MESSAGE_LENGTH
359  default:
360  warning("License error alert from server: code %u, state transition %u\n",
361  error_code, state_transition);
362  break;
363  }
364 
365  /* handle error codes, for now, just report them */
366  switch (error_info)
367  {
368  default:
369  break;
370  }
371 
373 }
unsigned int uint32
Definition: types.h:32
static int error_code[8]
Definition: odbccp32.c:62
#define True
Definition: types.h:24
#define in_uint32(s, v)
Definition: parse.h:83
GLdouble s
Definition: gl.h:2039
RD_BOOL g_licence_error_result
Definition: licence.c:45
#define warning(s)
Definition: debug.h:71
RD_BOOL g_licence_issued
Definition: licence.c:44

Referenced by licence_process().

◆ licence_process_new_license()

static void licence_process_new_license ( STREAM  s)
static

Definition at line 288 of file licence.c.

289 {
290  void * crypt_key;
291  uint32 length;
292  int i;
293 
294  in_uint8s(s, 2); // Skip license binary blob type
296  if (!s_check_rem(s, length))
297  return;
298 
299  crypt_key = rdssl_rc4_info_create();
300  rdssl_rc4_set_key(crypt_key, (char *)g_licence_key, 16);
301  rdssl_rc4_crypt(crypt_key, (char *)s->p, (char *)s->p, length);
302  rdssl_rc4_info_delete(crypt_key);
303 
304  /* Parse NEW_LICENSE_INFO block */
305  in_uint8s(s, 4); // skip dwVersion
306 
307  /* Skip strings, Scope, CompanyName and ProductId to get
308  to the LicenseInfo which we store in license blob. */
309  length = 0;
310  for (i = 0; i < 4; i++)
311  {
312  in_uint8s(s, length);
314  if (!s_check_rem(s, length))
315  return;
316  }
317 
319  save_licence(s->p, length);
320 }
void save_licence(unsigned char *data, int length)
unsigned int uint32
Definition: types.h:32
static uint8 g_licence_key[16]
Definition: licence.c:41
#define s_check_rem(s, n)
Definition: parse.h:43
void rdssl_rc4_crypt(void *rc4_info, char *in_data, char *out_data, int len)
Definition: ssl_calls.c:173
void rdssl_rc4_set_key(void *rc4_info, char *key, int len)
Definition: ssl_calls.c:123
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define in_uint8s(s, n)
Definition: parse.h:91
#define True
Definition: types.h:24
void rdssl_rc4_info_delete(void *rc4_info)
Definition: ssl_calls.c:90
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
GLdouble s
Definition: gl.h:2039
void * rdssl_rc4_info_create(void)
Definition: ssl_calls.c:51
#define in_uint32_le(s, v)
Definition: parse.h:56
#define in_uint16_le(s, v)
Definition: parse.h:55
RD_BOOL g_licence_issued
Definition: licence.c:44

Referenced by licence_process().

◆ licence_process_platform_challenge()

static void licence_process_platform_challenge ( STREAM  s)
static

Definition at line 253 of file licence.c.

254 {
255  uint8 *in_token = NULL, *in_sig;
256  uint8 out_token[LICENCE_TOKEN_SIZE], decrypt_token[LICENCE_TOKEN_SIZE];
257  uint8 hwid[LICENCE_HWID_SIZE], crypt_hwid[LICENCE_HWID_SIZE];
258  uint8 sealed_buffer[LICENCE_TOKEN_SIZE + LICENCE_HWID_SIZE];
259  uint8 out_sig[LICENCE_SIGNATURE_SIZE];
260  void * crypt_key;
261 
262  /* Parse incoming packet and save the encrypted token */
263  licence_parse_platform_challenge(s, &in_token, &in_sig);
264  memcpy(out_token, in_token, LICENCE_TOKEN_SIZE);
265 
266  /* Decrypt the token. It should read TEST in Unicode. */
267  crypt_key = rdssl_rc4_info_create();
268  rdssl_rc4_set_key(crypt_key, (char *)g_licence_key, 16);
269  rdssl_rc4_crypt(crypt_key, (char *)in_token, (char *)decrypt_token, LICENCE_TOKEN_SIZE);
270  rdssl_rc4_info_delete(crypt_key);
271 
272  /* Generate a signature for a buffer of token and HWID */
273  licence_generate_hwid(hwid);
274  memcpy(sealed_buffer, decrypt_token, LICENCE_TOKEN_SIZE);
275  memcpy(sealed_buffer + LICENCE_TOKEN_SIZE, hwid, LICENCE_HWID_SIZE);
276  sec_sign(out_sig, 16, g_licence_sign_key, 16, sealed_buffer, sizeof(sealed_buffer));
277 
278  /* Now encrypt the HWID */
279  crypt_key = rdssl_rc4_info_create();
280  rdssl_rc4_set_key(crypt_key, (char *)g_licence_key, 16);
281  rdssl_rc4_crypt(crypt_key, (char *)hwid, (char *)crypt_hwid, LICENCE_HWID_SIZE);
282 
283  licence_send_platform_challenge_response(out_token, crypt_hwid, out_sig);
284 }
static uint8 g_licence_key[16]
Definition: licence.c:41
void rdssl_rc4_crypt(void *rc4_info, char *in_data, char *out_data, int len)
Definition: ssl_calls.c:173
#define LICENCE_SIGNATURE_SIZE
Definition: constants.h:143
void rdssl_rc4_set_key(void *rc4_info, char *key, int len)
Definition: ssl_calls.c:123
#define LICENCE_TOKEN_SIZE
Definition: constants.h:141
static RD_BOOL licence_parse_platform_challenge(STREAM s, uint8 **token, uint8 **signature)
Definition: licence.c:232
smooth NULL
Definition: ftsmooth.c:416
static void licence_send_platform_challenge_response(uint8 *token, uint8 *crypt_hwid, uint8 *signature)
Definition: licence.c:204
void rdssl_rc4_info_delete(void *rc4_info)
Definition: ssl_calls.c:90
unsigned char uint8
Definition: types.h:28
static uint8 g_licence_sign_key[16]
Definition: licence.c:42
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLdouble s
Definition: gl.h:2039
void * rdssl_rc4_info_create(void)
Definition: ssl_calls.c:51
void sec_sign(uint8 *signature, int siglen, uint8 *session_key, int keylen, uint8 *data, int datalen)
Definition: secure.c:314
static void licence_generate_hwid(uint8 *hwid)
Definition: licence.c:66
#define LICENCE_HWID_SIZE
Definition: constants.h:142

Referenced by licence_process().

◆ licence_process_request()

static void licence_process_request ( STREAM  s)
static

Definition at line 156 of file licence.c.

157 {
158  uint8 null_data[SEC_MODULUS_SIZE];
159  uint8 *server_random;
160  uint8 signature[LICENCE_SIGNATURE_SIZE];
161  uint8 hwid[LICENCE_HWID_SIZE];
162  uint8 *licence_data;
163  int licence_size;
164  void * crypt_key;
165 
166  /* Retrieve the server random from the incoming packet */
167  in_uint8p(s, server_random, SEC_RANDOM_SIZE);
168 
169  /* We currently use null client keys. This is a bit naughty but, hey,
170  the security of licence negotiation isn't exactly paramount. */
171  memset(null_data, 0, sizeof(null_data));
172  licence_generate_keys(null_data, server_random, null_data);
173 
174  licence_size = load_licence(&licence_data);
175  if (licence_size > 0)
176  {
177  /* Generate a signature for the HWID buffer */
178  licence_generate_hwid(hwid);
179  sec_sign(signature, 16, g_licence_sign_key, 16, hwid, sizeof(hwid));
180 
181  /* Now encrypt the HWID */
182  crypt_key = rdssl_rc4_info_create();
183  rdssl_rc4_set_key(crypt_key, (char *)g_licence_key, 16);
184  rdssl_rc4_crypt(crypt_key, (char *)hwid, (char *)hwid, sizeof(hwid));
185  rdssl_rc4_info_delete(crypt_key);
186 
187 #if WITH_DEBUG
188  DEBUG(("Sending licensing PDU (message type 0x%02x)\n", LICENCE_TAG_LICENCE_INFO));
189 #endif
190  licence_info(null_data, null_data, licence_data, licence_size, hwid, signature);
191 
192  xfree(licence_data);
193  return;
194  }
195 
196 #if WITH_DEBUG
197  DEBUG(("Sending licensing PDU (message type 0x%02x)\n", LICENCE_TAG_NEW_LICENCE_REQUEST));
198 #endif
200 }
static uint8 g_licence_key[16]
Definition: licence.c:41
void rdssl_rc4_crypt(void *rc4_info, char *in_data, char *out_data, int len)
Definition: ssl_calls.c:173
#define in_uint8p(s, v, n)
Definition: parse.h:89
#define LICENCE_SIGNATURE_SIZE
Definition: constants.h:143
static void licence_generate_keys(uint8 *client_random, uint8 *server_random, uint8 *pre_master_secret)
Definition: licence.c:49
void rdssl_rc4_set_key(void *rc4_info, char *key, int len)
Definition: ssl_calls.c:123
static void licence_info(uint8 *client_random, uint8 *rsa_data, uint8 *licence_data, int licence_size, uint8 *hwid, uint8 *signature)
Definition: licence.c:74
int load_licence(unsigned char **data)
#define SEC_MODULUS_SIZE
Definition: constants.h:92
static void licence_send_new_licence_request(uint8 *client_random, uint8 *rsa_data, char *user, char *host)
Definition: licence.c:115
void xfree(void *mem)
Definition: uimain.c:758
void rdssl_rc4_info_delete(void *rc4_info)
Definition: ssl_calls.c:90
#define SEC_RANDOM_SIZE
Definition: constants.h:91
unsigned char uint8
Definition: types.h:28
static uint8 g_licence_sign_key[16]
Definition: licence.c:42
#define LICENCE_TAG_LICENCE_INFO
Definition: constants.h:149
GLdouble s
Definition: gl.h:2039
void * rdssl_rc4_info_create(void)
Definition: ssl_calls.c:51
void sec_sign(uint8 *signature, int siglen, uint8 *session_key, int keylen, uint8 *data, int datalen)
Definition: secure.c:314
char g_hostname[256]
Definition: uimain.c:26
static void licence_generate_hwid(uint8 *hwid)
Definition: licence.c:66
char g_username[256]
Definition: uimain.c:25
#define LICENCE_HWID_SIZE
Definition: constants.h:142
#define LICENCE_TAG_NEW_LICENCE_REQUEST
Definition: constants.h:150
#define DEBUG(args)
Definition: rdesktop.h:129
#define memset(x, y, z)
Definition: compat.h:39

Referenced by licence_process().

◆ licence_send_new_licence_request()

static void licence_send_new_licence_request ( uint8 client_random,
uint8 rsa_data,
char user,
char host 
)
static

Definition at line 115 of file licence.c.

116 {
117  uint32 sec_flags = SEC_LICENSE_PKT;
118  uint16 userlen = strlen(user) + 1;
119  uint16 hostlen = strlen(host) + 1;
120  uint16 length =
121  24 + SEC_RANDOM_SIZE + SEC_MODULUS_SIZE + SEC_PADDING_SIZE + userlen + hostlen;
122  STREAM s;
123 
124  s = sec_init(sec_flags, length + 2);
125 
127  out_uint8(s, ((g_rdp_version >= RDP_V5) ? 3 : 2)); /* version */
129 
130  out_uint32_le(s, 1); // KEY_EXCHANGE_ALG_RSA
131  out_uint16(s, 0);
132  out_uint16_le(s, 0xff01);
133 
134  out_uint8p(s, client_random, SEC_RANDOM_SIZE);
135  out_uint16_le(s, 2);
137  out_uint8p(s, rsa_data, SEC_MODULUS_SIZE);
139 
140  /* Username LICENSE_BINARY_BLOB */
142  out_uint16_le(s, userlen);
143  out_uint8p(s, user, userlen);
144 
145  /* Machinename LICENSE_BINARY_BLOB */
147  out_uint16_le(s, hostlen);
148  out_uint8p(s, host, hostlen);
149 
150  s_mark_end(s);
151  sec_send(s, sec_flags);
152 }
#define out_uint16_le(s, v)
Definition: parse.h:58
#define out_uint8p(s, v, n)
Definition: parse.h:93
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
unsigned int uint32
Definition: types.h:32
STREAM sec_init(uint32 flags, int maxlen)
Definition: secure.c:419
char * host
Definition: whois.c:55
#define out_uint32_le(s, v)
Definition: parse.h:59
#define out_uint16(s, v)
Definition: parse.h:84
RDP_VERSION g_rdp_version
Definition: uimain.c:74
#define out_uint8(s, v)
Definition: parse.h:92
#define BB_CLIENT_MACHINE_NAME_BLOB
Definition: constants.h:155
#define SEC_LICENSE_PKT
Definition: constants.h:105
#define out_uint8s(s, n)
Definition: parse.h:95
#define SEC_MODULUS_SIZE
Definition: constants.h:92
Definition: types.h:44
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define SEC_RANDOM_SIZE
Definition: constants.h:91
#define BB_CLIENT_USER_NAME_BLOB
Definition: constants.h:154
Definition: parse.h:22
#define SEC_PADDING_SIZE
Definition: constants.h:94
GLdouble s
Definition: gl.h:2039
void sec_send(STREAM s, uint32 flags)
Definition: secure.c:472
unsigned short uint16
Definition: types.h:30
#define LICENCE_TAG_NEW_LICENCE_REQUEST
Definition: constants.h:150
#define s_mark_end(s)
Definition: parse.h:41
void user(int argc, const char *argv[])
Definition: cmds.c:1350

Referenced by licence_process_request().

◆ licence_send_platform_challenge_response()

static void licence_send_platform_challenge_response ( uint8 token,
uint8 crypt_hwid,
uint8 signature 
)
static

Definition at line 204 of file licence.c.

205 {
206  uint32 sec_flags = SEC_LICENSE_PKT;
207  uint16 length = 58;
208  STREAM s;
209 
210  s = sec_init(sec_flags, length + 2);
211 
213  out_uint8(s, ((g_rdp_version >= RDP_V5) ? 3 : 2)); /* version */
215 
216  out_uint16_le(s, 1);
219 
220  out_uint16_le(s, 1);
222  out_uint8p(s, crypt_hwid, LICENCE_HWID_SIZE);
223 
224  out_uint8p(s, signature, LICENCE_SIGNATURE_SIZE);
225 
226  s_mark_end(s);
227  sec_send(s, sec_flags);
228 }
#define out_uint16_le(s, v)
Definition: parse.h:58
#define out_uint8p(s, v, n)
Definition: parse.h:93
unsigned int uint32
Definition: types.h:32
STREAM sec_init(uint32 flags, int maxlen)
Definition: secure.c:419
RDP_VERSION g_rdp_version
Definition: uimain.c:74
#define LICENCE_SIGNATURE_SIZE
Definition: constants.h:143
#define out_uint8(s, v)
Definition: parse.h:92
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
#define LICENCE_TOKEN_SIZE
Definition: constants.h:141
#define SEC_LICENSE_PKT
Definition: constants.h:105
Definition: types.h:44
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define LICENCE_TAG_PLATFORM_CHALLANGE_RESPONSE
Definition: constants.h:151
Definition: parse.h:22
GLdouble s
Definition: gl.h:2039
void sec_send(STREAM s, uint32 flags)
Definition: secure.c:472
unsigned short uint16
Definition: types.h:30
#define LICENCE_HWID_SIZE
Definition: constants.h:142
#define s_mark_end(s)
Definition: parse.h:41

Referenced by licence_process_platform_challenge().

◆ rdssl_mod_exp()

int rdssl_mod_exp ( char out,
int  out_len,
char in,
int  in_len,
char mod,
int  mod_len,
char exp,
int  exp_len 
)

Definition at line 1485 of file ssl_calls.c.

1487 {
1488  /* Computes y = x ^ e mod m */
1489  /* Binary left-to-right method */
1490  DIGIT_T mask;
1491  DIGIT_T* e;
1492  DIGIT_T* x;
1493  DIGIT_T* y;
1494  DIGIT_T* m;
1495  unsigned int n;
1496  int max_size;
1497  char* l_out;
1498  char* l_in;
1499  char* l_mod;
1500  char* l_exp;
1501 
1502  if (in_len > out_len || in_len == 0 ||
1503  out_len == 0 || mod_len == 0 || exp_len == 0)
1504  {
1505  return 0;
1506  }
1507  max_size = out_len;
1508  if (in_len > max_size)
1509  {
1510  max_size = in_len;
1511  }
1512  if (mod_len > max_size)
1513  {
1514  max_size = mod_len;
1515  }
1516  if (exp_len > max_size)
1517  {
1518  max_size = exp_len;
1519  }
1520  l_out = (char*)g_malloc(max_size, 1);
1521  l_in = (char*)g_malloc(max_size, 1);
1522  l_mod = (char*)g_malloc(max_size, 1);
1523  l_exp = (char*)g_malloc(max_size, 1);
1524  memcpy(l_in, in, in_len);
1525  memcpy(l_mod, mod, mod_len);
1526  memcpy(l_exp, exp, exp_len);
1527  e = (DIGIT_T*)l_exp;
1528  x = (DIGIT_T*)l_in;
1529  y = (DIGIT_T*)l_out;
1530  m = (DIGIT_T*)l_mod;
1531  /* Find second-most significant bit in e */
1532  n = mpSizeof(e, max_size / 4);
1533  for (mask = HIBITMASK; mask > 0; mask >>= 1)
1534  {
1535  if (e[n - 1] & mask)
1536  {
1537  break;
1538  }
1539  }
1540  mpNEXTBITMASK(mask, n);
1541  /* Set y = x */
1542  mpSetEqual(y, x, max_size / 4);
1543  /* For bit j = k - 2 downto 0 step -1 */
1544  while (n)
1545  {
1546  mpModMult(y, y, y, m, max_size / 4); /* Square */
1547  if (e[n - 1] & mask)
1548  {
1549  mpModMult(y, y, x, m, max_size / 4); /* Multiply */
1550  }
1551  /* Move to next bit */
1552  mpNEXTBITMASK(mask, n);
1553  }
1554  memcpy(out, l_out, out_len);
1555  g_free(l_out);
1556  g_free(l_in);
1557  g_free(l_mod);
1558  g_free(l_exp);
1559  return out_len;
1560 }
static unsigned int mpSizeof(DIGIT_T *a, unsigned int ndigits)
Definition: ssl_calls.c:795
static void g_free(void *in)
Definition: ssl_calls.c:39
GLdouble n
Definition: glext.h:7729
const GLfloat * m
Definition: glext.h:10848
INT INT y
Definition: msvc.h:62
GLenum GLint GLuint mask
Definition: glext.h:6028
#define e
Definition: ke_i.h:82
static INT max_size
Definition: history.c:51
static void mpSetEqual(DIGIT_T *a, DIGIT_T *b, unsigned int ndigits)
Definition: ssl_calls.c:783
static FILE * out
Definition: regtests2xml.c:44
unsigned int DIGIT_T
Definition: ssl_calls.c:673
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static void * g_malloc(int size, int zero)
Definition: ssl_calls.c:26
#define mpNEXTBITMASK(mask, n)
Definition: ssl_calls.c:684
GLuint in
Definition: glext.h:9616
static int mpModMult(DIGIT_T *a, DIGIT_T *x, DIGIT_T *y, DIGIT_T *m, unsigned int ndigits)
Definition: ssl_calls.c:1469
INT x
Definition: msvc.h:62
#define HIBITMASK
Definition: ssl_calls.c:674
DWORD exp
Definition: msg.c:15681
static int mod
Definition: i386-dis.c:1273

◆ rdssl_rc4_crypt()

void rdssl_rc4_crypt ( void rc4_info,
char in_data,
char out_data,
int  len 
)

Definition at line 173 of file ssl_calls.c.

174 {
175  struct rc4_state *info = rc4_info;
176  BOOL ret;
177  DWORD dwErr;
178  BYTE * intermediate_data;
179  DWORD dwLen = len;
180  if (!rc4_info || !in_data || !out_data || !len || !info->hKey)
181  {
182  error("rdssl_rc4_crypt %p %p %p %d\n", rc4_info, in_data, out_data, len);
183  return;
184  }
185  intermediate_data = g_malloc(len, 0);
186  if (!intermediate_data)
187  {
188  error("rdssl_rc4_set_key no memory\n");
189  return;
190  }
191  memcpy(intermediate_data, in_data, len);
192  ret = CryptEncrypt(info->hKey,
193  0,
194  FALSE,
195  0,
196  intermediate_data,
197  &dwLen,
198  dwLen);
199  if (!ret)
200  {
201  dwErr = GetLastError();
202  g_free(intermediate_data);
203  error("CryptEncrypt failed with %lx\n", dwErr);
204  return;
205  }
206  memcpy(out_data, intermediate_data, len);
207  g_free(intermediate_data);
208 }
#define error(str)
Definition: mkdosfs.c:1605
static void g_free(void *in)
Definition: ssl_calls.c:39
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD dwErr
Definition: service.c:36
BOOL WINAPI CryptEncrypt(HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen, DWORD dwBufLen)
Definition: crypt.c:1098
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
unsigned char BYTE
Definition: mem.h:68
static void * g_malloc(int size, int zero)
Definition: ssl_calls.c:26

Referenced by licence_process_new_license(), licence_process_platform_challenge(), and licence_process_request().

◆ rdssl_rc4_info_create()

void* rdssl_rc4_info_create ( void  )

Definition at line 51 of file ssl_calls.c.

52 {
53  struct rc4_state *info = g_malloc(sizeof(struct rc4_state), 1);
54  BOOL ret;
55  DWORD dwErr;
56  if (!info)
57  {
58  error("rdssl_rc4_info_create no memory\n");
59  return NULL;
60  }
61  ret = CryptAcquireContext(&info->hCryptProv,
62  L"MSTSC",
65  0);
66  if (!ret)
67  {
68  dwErr = GetLastError();
69  if (dwErr == NTE_BAD_KEYSET)
70  {
71  ret = CryptAcquireContext(&info->hCryptProv,
72  L"MSTSC",
76  }
77  }
78  if (!ret)
79  {
80  dwErr = GetLastError();
81  error("CryptAcquireContext failed with %lx\n", dwErr);
82  g_free(info);
83  return NULL;
84  }
85  return info;
86 }
#define CRYPT_NEWKEYSET
Definition: wincrypt.h:2070
#define error(str)
Definition: mkdosfs.c:1605
static void g_free(void *in)
Definition: ssl_calls.c:39
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define CryptAcquireContext
Definition: wincrypt.h:4164
struct _test_info info[]
Definition: SetCursorPos.c:19
smooth NULL
Definition: ftsmooth.c:416
DWORD dwErr
Definition: service.c:36
unsigned int BOOL
Definition: ntddk_ex.h:94
#define NTE_BAD_KEYSET
Definition: winerror.h:2890
unsigned long DWORD
Definition: ntddk_ex.h:95
#define MS_ENHANCED_PROV
Definition: wincrypt.h:1886
int ret
static const WCHAR L[]
Definition: oid.c:1250
static void * g_malloc(int size, int zero)
Definition: ssl_calls.c:26
#define PROV_RSA_FULL
Definition: wincrypt.h:2039

Referenced by licence_process_new_license(), licence_process_platform_challenge(), and licence_process_request().

◆ rdssl_rc4_info_delete()

void rdssl_rc4_info_delete ( void rc4_info)

Definition at line 90 of file ssl_calls.c.

91 {
92  struct rc4_state *info = rc4_info;
93  BOOL ret = TRUE;
94  DWORD dwErr;
95  if (!info)
96  {
97  //error("rdssl_rc4_info_delete rc4_info is null\n");
98  return;
99  }
100  if (info->hKey)
101  {
102  ret = CryptDestroyKey(info->hKey);
103  if (!ret)
104  {
105  dwErr = GetLastError();
106  error("CryptDestroyKey failed with %lx\n", dwErr);
107  }
108  }
109  if (info->hCryptProv)
110  {
111  ret = CryptReleaseContext(info->hCryptProv, 0);
112  if (!ret)
113  {
114  dwErr = GetLastError();
115  error("CryptReleaseContext failed with %lx\n", dwErr);
116  }
117  }
118  g_free(rc4_info);
119 }
#define TRUE
Definition: types.h:120
#define error(str)
Definition: mkdosfs.c:1605
static void g_free(void *in)
Definition: ssl_calls.c:39
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI CryptDestroyKey(HCRYPTKEY hKey)
Definition: crypt.c:935
DWORD dwErr
Definition: service.c:36
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
BOOL WINAPI CryptReleaseContext(HCRYPTPROV hProv, ULONG_PTR dwFlags)
Definition: crypt.c:651

Referenced by licence_process_new_license(), licence_process_platform_challenge(), and licence_process_request().

◆ rdssl_rc4_set_key()

void rdssl_rc4_set_key ( void rc4_info,
char key,
int  len 
)

Definition at line 123 of file ssl_calls.c.

124 {
125  struct rc4_state *info = rc4_info;
126  BOOL ret;
127  DWORD dwErr;
128  BYTE * blob;
130  DWORD * keySize;
131  BYTE * keyBuf;
132  if (!rc4_info || !key || !len || !info->hCryptProv)
133  {
134  error("rdssl_rc4_set_key %p %p %d\n", rc4_info, key, len);
135  return;
136  }
137  blob = g_malloc(sizeof(PUBLICKEYSTRUC) + sizeof(DWORD) + len, 0);
138  if (!blob)
139  {
140  error("rdssl_rc4_set_key no memory\n");
141  return;
142  }
143  desc = (PUBLICKEYSTRUC *)blob;
144  keySize = (DWORD *)(blob + sizeof(PUBLICKEYSTRUC));
145  keyBuf = blob + sizeof(PUBLICKEYSTRUC) + sizeof(DWORD);
146  desc->aiKeyAlg = CALG_RC4;
147  desc->bType = PLAINTEXTKEYBLOB;
148  desc->bVersion = CUR_BLOB_VERSION;
149  desc->reserved = 0;
150  *keySize = len;
151  memcpy(keyBuf, key, len);
152  if (info->hKey)
153  {
154  CryptDestroyKey(info->hKey);
155  info->hKey = 0;
156  }
157  ret = CryptImportKey(info->hCryptProv,
158  blob,
159  sizeof(PUBLICKEYSTRUC) + sizeof(DWORD) + len,
160  0,
162  &info->hKey);
163  g_free(blob);
164  if (!ret)
165  {
166  dwErr = GetLastError();
167  error("CryptImportKey failed with %lx\n", dwErr);
168  }
169 }
#define error(str)
Definition: mkdosfs.c:1605
Definition: image.c:133
static void g_free(void *in)
Definition: ssl_calls.c:39
#define CALG_RC4
Definition: wincrypt.h:1837
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
const struct builtin_class_descr * desc
Definition: regcontrol.c:48
BOOL WINAPI CryptDestroyKey(HCRYPTKEY hKey)
Definition: crypt.c:935
DWORD dwErr
Definition: service.c:36
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
unsigned char BYTE
Definition: mem.h:68
static void * g_malloc(int size, int zero)
Definition: ssl_calls.c:26
struct _PUBLICKEYSTRUC PUBLICKEYSTRUC
#define PLAINTEXTKEYBLOB
Definition: wincrypt.h:2242
#define CUR_BLOB_VERSION
Definition: wincrypt.h:2247
#define CRYPT_EXPORTABLE
Definition: wincrypt.h:2206
BOOL WINAPI CryptImportKey(HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey)
Definition: crypt.c:1855
Definition: path.c:42

Referenced by licence_process_new_license(), licence_process_platform_challenge(), and licence_process_request().

Variable Documentation

◆ g_hostname

char g_hostname[256]

Definition at line 26 of file uimain.c.

Referenced by licence_generate_hwid(), and licence_process_request().

◆ g_licence_error_result

RD_BOOL g_licence_error_result = False

◆ g_licence_issued

◆ g_licence_key

◆ g_licence_sign_key

uint8 g_licence_sign_key[16]
static

◆ g_rdp_version

◆ g_username

char g_username[256]

Definition at line 25 of file uimain.c.

Referenced by licence_process_request().