I'm facing a problem now though, for some reason the TQ server / client doesn't seem to like when I change the public key within those two packets.
Below is the code that handles the calls to the DHKeyExchange. When those exchange calls are commented the client is able to login, however the data is encrypted.
PHP Code:
public void HandleHandshake(byte[] Packet)
{
// exchange.HandleServerKeyPacket(Packet);
Send(Packet, DataDirection.Client);
}
public void HandleHandshakeReply(byte[] Packet)
{
// exchange.HandleClientKeyPacket(Packet);
Send(Packet, DataDirection.Server);
//exchange.UpdateEncryptionKeys(clientCipher, serverCipher);
}
PHP Code:
public void Send(byte[] Packet, DataDirection Direction)
{
if (Direction == DataDirection.Client)
{
localSocket.Send(clientCipher.Encrypt(Packet));
}
else
{
remoteSocket.Send(serverCipher.Encrypt(Packet));
}
}
public void Decrypt(byte[] Packet, DataDirection Direction)
{
if (Direction == DataDirection.Client)
{
byte[] Decrypted = clientCipher.Decrypt(Packet);
Buffer.BlockCopy(Decrypted, 0, Packet, 0, Decrypted.Length);
}
else
{
byte[] Decrypted = serverCipher.Decrypt(Packet);
Buffer.BlockCopy(Decrypted, 0, Packet, 0, Decrypted.Length);
}
}
EDIT: It should be noted that I can actually decrypt the server and client packets properly. The problem could be also when encrypting the data for re-send (client -> server perhaps? since the client answers with the reply I can assume that the server->client portion should be fine)






