Browse Source

fixed small issues

pull/60/head
orignal 11 years ago
parent
commit
9f8f91a2ee
  1. 75
      SSU.cpp
  2. 1
      SSU.h

75
SSU.cpp

@ -138,23 +138,42 @@ namespace ssu @@ -138,23 +138,42 @@ namespace ssu
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;
switch (header->GetPayloadType ())
LogPrint ("SSU is not supported");
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:
ProcessSessionRequest (buf, len, senderEndpoint);
break;
case PAYLOAD_TYPE_SESSION_CREATED:
ProcessSessionCreated (buf, len);
LogPrint ("SSU session destroy with into key received");
m_Server.DeleteSession (this); // delete this
break;
case PAYLOAD_TYPE_PEER_TEST:
// TODO
break;
default: ;
}
}
}
case PAYLOAD_TYPE_PEER_TEST:
// TODO
break;
default: ;
}
}
void SSUSession::ProcessSessionRequest (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint)
@ -414,29 +433,6 @@ namespace ssu @@ -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,
const uint8_t * aesKey, const uint8_t * iv, const uint8_t * macKey)
{
@ -734,12 +730,13 @@ namespace ssu @@ -734,12 +730,13 @@ namespace ssu
void SSUSession::SendPeerTest ()
{
auto introKey = GetIntroKey ();
if (!introKey)
auto address = i2p::context.GetRouterInfo ().GetSSUAddress ();
if (!address)
{
LogPrint ("SSU is not supported. Can't send peer test");
return;
}
auto introKey = address->key;
uint8_t buf[80 + 18];
uint8_t * payload = buf + sizeof (SSUHeader);
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();

1
SSU.h

@ -110,7 +110,6 @@ namespace ssu @@ -110,7 +110,6 @@ namespace ssu
void Send (i2p::I2NPMessage * msg);
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 Decrypt (uint8_t * buf, size_t len, const uint8_t * aesKey);
bool Validate (uint8_t * buf, size_t len, const uint8_t * macKey);

Loading…
Cancel
Save