Browse Source

support of RI with EcDSA

pull/113/head
orignal 10 years ago
parent
commit
f9ec60265a
  1. 11
      Identity.cpp
  2. 4
      Identity.h
  3. 2
      RouterContext.cpp
  4. 24
      RouterInfo.cpp
  5. 15
      RouterInfo.h
  6. 4
      version.h

11
Identity.cpp

@ -100,7 +100,7 @@ namespace data
m_ExtendedBuffer = nullptr; m_ExtendedBuffer = nullptr;
delete m_Verifier; delete m_Verifier;
CreateVerifier (); m_Verifier = nullptr;
return *this; return *this;
} }
@ -115,7 +115,7 @@ namespace data
m_ExtendedLen = 0; m_ExtendedLen = 0;
delete m_Verifier; delete m_Verifier;
CreateVerifier (); m_Verifier = nullptr;
return *this; return *this;
} }
@ -139,7 +139,7 @@ namespace data
CryptoPP::SHA256().CalculateDigest(m_IdentHash, buf, GetFullLen ()); CryptoPP::SHA256().CalculateDigest(m_IdentHash, buf, GetFullLen ());
delete m_Verifier; delete m_Verifier;
CreateVerifier (); m_Verifier = nullptr;
return GetFullLen (); return GetFullLen ();
} }
@ -161,6 +161,7 @@ namespace data
size_t IdentityEx::GetSigningPublicKeyLen () const size_t IdentityEx::GetSigningPublicKeyLen () const
{ {
if (!m_Verifier) CreateVerifier ();
if (m_Verifier) if (m_Verifier)
return m_Verifier->GetPublicKeyLen (); return m_Verifier->GetPublicKeyLen ();
return 128; return 128;
@ -168,12 +169,14 @@ namespace data
size_t IdentityEx::GetSignatureLen () const size_t IdentityEx::GetSignatureLen () const
{ {
if (!m_Verifier) CreateVerifier ();
if (m_Verifier) if (m_Verifier)
return m_Verifier->GetSignatureLen (); return m_Verifier->GetSignatureLen ();
return 40; return 40;
} }
bool IdentityEx::Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const bool IdentityEx::Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const
{ {
if (!m_Verifier) CreateVerifier ();
if (m_Verifier) if (m_Verifier)
return m_Verifier->Verify (buf, len, signature); return m_Verifier->Verify (buf, len, signature);
return false; return false;
@ -186,7 +189,7 @@ namespace data
return SIGNING_KEY_TYPE_DSA_SHA1; return SIGNING_KEY_TYPE_DSA_SHA1;
} }
void IdentityEx::CreateVerifier () void IdentityEx::CreateVerifier () const
{ {
auto keyType = GetSigningKeyType (); auto keyType = GetSigningKeyType ();
switch (keyType) switch (keyType)

4
Identity.h

@ -134,13 +134,13 @@ namespace data
private: private:
void CreateVerifier (); void CreateVerifier () const;
private: private:
Identity m_StandardIdentity; Identity m_StandardIdentity;
IdentHash m_IdentHash; IdentHash m_IdentHash;
i2p::crypto::Verifier * m_Verifier; mutable i2p::crypto::Verifier * m_Verifier;
size_t m_ExtendedLen; size_t m_ExtendedLen;
uint8_t * m_ExtendedBuffer; uint8_t * m_ExtendedBuffer;
}; };

2
RouterContext.cpp

@ -34,7 +34,7 @@ namespace i2p
void RouterContext::NewRouterInfo () void RouterContext::NewRouterInfo ()
{ {
i2p::data::RouterInfo routerInfo; i2p::data::RouterInfo routerInfo;
routerInfo.SetRouterIdentity (GetIdentity ().GetStandardIdentity ()); routerInfo.SetRouterIdentity (GetIdentity ());
int port = i2p::util::config::GetArg("-port", 0); int port = i2p::util::config::GetArg("-port", 0);
if (!port) if (!port)
port = m_Rnd.GenerateWord32 (9111, 30777); // I2P network ports range port = m_Rnd.GenerateWord32 (9111, 30777); // I2P network ports range

24
RouterInfo.cpp

@ -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");
}
} }
} }
@ -235,8 +221,6 @@ namespace data
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);
} }

15
RouterInfo.h

@ -90,10 +90,10 @@ namespace data
RouterInfo (const uint8_t * buf, int len); RouterInfo (const uint8_t * buf, int len);
~RouterInfo (); ~RouterInfo ();
const Identity& GetRouterIdentity () const { return m_RouterIdentity; }; const IdentityEx& GetRouterIdentity () const { return m_RouterIdentity; };
void SetRouterIdentity (const Identity& identity); void SetRouterIdentity (const IdentityEx& identity);
std::string GetIdentHashBase64 () const { return m_IdentHash.ToBase64 (); }; std::string GetIdentHashBase64 () const { return GetIdentHash ().ToBase64 (); };
std::string GetIdentHashAbbreviation () const { return m_IdentHash.ToBase64 ().substr (0, 4); }; std::string GetIdentHashAbbreviation () const { return GetIdentHash ().ToBase64 ().substr (0, 4); };
uint64_t GetTimestamp () const { return m_Timestamp; }; uint64_t GetTimestamp () const { return m_Timestamp; };
std::vector<Address>& GetAddresses () { return m_Addresses; }; std::vector<Address>& GetAddresses () { return m_Addresses; };
const Address * GetNTCPAddress (bool v4only = true) const; const Address * GetNTCPAddress (bool v4only = true) const;
@ -138,8 +138,8 @@ namespace data
void DeleteBuffer () { delete m_Buffer; m_Buffer = nullptr; }; void DeleteBuffer () { delete m_Buffer; m_Buffer = nullptr; };
// implements RoutingDestination // implements RoutingDestination
const IdentHash& GetIdentHash () const { return m_IdentHash; }; const IdentHash& GetIdentHash () const { return m_RouterIdentity.GetIdentHash (); };
const uint8_t * GetEncryptionPublicKey () const { return m_RouterIdentity.publicKey; }; const uint8_t * GetEncryptionPublicKey () const { return m_RouterIdentity.GetStandardIdentity ().publicKey; };
bool IsDestination () const { return false; }; bool IsDestination () const { return false; };
@ -159,8 +159,7 @@ namespace data
private: private:
std::string m_FullPath; std::string m_FullPath;
Identity m_RouterIdentity; IdentityEx m_RouterIdentity;
IdentHash m_IdentHash;
uint8_t * m_Buffer; uint8_t * m_Buffer;
int m_BufferLen; int m_BufferLen;
uint64_t m_Timestamp; uint64_t m_Timestamp;

4
version.h

@ -2,7 +2,7 @@
#define _VERSION_H_ #define _VERSION_H_
#define CODENAME "Purple" #define CODENAME "Purple"
#define VERSION "0.2.1" #define VERSION "0.3.0"
#define I2P_VERSION "0.9.15" #define I2P_VERSION "0.9.16"
#endif #endif

Loading…
Cancel
Save