static uint8 sec_encrypt_update_key[16];
static uint8 sec_crypted_random[SEC_MODULUS_SIZE];
+RSA *privkey;
+
uint16 g_server_rdp_version = 0;
/*
/* Initialise RC4 state arrays */
RC4_set_key(&rc4_decrypt_key, rc4_key_len, sec_decrypt_key);
RC4_set_key(&rc4_encrypt_key, rc4_key_len, sec_encrypt_key);
+
+ {
+ int i;
+ printf("sec_decrypt_key: ");
+ for (i = 0; i < 16; ++i)
+ printf("0x%02x ", sec_decrypt_key[i]);
+ printf("\n");
+
+ printf("sec_encrypt_key: ");
+ for (i = 0; i < 16; ++i)
+ printf("0x%02x ", sec_encrypt_key[i]);
+ printf("\n");
+ }
}
static uint8 pad_54[40] = {
if (use_count == 4096)
{
- sec_update(sec_encrypt_key, sec_encrypt_update_key);
- RC4_set_key(&rc4_encrypt_key, rc4_key_len, sec_encrypt_key);
+ sec_update(sec_decrypt_key, sec_decrypt_update_key);
+ RC4_set_key(&rc4_decrypt_key, rc4_key_len, sec_decrypt_key);
use_count = 0;
}
- RC4(&rc4_encrypt_key, length, data, data);
+ RC4(&rc4_decrypt_key, length, data, data);
use_count++;
}
if (use_count == 4096)
{
- sec_update(sec_decrypt_key, sec_decrypt_update_key);
- RC4_set_key(&rc4_decrypt_key, rc4_key_len, sec_decrypt_key);
+ sec_update(sec_encrypt_key, sec_encrypt_update_key);
+ RC4_set_key(&rc4_encrypt_key, rc4_key_len, sec_encrypt_key);
use_count = 0;
}
- RC4(&rc4_decrypt_key, length, data, data);
+ RC4(&rc4_encrypt_key, length, data, data);
use_count++;
}
{
int datalen;
- DEBUG(("sending packet to channel %u", channel));
+// DEBUG(("sending packet to channel %u\n", channel));
s_pop_layer(s, sec_hdr);
// if (!g_licence_issued || (flags & SEC_ENCRYPT))
}
}
+extern unsigned char cacert[];
+
+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
+};
+
/* Receive secure transport packet */
STREAM
sec_recv(void)
{
printf("Received logon packet!\n");
rdp_get_logon_info(s);
+
+ // demand a license
+ {
+ STREAM s;
+
+ s = sec_init(sizeof(demand_license), SEC_LICENCE_NEG);
+ out_uint8p(s, demand_license, sizeof(demand_license));
+ s_mark_end(s);
+ sec_send(s, SEC_LICENCE_NEG);
+ }
+
+ continue;
+ }
+
+ if (sec_flags & SEC_CLIENT_RANDOM) {
+ uint32 length;
+ 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);
+ }
+ in_uint8a(s, sec_crypted_random, SEC_MODULUS_SIZE);
+ in_uint8s(s, SEC_PADDING_SIZE);
+ if (!s_check_end(s)) {
+ error("Junk after client random\n");
+ }
+
+ reverse(sec_crypted_random, SEC_MODULUS_SIZE);
+
+ RSA_private_decrypt(SEC_MODULUS_SIZE, sec_crypted_random, inr, privkey, RSA_NO_PADDING);
+
+ reverse(inr + SEC_RANDOM_SIZE, SEC_RANDOM_SIZE);
+
+ printf("Unencrypted client random: ");
+ for (i = 0; i < SEC_RANDOM_SIZE; ++i) {
+ printf("0x%x ", inr[i + SEC_RANDOM_SIZE]);
+ }
+ printf("\n");
+
+ // now we can generate the keys
+ sec_generate_keys(inr + SEC_RANDOM_SIZE, cacert, 1);
+ continue;
}
}