libfreerdp-core: fix MCS unit tests
authorMarc-André Moreau <marcandre.moreau@gmail.com>
Fri, 8 Jul 2011 20:05:30 +0000 (16:05 -0400)
committerMarc-André Moreau <marcandre.moreau@gmail.com>
Fri, 8 Jul 2011 20:05:30 +0000 (16:05 -0400)
cunit/test_gcc.c
include/freerdp/settings.h
libfreerdp-core/ber.c
libfreerdp-core/gcc.c
libfreerdp-core/gcc.h
libfreerdp-core/mcs.c
libfreerdp-core/settings.c

index 9c53a43..85cecac 100644 (file)
@@ -154,6 +154,12 @@ void test_gcc_write_client_security_data(void)
        s = stream_new(12);
        settings = settings_new();
 
+       settings->encryption_methods =
+                       ENCRYPTION_40BIT_FLAG |
+                       ENCRYPTION_56BIT_FLAG |
+                       ENCRYPTION_128BIT_FLAG |
+                       ENCRYPTION_FIPS_FLAG;
+
        gcc_write_client_security_data(s, settings);
 
        ASSERT_STREAM(s, (uint8*) gcc_client_security_data_expected, sizeof(gcc_client_security_data_expected));
index 948c751..955f67a 100644 (file)
 #include <freerdp/types.h>
 #include <freerdp/utils/unicode.h>
 
