|
|
@ -24,6 +24,12 @@ namespace i2p |
|
|
|
{ |
|
|
|
{ |
|
|
|
namespace transport |
|
|
|
namespace transport |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct NTCPWork |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::shared_ptr<NTCPSession> session; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
NTCPSession::NTCPSession (NTCPServer& server, std::shared_ptr<const i2p::data::RouterInfo> in_RemoteRouter): |
|
|
|
NTCPSession::NTCPSession (NTCPServer& server, std::shared_ptr<const i2p::data::RouterInfo> in_RemoteRouter): |
|
|
|
TransportSession (in_RemoteRouter, NTCP_ESTABLISH_TIMEOUT), |
|
|
|
TransportSession (in_RemoteRouter, NTCP_ESTABLISH_TIMEOUT), |
|
|
|
m_Server (server), m_Socket (m_Server.GetService ()), |
|
|
|
m_Server (server), m_Socket (m_Server.GetService ()), |
|
|
@ -177,19 +183,20 @@ namespace transport |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// TODO: check for number of pending keys
|
|
|
|
// TODO: check for number of pending keys
|
|
|
|
auto s = shared_from_this (); |
|
|
|
auto work = new NTCPWork{shared_from_this()}; |
|
|
|
// TODO: we need to pass this for gcc 4.7, should be removed later on
|
|
|
|
m_Server.Work(work->session, [work, this]() -> std::function<void(void)> { |
|
|
|
m_Server.Work(s, [s, this]() -> std::function<void(void)> { |
|
|
|
if (!work->session->m_DHKeysPair) |
|
|
|
if (!s->m_DHKeysPair) |
|
|
|
work->session->m_DHKeysPair = transports.GetNextDHKeysPair (); |
|
|
|
s->m_DHKeysPair = transports.GetNextDHKeysPair (); |
|
|
|
work->session->CreateAESKey (work->session->m_Establisher->phase1.pubKey); |
|
|
|
s->CreateAESKey (s->m_Establisher->phase1.pubKey); |
|
|
|
return std::bind(&NTCPSession::SendPhase2, work->session, work); |
|
|
|
return std::bind(&NTCPSession::SendPhase2, s); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void NTCPSession::SendPhase2 () |
|
|
|
void NTCPSession::SendPhase2 (NTCPWork * work) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if(work) |
|
|
|
|
|
|
|
delete work; |
|
|
|
const uint8_t * y = m_DHKeysPair->GetPublicKey (); |
|
|
|
const uint8_t * y = m_DHKeysPair->GetPublicKey (); |
|
|
|
memcpy (m_Establisher->phase2.pubKey, y, 256); |
|
|
|
memcpy (m_Establisher->phase2.pubKey, y, 256); |
|
|
|
uint8_t xy[512]; |
|
|
|
uint8_t xy[512]; |
|
|
@ -242,17 +249,17 @@ namespace transport |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto s = shared_from_this (); |
|
|
|
auto work = new NTCPWork{shared_from_this()}; |
|
|
|
// TODO: we need to pass this for gcc 4.7, should be removed later on
|
|
|
|
m_Server.Work(work->session, [work, this]() -> std::function<void(void)> { |
|
|
|
m_Server.Work(s, [s, this]() -> std::function<void(void)> { |
|
|
|
work->session->CreateAESKey (work->session->m_Establisher->phase2.pubKey); |
|
|
|
s->CreateAESKey (s->m_Establisher->phase2.pubKey); |
|
|
|
return std::bind(&NTCPSession::HandlePhase2, work->session, work); |
|
|
|
return std::bind(&NTCPSession::HandlePhase2, s); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void NTCPSession::HandlePhase2 () |
|
|
|
void NTCPSession::HandlePhase2 (NTCPWork * work) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if(work) delete work; |
|
|
|
m_Decryption.SetIV (m_Establisher->phase2.pubKey + 240); |
|
|
|
m_Decryption.SetIV (m_Establisher->phase2.pubKey + 240); |
|
|
|
m_Encryption.SetIV (m_Establisher->phase1.HXxorHI + 16); |
|
|
|
m_Encryption.SetIV (m_Establisher->phase1.HXxorHI + 16); |
|
|
|
|
|
|
|
|
|
|
|