]> git.sesse.net Git - rdpsrv/blobdiff - secure.c
Reduce small block size to 32x32, and parametrize (#defines instead of hardcoding)
[rdpsrv] / secure.c
index 4a16ceaec2cbbc0f2605f908d03a45cab060f63c..cf9867664a9a155e32c07bfa5d331757dd881133 100644 (file)
--- a/secure.c
+++ b/secure.c
@@ -31,7 +31,7 @@ extern int g_width;
 extern int g_height;
 extern int keylayout;
 extern BOOL g_encryption;
-extern BOOL g_licence_issued;
+BOOL g_licence_issued;
 extern BOOL g_use_rdp5;
 extern BOOL g_console_session;
 extern int g_server_bpp;
@@ -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;
@@ -266,8 +266,6 @@ sec_encrypt(uint8 * data, int length)
                use_count = 0;
        }
 
-       printf("RC4-ing %u bytes with DECRYPT, uc=%u\n", length, use_count);
-
        RC4(&rc4_decrypt_key, length, data, data);
        use_count++;
 }
@@ -738,21 +736,9 @@ sec_process_mcs_data(STREAM s)
 extern unsigned char cacert[];
 extern BOOL g_licence_issued;
 
-unsigned char demand_license[] = {
-       0x01, 0x03, 0x86, 0x00, 0x9c, 0x6e, 0xef, 0x5a, 0x26, 0x45, 0x88, 0x86, 0x0e, 0xdf, 0xa4, 0x4a,
-       0x45, 0xc7, 0x5a, 0x4c, 0xec, 0x33, 0xff, 0x4c, 0xd8, 0x4b, 0xd2, 0x4e, 0xd2, 0x22, 0x16, 0xde,
-       0x1e, 0x5b, 0x06, 0x6e, 0x00, 0x00, 0x05, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x69, 0x00,
-       0x63, 0x00, 0x72, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x6f, 0x00, 0x66, 0x00, 0x74, 0x00, 0x20, 0x00,
-       0x43, 0x00, 0x6f, 0x00, 0x72, 0x00, 0x70, 0x00, 0x6f, 0x00, 0x72, 0x00, 0x61, 0x00, 0x74, 0x00,
-       0x69, 0x00, 0x6f, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x41, 0x00, 0x30, 0x00,
-       0x32, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0xf6, 0x00, 0x00,
-       0x01, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66,
-       0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x00 
-};
 unsigned char result_license[] = {
         0xff, 0x03, 0x10, 0x00, 0x07, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xa0, 0x5f, 0x00, 0x00
 };
