|
|
@ -55,10 +55,9 @@ namespace data |
|
|
|
// don't delete buffer until save to file
|
|
|
|
// don't delete buffer until save to file
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RouterInfo::SetRouterIdentity (const Identity& identity) |
|
|
|
void RouterInfo::SetRouterIdentity (const IdentityEx& identity) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_RouterIdentity = identity; |
|
|
|
m_RouterIdentity = identity; |
|
|
|
m_IdentHash = m_RouterIdentity.Hash (); |
|
|
|
|
|
|
|
m_Timestamp = i2p::util::GetMillisecondsSinceEpoch (); |
|
|
|
m_Timestamp = i2p::util::GetMillisecondsSinceEpoch (); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -95,28 +94,15 @@ namespace data |
|
|
|
|
|
|
|
|
|
|
|
void RouterInfo::ReadFromBuffer (bool verifySignature) |
|
|
|
void RouterInfo::ReadFromBuffer (bool verifySignature) |
|
|
|
{ |
|
|
|
{ |
|
|
|
size_t identityLen = DEFAULT_IDENTITY_SIZE; |
|
|
|
size_t identityLen = m_RouterIdentity.FromBuffer (m_Buffer, m_BufferLen); |
|
|
|
memcpy (&m_RouterIdentity, m_Buffer, DEFAULT_IDENTITY_SIZE); |
|
|
|
|
|
|
|
if (m_RouterIdentity.certificate.type != CERTIFICATE_TYPE_NULL) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint (eLogError, "Certificate type ", m_RouterIdentity.certificate.type, " is not supported"); |
|
|
|
|
|
|
|
SetUnreachable (true); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::stringstream str (std::string ((char *)m_Buffer + identityLen, m_BufferLen - identityLen)); |
|
|
|
std::stringstream str (std::string ((char *)m_Buffer + identityLen, m_BufferLen - identityLen)); |
|
|
|
ReadFromStream (str); |
|
|
|
ReadFromStream (str); |
|
|
|
if (verifySignature) |
|
|
|
if (verifySignature) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// verify signature
|
|
|
|
// verify signature
|
|
|
|
CryptoPP::DSA::PublicKey pubKey; |
|
|
|
int l = m_BufferLen - m_RouterIdentity.GetSignatureLen (); |
|
|
|
pubKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag, CryptoPP::Integer (m_RouterIdentity.signingKey, 128)); |
|
|
|
if (!m_RouterIdentity.Verify ((uint8_t *)m_Buffer, l, (uint8_t *)m_Buffer + l)) |
|
|
|
CryptoPP::DSA::Verifier verifier (pubKey); |
|
|
|
|
|
|
|
int l = m_BufferLen - 40; |
|
|
|
|
|
|
|
if (!verifier.VerifyMessage ((uint8_t *)m_Buffer, l, (uint8_t *)m_Buffer + l, 40)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint (eLogError, "signature verification failed"); |
|
|
|
LogPrint (eLogError, "signature verification failed"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -234,8 +220,6 @@ namespace data |
|
|
|
if (!strcmp (key, "caps")) |
|
|
|
if (!strcmp (key, "caps")) |
|
|
|
ExtractCaps (value); |
|
|
|
ExtractCaps (value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CryptoPP::SHA256().CalculateDigest(m_IdentHash, (uint8_t *)&m_RouterIdentity, sizeof (m_RouterIdentity)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!m_SupportedTransports || !m_Addresses.size() || (UsesIntroducer () && !introducers)) |
|
|
|
if (!m_SupportedTransports || !m_Addresses.size() || (UsesIntroducer () && !introducers)) |
|
|
|
SetUnreachable (true); |
|
|
|
SetUnreachable (true); |
|
|
|