Browse Source

check for correctly loaded privatekeys

pull/628/head
Jeff Becker 9 years ago
parent
commit
eeeae12639
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
  1. 34
      ClientContext.cpp
  2. 2
      ClientContext.h

34
ClientContext.cpp

@ -51,8 +51,10 @@ namespace client
if (httpProxyKeys.length () > 0) if (httpProxyKeys.length () > 0)
{ {
i2p::data::PrivateKeys keys; i2p::data::PrivateKeys keys;
LoadPrivateKeys (keys, httpProxyKeys); if(LoadPrivateKeys (keys, httpProxyKeys))
localDestination = CreateNewLocalDestination (keys, false); localDestination = CreateNewLocalDestination (keys, false);
else
LogPrint(eLogError, "Clients: failed to load HTTP Proxy key");
} }
try { try {
m_HttpProxy = new i2p::proxy::HTTPProxy(httpProxyAddr, httpProxyPort, localDestination); m_HttpProxy = new i2p::proxy::HTTPProxy(httpProxyAddr, httpProxyPort, localDestination);
@ -208,8 +210,9 @@ namespace client
Start(); Start();
} }
void ClientContext::LoadPrivateKeys (i2p::data::PrivateKeys& keys, const std::string& filename, i2p::data::SigningKeyType sigType) bool ClientContext::LoadPrivateKeys (i2p::data::PrivateKeys& keys, const std::string& filename, i2p::data::SigningKeyType sigType)
{ {
bool success = true;
std::string fullPath = i2p::fs::DataDirPath (filename); std::string fullPath = i2p::fs::DataDirPath (filename);
std::ifstream s(fullPath, std::ifstream::binary); std::ifstream s(fullPath, std::ifstream::binary);
if (s.is_open ()) if (s.is_open ())
@ -219,9 +222,14 @@ namespace client
s.seekg (0, std::ios::beg); s.seekg (0, std::ios::beg);
uint8_t * buf = new uint8_t[len]; uint8_t * buf = new uint8_t[len];
s.read ((char *)buf, len); s.read ((char *)buf, len);
keys.FromBuffer (buf, len); if(!keys.FromBuffer (buf, len))
{
LogPrint (eLogError, "Clients: failed to load keyfile ", filename);
success = false;
}
else
LogPrint (eLogInfo, "Clients: Local address ", m_AddressBook.ToAddress(keys.GetPublic ()->GetIdentHash ()), " loaded");
delete[] buf; delete[] buf;
LogPrint (eLogInfo, "Clients: Local address ", m_AddressBook.ToAddress(keys.GetPublic ()->GetIdentHash ()), " loaded");
} }
else else
{ {
@ -235,7 +243,8 @@ namespace client
delete[] buf; delete[] buf;
LogPrint (eLogInfo, "Clients: New private keys file ", fullPath, " for ", m_AddressBook.ToAddress(keys.GetPublic ()->GetIdentHash ()), " created"); LogPrint (eLogInfo, "Clients: New private keys file ", fullPath, " for ", m_AddressBook.ToAddress(keys.GetPublic ()->GetIdentHash ()), " created");
} }
return success;
} }
std::shared_ptr<ClientDestination> ClientContext::CreateNewLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType, std::shared_ptr<ClientDestination> ClientContext::CreateNewLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType,
@ -358,10 +367,12 @@ namespace client
if (keys.length () > 0) if (keys.length () > 0)
{ {
i2p::data::PrivateKeys k; i2p::data::PrivateKeys k;
LoadPrivateKeys (k, keys, sigType); if(LoadPrivateKeys (k, keys, sigType))
localDestination = FindLocalDestination (k.GetPublic ()->GetIdentHash ()); {
if (!localDestination) localDestination = FindLocalDestination (k.GetPublic ()->GetIdentHash ());
localDestination = CreateNewLocalDestination (k, false, &options); if (!localDestination)
localDestination = CreateNewLocalDestination (k, false, &options);
}
} }
auto clientTunnel = new I2PClientTunnel (name, dest, address, port, localDestination, destinationPort); auto clientTunnel = new I2PClientTunnel (name, dest, address, port, localDestination, destinationPort);
if (m_ClientTunnels.insert (std::make_pair (clientTunnel->GetAcceptor ().local_endpoint (), if (m_ClientTunnels.insert (std::make_pair (clientTunnel->GetAcceptor ().local_endpoint (),
@ -392,7 +403,8 @@ namespace client
std::shared_ptr<ClientDestination> localDestination = nullptr; std::shared_ptr<ClientDestination> localDestination = nullptr;
i2p::data::PrivateKeys k; i2p::data::PrivateKeys k;
LoadPrivateKeys (k, keys, sigType); if(!LoadPrivateKeys (k, keys, sigType))
continue;
localDestination = FindLocalDestination (k.GetPublic ()->GetIdentHash ()); localDestination = FindLocalDestination (k.GetPublic ()->GetIdentHash ());
if (!localDestination) if (!localDestination)
localDestination = CreateNewLocalDestination (k, true, &options); localDestination = CreateNewLocalDestination (k, true, &options);

2
ClientContext.h

@ -59,7 +59,7 @@ namespace client
const std::map<std::string, std::string> * params = nullptr); const std::map<std::string, std::string> * params = nullptr);
void DeleteLocalDestination (std::shared_ptr<ClientDestination> destination); void DeleteLocalDestination (std::shared_ptr<ClientDestination> destination);
std::shared_ptr<ClientDestination> FindLocalDestination (const i2p::data::IdentHash& destination) const; std::shared_ptr<ClientDestination> FindLocalDestination (const i2p::data::IdentHash& destination) const;
void LoadPrivateKeys (i2p::data::PrivateKeys& keys, const std::string& filename, i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256); bool LoadPrivateKeys (i2p::data::PrivateKeys& keys, const std::string& filename, i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256);
AddressBook& GetAddressBook () { return m_AddressBook; }; AddressBook& GetAddressBook () { return m_AddressBook; };
const SAMBridge * GetSAMBridge () const { return m_SamBridge; }; const SAMBridge * GetSAMBridge () const { return m_SamBridge; };

Loading…
Cancel
Save