mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
correct buffer size for fragments of SessionConfirmed
This commit is contained in:
parent
f1d3d6a7b5
commit
0c34189d94
@ -374,7 +374,11 @@ namespace transport
|
|||||||
m_LastSession->ProcessData (buf, len);
|
m_LastSession->ProcessData (buf, len);
|
||||||
break;
|
break;
|
||||||
case eSSU2SessionStateSessionCreatedSent:
|
case eSSU2SessionStateSessionCreatedSent:
|
||||||
m_LastSession->ProcessSessionConfirmed (buf, len);
|
if (!m_LastSession->ProcessSessionConfirmed (buf, len))
|
||||||
|
{
|
||||||
|
m_LastSession->Terminate ();
|
||||||
|
m_LastSession = nullptr;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case eSSU2SessionStateIntroduced:
|
case eSSU2SessionStateIntroduced:
|
||||||
if (m_LastSession->GetRemoteEndpoint ().address ().is_unspecified ())
|
if (m_LastSession->GetRemoteEndpoint ().address ().is_unspecified ())
|
||||||
|
@ -325,7 +325,6 @@ namespace transport
|
|||||||
LogPrint (eLogDebug, "SSU2: Resending ", (int)m_State);
|
LogPrint (eLogDebug, "SSU2: Resending ", (int)m_State);
|
||||||
m_Server.Send (m_SentHandshakePacket->header.buf, 16, m_SentHandshakePacket->headerX, 48,
|
m_Server.Send (m_SentHandshakePacket->header.buf, 16, m_SentHandshakePacket->headerX, 48,
|
||||||
m_SentHandshakePacket->payload, m_SentHandshakePacket->payloadSize, m_RemoteEndpoint);
|
m_SentHandshakePacket->payload, m_SentHandshakePacket->payloadSize, m_RemoteEndpoint);
|
||||||
m_SentHandshakePacket->numResends++;
|
|
||||||
m_SentHandshakePacket->nextResendTime = ts + SSU2_HANDSHAKE_RESEND_INTERVAL;
|
m_SentHandshakePacket->nextResendTime = ts + SSU2_HANDSHAKE_RESEND_INTERVAL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -678,22 +677,24 @@ namespace transport
|
|||||||
if (!(header.h.flags[0] & 0xF0))
|
if (!(header.h.flags[0] & 0xF0))
|
||||||
{
|
{
|
||||||
// first fragment
|
// first fragment
|
||||||
m_SessionConfirmedFragment1.reset (new HandshakePacket);
|
if (!m_SessionConfirmedFragment1)
|
||||||
m_SessionConfirmedFragment1->header = header;
|
{
|
||||||
memcpy (m_SessionConfirmedFragment1->payload, buf + 16, len - 16);
|
m_SessionConfirmedFragment1.reset (new HandshakePacket);
|
||||||
m_SessionConfirmedFragment1->payloadSize = len - 16;
|
m_SessionConfirmedFragment1->header = header;
|
||||||
|
memcpy (m_SessionConfirmedFragment1->payload, buf + 16, len - 16);
|
||||||
|
m_SessionConfirmedFragment1->payloadSize = len - 16;
|
||||||
|
}
|
||||||
return true; // wait for second fragment
|
return true; // wait for second fragment
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// second fragment
|
// second fragment
|
||||||
if (!m_SessionConfirmedFragment1) return false; // out of sequence
|
if (!m_SessionConfirmedFragment1) return false; // out of sequence
|
||||||
uint8_t fullMsg[2*SSU2_MTU];
|
|
||||||
header = m_SessionConfirmedFragment1->header;
|
header = m_SessionConfirmedFragment1->header;
|
||||||
memcpy (fullMsg + 16, m_SessionConfirmedFragment1->payload, m_SessionConfirmedFragment1->payloadSize);
|
memcpy (m_SessionConfirmedFragment1->payload + m_SessionConfirmedFragment1->payloadSize, buf + 16, len - 16);
|
||||||
memcpy (fullMsg + 16 + m_SessionConfirmedFragment1->payloadSize, buf + 16, len - 16);
|
m_SessionConfirmedFragment1->payloadSize += (len - 16);
|
||||||
buf = fullMsg;
|
buf = m_SessionConfirmedFragment1->payload - 16;
|
||||||
len += m_SessionConfirmedFragment1->payloadSize;
|
len = m_SessionConfirmedFragment1->payloadSize + 16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// KDF for Session Confirmed part 1
|
// KDF for Session Confirmed part 1
|
||||||
@ -724,6 +725,7 @@ namespace transport
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
m_NoiseState->MixHash (payload, len - 64); // h = SHA256(h || ciphertext);
|
m_NoiseState->MixHash (payload, len - 64); // h = SHA256(h || ciphertext);
|
||||||
|
if (m_SessionConfirmedFragment1) m_SessionConfirmedFragment1.reset (nullptr);
|
||||||
// payload
|
// payload
|
||||||
// handle RouterInfo block that must be first
|
// handle RouterInfo block that must be first
|
||||||
if (decryptedPayload[0] != eSSU2BlkRouterInfo)
|
if (decryptedPayload[0] != eSSU2BlkRouterInfo)
|
||||||
|
@ -190,10 +190,13 @@ namespace transport
|
|||||||
int numResends = 0;
|
int numResends = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HandshakePacket: public SentPacket
|
struct HandshakePacket
|
||||||
{
|
{
|
||||||
Header header;
|
Header header;
|
||||||
uint8_t headerX[48]; // part1 for SessionConfirmed
|
uint8_t headerX[48]; // part1 for SessionConfirmed
|
||||||
|
uint8_t payload[SSU2_MAX_PACKET_SIZE*2];
|
||||||
|
size_t payloadSize = 0;
|
||||||
|
uint32_t nextResendTime = 0; // in seconds
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::function<void ()> OnEstablished;
|
typedef std::function<void ()> OnEstablished;
|
||||||
|
Loading…
Reference in New Issue
Block a user