Browse Source

upddate DSA router keys

pull/1583/head
orignal 4 years ago
parent
commit
0436a65baa
  1. 53
      libi2pd/RouterContext.cpp

53
libi2pd/RouterContext.cpp

@ -564,31 +564,42 @@ namespace i2p
bool RouterContext::Load () bool RouterContext::Load ()
{ {
std::ifstream fk (i2p::fs::DataDirPath (ROUTER_KEYS), std::ifstream::in | std::ifstream::binary);
if (!fk.is_open ()) return false;
fk.seekg (0, std::ios::end);
size_t len = fk.tellg();
fk.seekg (0, std::ios::beg);
if (len == sizeof (i2p::data::Keys)) // old keys file format
{ {
i2p::data::Keys keys; std::ifstream fk (i2p::fs::DataDirPath (ROUTER_KEYS), std::ifstream::in | std::ifstream::binary);
fk.read ((char *)&keys, sizeof (keys)); if (!fk.is_open ()) return false;
m_Keys = keys; fk.seekg (0, std::ios::end);
size_t len = fk.tellg();
fk.seekg (0, std::ios::beg);
if (len == sizeof (i2p::data::Keys)) // old keys file format
{
i2p::data::Keys keys;
fk.read ((char *)&keys, sizeof (keys));
m_Keys = keys;
}
else // new keys file format
{
uint8_t * buf = new uint8_t[len];
fk.read ((char *)buf, len);
m_Keys.FromBuffer (buf, len);
delete[] buf;
}
} }
else // new keys file format std::shared_ptr<const i2p::data::IdentityEx> oldIdentity;
if (m_Keys.GetPublic ()->GetSigningKeyType () == i2p::data::SIGNING_KEY_TYPE_DSA_SHA1)
{ {
uint8_t * buf = new uint8_t[len]; // update keys
fk.read ((char *)buf, len); LogPrint (eLogInfo, "Router: router keys are obsolete. Creating new");
m_Keys.FromBuffer (buf, len); oldIdentity = m_Keys.GetPublic ();
delete[] buf; m_Keys = i2p::data::PrivateKeys::CreateRandomKeys (i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519);
} SaveKeys ();
}
// read NTCP2 keys if available // read NTCP2 keys if available
std::ifstream n2k (i2p::fs::DataDirPath (NTCP2_KEYS), std::ifstream::in | std::ifstream::binary); std::ifstream n2k (i2p::fs::DataDirPath (NTCP2_KEYS), std::ifstream::in | std::ifstream::binary);
if (n2k) if (n2k)
{ {
n2k.seekg (0, std::ios::end); n2k.seekg (0, std::ios::end);
len = n2k.tellg(); size_t len = n2k.tellg();
n2k.seekg (0, std::ios::beg); n2k.seekg (0, std::ios::beg);
if (len == sizeof (NTCP2PrivateKeys)) if (len == sizeof (NTCP2PrivateKeys))
{ {
@ -598,17 +609,15 @@ namespace i2p
n2k.close (); n2k.close ();
} }
// read RouterInfo // read RouterInfo
m_RouterInfo.SetRouterIdentity (GetIdentity ()); m_RouterInfo.SetRouterIdentity (oldIdentity ? oldIdentity : GetIdentity ());
i2p::data::RouterInfo routerInfo(i2p::fs::DataDirPath (ROUTER_INFO)); i2p::data::RouterInfo routerInfo(i2p::fs::DataDirPath (ROUTER_INFO));
if (!routerInfo.IsUnreachable ()) // router.info looks good if (!routerInfo.IsUnreachable ()) // router.info looks good
{ {
m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ()); m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ());
if (oldIdentity)
m_RouterInfo.SetRouterIdentity (GetIdentity ()); // from new keys
m_RouterInfo.SetProperty ("coreVersion", I2P_VERSION); m_RouterInfo.SetProperty ("coreVersion", I2P_VERSION);
m_RouterInfo.SetProperty ("router.version", I2P_VERSION); m_RouterInfo.SetProperty ("router.version", I2P_VERSION);
// Migration to 0.9.24. TODO: remove later
m_RouterInfo.DeleteProperty ("coreVersion");
m_RouterInfo.DeleteProperty ("stat_uptime");
} }
else else
{ {

Loading…
Cancel
Save