mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
use PrivateKeys for RoutingContext
This commit is contained in:
parent
711b4ab9ae
commit
04c9a96fcb
2 changed files with 19 additions and 23 deletions
|
@ -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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue