|
|
@ -853,6 +853,8 @@ namespace transport |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case eSSU2BlkRelayTag: |
|
|
|
case eSSU2BlkRelayTag: |
|
|
|
|
|
|
|
LogPrint (eLogDebug, "SSU2: RelayTag"); |
|
|
|
|
|
|
|
m_RelayTag = bufbe32toh (buf + offset); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case eSSU2BlkNewToken: |
|
|
|
case eSSU2BlkNewToken: |
|
|
|
{ |
|
|
|
{ |
|
|
@ -1026,8 +1028,8 @@ namespace transport |
|
|
|
s.Insert (session->GetRemoteIdentity ()->GetIdentHash (), 32); // chash
|
|
|
|
s.Insert (session->GetRemoteIdentity ()->GetIdentHash (), 32); // chash
|
|
|
|
s.Insert (buf + 1, 14); // nonce, relay tag, timestamp, ver, asz
|
|
|
|
s.Insert (buf + 1, 14); // nonce, relay tag, timestamp, ver, asz
|
|
|
|
uint8_t asz = buf[14]; |
|
|
|
uint8_t asz = buf[14]; |
|
|
|
s.Insert (buf + 15, asz + 2); // Alice IP, Alice Port
|
|
|
|
s.Insert (buf + 15, asz); // Alice Port, Alice IP
|
|
|
|
if (!s.Verify (GetRemoteIdentity (), buf + 17 + asz)) |
|
|
|
if (!s.Verify (GetRemoteIdentity (), buf + 15 + asz)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogWarning, "SSU2: RelayRequest signature verification failed"); |
|
|
|
LogPrint (eLogWarning, "SSU2: RelayRequest signature verification failed"); |
|
|
|
return; // TODO: send relay response
|
|
|
|
return; // TODO: send relay response
|
|
|
@ -1040,6 +1042,29 @@ namespace transport |
|
|
|
session->SendData (payload, payloadSize); |
|
|
|
session->SendData (payload, payloadSize); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SSU2Session::HandleRelayIntro (const uint8_t * buf, size_t len) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// we are Charlie
|
|
|
|
|
|
|
|
SignedData s; |
|
|
|
|
|
|
|
s.Insert ((const uint8_t *)"RelayRequestData", 16); // prologue
|
|
|
|
|
|
|
|
s.Insert (GetRemoteIdentity ()->GetIdentHash (), 32); // bhash
|
|
|
|
|
|
|
|
s.Insert (i2p::context.GetIdentHash (), 32); // chash
|
|
|
|
|
|
|
|
s.Insert (buf + 33, 14); // nonce, relay tag, timestamp, ver, asz
|
|
|
|
|
|
|
|
uint8_t asz = buf[46]; |
|
|
|
|
|
|
|
s.Insert (buf + 47, asz); // Alice Port, Alice IP
|
|
|
|
|
|
|
|
if (!s.Verify (GetRemoteIdentity (), buf + 47 + asz)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint (eLogWarning, "SSU2: RelayIntro signature verification failed"); |
|
|
|
|
|
|
|
return; // TODO: send relay response
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: send RelayResponse to Bob
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boost::asio::ip::udp::endpoint ep; |
|
|
|
|
|
|
|
if (ExtractEndpoint (buf + 47, asz, ep)) |
|
|
|
|
|
|
|
m_Server.SendHolePunch (ep); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool SSU2Session::ExtractEndpoint (const uint8_t * buf, size_t size, boost::asio::ip::udp::endpoint& ep) |
|
|
|
bool SSU2Session::ExtractEndpoint (const uint8_t * buf, size_t size, boost::asio::ip::udp::endpoint& ep) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (size < 2) return false; |
|
|
|
if (size < 2) return false; |
|
|
@ -1580,7 +1605,10 @@ namespace transport |
|
|
|
m_SocketV6.send_to (bufs, to, 0, ec); |
|
|
|
m_SocketV6.send_to (bufs, to, 0, ec); |
|
|
|
else |
|
|
|
else |
|
|
|
m_SocketV4.send_to (bufs, to, 0, ec); |
|
|
|
m_SocketV4.send_to (bufs, to, 0, ec); |
|
|
|
|
|
|
|
if (!ec) |
|
|
|
i2p::transport::transports.UpdateSentBytes (headerLen + payloadLen); |
|
|
|
i2p::transport::transports.UpdateSentBytes (headerLen + payloadLen); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
LogPrint (eLogError, "SSU2: Send exception: ", ec.message (), " to ", to); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SSU2Server::Send (const uint8_t * header, size_t headerLen, const uint8_t * headerX, size_t headerXLen, |
|
|
|
void SSU2Server::Send (const uint8_t * header, size_t headerLen, const uint8_t * headerX, size_t headerXLen, |
|
|
@ -1597,7 +1625,23 @@ namespace transport |
|
|
|
m_SocketV6.send_to (bufs, to, 0, ec); |
|
|
|
m_SocketV6.send_to (bufs, to, 0, ec); |
|
|
|
else |
|
|
|
else |
|
|
|
m_SocketV4.send_to (bufs, to, 0, ec); |
|
|
|
m_SocketV4.send_to (bufs, to, 0, ec); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!ec) |
|
|
|
i2p::transport::transports.UpdateSentBytes (headerLen + headerXLen + payloadLen); |
|
|
|
i2p::transport::transports.UpdateSentBytes (headerLen + headerXLen + payloadLen); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
LogPrint (eLogError, "SSU2: Send exception: ", ec.message (), " to ", to); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SSU2Server::SendHolePunch (const boost::asio::ip::udp::endpoint& to) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
boost::system::error_code ec; |
|
|
|
|
|
|
|
if (to.address ().is_v6 ()) |
|
|
|
|
|
|
|
m_SocketV6.send_to (boost::asio::buffer ((uint8_t *)nullptr, 0), to, 0, ec); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
m_SocketV4.send_to (boost::asio::buffer ((uint8_t *)nullptr, 0), to, 0, ec); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ec) |
|
|
|
|
|
|
|
LogPrint (eLogError, "SSU2: Send exception: ", ec.message (), " to ", to); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool SSU2Server::CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, |
|
|
|
bool SSU2Server::CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, |
|
|
|