1 |
/* |
/* |
2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
Protocol services - RDP encryption and licensing |
Protocol services - RDP encryption and licensing |
4 |
Copyright (C) Matthew Chapman 1999-2001 |
Copyright (C) Matthew Chapman 1999-2002 |
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 |
38 |
extern int keylayout; |
extern int keylayout; |
39 |
extern BOOL encryption; |
extern BOOL encryption; |
40 |
extern BOOL licence_issued; |
extern BOOL licence_issued; |
41 |
|
extern int server_bpp; |
42 |
|
|
43 |
static int rc4_key_len; |
static int rc4_key_len; |
44 |
static RC4_KEY rc4_decrypt_key; |
static RC4_KEY rc4_decrypt_key; |
286 |
static void |
static void |
287 |
sec_rsa_encrypt(uint8 * out, uint8 * in, int len, uint8 * modulus, uint8 * exponent) |
sec_rsa_encrypt(uint8 * out, uint8 * in, int len, uint8 * modulus, uint8 * exponent) |
288 |
{ |
{ |
289 |
BN_CTX ctx; |
BN_CTX *ctx; |
290 |
BIGNUM mod, exp, x, y; |
BIGNUM mod, exp, x, y; |
291 |
uint8 inr[SEC_MODULUS_SIZE]; |
uint8 inr[SEC_MODULUS_SIZE]; |
292 |
int outlen; |
int outlen; |
296 |
memcpy(inr, in, len); |
memcpy(inr, in, len); |
297 |
reverse(inr, len); |
reverse(inr, len); |
298 |
|
|
299 |
BN_CTX_init(&ctx); |
ctx = BN_CTX_new(); |
300 |
BN_init(&mod); |
BN_init(&mod); |
301 |
BN_init(&exp); |
BN_init(&exp); |
302 |
BN_init(&x); |
BN_init(&x); |
305 |
BN_bin2bn(modulus, SEC_MODULUS_SIZE, &mod); |
BN_bin2bn(modulus, SEC_MODULUS_SIZE, &mod); |
306 |
BN_bin2bn(exponent, SEC_EXPONENT_SIZE, &exp); |
BN_bin2bn(exponent, SEC_EXPONENT_SIZE, &exp); |
307 |
BN_bin2bn(inr, len, &x); |
BN_bin2bn(inr, len, &x); |
308 |
BN_mod_exp(&y, &x, &exp, &mod, &ctx); |
BN_mod_exp(&y, &x, &exp, &mod, ctx); |
309 |
outlen = BN_bn2bin(&y, out); |
outlen = BN_bn2bin(&y, out); |
310 |
reverse(out, outlen); |
reverse(out, outlen); |
311 |
if (outlen < SEC_MODULUS_SIZE) |
if (outlen < SEC_MODULUS_SIZE) |
315 |
BN_clear_free(&x); |
BN_clear_free(&x); |
316 |
BN_free(&exp); |
BN_free(&exp); |
317 |
BN_free(&mod); |
BN_free(&mod); |
318 |
BN_CTX_free(&ctx); |
BN_CTX_free(ctx); |
319 |
} |
} |
320 |
|
|
321 |
/* Initialise secure transport packet */ |
/* Initialise secure transport packet */ |
364 |
|
|
365 |
/* Transfer the client random to the server */ |
/* Transfer the client random to the server */ |
366 |
static void |
static void |
367 |
sec_establish_key() |
sec_establish_key(void) |
368 |
{ |
{ |
369 |
uint32 length = SEC_MODULUS_SIZE + SEC_PADDING_SIZE; |
uint32 length = SEC_MODULUS_SIZE + SEC_PADDING_SIZE; |
370 |
uint32 flags = SEC_CLIENT_RANDOM; |
uint32 flags = SEC_CLIENT_RANDOM; |
385 |
sec_out_mcs_data(STREAM s) |
sec_out_mcs_data(STREAM s) |
386 |
{ |
{ |
387 |
int hostlen = 2 * strlen(hostname); |
int hostlen = 2 * strlen(hostname); |
388 |
|
|
389 |
if (hostlen > 30) |
if (hostlen > 30) |
390 |
hostlen = 30; |
hostlen = 30; |
391 |
|
|
426 |
out_uint32_le(s, 12); |
out_uint32_le(s, 12); |
427 |
out_uint8s(s, 64); /* reserved? 4 + 12 doublewords */ |
out_uint8s(s, 64); /* reserved? 4 + 12 doublewords */ |
428 |
|
|
429 |
out_uint16(s, 0xca01); |
switch (server_bpp) |
430 |
|
{ |
431 |
|
case 8: |
432 |
|
out_uint16_le(s, 0xca01); |
433 |
|
break; |
434 |
|
case 15: |
435 |
|
out_uint16_le(s, 0xca02); |
436 |
|
break; |
437 |
|
case 16: |
438 |
|
out_uint16_le(s, 0xca03); |
439 |
|
break; |
440 |
|
case 24: |
441 |
|
out_uint16_le(s, 0xca04); |
442 |
|
break; |
443 |
|
} |
444 |
out_uint16(s, 0); |
out_uint16(s, 0); |
445 |
|
|
446 |
/* Client encryption settings */ |
/* Client encryption settings */ |
447 |
out_uint16_le(s, SEC_TAG_CLI_CRYPT); |
out_uint16_le(s, SEC_TAG_CLI_CRYPT); |
448 |
out_uint16(s, 8); /* length */ |
out_uint16_le(s, 8); /* length */ |
449 |
out_uint32_le(s, encryption ? 0x3 : 0); /* encryption supported, 128-bit supported */ |
out_uint32_le(s, encryption ? 0x3 : 0); /* encryption supported, 128-bit supported */ |
450 |
s_mark_end(s); |
s_mark_end(s); |
451 |
} |
} |
562 |
{ |
{ |
563 |
uint16 tag, length; |
uint16 tag, length; |
564 |
uint8 *next_tag; |
uint8 *next_tag; |
565 |
|
uint8 len; |
566 |
|
|
567 |
in_uint8s(s, 23); /* header */ |
in_uint8s(s, 21); /* header */ |
568 |
|
in_uint8(s, len); |
569 |
|
if (len & 0x80) |
570 |
|
in_uint8(s, len); |
571 |
|
|
572 |
while (s->p < s->end) |
while (s->p < s->end) |
573 |
{ |
{ |
599 |
|
|
600 |
/* Receive secure transport packet */ |
/* Receive secure transport packet */ |
601 |
STREAM |
STREAM |
602 |
sec_recv() |
sec_recv(void) |
603 |
{ |
{ |
604 |
uint32 sec_flags; |
uint32 sec_flags; |
605 |
STREAM s; |
STREAM s; |
646 |
sec_process_mcs_data(&mcs_data); |
sec_process_mcs_data(&mcs_data); |
647 |
if (encryption) |
if (encryption) |
648 |
sec_establish_key(); |
sec_establish_key(); |
649 |
|
xfree(mcs_data.data); |
650 |
return True; |
return True; |
651 |
} |
} |
652 |
|
|
653 |
/* Disconnect a connection */ |
/* Disconnect a connection */ |
654 |
void |
void |
655 |
sec_disconnect() |
sec_disconnect(void) |
656 |
{ |
{ |
657 |
mcs_disconnect(); |
mcs_disconnect(); |
658 |
} |
} |