Add handshake session timeout protection

This commit is contained in:
savis
2025-12-28 05:03:47 +01:00
parent c34a721328
commit e4182a1b9e
3 changed files with 28 additions and 0 deletions

View File

@@ -52,6 +52,7 @@ void DESC::Initialize()
m_iHandshakeRetry = 0;
m_dwClientTime = 0;
m_bHandshaking = false;
m_handshake_time = get_dword_time();
m_lpBufferedOutputBuffer = NULL;
m_lpOutputBuffer = NULL;
@@ -715,6 +716,14 @@ bool DESC::IsHandshaking()
return m_bHandshaking;
}
bool DESC::IsExpiredHandshake() const
{
if (m_handshake_time == 0)
return false;
return (m_handshake_time + (5 * 1000)) < get_dword_time();
}
DWORD DESC::GetClientTime()
{
return m_dwClientTime;

View File

@@ -174,6 +174,10 @@ class DESC
bool isChannelStatusRequested() const { return m_bChannelStatusRequested; }
void SetChannelStatusRequested(bool bChannelStatusRequested) { m_bChannelStatusRequested = bChannelStatusRequested; }
// Handshake timeout check
bool IsExpiredHandshake() const;
void SetHandshakeTime(uint32_t handshake_time) { m_handshake_time = handshake_time; }
protected:
void Initialize();
@@ -246,6 +250,9 @@ class DESC
bool m_bDestroyed;
bool m_bChannelStatusRequested;
// Handshake timeout protection
uint32_t m_handshake_time;
#ifdef _IMPROVED_PACKET_ENCRYPTION_
Cipher cipher_;
#else

View File

@@ -224,6 +224,18 @@ void DESC_MANAGER::DestroyClosed()
DestroyDesc(d, false);
m_set_pkDesc.erase(ci);
}
else if (d->IsPhase(PHASE_HANDSHAKE))
{
if (d->GetType() == DESC_TYPE_ACCEPTOR)
{
if (d->IsExpiredHandshake())
{
sys_log(0, "[%s]: handshake session has expired!", d->GetHostName());
DestroyDesc(d, false);
m_set_pkDesc.erase(ci);
}
}
}
}
}