fix cipher desync issue

update the handshake phase to call the new method after activating the cipher, ensuring buffered data (likely from a second login attempt, GC_PHASE) is properly decrypted, and fix a logging format issue.
This commit is contained in:
mq1n
2025-09-07 20:24:38 +03:00
parent 397e2b1890
commit eaecf67d33
4 changed files with 17 additions and 2 deletions

View File

@@ -780,7 +780,7 @@ bool CNetworkStream::Send(int size, const char * pSrcBuf)
if (*pSrcBuf != 0)
{
const auto kHeader = *pSrcBuf;
TraceError("SEND> %s %u(0x%X) (%d)", GetRecvHeaderName(kHeader), kHeader, kHeader, size);
TraceError("SEND> %s %u(0x%X) (%d)", GetSendHeaderName(kHeader), kHeader, kHeader, size);
const auto contents = dump_hex(reinterpret_cast<const uint8_t*>(pSrcBuf), size);
TraceError("%s", contents.c_str());
@@ -956,4 +956,17 @@ void CNetworkStream::ActivateCipher()
{
return m_cipher.set_activated(true);
}
// If cipher is active and there's unread data in buffer, decrypt it in-place
void CNetworkStream::DecryptAlreadyReceivedData()
{
if (!IsSecurityMode())
return;
const int unreadSize = m_recvBufInputPos - m_recvBufOutputPos;
if (unreadSize <= 0)
return;
m_cipher.Decrypt(m_recvBuf + m_recvBufOutputPos, unreadSize);
}
#endif // _IMPROVED_PACKET_ENCRYPTION_