From 04c9a96fcbb0f872d7d9f9e6f89b21a9526ee05a Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 25 Aug 2014 16:25:12 -0400 Subject: [PATCH] use PrivateKeys for RoutingContext --- RouterContext.cpp | 30 ++++++++++++++---------------- RouterContext.h | 12 +++++------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/RouterContext.cpp b/RouterContext.cpp index 089f7e37..3ecf1de4 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -20,18 +20,13 @@ namespace i2p void RouterContext::CreateNewRouter () { m_Keys = i2p::data::CreateRandomKeys (); - m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag, - CryptoPP::Integer (m_Keys.signingPrivateKey, 20)); UpdateRouterInfo (); } void RouterContext::UpdateRouterInfo () { - i2p::data::Identity ident; - ident = m_Keys; - i2p::data::RouterInfo routerInfo; - routerInfo.SetRouterIdentity (ident); + routerInfo.SetRouterIdentity (GetIdentity ().GetStandardIdentity ()); routerInfo.AddSSUAddress (i2p::util::config::GetCharArg("-host", "127.0.0.1"), i2p::util::config::GetArg("-port", 17007), routerInfo.GetIdentHash ()); routerInfo.AddNTCPAddress (i2p::util::config::GetCharArg("-host", "127.0.0.1"), @@ -42,9 +37,7 @@ namespace i2p routerInfo.SetProperty ("router.version", I2P_VERSION); routerInfo.SetProperty ("start_uptime", "90m"); routerInfo.CreateBuffer (); - m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ()); - m_Identity = m_RouterInfo.GetRouterIdentity (); } void RouterContext::OverrideNTCPAddress (const char * host, int port) @@ -70,22 +63,20 @@ namespace i2p void RouterContext::Sign (const uint8_t * buf, int len, uint8_t * signature) const { - CryptoPP::DSA::Signer signer (m_SigningPrivateKey); - signer.SignMessage (i2p::context.GetRandomNumberGenerator (), buf, len, signature); + m_Keys.Sign(buf, len, signature); } bool RouterContext::Load () { std::ifstream fk (i2p::util::filesystem::GetFullPath (ROUTER_KEYS).c_str (), std::ifstream::binary | std::ofstream::in); if (!fk.is_open ()) return false; - - fk.read ((char *)&m_Keys, sizeof (m_Keys)); - m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag, - CryptoPP::Integer (m_Keys.signingPrivateKey, 20)); + + i2p::data::Keys keys; + fk.read ((char *)&keys, sizeof (keys)); + m_Keys = keys; i2p::data::RouterInfo routerInfo(i2p::util::filesystem::GetFullPath (ROUTER_INFO)); // TODO m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ()); - m_Identity = m_RouterInfo.GetRouterIdentity (); return true; } @@ -95,7 +86,14 @@ namespace i2p if (!infoOnly) { std::ofstream fk (i2p::util::filesystem::GetFullPath (ROUTER_KEYS).c_str (), std::ofstream::binary | std::ofstream::out); - fk.write ((char *)&m_Keys, sizeof (m_Keys)); + i2p::data::Keys keys; + memcpy (keys.privateKey, m_Keys.GetPrivateKey (), sizeof (keys.privateKey)); + memcpy (keys.signingPrivateKey, m_Keys.GetSigningPrivateKey (), sizeof (keys.signingPrivateKey)); + auto& ident = GetIdentity ().GetStandardIdentity (); + memcpy (keys.publicKey, ident.publicKey, sizeof (keys.publicKey)); + memcpy (keys.signingKey, ident.signingKey, sizeof (keys.signingKey)); + + fk.write ((char *)&keys, sizeof (keys)); } m_RouterInfo.SaveToFile (i2p::util::filesystem::GetFullPath (ROUTER_INFO)); diff --git a/RouterContext.h b/RouterContext.h index 17b1d4c9..ac4cb04a 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -19,8 +19,8 @@ namespace i2p RouterContext (); i2p::data::RouterInfo& GetRouterInfo () { return m_RouterInfo; }; - const uint8_t * GetPrivateKey () const { return m_Keys.privateKey; }; - const uint8_t * GetSigningPrivateKey () const { return m_Keys.signingPrivateKey; }; + const uint8_t * GetPrivateKey () const { return m_Keys.GetPrivateKey (); }; + const uint8_t * GetSigningPrivateKey () const { return m_Keys.GetSigningPrivateKey (); }; const i2p::data::Identity& GetRouterIdentity () const { return m_RouterInfo.GetRouterIdentity (); }; const i2p::data::IdentHash& GetRouterIdentHash () const { return m_RouterInfo.GetIdentHash (); }; CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; }; @@ -29,9 +29,9 @@ namespace i2p void UpdateAddress (const char * host); // called from SSU // implements LocalDestination - const i2p::data::IdentityEx& GetIdentity () const { return m_Identity; }; + const i2p::data::IdentityEx& GetIdentity () const { return m_Keys.GetPublic (); }; const uint8_t * GetEncryptionPrivateKey () const { return GetPrivateKey (); }; - const uint8_t * GetEncryptionPublicKey () const { return m_Keys.publicKey; }; + const uint8_t * GetEncryptionPublicKey () const { return GetIdentity ().GetStandardIdentity ().publicKey; }; void Sign (const uint8_t * buf, int len, uint8_t * signature) const; void SetLeaseSetUpdated () {}; @@ -45,9 +45,7 @@ namespace i2p private: i2p::data::RouterInfo m_RouterInfo; - i2p::data::IdentityEx m_Identity; // TODO: move to RI - i2p::data::Keys m_Keys; - CryptoPP::DSA::PrivateKey m_SigningPrivateKey; + i2p::data::PrivateKeys m_Keys; CryptoPP::AutoSeededRandomPool m_Rnd; };