mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
use PrivateKeys for RoutingContext
This commit is contained in:
parent
711b4ab9ae
commit
04c9a96fcb
|
@ -20,18 +20,13 @@ namespace i2p
|
||||||
void RouterContext::CreateNewRouter ()
|
void RouterContext::CreateNewRouter ()
|
||||||
{
|
{
|
||||||
m_Keys = i2p::data::CreateRandomKeys ();
|
m_Keys = i2p::data::CreateRandomKeys ();
|
||||||
m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag,
|
|
||||||
CryptoPP::Integer (m_Keys.signingPrivateKey, 20));
|
|
||||||
UpdateRouterInfo ();
|
UpdateRouterInfo ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterContext::UpdateRouterInfo ()
|
void RouterContext::UpdateRouterInfo ()
|
||||||
{
|
{
|
||||||
i2p::data::Identity ident;
|
|
||||||
ident = m_Keys;
|
|
||||||
|
|
||||||
i2p::data::RouterInfo routerInfo;
|
i2p::data::RouterInfo routerInfo;
|
||||||
routerInfo.SetRouterIdentity (ident);
|
routerInfo.SetRouterIdentity (GetIdentity ().GetStandardIdentity ());
|
||||||
routerInfo.AddSSUAddress (i2p::util::config::GetCharArg("-host", "127.0.0.1"),
|
routerInfo.AddSSUAddress (i2p::util::config::GetCharArg("-host", "127.0.0.1"),
|
||||||
i2p::util::config::GetArg("-port", 17007), routerInfo.GetIdentHash ());
|
i2p::util::config::GetArg("-port", 17007), routerInfo.GetIdentHash ());
|
||||||
routerInfo.AddNTCPAddress (i2p::util::config::GetCharArg("-host", "127.0.0.1"),
|
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 ("router.version", I2P_VERSION);
|
||||||
routerInfo.SetProperty ("start_uptime", "90m");
|
routerInfo.SetProperty ("start_uptime", "90m");
|
||||||
routerInfo.CreateBuffer ();
|
routerInfo.CreateBuffer ();
|
||||||
|
|
||||||
m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ());
|
m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ());
|
||||||
m_Identity = m_RouterInfo.GetRouterIdentity ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterContext::OverrideNTCPAddress (const char * host, int port)
|
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
|
void RouterContext::Sign (const uint8_t * buf, int len, uint8_t * signature) const
|
||||||
{
|
{
|
||||||
CryptoPP::DSA::Signer signer (m_SigningPrivateKey);
|
m_Keys.Sign(buf, len, signature);
|
||||||
signer.SignMessage (i2p::context.GetRandomNumberGenerator (), buf, len, signature);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RouterContext::Load ()
|
bool RouterContext::Load ()
|
||||||
{
|
{
|
||||||
std::ifstream fk (i2p::util::filesystem::GetFullPath (ROUTER_KEYS).c_str (), std::ifstream::binary | std::ofstream::in);
|
std::ifstream fk (i2p::util::filesystem::GetFullPath (ROUTER_KEYS).c_str (), std::ifstream::binary | std::ofstream::in);
|
||||||
if (!fk.is_open ()) return false;
|
if (!fk.is_open ()) return false;
|
||||||
|
|
||||||
fk.read ((char *)&m_Keys, sizeof (m_Keys));
|
i2p::data::Keys keys;
|
||||||
m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag,
|
fk.read ((char *)&keys, sizeof (keys));
|
||||||
CryptoPP::Integer (m_Keys.signingPrivateKey, 20));
|
m_Keys = keys;
|
||||||
|
|
||||||
i2p::data::RouterInfo routerInfo(i2p::util::filesystem::GetFullPath (ROUTER_INFO)); // TODO
|
i2p::data::RouterInfo routerInfo(i2p::util::filesystem::GetFullPath (ROUTER_INFO)); // TODO
|
||||||
m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ());
|
m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ());
|
||||||
m_Identity = m_RouterInfo.GetRouterIdentity ();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +86,14 @@ namespace i2p
|
||||||
if (!infoOnly)
|
if (!infoOnly)
|
||||||
{
|
{
|
||||||
std::ofstream fk (i2p::util::filesystem::GetFullPath (ROUTER_KEYS).c_str (), std::ofstream::binary | std::ofstream::out);
|
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));
|
m_RouterInfo.SaveToFile (i2p::util::filesystem::GetFullPath (ROUTER_INFO));
|
||||||
|
|
|
@ -19,8 +19,8 @@ namespace i2p
|
||||||
RouterContext ();
|
RouterContext ();
|
||||||
|
|
||||||
i2p::data::RouterInfo& GetRouterInfo () { return m_RouterInfo; };
|
i2p::data::RouterInfo& GetRouterInfo () { return m_RouterInfo; };
|
||||||
const uint8_t * GetPrivateKey () const { return m_Keys.privateKey; };
|
const uint8_t * GetPrivateKey () const { return m_Keys.GetPrivateKey (); };
|
||||||
const uint8_t * GetSigningPrivateKey () const { return m_Keys.signingPrivateKey; };
|
const uint8_t * GetSigningPrivateKey () const { return m_Keys.GetSigningPrivateKey (); };
|
||||||
const i2p::data::Identity& GetRouterIdentity () const { return m_RouterInfo.GetRouterIdentity (); };
|
const i2p::data::Identity& GetRouterIdentity () const { return m_RouterInfo.GetRouterIdentity (); };
|
||||||
const i2p::data::IdentHash& GetRouterIdentHash () const { return m_RouterInfo.GetIdentHash (); };
|
const i2p::data::IdentHash& GetRouterIdentHash () const { return m_RouterInfo.GetIdentHash (); };
|
||||||
CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; };
|
CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; };
|
||||||
|
@ -29,9 +29,9 @@ namespace i2p
|
||||||
void UpdateAddress (const char * host); // called from SSU
|
void UpdateAddress (const char * host); // called from SSU
|
||||||
|
|
||||||
// implements LocalDestination
|
// 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 * 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 Sign (const uint8_t * buf, int len, uint8_t * signature) const;
|
||||||
void SetLeaseSetUpdated () {};
|
void SetLeaseSetUpdated () {};
|
||||||
|
|
||||||
|
@ -45,9 +45,7 @@ namespace i2p
|
||||||
private:
|
private:
|
||||||
|
|
||||||
i2p::data::RouterInfo m_RouterInfo;
|
i2p::data::RouterInfo m_RouterInfo;
|
||||||
i2p::data::IdentityEx m_Identity; // TODO: move to RI
|
i2p::data::PrivateKeys m_Keys;
|
||||||
i2p::data::Keys m_Keys;
|
|
||||||
CryptoPP::DSA::PrivateKey m_SigningPrivateKey;
|
|
||||||
CryptoPP::AutoSeededRandomPool m_Rnd;
|
CryptoPP::AutoSeededRandomPool m_Rnd;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue