56 |
|
|
57 |
uint16 g_server_rdp_version = 0; |
uint16 g_server_rdp_version = 0; |
58 |
|
|
59 |
|
/* These values must be available to reset state - Session Directory */ |
60 |
|
static int sec_encrypt_use_count = 0; |
61 |
|
static int sec_decrypt_use_count = 0; |
62 |
|
|
63 |
/* |
/* |
64 |
* I believe this is based on SSLv3 with the following differences: |
* I believe this is based on SSLv3 with the following differences: |
65 |
* MAC algorithm (5.2.3.1) uses only 32-bit length in place of seq_num/type/length fields |
* MAC algorithm (5.2.3.1) uses only 32-bit length in place of seq_num/type/length fields |
255 |
static void |
static void |
256 |
sec_encrypt(uint8 * data, int length) |
sec_encrypt(uint8 * data, int length) |
257 |
{ |
{ |
258 |
static int use_count; |
if (sec_encrypt_use_count == 4096) |
|
|
|
|
if (use_count == 4096) |
|
259 |
{ |
{ |
260 |
sec_update(sec_encrypt_key, sec_encrypt_update_key); |
sec_update(sec_encrypt_key, sec_encrypt_update_key); |
261 |
RC4_set_key(&rc4_encrypt_key, rc4_key_len, sec_encrypt_key); |
RC4_set_key(&rc4_encrypt_key, rc4_key_len, sec_encrypt_key); |
262 |
use_count = 0; |
sec_encrypt_use_count = 0; |
263 |
} |
} |
264 |
|
|
265 |
RC4(&rc4_encrypt_key, length, data, data); |
RC4(&rc4_encrypt_key, length, data, data); |
266 |
use_count++; |
sec_encrypt_use_count++; |
267 |
} |
} |
268 |
|
|
269 |
/* Decrypt data using RC4 */ |
/* Decrypt data using RC4 */ |
270 |
void |
void |
271 |
sec_decrypt(uint8 * data, int length) |
sec_decrypt(uint8 * data, int length) |
272 |
{ |
{ |
273 |
static int use_count; |
if (sec_decrypt_use_count == 4096) |
|
|
|
|
if (use_count == 4096) |
|
274 |
{ |
{ |
275 |
sec_update(sec_decrypt_key, sec_decrypt_update_key); |
sec_update(sec_decrypt_key, sec_decrypt_update_key); |
276 |
RC4_set_key(&rc4_decrypt_key, rc4_key_len, sec_decrypt_key); |
RC4_set_key(&rc4_decrypt_key, rc4_key_len, sec_decrypt_key); |
277 |
use_count = 0; |
sec_decrypt_use_count = 0; |
278 |
} |
} |
279 |
|
|
280 |
RC4(&rc4_decrypt_key, length, data, data); |
RC4(&rc4_decrypt_key, length, data, data); |
281 |
use_count++; |
sec_decrypt_use_count++; |
282 |
} |
} |
283 |
|
|
284 |
static void |
static void |
853 |
licence_process(s); |
licence_process(s); |
854 |
continue; |
continue; |
855 |
} |
} |
856 |
|
|
857 |
|
if (sec_flags & 0x0400) /* SEC_REDIRECT_ENCRYPT */ |
858 |
|
{ |
859 |
|
uint8 swapbyte; |
860 |
|
|
861 |
|
in_uint8s(s, 8); /* signature */ |
862 |
|
sec_decrypt(s->p, s->end - s->p); |
863 |
|
|
864 |
|
/* Check for a redirect packet, starts with 00 04 */ |
865 |
|
if (s->p[0] == 0 && s->p[1] == 4) |
866 |
|
{ |
867 |
|
/* for some reason the PDU and the length seem to be swapped. |
868 |
|
This isn't good, but we're going to do a byte for byte |
869 |
|
swap. So the first foure value appear as: 00 04 XX YY, |
870 |
|
where XX YY is the little endian length. We're going to |
871 |
|
use 04 00 as the PDU type, so after our swap this will look |
872 |
|
like: XX YY 04 00 */ |
873 |
|
swapbyte = s->p[0]; |
874 |
|
s->p[0] = s->p[2]; |
875 |
|
s->p[2] = swapbyte; |
876 |
|
|
877 |
|
swapbyte = s->p[1]; |
878 |
|
s->p[1] = s->p[3]; |
879 |
|
s->p[3] = swapbyte; |
880 |
|
|
881 |
|
swapbyte = s->p[2]; |
882 |
|
s->p[2] = s->p[3]; |
883 |
|
s->p[3] = swapbyte; |
884 |
|
} |
885 |
|
#ifdef WITH_DEBUG |
886 |
|
/* warning! this debug statement will show passwords in the clear! */ |
887 |
|
hexdump(s->p, s->end - s->p); |
888 |
|
#endif |
889 |
|
} |
890 |
|
|
891 |
} |
} |
892 |
|
|
893 |
if (channel != MCS_GLOBAL_CHANNEL) |
if (channel != MCS_GLOBAL_CHANNEL) |
924 |
return True; |
return True; |
925 |
} |
} |
926 |
|
|
927 |
|
/* Establish a secure connection */ |
928 |
|
BOOL |
929 |
|
sec_reconnect(char *server) |
930 |
|
{ |
931 |
|
struct stream mcs_data; |
932 |
|
|
933 |
|
/* We exchange some RDP data during the MCS-Connect */ |
934 |
|
mcs_data.size = 512; |
935 |
|
mcs_data.p = mcs_data.data = (uint8 *) xmalloc(mcs_data.size); |
936 |
|
sec_out_mcs_data(&mcs_data); |
937 |
|
|
938 |
|
if (!mcs_reconnect(server, &mcs_data)) |
939 |
|
return False; |
940 |
|
|
941 |
|
/* sec_process_mcs_data(&mcs_data); */ |
942 |
|
if (g_encryption) |
943 |
|
sec_establish_key(); |
944 |
|
xfree(mcs_data.data); |
945 |
|
return True; |
946 |
|
} |
947 |
|
|
948 |
/* Disconnect a connection */ |
/* Disconnect a connection */ |
949 |
void |
void |
950 |
sec_disconnect(void) |
sec_disconnect(void) |
951 |
{ |
{ |
952 |
mcs_disconnect(); |
mcs_disconnect(); |
953 |
} |
} |
954 |
|
|
955 |
|
/* reset the state of the sec layer */ |
956 |
|
void |
957 |
|
sec_reset_state(void) |
958 |
|
{ |
959 |
|
g_server_rdp_version = 0; |
960 |
|
sec_encrypt_use_count = 0; |
961 |
|
sec_decrypt_use_count = 0; |
962 |
|
mcs_reset_state(); |
963 |
|
} |