]> git.sesse.net Git - rdpsrv/blobdiff - mcs.c
Separated the RDP5 sending into its own protocol layer.
[rdpsrv] / mcs.c
diff --git a/mcs.c b/mcs.c
index ce10a6874113b3dfb14bf3fdc5e4c8653102250f..b0ddff7dc9a4bd91a76be110b33a6cb7ea173bbd 100644 (file)
--- a/mcs.c
+++ b/mcs.c
 */
 
 #include "rdesktop.h"
+#include <openssl/rsa.h>
 
 uint16 g_mcs_userid;
 extern VCHANNEL g_channels[];
 extern unsigned int g_num_channels;
+extern RSA *privkey;
 
 /* Parse an ASN.1 BER header */
 static BOOL
@@ -193,59 +195,123 @@ mcs_recv_connect_initial()
        return s_check_end(s);
 }
 
-/* key generated with "openssl genrsa 512 | openssl rsa -text":
-modulus:
-    00:b1:e0:36:2f:fd:dd:8b:d6:64:e9:2b:14:f8:b9:
-    0b:ba:3b:b7:0a:f1:f3:97:56:93:38:01:2f:d1:31:
-    2d:70:59:de:97:6a:61:3f:cb:a4:b4:12:05:89:14:
-    d9:b0:8a:70:03:b6:f1:ad:c5:b9:19:9b:b9:8f:03:
-    51:bf:fe:f8:e5
-publicExponent: 65537 (0x10001)
-privateExponent:
-    00:a4:86:68:58:97:8d:f6:2c:06:06:8d:ac:c6:2a:
-    12:a8:dd:56:ff:2e:b0:4b:08:ee:fe:dc:4a:28:4a:
-    3e:67:2d:8e:08:6b:5f:87:69:a4:c5:a0:e7:50:1a:
-    f0:71:03:46:f2:52:7c:e6:09:40:40:61:51:76:32:
-    f8:28:72:99:41
-prime1:
-    00:db:46:d9:34:10:ce:0d:f6:f7:48:30:0f:2b:f6:
-    4d:66:40:27:00:97:db:48:77:cd:96:b5:a6:51:81:
-    a1:7c:ad
-prime2:
-    00:cf:aa:5c:d3:8a:0d:d4:91:a6:40:92:ff:2c:31:
-    d6:f9:08:8d:e8:d2:a8:2f:89:a6:88:2c:61:68:8e:
-    ee:7c:19
-*/
-unsigned char my_modulus[SEC_MODULUS_SIZE] = {
-       0xe5, 0xf8, 0xfe, 0xbf, 0x51,
-       0x03, 0x8f, 0xb9, 0x9b, 0x19, 0xb9, 0xc5, 0xad, 0xf1, 0xb6, 0x03, 0x70, 0x8a, 0xb0, 0xd9,
-       0x14, 0x89, 0x05, 0x12, 0xb4, 0xa4, 0xcb, 0x3f, 0x61, 0x6a, 0x97, 0xde, 0x59, 0x70, 0x2d,
-       0x31, 0xd1, 0x2f, 0x01, 0x38, 0x93, 0x56, 0x97, 0xf3, 0xf1, 0x0a, 0xb7, 0x3b, 0xba, 0x0b,
-       0xb9, 0xf8, 0x14, 0x2b, 0xe9, 0x64, 0xd6, 0x8b, 0xdd, 0xfd, 0x2f, 0x36, 0xe0, 0xb1
+/* keys grabbed from rdpproxy, look at http://www.cse.unsw.edu.au/~matthewc/rdesktop/rdpproxy/openssl/ */
+unsigned char cacert[] = {
+       0x30, 0x82, 0x01, 0x6b, 0x30, 0x82, 0x01, 0x19, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x08, 0x01,
+       0x9d, 0xfb, 0xeb, 0x46, 0x78, 0x5b, 0x00, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1d,
+       0x05, 0x00, 0x30, 0x34, 0x31, 0x32, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, 0x1e, 0x0e, 0x00,
+       0x56, 0x00, 0x49, 0x00, 0x56, 0x00, 0x41, 0x00, 0x4c, 0x00, 0x44, 0x00, 0x49, 0x30, 0x19, 0x06,
+       0x03, 0x55, 0x04, 0x07, 0x1e, 0x12, 0x00, 0x57, 0x00, 0x4f, 0x00, 0x52, 0x00, 0x4b, 0x00, 0x47,
+       0x00, 0x52, 0x00, 0x4f, 0x00, 0x55, 0x00, 0x50, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x32, 0x30, 0x36,
+       0x33, 0x30, 0x31, 0x35, 0x31, 0x31, 0x31, 0x39, 0x5a, 0x17, 0x0d, 0x30, 0x33, 0x30, 0x36, 0x33,
+       0x30, 0x31, 0x35, 0x31, 0x31, 0x31, 0x39, 0x5a, 0x30, 0x34, 0x31, 0x32, 0x30, 0x15, 0x06, 0x03,
+       0x55, 0x04, 0x03, 0x1e, 0x0e, 0x00, 0x56, 0x00, 0x49, 0x00, 0x56, 0x00, 0x41, 0x00, 0x4c, 0x00,
+       0x44, 0x00, 0x49, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04, 0x07, 0x1e, 0x12, 0x00, 0x57, 0x00, 0x4f,
+       0x00, 0x52, 0x00, 0x4b, 0x00, 0x47, 0x00, 0x52, 0x00, 0x4f, 0x00, 0x55, 0x00, 0x50, 0x30, 0x5c,
+       0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03,
+       0x4b, 0x00, 0x30, 0x48, 0x02, 0x41, 0x00, 0xc8, 0xc6, 0xb4, 0xd6, 0x31, 0x35, 0x5e, 0x6f, 0x01,
+       0x06, 0x1a, 0x02, 0x1d, 0x55, 0x46, 0x91, 0xe6, 0xa0, 0x19, 0x28, 0x4d, 0x87, 0x28, 0x5d, 0x22,
+       0xc8, 0xba, 0x8b, 0x6b, 0x93, 0x18, 0xbb, 0x93, 0x47, 0x14, 0xe5, 0x85, 0xe4, 0xfc, 0x49, 0x3d,
+       0x94, 0xbd, 0x5b, 0x2f, 0x7d, 0x0e, 0xa4, 0xa8, 0xc2, 0x79, 0x7c, 0x74, 0x6e, 0x39, 0x5d, 0x8a,
+       0xe4, 0x71, 0x22, 0xca, 0x37, 0x7e, 0x49, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x13, 0x30, 0x11,
+       0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01,
+       0x00, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1d, 0x05, 0x00, 0x03, 0x41, 0x00, 0x12,
+       0x79, 0xdd, 0xf9, 0x90, 0xb0, 0x39, 0x24, 0x35, 0x4d, 0x0b, 0xc6, 0xff, 0x8a, 0x96, 0x10, 0x4b,
+       0xac, 0xd0, 0x26, 0x5e, 0x44, 0xe1, 0x09, 0x72, 0x1b, 0xad, 0x4e, 0x34, 0x78, 0x32, 0xde, 0x29,
+       0x11, 0x08, 0x31, 0xba, 0x6d, 0x1b, 0x42, 0x7a, 0xa7, 0x45, 0xc6, 0xb7, 0xd3, 0xd3, 0x0f, 0x8b,
+       0xf3, 0xe5, 0x57, 0xde, 0x0d, 0x0c, 0xc1, 0x75, 0x60, 0x57, 0x1c, 0x0e, 0xf8, 0xf3, 0x0c
 };
-unsigned char my_exponent[SEC_EXPONENT_SIZE] = {
-       0x01, 0x00, 0x01, 0x00
+unsigned char server_cert[] = {
+       0x30, 0x82, 0x03, 0x79, 0x30, 0x82, 0x03, 0x27, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x05, 0x01,
+       0x00, 0x00, 0x00, 0x03, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1d, 0x05, 0x00, 0x30,
+       0x34, 0x31, 0x32, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, 0x1e, 0x0e, 0x00, 0x56, 0x00, 0x49,
+       0x00, 0x56, 0x00, 0x41, 0x00, 0x4c, 0x00, 0x44, 0x00, 0x49, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04,
+       0x07, 0x1e, 0x12, 0x00, 0x57, 0x00, 0x4f, 0x00, 0x52, 0x00, 0x4b, 0x00, 0x47, 0x00, 0x52, 0x00,
+       0x4f, 0x00, 0x55, 0x00, 0x50, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x32, 0x30, 0x36, 0x33, 0x30, 0x31,
+       0x35, 0x31, 0x32, 0x30, 0x38, 0x5a, 0x17, 0x0d, 0x30, 0x33, 0x30, 0x36, 0x33, 0x30, 0x31, 0x35,
+       0x31, 0x32, 0x30, 0x38, 0x5a, 0x30, 0x81, 0x92, 0x31, 0x81, 0x8f, 0x30, 0x25, 0x06, 0x03, 0x55,
+       0x04, 0x03, 0x1e, 0x1e, 0x00, 0x6e, 0x00, 0x63, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x72, 0x00, 0x70,
+       0x00, 0x63, 0x00, 0x3a, 0x00, 0x56, 0x00, 0x49, 0x00, 0x56, 0x00, 0x41, 0x00, 0x4c, 0x00, 0x44,
+       0x00, 0x49, 0x30, 0x25, 0x06, 0x03, 0x55, 0x04, 0x07, 0x1e, 0x1e, 0x00, 0x6e, 0x00, 0x63, 0x00,
+       0x61, 0x00, 0x6c, 0x00, 0x72, 0x00, 0x70, 0x00, 0x63, 0x00, 0x3a, 0x00, 0x56, 0x00, 0x49, 0x00,
+       0x56, 0x00, 0x41, 0x00, 0x4c, 0x00, 0x44, 0x00, 0x49, 0x30, 0x3f, 0x06, 0x03, 0x55, 0x04, 0x05,
+       0x1e, 0x38, 0x00, 0x31, 0x00, 0x42, 0x00, 0x63, 0x00, 0x4b, 0x00, 0x65, 0x00, 0x57, 0x00, 0x39,
+       0x00, 0x64, 0x00, 0x34, 0x00, 0x43, 0x00, 0x4f, 0x00, 0x59, 0x00, 0x44, 0x00, 0x48, 0x00, 0x2f,
+       0x00, 0x56, 0x00, 0x35, 0x00, 0x65, 0x00, 0x67, 0x00, 0x45, 0x00, 0x72, 0x00, 0x70, 0x00, 0x66,
+       0x00, 0x55, 0x00, 0x55, 0x00, 0x4f, 0x00, 0x63, 0x00, 0x3d, 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09,
+       0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48,
+       0x02, 0x41, 0x00, 0xb6, 0x88, 0xff, 0x4a, 0x6d, 0x44, 0x59, 0x6c, 0x3a, 0xe8, 0x5b, 0x53, 0x72,
+       0x2e, 0x0a, 0x3f, 0x0b, 0xbf, 0x33, 0x87, 0x25, 0x30, 0xeb, 0x82, 0xf7, 0xd4, 0x98, 0xf1, 0x60,
+       0xee, 0x6e, 0x99, 0xdd, 0x6f, 0x07, 0xd9, 0xc0, 0xa1, 0x6c, 0x1c, 0x50, 0xd7, 0xc1, 0x18, 0xe1,
+       0x5e, 0x70, 0x89, 0x3e, 0x6a, 0x98, 0x2c, 0x8b, 0xef, 0x76, 0x6d, 0x9b, 0x70, 0xb8, 0xd7, 0x41,
+       0x25, 0xa1, 0x01, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x01, 0xc3, 0x30, 0x82, 0x01, 0xbf,
+       0x30, 0x14, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x12, 0x04, 0x01, 0x01, 0xff,
+       0x04, 0x04, 0x01, 0x00, 0x05, 0x00, 0x30, 0x3c, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82,
+       0x37, 0x12, 0x02, 0x01, 0x01, 0xff, 0x04, 0x2c, 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, 0x30, 0x81, 0xcd, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37,
+       0x12, 0x05, 0x01, 0x01, 0xff, 0x04, 0x81, 0xbc, 0x00, 0x30, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+       0x02, 0x00, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00, 0x1c, 0x00, 0x4a, 0x00, 0x66, 0x00, 0x4a, 0x00,
+       0xb0, 0x00, 0x01, 0x00, 0x33, 0x00, 0x64, 0x00, 0x32, 0x00, 0x36, 0x00, 0x37, 0x00, 0x39, 0x00,
+       0x35, 0x00, 0x34, 0x00, 0x2d, 0x00, 0x65, 0x00, 0x65, 0x00, 0x62, 0x00, 0x37, 0x00, 0x2d, 0x00,
+       0x31, 0x00, 0x31, 0x00, 0x64, 0x00, 0x31, 0x00, 0x2d, 0x00, 0x62, 0x00, 0x39, 0x00, 0x34, 0x00,
+       0x65, 0x00, 0x2d, 0x00, 0x30, 0x00, 0x30, 0x00, 0x63, 0x00, 0x30, 0x00, 0x34, 0x00, 0x66, 0x00,
+       0x61, 0x00, 0x33, 0x00, 0x30, 0x00, 0x38, 0x00, 0x30, 0x00, 0x64, 0x00, 0x00, 0x00, 0x33, 0x00,
+       0x64, 0x00, 0x32, 0x00, 0x36, 0x00, 0x37, 0x00, 0x39, 0x00, 0x35, 0x00, 0x34, 0x00, 0x2d, 0x00,
+       0x65, 0x00, 0x65, 0x00, 0x62, 0x00, 0x37, 0x00, 0x2d, 0x00, 0x31, 0x00, 0x31, 0x00, 0x64, 0x00,
+       0x31, 0x00, 0x2d, 0x00, 0x62, 0x00, 0x39, 0x00, 0x34, 0x00, 0x65, 0x00, 0x2d, 0x00, 0x30, 0x00,
+       0x30, 0x00, 0x63, 0x00, 0x30, 0x00, 0x34, 0x00, 0x66, 0x00, 0x61, 0x00, 0x33, 0x00, 0x30, 0x00,
+       0x38, 0x00, 0x30, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0xd4, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x30, 0x70, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x12,
+       0x06, 0x01, 0x01, 0xff, 0x04, 0x60, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00,
+       0x56, 0x00, 0x49, 0x00, 0x56, 0x00, 0x41, 0x00, 0x4c, 0x00, 0x44, 0x00, 0x49, 0x00, 0x00, 0x00,
+       0x35, 0x00, 0x31, 0x00, 0x38, 0x00, 0x37, 0x00, 0x39, 0x00, 0x2d, 0x00, 0x33, 0x00, 0x33, 0x00,
+       0x35, 0x00, 0x2d, 0x00, 0x38, 0x00, 0x33, 0x00, 0x39, 0x00, 0x31, 0x00, 0x30, 0x00, 0x30, 0x00,
+       0x37, 0x00, 0x2d, 0x00, 0x35, 0x00, 0x39, 0x00, 0x33, 0x00, 0x37, 0x00, 0x38, 0x00, 0x00, 0x00,
+       0x57, 0x00, 0x4f, 0x00, 0x52, 0x00, 0x4b, 0x00, 0x47, 0x00, 0x52, 0x00, 0x4f, 0x00, 0x55, 0x00,
+       0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x27, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x01, 0x01, 0xff,
+       0x04, 0x1d, 0x30, 0x1b, 0xa1, 0x12, 0xa4, 0x10, 0x56, 0x00, 0x49, 0x00, 0x56, 0x00, 0x41, 0x00,
+       0x4c, 0x00, 0x44, 0x00, 0x49, 0x00, 0x00, 0x00, 0x82, 0x05, 0x01, 0x00, 0x00, 0x00, 0x03, 0x30,
+       0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1d, 0x05, 0x00, 0x03, 0x41, 0x00, 0xa8, 0x61, 0x11,
+       0x69, 0xab, 0x41, 0xee, 0x71, 0xd0, 0xa8, 0x4c, 0x8f, 0x65, 0x9d, 0x9d, 0xaf, 0xab, 0x4f, 0x43,
+       0xaf, 0xa8, 0x21, 0xb7, 0xf2, 0x2c, 0x3a, 0xa5, 0xfe, 0x9e, 0x2c, 0xbc, 0xbb, 0x5c, 0x64, 0x31,
+       0x15, 0x3c, 0xdc, 0x09, 0x4c, 0x36, 0x9a, 0x2b, 0x5e, 0xe0, 0xe6, 0x07, 0x79, 0xfd, 0xcd, 0x1d,
+       0x06, 0x63, 0xfa, 0xb4, 0x2c, 0xcc, 0x00, 0x25, 0x43, 0x71, 0x65, 0xff, 0xf7
 };
-unsigned char my_private_exponent[] = {
-       0x41, 0x99, 0x72, 0x28, 0xf8,
-       0x32, 0x76, 0x51, 0x61, 0x40, 0x40, 0x09, 0xe6, 0x7c, 0x52, 0xf2, 0x46, 0x03, 0x71, 0xf0,
-       0x1a, 0x50, 0xe7, 0xa0, 0xc5, 0xa4, 0x69, 0x87, 0x5f, 0x6b, 0x08, 0x8e, 0x2d, 0x67, 0x3e,
-       0x4a, 0x28, 0x4a, 0xdc, 0xfe, 0xee, 0x08, 0x4b, 0xb0, 0x2e, 0xff, 0x56, 0xdd, 0xa8, 0x12,
-       0x2a, 0xc6, 0xac, 0x8d, 0x06, 0x06, 0x2c, 0xf6, 0x8d, 0x97, 0x58, 0x68, 0x86, 0xa4
+unsigned char private_key[] = {
+       0x30, 0x82, 0x01, 0x3a, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, 0xb6, 0x88, 0xff, 0x4a, 0x6d, 0x44,
+       0x59, 0x6c, 0x3a, 0xe8, 0x5b, 0x53, 0x72, 0x2e, 0x0a, 0x3f, 0x0b, 0xbf, 0x33, 0x87, 0x25, 0x30,
+       0xeb, 0x82, 0xf7, 0xd4, 0x98, 0xf1, 0x60, 0xee, 0x6e, 0x99, 0xdd, 0x6f, 0x07, 0xd9, 0xc0, 0xa1,
+       0x6c, 0x1c, 0x50, 0xd7, 0xc1, 0x18, 0xe1, 0x5e, 0x70, 0x89, 0x3e, 0x6a, 0x98, 0x2c, 0x8b, 0xef,
+       0x76, 0x6d, 0x9b, 0x70, 0xb8, 0xd7, 0x41, 0x25, 0xa1, 0x01, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02,
+       0x40, 0x1f, 0xf8, 0x02, 0x6e, 0x30, 0x90, 0xe5, 0xf0, 0x74, 0xa8, 0xb9, 0x45, 0xf6, 0x1b, 0x66,
+       0x24, 0x00, 0x94, 0xae, 0x1b, 0x9f, 0x41, 0xe0, 0x1d, 0x81, 0xf6, 0x34, 0x0b, 0x22, 0x64, 0xdf,
+       0xed, 0xbb, 0x05, 0xfb, 0x56, 0xcb, 0xb7, 0xef, 0x14, 0xf6, 0xb7, 0x62, 0xb5, 0x5c, 0xaf, 0x98,
+       0xf8, 0x90, 0x4d, 0x40, 0x4b, 0xc4, 0xf2, 0x1c, 0x79, 0xe5, 0x81, 0x4c, 0xae, 0xa9, 0x60, 0xf3,
+       0x21, 0x02, 0x21, 0x00, 0xdb, 0x74, 0x23, 0x81, 0x46, 0xa4, 0x28, 0x97, 0xc1, 0x88, 0x3f, 0x07,
+       0xbd, 0xdc, 0x39, 0xa7, 0x16, 0xff, 0x75, 0xaa, 0x5e, 0x61, 0xff, 0xe4, 0x5c, 0x0e, 0x3d, 0xbd,
+       0x05, 0x90, 0xc8, 0xbd, 0x02, 0x21, 0x00, 0xd4, 0xee, 0xed, 0xdf, 0xca, 0x71, 0xb7, 0x07, 0xb5,
+       0x87, 0xf2, 0xe7, 0xfa, 0xd9, 0xa6, 0xe3, 0x5f, 0xe5, 0x2a, 0x9a, 0xaf, 0x23, 0x88, 0xbc, 0x52,
+       0xb7, 0xad, 0x1b, 0x9d, 0x3c, 0x27, 0x95, 0x02, 0x20, 0x74, 0x47, 0x3c, 0x4c, 0xd2, 0x46, 0x46,
+       0xef, 0xe9, 0xee, 0xac, 0x1f, 0x08, 0xfd, 0x78, 0x5a, 0xcd, 0x77, 0xbc, 0x3b, 0xf2, 0x58, 0x90,
+       0xc2, 0xc9, 0xf8, 0x0d, 0xc4, 0x6a, 0xff, 0x85, 0x2d, 0x02, 0x21, 0x00, 0xa2, 0x4e, 0x79, 0x8d,
+       0x83, 0x3f, 0xc8, 0xb7, 0x1c, 0x9d, 0x42, 0xff, 0xa6, 0xcb, 0x6f, 0x15, 0x94, 0x0c, 0x17, 0xbc,
+       0x8e, 0xd1, 0x74, 0x31, 0xb0, 0x8f, 0x87, 0x69, 0x2c, 0x22, 0x25, 0x3d, 0x02, 0x20, 0x24, 0x9e,
+       0xf6, 0x03, 0x5f, 0x7e, 0x2d, 0xc7, 0x8c, 0x88, 0xf7, 0x43, 0x14, 0xb7, 0x75, 0x72, 0x1e, 0x16,
+       0xae, 0x43, 0x71, 0x97, 0xcc, 0xc2, 0x0c, 0xde, 0x63, 0x35, 0x87, 0x50, 0xbf, 0xad
 };
 
 void
 mcs_send_connect_response()
 {
        STREAM s;
        int i, length;
 
-       s = iso_init(250);
+       s = iso_init(174 + sizeof(cacert) + sizeof(server_cert));
        printf("INITLEN: %u\n", s->p - s->iso_hdr);
 
-       ber_out_header(s, MCS_CONNECT_RESPONSE, 245);
+       ber_out_header(s, MCS_CONNECT_RESPONSE, 169 + sizeof(cacert) + sizeof(server_cert) );
        ber_out_header(s, BER_TAG_RESULT, 1);
        out_uint8(s, 0);
 
@@ -254,7 +320,7 @@ mcs_send_connect_response()
        
        mcs_out_domain_params(s, 34, 2, 0, 0xffff);  // dumdidum?
 
-       ber_out_header(s, BER_TAG_OCTET_STRING, 207);
+       ber_out_header(s, BER_TAG_OCTET_STRING, 131 + sizeof(cacert) + sizeof(server_cert));
 
        // some unknown header of sorts
        out_uint8(s, 0x00);
@@ -279,7 +345,7 @@ mcs_send_connect_response()
        out_uint8(s, 0x44);
        out_uint8(s, 0x6e);
 
-       length = 184;
+       length = 108 + sizeof(cacert) + sizeof(server_cert);
        
        // two bytes of length
        out_uint8(s, 0x80 | (length >> 8));
@@ -303,31 +369,40 @@ mcs_send_connect_response()
        
        // crypto info
        out_uint16_le(s, SEC_TAG_SRV_CRYPT);
-       out_uint16_le(s, 160); // length
-       out_uint32_le(s, 2); // 128-bit
-       out_uint32_le(s, 3); // high
+       out_uint16_le(s, 84 + sizeof(cacert) + sizeof(server_cert)); // length
+       out_uint32_le(s, 1); // 128-bit
+       out_uint32_le(s, 2); // medium
 
        out_uint32_le(s, SEC_RANDOM_SIZE); // random_len
-       out_uint32_le(s, 108);             // rsa_info_len
-       out_uint8s(s, SEC_RANDOM_SIZE);    // server_random
-       out_uint32_le(s, 1);               // RDP4-style
-       // unknown
-       out_uint32_le(s, 1);            
-       out_uint32_le(s, 1);
-
-       out_uint16_le(s, SEC_TAG_PUBKEY);
-       out_uint16_le(s, 92);
-       out_uint32_le(s, SEC_RSA_MAGIC);
-       out_uint32_le(s, SEC_MODULUS_SIZE + SEC_PADDING_SIZE);  // modulus_len
-       out_uint32_le(s, SEC_MODULUS_SIZE * 8);                 // modulus_bits
-       out_uint32_le(s, 0x3f);                                 // unknown
-       out_uint8p(s, my_exponent, SEC_EXPONENT_SIZE);
-       out_uint8p(s, my_modulus, SEC_MODULUS_SIZE);
-       out_uint8s(s, SEC_PADDING_SIZE);
+       out_uint32_le(s, 32 + sizeof(cacert) + sizeof(server_cert));             // rsa_info_len
+       out_uint8p(s, cacert, SEC_RANDOM_SIZE);    // server_"random"
+       out_uint32_le(s, 0x80000002);      // X.509
+       out_uint32_le(s, 2);               // number of certificates
+
+       // CA certificate
+       out_uint32_le(s, sizeof(cacert));
+       out_uint8p(s, cacert, sizeof(cacert));
+
+       // server certificate
+       out_uint32_le(s, sizeof(server_cert));
+       out_uint8p(s, server_cert, sizeof(server_cert));
+       
+       out_uint8s(s, 16);                 // padding
        
        s_mark_end(s);
        iso_send(s);
 
+       // this is a good time to load our private key :-)
+       {
+               unsigned char *buf = (unsigned char *)malloc(1024);
+               const unsigned char *ptr = buf;
+               memcpy(buf, private_key, sizeof(private_key));
+               privkey = d2i_RSAPrivateKey(NULL, &ptr, sizeof(private_key));
+               RSA_blinding_off(privkey);   // fix Valgrind hits -- YES, I know it's evil
+               free(buf);
+
+               printf("Loaded private key (%u bytes)\n", sizeof(private_key));
+       }
 }
 
 /* Send an EDrq message (ASN.1 PER) */