1 |
/* -*- c-basic-offset: 8 -*- |
/* -*- c-basic-offset: 8 -*- |
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-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 |
20 |
|
|
21 |
#include "rdesktop.h" |
#include "rdesktop.h" |
22 |
|
|
|
#ifdef WITH_OPENSSL |
|
23 |
#include <openssl/rc4.h> |
#include <openssl/rc4.h> |
24 |
#include <openssl/md5.h> |
#include <openssl/md5.h> |
25 |
#include <openssl/sha.h> |
#include <openssl/sha.h> |
26 |
#include <openssl/bn.h> |
#include <openssl/bn.h> |
27 |
#include <openssl/x509v3.h> |
#include <openssl/x509v3.h> |
|
#else |
|
|
#include "crypto/rc4.h" |
|
|
#include "crypto/md5.h" |
|
|
#include "crypto/sha.h" |
|
|
#include "crypto/bn.h" |
|
|
#endif |
|
28 |
|
|
29 |
extern char hostname[16]; |
extern char g_hostname[16]; |
30 |
extern int g_width; |
extern int g_width; |
31 |
extern int g_height; |
extern int g_height; |
32 |
extern int keylayout; |
extern int g_keylayout; |
33 |
|
extern int g_keyboard_type; |
34 |
|
extern int g_keyboard_subtype; |
35 |
|
extern int g_keyboard_functionkeys; |
36 |
extern BOOL g_encryption; |
extern BOOL g_encryption; |
37 |
extern BOOL g_licence_issued; |
extern BOOL g_licence_issued; |
38 |
extern BOOL g_use_rdp5; |
extern BOOL g_use_rdp5; |
130 |
uint8 key_block[48]; |
uint8 key_block[48]; |
131 |
|
|
132 |
/* Construct pre-master secret */ |
/* Construct pre-master secret */ |
133 |
memcpy(pre_master_secret, client_random, 24); |
memcpy(pre_master_secret, client_random, 24); |
134 |
memcpy(pre_master_secret + 24, server_random, 24); |
memcpy(pre_master_secret + 24, server_random, 24); |
135 |
|
|
136 |
/* Generate master secret and then key material */ |
/* Generate master secret and then key material */ |
137 |
sec_hash_48(master_secret, pre_master_secret, client_random, server_random, 'A'); |
sec_hash_48(master_secret, pre_master_secret, client_random, server_random, 'A'); |
138 |
sec_hash_48(key_block, master_secret, client_random, server_random, 'X'); |
sec_hash_48(key_block, master_secret, client_random, server_random, 'X'); |
139 |
|
|
140 |
/* First 16 bytes of key material is MAC secret */ |
/* First 16 bytes of key material is MAC secret */ |
141 |
memcpy(sec_sign_key, key_block, 16); |
memcpy(sec_sign_key, key_block, 16); |
406 |
static void |
static void |
407 |
sec_out_mcs_data(STREAM s) |
sec_out_mcs_data(STREAM s) |
408 |
{ |
{ |
409 |
int hostlen = 2 * strlen(hostname); |
int hostlen = 2 * strlen(g_hostname); |
410 |
int length = 158 + 76 + 12 + 4; |
int length = 158 + 76 + 12 + 4; |
411 |
unsigned int i; |
unsigned int i; |
412 |
|
|
442 |
out_uint16_le(s, g_height); |
out_uint16_le(s, g_height); |
443 |
out_uint16_le(s, 0xca01); |
out_uint16_le(s, 0xca01); |
444 |
out_uint16_le(s, 0xaa03); |
out_uint16_le(s, 0xaa03); |
445 |
out_uint32_le(s, keylayout); |
out_uint32_le(s, g_keylayout); |
446 |
out_uint32_le(s, 2600); /* Client build. We are now 2600 compatible :-) */ |
out_uint32_le(s, 2600); /* Client build. We are now 2600 compatible :-) */ |
447 |
|
|
448 |
/* Unicode name of client, padded to 32 bytes */ |
/* Unicode name of client, padded to 32 bytes */ |
449 |
rdp_out_unistr(s, hostname, hostlen); |
rdp_out_unistr(s, g_hostname, hostlen); |
450 |
out_uint8s(s, 30 - hostlen); |
out_uint8s(s, 30 - hostlen); |
451 |
|
|
452 |
out_uint32_le(s, 4); |
/* See |
453 |
out_uint32(s, 0); |
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceddk40/html/cxtsksupportingremotedesktopprotocol.asp */ |
454 |
out_uint32_le(s, 12); |
out_uint32_le(s, g_keyboard_type); |
455 |
|
out_uint32_le(s, g_keyboard_subtype); |
456 |
|
out_uint32_le(s, g_keyboard_functionkeys); |
457 |
out_uint8s(s, 64); /* reserved? 4 + 12 doublewords */ |
out_uint8s(s, 64); /* reserved? 4 + 12 doublewords */ |
458 |
out_uint16_le(s, 0xca01); /* colour depth? */ |
out_uint16_le(s, 0xca01); /* colour depth? */ |
459 |
out_uint16_le(s, 1); |
out_uint16_le(s, 1); |
818 |
|
|
819 |
/* Receive secure transport packet */ |
/* Receive secure transport packet */ |
820 |
STREAM |
STREAM |
821 |
sec_recv(void) |
sec_recv(uint8 * rdpver) |
822 |
{ |
{ |
823 |
uint32 sec_flags; |
uint32 sec_flags; |
824 |
uint16 channel; |
uint16 channel; |
825 |
STREAM s; |
STREAM s; |
826 |
|
|
827 |
while ((s = mcs_recv(&channel)) != NULL) |
while ((s = mcs_recv(&channel, rdpver)) != NULL) |
828 |
{ |
{ |
829 |
|
if (rdpver != NULL) |
830 |
|
{ |
831 |
|
if (*rdpver != 3) |
832 |
|
{ |
833 |
|
if (*rdpver & 0x80) |
834 |
|
{ |
835 |
|
in_uint8s(s, 8); /* signature */ |
836 |
|
sec_decrypt(s->p, s->end - s->p); |
837 |
|
} |
838 |
|
return s; |
839 |
|
} |
840 |
|
} |
841 |
if (g_encryption || !g_licence_issued) |
if (g_encryption || !g_licence_issued) |
842 |
{ |
{ |
843 |
in_uint32_le(s, sec_flags); |
in_uint32_le(s, sec_flags); |
858 |
if (channel != MCS_GLOBAL_CHANNEL) |
if (channel != MCS_GLOBAL_CHANNEL) |
859 |
{ |
{ |
860 |
channel_process(s, channel); |
channel_process(s, channel); |
861 |
continue; |
*rdpver = 0xff; |
862 |
|
return s; |
863 |
} |
} |
864 |
|
|
865 |
return s; |
return s; |