From 4ec44751e2ae35542d7364b9bcad95b1a32cb135 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 6 Jul 2021 12:47:03 +0100 Subject: ProtoProxy: encrypt in-place --- Tools/ProtoProxy/Connection.cpp | 20 +++++--------------- Tools/ProtoProxy/Connection.h | 2 +- 2 files changed, 6 insertions(+), 16 deletions(-) (limited to 'Tools') diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index ba4614382..2bb6c9a43 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -421,7 +421,7 @@ bool cConnection::RelayFromClient(void) case csEncryptedUnknown: { DataLog(Buffer, static_cast(res), "Decrypted %d bytes from the CLIENT", res); - m_ServerEncryptor.ProcessData(reinterpret_cast(Buffer), reinterpret_cast(Buffer), static_cast(res)); + m_ServerEncryptor.ProcessData(reinterpret_cast(Buffer), static_cast(res)); return SERVERSEND({ reinterpret_cast(Buffer), static_cast(res) }); } } @@ -472,22 +472,12 @@ bool cConnection::SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a -bool cConnection::SendEncryptedData(SOCKET a_Socket, cAesCfb128Encryptor & a_Encryptor, ContiguousByteBufferView a_Data, const char * a_Peer) +bool cConnection::SendEncryptedData(SOCKET a_Socket, cAesCfb128Encryptor & a_Encryptor, ContiguousByteBuffer & a_Data, const char * a_Peer) { DataLog(a_Data.data(), a_Data.size(), "Encrypting %zu bytes to %s", a_Data.size(), a_Peer); - while (a_Data.size() > 0) - { - std::byte Buffer[64 KiB]; - size_t NumBytes = (a_Data.size() > sizeof(Buffer)) ? sizeof(Buffer) : a_Data.size(); - a_Encryptor.ProcessData(Buffer, a_Data.data(), NumBytes); - bool res = SendData(a_Socket, { Buffer, NumBytes }, a_Peer); - if (!res) - { - return false; - } - a_Data = a_Data.substr(NumBytes); - } - return true; + + a_Encryptor.ProcessData(a_Data.data(), a_Data.size()); + return SendData(a_Socket, a_Data, a_Peer); } diff --git a/Tools/ProtoProxy/Connection.h b/Tools/ProtoProxy/Connection.h index b524561a1..b5e1b4ce0 100644 --- a/Tools/ProtoProxy/Connection.h +++ b/Tools/ProtoProxy/Connection.h @@ -129,7 +129,7 @@ protected: bool SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a_Peer); /** Sends data to the specfied socket, after encrypting it using a_Encryptor. If sending fails, prints a fail message using a_Peer and returns false */ - bool SendEncryptedData(SOCKET a_Socket, cAesCfb128Encryptor & a_Encryptor, ContiguousByteBufferView a_Data, const char * a_Peer); + bool SendEncryptedData(SOCKET a_Socket, cAesCfb128Encryptor & a_Encryptor, ContiguousByteBuffer & a_Data, const char * a_Peer); /** Sends data to the specfied socket, after encrypting it using a_Encryptor. If sending fails, prints a fail message using a_Peer and returns false */ bool SendEncryptedData(SOCKET a_Socket, cAesCfb128Encryptor & a_Encryptor, cByteBuffer & a_Data, const char * a_Peer); -- cgit v1.2.3