]> git.sesse.net Git - rdpsrv/commitdiff
Separated the RDP5 sending into its own protocol layer.
authorSteinar H. Gunderson <sesse@samfundet.no>
Sun, 6 Feb 2005 03:13:19 +0000 (03:13 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Sun, 6 Feb 2005 03:13:19 +0000 (03:13 +0000)
proto.h
rdp.c
rdp5.c
secure.c

diff --git a/proto.h b/proto.h
index ea5eeda78f6c7560faefbcc719a90c05c055645a..20710c024069a3ab28b4409ae2b7d64359e11779 100644 (file)
--- 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 e0ce66af31662f88b529c6a514980997082b6ce9..538e053ae821ea14f089036fd2c40c32aaf4dc02 100644 (file)
--- 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 0ac38076132bbcd5768c83df303537cbba25ccc7..1612643de0bf497390679563be8eb812b39e80fe 100644 (file)
--- a/rdp5.c
+++ b/rdp5.c
 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)
 {
index 4a16ceaec2cbbc0f2605f908d03a45cab060f63c..1f7797b023e73fc05601a09ad89dfe9fbc8d0ebf 100644 (file)
--- 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;