|
|
@ -24,13 +24,19 @@ namespace ntcp |
|
|
|
m_Socket (service), m_TerminationTimer (service), m_IsEstablished (false), |
|
|
|
m_Socket (service), m_TerminationTimer (service), m_IsEstablished (false), |
|
|
|
m_RemoteRouterInfo (in_RemoteRouterInfo), m_ReceiveBufferOffset (0), m_NextMessage (nullptr) |
|
|
|
m_RemoteRouterInfo (in_RemoteRouterInfo), m_ReceiveBufferOffset (0), m_NextMessage (nullptr) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
m_DHKeysPair = i2p::transports.GetNextDHKeysPair (); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NTCPSession::~NTCPSession () |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
delete m_DHKeysPair; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void NTCPSession::CreateAESKey (uint8_t * pubKey, uint8_t * aesKey) |
|
|
|
void NTCPSession::CreateAESKey (uint8_t * pubKey, uint8_t * aesKey) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CryptoPP::DH dh (elgp, elgg); |
|
|
|
CryptoPP::DH dh (elgp, elgg); |
|
|
|
CryptoPP::SecByteBlock secretKey(dh.AgreedValueLength()); |
|
|
|
CryptoPP::SecByteBlock secretKey(dh.AgreedValueLength()); |
|
|
|
if (!dh.Agree (secretKey, i2p::context.GetPrivateKey (), pubKey)) |
|
|
|
if (!dh.Agree (secretKey, m_DHKeysPair->privateKey, pubKey)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("Couldn't create shared key"); |
|
|
|
LogPrint ("Couldn't create shared key"); |
|
|
|
Terminate (); |
|
|
|
Terminate (); |
|
|
@ -78,7 +84,7 @@ namespace ntcp |
|
|
|
void NTCPSession::ClientLogin () |
|
|
|
void NTCPSession::ClientLogin () |
|
|
|
{ |
|
|
|
{ |
|
|
|
// send Phase1
|
|
|
|
// send Phase1
|
|
|
|
const uint8_t * x = i2p::context.GetRouterIdentity ().publicKey; |
|
|
|
const uint8_t * x = m_DHKeysPair->publicKey; |
|
|
|
memcpy (m_Phase1.pubKey, x, 256); |
|
|
|
memcpy (m_Phase1.pubKey, x, 256); |
|
|
|
CryptoPP::SHA256().CalculateDigest(m_Phase1.HXxorHI, x, 256); |
|
|
|
CryptoPP::SHA256().CalculateDigest(m_Phase1.HXxorHI, x, 256); |
|
|
|
const uint8_t * ident = m_RemoteRouterInfo.GetIdentHash (); |
|
|
|
const uint8_t * ident = m_RemoteRouterInfo.GetIdentHash (); |
|
|
@ -143,7 +149,7 @@ namespace ntcp |
|
|
|
|
|
|
|
|
|
|
|
void NTCPSession::SendPhase2 () |
|
|
|
void NTCPSession::SendPhase2 () |
|
|
|
{ |
|
|
|
{ |
|
|
|
const uint8_t * y = i2p::context.GetRouterIdentity ().publicKey; |
|
|
|
const uint8_t * y = m_DHKeysPair->publicKey; |
|
|
|
memcpy (m_Phase2.pubKey, y, 256); |
|
|
|
memcpy (m_Phase2.pubKey, y, 256); |
|
|
|
uint8_t xy[512]; |
|
|
|
uint8_t xy[512]; |
|
|
|
memcpy (xy, m_Phase1.pubKey, 256); |
|
|
|
memcpy (xy, m_Phase1.pubKey, 256); |
|
|
@ -200,7 +206,7 @@ namespace ntcp |
|
|
|
m_Decryption.ProcessData((uint8_t *)&m_Phase2.encrypted, (uint8_t *)&m_Phase2.encrypted, sizeof(m_Phase2.encrypted)); |
|
|
|
m_Decryption.ProcessData((uint8_t *)&m_Phase2.encrypted, (uint8_t *)&m_Phase2.encrypted, sizeof(m_Phase2.encrypted)); |
|
|
|
// verify
|
|
|
|
// verify
|
|
|
|
uint8_t xy[512], hxy[32]; |
|
|
|
uint8_t xy[512], hxy[32]; |
|
|
|
memcpy (xy, i2p::context.GetRouterIdentity ().publicKey, 256); |
|
|
|
memcpy (xy, m_DHKeysPair->publicKey, 256); |
|
|
|
memcpy (xy + 256, m_Phase2.pubKey, 256); |
|
|
|
memcpy (xy + 256, m_Phase2.pubKey, 256); |
|
|
|
CryptoPP::SHA256().CalculateDigest(hxy, xy, 512); |
|
|
|
CryptoPP::SHA256().CalculateDigest(hxy, xy, 512); |
|
|
|
if (memcmp (hxy, m_Phase2.encrypted.hxy, 32)) |
|
|
|
if (memcmp (hxy, m_Phase2.encrypted.hxy, 32)) |
|
|
|