From baeaf1330ff12ff44eeb191b85430e3657ddb7ab Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 6 Feb 2005 02:12:18 +0000 Subject: [PATCH] Fix encryption, client connects!! --- channels.c | 8 ++++---- secure.c | 33 +++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/channels.c b/channels.c index ba3248c..b14f82a 100644 --- a/channels.c +++ b/channels.c @@ -68,7 +68,7 @@ channel_init(VCHANNEL * channel, uint32 length) { STREAM s; - s = sec_init(/*g_encryption ? SEC_ENCRYPT :*/ 0, length + 8); + s = sec_init(g_encryption ? SEC_ENCRYPT : 0, length + 8); s_push_layer(s, channel_hdr, 8); return s; } @@ -100,7 +100,7 @@ channel_send(STREAM s, VCHANNEL * channel) out_uint32_le(s, flags); data = s->end = s->p + thislength; DEBUG_CLIPBOARD(("Sending %d bytes with FLAG_FIRST\n", thislength)); - sec_send_to_channel(s, /*g_encryption ? SEC_ENCRYPT :*/ 0, channel->mcs_id); + sec_send_to_channel(s, g_encryption ? SEC_ENCRYPT : 0, channel->mcs_id); /* subsequent segments copied (otherwise would have to generate headers backwards) */ while (remaining > 0) @@ -113,12 +113,12 @@ channel_send(STREAM s, VCHANNEL * channel) DEBUG_CLIPBOARD(("Sending %d bytes with flags %d\n", thislength, flags)); - s = sec_init(/*g_encryption ? SEC_ENCRYPT : */0, thislength + 8); + s = sec_init(g_encryption ? SEC_ENCRYPT : 0, thislength + 8); out_uint32_le(s, length); out_uint32_le(s, flags); out_uint8p(s, data, thislength); s_mark_end(s); - sec_send_to_channel(s, /*g_encryption ? SEC_ENCRYPT : */0, channel->mcs_id); + sec_send_to_channel(s, g_encryption ? SEC_ENCRYPT : 0, channel->mcs_id); data += thislength; } diff --git a/secure.c b/secure.c index 1282a7f..62e59a5 100644 --- a/secure.c +++ b/secure.c @@ -169,6 +169,8 @@ sec_generate_keys(uint8 * client_key, uint8 * server_key, int rc4_key_size) printf("0x%02x ", sec_encrypt_key[i]); printf("\n"); } + + g_encryption = 1; } static uint8 pad_54[40] = { @@ -264,6 +266,8 @@ 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++; } @@ -346,6 +350,7 @@ sec_init(uint32 flags, int maxlen) hdrlen = (flags & SEC_ENCRYPT) ? 12 : 4; else hdrlen = (flags & SEC_ENCRYPT) ? 12 : 0; + printf("HDRLEN is %u\n", hdrlen); s = mcs_init(maxlen + hdrlen); s_push_layer(s, sec_hdr, hdrlen); @@ -860,18 +865,22 @@ sec_recv(void) if (tag == LICENCE_TAG_PRESENT) { process_presented_license(s); - s = sec_init(sizeof(result_license), SEC_LICENCE_NEG); - out_uint8p(s, result_license, sizeof(result_license)); - s_mark_end(s); - sec_send(s, SEC_LICENCE_NEG); - - //g_licence_issued = 1; + { + 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); + } - printf("Sending DEMAND_ACTIVE (0x%x bytes)\n", sizeof(demand_active)); - s = sec_init(sizeof(demand_active), SEC_ENCRYPT); - out_uint8p(s, demand_active, sizeof(demand_active)); - s_mark_end(s); - sec_send(s, SEC_ENCRYPT); + { + 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); + } } continue; @@ -886,7 +895,7 @@ sec_recv(void) { STREAM s; - s = sec_init(sizeof(demand_license), SEC_LICENCE_NEG); + s = sec_init(SEC_LICENCE_NEG, sizeof(demand_license)); out_uint8p(s, demand_license, sizeof(demand_license)); s_mark_end(s); sec_send(s, SEC_LICENCE_NEG); -- 2.39.2