-#define PERF_FLAG_NONE                  0x00000000
-#define PERF_DISABLE_WALLPAPER          0x00000001
-#define PERF_DISABLE_FULLWINDOWDRAG     0x00000002
-#define PERF_DISABLE_MENUANIMATIONS     0x00000004
-#define PERF_DISABLE_THEMING            0x00000008
-#define PERF_DISABLE_CURSOR_SHADOW      0x00000020
-#define PERF_DISABLE_CURSORSETTINGS     0x00000040
-#define PERF_ENABLE_FONT_SMOOTHING      0x00000080
-#define PERF_ENABLE_DESKTOP_COMPOSITION 0x00000100
+/* Performance Flags */
+#define PERF_FLAG_NONE                         0x00000000
+#define PERF_DISABLE_WALLPAPER                 0x00000001
+#define PERF_DISABLE_FULLWINDOWDRAG                    0x00000002
+#define PERF_DISABLE_MENUANIMATIONS            0x00000004
+#define PERF_DISABLE_THEMING                   0x00000008
+#define PERF_DISABLE_CURSOR_SHADOW             0x00000020
+#define PERF_DISABLE_CURSORSETTINGS            0x00000040
+#define PERF_ENABLE_FONT_SMOOTHING             0x00000080
+#define PERF_ENABLE_DESKTOP_COMPOSITION        0x00000100
+
+/* Encryption Methods */
+#define ENCRYPTION_40BIT_FLAG                  0x00000001
+#define ENCRYPTION_128BIT_FLAG                 0x00000002
+#define ENCRYPTION_56BIT_FLAG                  0x00000008
+#define ENCRYPTION_FIPS_FLAG                   0x00000010
 
 struct rdp_chan
 {
@@ -68,6 +75,7 @@ struct rdp_settings
        uint32 kbd_fn_keys;
        uint32 client_build;
        uint32 selected_protocol;
+       uint32 encryption_methods;
 
        int console_session;
        uint32 redirected_session_id;
index 934faa0..b804fd0 100644 (file)
@@ -119,6 +119,20 @@ void ber_write_boolean(STREAM* s, boolean value)
 void ber_write_integer(STREAM* s, uint32 value)
 {
        ber_write_universal_tag(s, BER_TAG_INTEGER);
-       ber_write_length(s, 2);
-       stream_write_uint16_be(s, value);
+
+       if (value <= 0xFF)
+       {
+               ber_write_length(s, 1);
+               stream_write_uint8(s, value);
+       }
+       else if (value <= 0xFFFF)
+       {
+               ber_write_length(s, 2);
+               stream_write_uint16_be(s, value);
+       }
+       else if (value <= 0xFFFFFFFF)
+       {
+               ber_write_length(s, 4);
+               stream_write_uint32_be(s, value);
+       }
 }
index 57b078f..038dfa1 100644 (file)
@@ -255,22 +255,18 @@ void gcc_write_client_core_data(STREAM* s, rdpSettings *settings)
 
 void gcc_write_client_security_data(STREAM* s, rdpSettings *settings)
 {
-       uint16 encryptionMethods;
-
        gcc_write_user_data_header(s, CS_SECURITY, 12);
 
-       encryptionMethods = ENCRYPTION_40BIT_FLAG | ENCRYPTION_128BIT_FLAG;
-
        if (settings->encryption > 0)
        {
-               stream_write_uint32(s, encryptionMethods); /* encryptionMethods */
+               stream_write_uint32(s, settings->encryption_methods); /* encryptionMethods */
                stream_write_uint32(s, 0); /* extEncryptionMethods */
        }
        else
        {
                /* French locale, disable encryption */
                stream_write_uint32(s, 0); /* encryptionMethods */
-               stream_write_uint32(s, encryptionMethods); /* extEncryptionMethods */
+               stream_write_uint32(s, settings->encryption_methods); /* extEncryptionMethods */
        }
 }
 
index 3a981f1..5f38b87 100644 (file)
 #define CONNECTION_TYPE_WAN                    0x05
 #define CONNECTION_TYPE_LAN                    0x06
 
-/* Encryption Methods */
-#define ENCRYPTION_40BIT_FLAG                  0x00000001
-#define ENCRYPTION_128BIT_FLAG                 0x00000002
-#define ENCRYPTION_56BIT_FLAG                  0x00000008
-#define ENCRYPTION_FIPS_FLAG                   0x00000010
-
 /* Cluster Information Flags */
 #define REDIRECTION_SUPPORTED                  0x00000001
 #define REDIRECTED_SESSIONID_FIELD_VALID       0x00000002
index 3a845ef..48e2c7a 100644 (file)
@@ -88,7 +88,12 @@ static void mcs_init_domain_parameters(DOMAIN_PARAMETERS* domainParameters,
 
 static void mcs_write_domain_parameters(STREAM* s, DOMAIN_PARAMETERS* domainParameters)
 {
-       ber_write_sequence_of_tag(s, 32);
+       int length;
+       uint8 *bm, *em;
+
+       stream_get_mark(s, bm);
+       stream_seek(s, 2);
+
        ber_write_integer(s, domainParameters->maxChannelIds);
        ber_write_integer(s, domainParameters->maxUserIds);
        ber_write_integer(s, domainParameters->maxTokenIds);
@@ -97,6 +102,13 @@ static void mcs_write_domain_parameters(STREAM* s, DOMAIN_PARAMETERS* domainPara
        ber_write_integer(s, domainParameters->maxHeight);
        ber_write_integer(s, domainParameters->maxMCSPDUsize);
        ber_write_integer(s, domainParameters->protocolVersion);
+
+       stream_get_mark(s, em);
+       length = (em - bm) - 2;
+       stream_set_mark(s, bm);
+
+       ber_write_sequence_of_tag(s, length);
+       stream_set_mark(s, em);
 }
 
 /**
@@ -109,12 +121,12 @@ static void mcs_write_domain_parameters(STREAM* s, DOMAIN_PARAMETERS* domainPara
 void mcs_write_connect_initial(STREAM* s, rdpMcs* mcs, STREAM* user_data)
 {
        int length;
-       int gcc_CCrq_length = stream_get_length(user_data);
+       uint8 *bm, *em;
 
-       length = gcc_CCrq_length + (3* 34) + 13;
+       int gcc_CCrq_length = stream_get_length(user_data);
 
-       /* Connect-Initial (APPLICATION 101, IMPLICIT SEQUENCE) */
-       ber_write_application_tag(s, MCS_TYPE_CONNECT_INITIAL, length);
+       stream_get_mark(s, bm);
+       stream_seek(s, 5);
 
        /* callingDomainSelector (OCTET_STRING) */
        ber_write_octet_string(s, callingDomainSelector, sizeof(callingDomainSelector));
@@ -136,6 +148,14 @@ void mcs_write_connect_initial(STREAM* s, rdpMcs* mcs, STREAM* user_data)
 
        /* userData (OCTET_STRING) */
        ber_write_octet_string(s, user_data->data, gcc_CCrq_length);
+
+       stream_get_mark(s, em);
+       length = (em - bm) - 5;
+       stream_set_mark(s, bm);
+
+       /* Connect-Initial (APPLICATION 101, IMPLICIT SEQUENCE) */
+       ber_write_application_tag(s, MCS_TYPE_CONNECT_INITIAL, length);
+       stream_set_mark(s, em);
 }
 
 int mcs_recv(rdpMcs* mcs)
index 1c6404e..e83f57c 100644 (file)
@@ -48,6 +48,10 @@ rdpSettings* settings_new()
                                PERF_DISABLE_MENUANIMATIONS |
                                PERF_DISABLE_WALLPAPER;
 
+               settings->encryption_methods =
+                               ENCRYPTION_40BIT_FLAG |
+                               ENCRYPTION_128BIT_FLAG;
+
                settings->uniconv = freerdp_uniconv_new();
                gethostname(settings->client_hostname, sizeof(settings->client_hostname) - 1);
        }