Browse Source

use PrivateKeys for RoutingContext

pull/93/head
orignal 10 years ago
parent
commit
04c9a96fcb
  1. 28
      RouterContext.cpp
  2. 12
      RouterContext.h

28
RouterContext.cpp

@ -20,18 +20,13 @@ namespace i2p @@ -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 @@ -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,8 +63,7 @@ namespace i2p @@ -70,8 +63,7 @@ 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 ()
@ -79,13 +71,12 @@ namespace i2p @@ -79,13 +71,12 @@ namespace i2p
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 @@ -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));

12
RouterContext.h

@ -19,8 +19,8 @@ namespace i2p @@ -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 @@ -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 @@ -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;
};

Loading…
Cancel
Save