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

4
Identity.h

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

2
RouterContext.cpp

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

24
RouterInfo.cpp

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

15
RouterInfo.h

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

4
version.h

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

Loading…
Cancel
Save