From: Steinar H. Gunderson Date: Sun, 6 Feb 2005 03:13:19 +0000 (+0000) Subject: Separated the RDP5 sending into its own protocol layer. X-Git-Url: https://git.sesse.net/?p=rdpsrv;a=commitdiff_plain;h=55a546ab6b5970438e6cca1a962ec4e7dd669d11 Separated the RDP5 sending into its own protocol layer. --- diff --git a/proto.h b/proto.h index ea5eeda..20710c0 100644 --- a/proto.h +++ b/proto.h @@ -62,6 +62,8 @@ void hexdump(unsigned char *p, int len); int load_licence(unsigned char **data); void save_licence(unsigned char *data, int length); /* rdp5.c */ +STREAM rdp5_init(int maxlen, BOOL encryption); +void rdp5_send(STREAM s, BOOL encryption); void rdp5_process(STREAM s, BOOL encryption); /* rdp.c */ STREAM rdp_recv(uint8 * type); @@ -101,6 +103,7 @@ void wave_out_volume(uint16 left, uint16 right); void wave_out_write(STREAM s, uint16 tick, uint8 index); void wave_out_play(void); /* secure.c */ +void sec_encrypt(uint8 * data, int length); void sec_hash_48(uint8 * out, uint8 * in, uint8 * salt1, uint8 * salt2, uint8 salt); void sec_hash_16(uint8 * out, uint8 * in, uint8 * salt1, uint8 * salt2); void buf_out_uint32(uint8 * buffer, uint32 value); diff --git a/rdp.c b/rdp.c index e0ce66a..538e053 100644 --- a/rdp.c +++ b/rdp.c @@ -152,14 +152,9 @@ void rdp_send_bitmap_update(unsigned x, unsigned y, unsigned width, unsigned hei { STREAM s; - int length = 10*2 + width*height*3 + 8; + int length = 10*2 + width*height*3 + 5; - printf("RDP5 chunk length: %u\n", 10*2 + width*height*3 + 2); - - s = tcp_init(length); - out_uint8(s, 0); // version (RDP5) - out_uint8(s, 0x80 | (length >> 8)); - out_uint8(s, length & 0xff); + s = rdp5_init(length, 0); out_uint8(s, 1); // process bitmap update out_uint16_le(s, 10*2 + width*height*3 + 2); // RDP5 chunk length @@ -179,7 +174,7 @@ void rdp_send_bitmap_update(unsigned x, unsigned y, unsigned width, unsigned hei out_uint8p(s, data, width*height*3); s_mark_end(s); - tcp_send(s); + rdp5_send(s, 0); } #define EXPECT16(value) { in_uint16_le(s, unknown); if (unknown != (value)) printf("Unknown value on code line %u; expected 0x%x, got 0x%x\n", __LINE__, (value), unknown); } diff --git a/rdp5.c b/rdp5.c index 0ac3807..1612643 100644 --- a/rdp5.c +++ b/rdp5.c @@ -24,6 +24,46 @@ extern uint8 *g_next_packet; extern int listen_on_vnc; +extern uint8 sec_sign_key[16]; +extern int rc4_key_len; + +/* Initialise secure transport packet */ +STREAM +rdp5_init(int maxlen, BOOL encryption) +{ + int hdrlen; + STREAM s; + + hdrlen = encryption ? 11 : 3; + s = tcp_init(maxlen + hdrlen); + s_push_layer(s, sec_hdr, hdrlen); + + return s; +} + +void +rdp5_send(STREAM s, BOOL encryption) +{ + int datalen; + + s_pop_layer(s, sec_hdr); + + datalen = s->end - s->p; + + out_uint8(s, encryption ? 0x80 : 0); // protocol + out_uint8(s, 0x80 | (datalen >> 8)); + out_uint8(s, datalen & 0xff); + + if (encryption) { + datalen -= 8; + + sec_sign(s->p, 8, sec_sign_key, rc4_key_len, s->p + 8, datalen); + sec_encrypt(s->p + 8, datalen); + } + + tcp_send(s); +} + void rdp5_process(STREAM s, BOOL encryption) { diff --git a/secure.c b/secure.c index 4a16cea..1f7797b 100644 --- a/secure.c +++ b/secure.c @@ -39,12 +39,12 @@ extern uint16 mcs_userid; extern VCHANNEL g_channels[]; extern unsigned int g_num_channels; -static int rc4_key_len; +int rc4_key_len; static RC4_KEY rc4_decrypt_key; static RC4_KEY rc4_encrypt_key; static RSA *server_public_key; -static uint8 sec_sign_key[16]; +uint8 sec_sign_key[16]; static uint8 sec_decrypt_key[16]; static uint8 sec_encrypt_key[16]; static uint8 sec_decrypt_update_key[16]; @@ -254,7 +254,7 @@ sec_update(uint8 * key, uint8 * update_key) } /* Encrypt data using RC4 */ -static void +void sec_encrypt(uint8 * data, int length) { static int use_count;