-
 unsigned char demand_active[] = {
        0x24, 0x01, 0x11, 0x00, 0xea, 0x03, 0xea, 0x03, 0x01, 0x00, 0x04, 0x00, 0x0e, 0x01, 0x52, 0x44,
        0x50, 0x00, 0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x08, 0x00, 0xea, 0x03, 0x40, 0xe4, 0x01, 0x00,
@@ -779,60 +765,6 @@ unsigned char demand_active[] = {
 #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); }
 #define EXPECT32(value) { in_uint32_le(s, unknown); if (unknown != (value)) printf("Unknown value on code line %u; expected 0x%x, got 0x%x\n", __LINE__, (value), unknown); }
 
-void
-process_presented_license(STREAM s)
-{
-       unsigned char client_license_random[SEC_RANDOM_SIZE];
-       unsigned char client_license_rsa_data[SEC_MODULUS_SIZE];
-
-       uint16 length, license_size;
-       uint32 unknown;
-       uint8 *license, hwid[LICENCE_HWID_SIZE], signature[LICENCE_SIGNATURE_SIZE];
-       int i;
-       
-       EXPECT8(2);                   // version
-       in_uint16_le(s, length);
-
-       EXPECT32(1);                  // unknown
-       EXPECT16(0);
-       EXPECT16(0x0201);
-
-       in_uint8a(s, client_license_random, SEC_RANDOM_SIZE);
-       EXPECT16(0);
-       EXPECT16(SEC_MODULUS_SIZE + SEC_PADDING_SIZE);
-       in_uint8a(s, client_license_rsa_data, SEC_MODULUS_SIZE);
-       in_uint8s(s, SEC_PADDING_SIZE);
-
-       EXPECT16(1);
-       in_uint16_le(s, license_size);
-
-       license = (uint8 *)xmalloc(license_size);
-       in_uint8a(s, license, license_size);
-
-       printf("Received license:\n");
-       for (i = 0; i < license_size; ++i)
-               printf(" 0x%02x", license[i]);
-       printf("\n");
-
-       EXPECT16(1);
-       EXPECT16(LICENCE_HWID_SIZE);
-       in_uint8a(s, hwid, LICENCE_HWID_SIZE);
-
-       printf("License hardware ID:\n");
-       for (i = 0; i < LICENCE_HWID_SIZE; ++i)
-               printf(" 0x%02x", hwid[i]);
-       printf("\n");
-
-       in_uint8a(s, signature, LICENCE_SIGNATURE_SIZE);
-
-       if (!s_check_end(s)) {
-               printf("Unknown data at the end of presented license!");
-       }
-
-       // now we can generate the keys we need
-       licence_generate_keys(client_license_random, demand_license + 4, client_license_rsa_data);
-//     send_authreq();
-}
 
 /* Receive secure transport packet */
 STREAM
@@ -847,11 +779,9 @@ sec_recv(void)
                if (/*g_encryption || !g_licence_issued*/ 1)
                {
                        in_uint32_le(s, sec_flags);
-                       printf("sec_flags=%x\n", sec_flags);
                        
                        if (sec_flags & SEC_ENCRYPT)
                        {
-                               printf("encrypt\n");
                                in_uint8s(s, 8);        /* signature */
                                sec_decrypt(s->p, s->end - s->p);
                        }
@@ -860,47 +790,34 @@ sec_recv(void)
                        {
                                uint8 tag;
                                in_uint8(s, tag);
-                               printf("SEC_LICENSE_NEG tag %x\n", tag);
-                               
-                               if (tag == LICENCE_TAG_PRESENT) {
-                                       process_presented_license(s);
-
-                                       {
-                                               STREAM s;
-                                               s = sec_init(SEC_LICENCE_NEG, sizeof(result_license));
-                                               out_uint8p(s, result_license, sizeof(result_license));
-                                               s_mark_end(s);
-                                               sec_send(s, SEC_LICENCE_NEG);
-                                       }
-                                       
-                                       {
-                                               STREAM s;
-                                               printf("Sending DEMAND_ACTIVE (0x%x bytes)\n", sizeof(demand_active));
-                                               s = sec_init(SEC_ENCRYPT, sizeof(demand_active));
-                                               out_uint8p(s, demand_active, sizeof(demand_active));
-                                               s_mark_end(s);
-                                               sec_send(s, SEC_ENCRYPT);
-                                       }
-                               }
+                       
+                               printf("License tag %x, unimplemented\n", tag);
                                
                                return NULL;
                        }
 
                        if (sec_flags & SEC_LOGON_INFO) 
                        {
-                               printf("Received logon packet!\n");
                                rdp_get_logon_info(s);
-                       
-                               // demand a license
+                               
+                               // say "licensing is OK", then demand
+                               // activity
                                {
                                        STREAM s;
-
-                                       s = sec_init(SEC_LICENCE_NEG, sizeof(demand_license));
-                                       out_uint8p(s, demand_license, sizeof(demand_license));
+                                       s = sec_init(SEC_LICENCE_NEG, sizeof(result_license));
+                                       out_uint8p(s, result_license, sizeof(result_license));
                                        s_mark_end(s);
                                        sec_send(s, SEC_LICENCE_NEG);
                                }
-                               
+                       
+                               {
+                                       STREAM s;
+                                       s = sec_init(SEC_ENCRYPT, sizeof(demand_active));
+                                       out_uint8p(s, demand_active, sizeof(demand_active));
+                                       s_mark_end(s);
+                                       sec_send(s, SEC_ENCRYPT);
+                               }
+
                                return NULL;
                        }
 
@@ -909,7 +826,6 @@ sec_recv(void)
                                uint8 inr[SEC_MODULUS_SIZE];
                                int i;
                                
-                               printf("Receiving the client random!\n");
                                in_uint32_le(s, length);
                                if (length != SEC_MODULUS_SIZE + SEC_PADDING_SIZE) {
                                        error("Client random was wrong size, %u bytes\n", length);