mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 08:00:38 +03:00
fixed small issues
This commit is contained in:
parent
be563dcbd1
commit
9f8f91a2ee
71
SSU.cpp
71
SSU.cpp
@ -138,22 +138,41 @@ namespace ssu
|
|||||||
|
|
||||||
void SSUSession::ProcessIntroKeyMessage (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint)
|
void SSUSession::ProcessIntroKeyMessage (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint)
|
||||||
{
|
{
|
||||||
if (ProcessIntroKeyEncryptedMessage (buf, len))
|
auto introKey = GetIntroKey ();
|
||||||
|
if (!introKey)
|
||||||
{
|
{
|
||||||
SSUHeader * header = (SSUHeader *)buf;
|
LogPrint ("SSU is not supported");
|
||||||
switch (header->GetPayloadType ())
|
return;
|
||||||
|
}
|
||||||
|
// use intro key for verification and decryption
|
||||||
|
if (!Validate (buf, len, introKey))
|
||||||
|
{
|
||||||
|
LogPrint ("MAC verification intro key failed");
|
||||||
|
Failed ();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Decrypt (buf, len, introKey);
|
||||||
|
CreateAESandMacKey (buf + sizeof (SSUHeader), m_SessionKey, m_MacKey);
|
||||||
|
SSUHeader * header = (SSUHeader *)buf;
|
||||||
|
switch (header->GetPayloadType ())
|
||||||
|
{
|
||||||
|
case PAYLOAD_TYPE_SESSION_REQUEST:
|
||||||
|
ProcessSessionRequest (buf, len, senderEndpoint);
|
||||||
|
break;
|
||||||
|
case PAYLOAD_TYPE_SESSION_CREATED:
|
||||||
|
ProcessSessionCreated (buf, len);
|
||||||
|
break;
|
||||||
|
case PAYLOAD_TYPE_SESSION_DESTROYED:
|
||||||
{
|
{
|
||||||
case PAYLOAD_TYPE_SESSION_REQUEST:
|
LogPrint ("SSU session destroy with into key received");
|
||||||
ProcessSessionRequest (buf, len, senderEndpoint);
|
m_Server.DeleteSession (this); // delete this
|
||||||
break;
|
break;
|
||||||
case PAYLOAD_TYPE_SESSION_CREATED:
|
|
||||||
ProcessSessionCreated (buf, len);
|
|
||||||
break;
|
|
||||||
case PAYLOAD_TYPE_PEER_TEST:
|
|
||||||
// TODO
|
|
||||||
break;
|
|
||||||
default: ;
|
|
||||||
}
|
}
|
||||||
|
case PAYLOAD_TYPE_PEER_TEST:
|
||||||
|
// TODO
|
||||||
|
break;
|
||||||
|
default: ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,29 +433,6 @@ namespace ssu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SSUSession::ProcessIntroKeyEncryptedMessage (uint8_t * buf, size_t len)
|
|
||||||
{
|
|
||||||
auto introKey = GetIntroKey ();
|
|
||||||
if (introKey)
|
|
||||||
{
|
|
||||||
// use intro key for verification and decryption
|
|
||||||
if (Validate (buf, len, introKey))
|
|
||||||
{
|
|
||||||
Decrypt (buf, len, introKey);
|
|
||||||
CreateAESandMacKey (buf + sizeof (SSUHeader), m_SessionKey, m_MacKey);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LogPrint ("MAC verification failed");
|
|
||||||
Failed ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
LogPrint ("SSU is not supported");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SSUSession::FillHeaderAndEncrypt (uint8_t payloadType, uint8_t * buf, size_t len,
|
void SSUSession::FillHeaderAndEncrypt (uint8_t payloadType, uint8_t * buf, size_t len,
|
||||||
const uint8_t * aesKey, const uint8_t * iv, const uint8_t * macKey)
|
const uint8_t * aesKey, const uint8_t * iv, const uint8_t * macKey)
|
||||||
{
|
{
|
||||||
@ -734,12 +730,13 @@ namespace ssu
|
|||||||
|
|
||||||
void SSUSession::SendPeerTest ()
|
void SSUSession::SendPeerTest ()
|
||||||
{
|
{
|
||||||
auto introKey = GetIntroKey ();
|
auto address = i2p::context.GetRouterInfo ().GetSSUAddress ();
|
||||||
if (!introKey)
|
if (!address)
|
||||||
{
|
{
|
||||||
LogPrint ("SSU is not supported. Can't send peer test");
|
LogPrint ("SSU is not supported. Can't send peer test");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
auto introKey = address->key;
|
||||||
uint8_t buf[80 + 18];
|
uint8_t buf[80 + 18];
|
||||||
uint8_t * payload = buf + sizeof (SSUHeader);
|
uint8_t * payload = buf + sizeof (SSUHeader);
|
||||||
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
|
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
|
||||||
|
1
SSU.h
1
SSU.h
@ -110,7 +110,6 @@ namespace ssu
|
|||||||
void Send (i2p::I2NPMessage * msg);
|
void Send (i2p::I2NPMessage * msg);
|
||||||
void Send (uint8_t type, const uint8_t * payload, size_t len); // with session key
|
void Send (uint8_t type, const uint8_t * payload, size_t len); // with session key
|
||||||
|
|
||||||
bool ProcessIntroKeyEncryptedMessage (uint8_t * buf, size_t len);
|
|
||||||
void FillHeaderAndEncrypt (uint8_t payloadType, uint8_t * buf, size_t len, const uint8_t * aesKey, const uint8_t * iv, const uint8_t * macKey);
|
void FillHeaderAndEncrypt (uint8_t payloadType, uint8_t * buf, size_t len, const uint8_t * aesKey, const uint8_t * iv, const uint8_t * macKey);
|
||||||
void Decrypt (uint8_t * buf, size_t len, const uint8_t * aesKey);
|
void Decrypt (uint8_t * buf, size_t len, const uint8_t * aesKey);
|
||||||
bool Validate (uint8_t * buf, size_t len, const uint8_t * macKey);
|
bool Validate (uint8_t * buf, size_t len, const uint8_t * macKey);
|
||||||
|
Loading…
Reference in New Issue
Block a user