This commit is contained in:
orignal 2014-04-07 15:31:48 -04:00
commit 654fe138a8
3 changed files with 24 additions and 3 deletions

View File

@ -80,7 +80,7 @@ void AddressBook::LoadHosts ()
getline(f, s);
if (!s.length())
break;
continue; // skip empty line
size_t pos = s.find('=');
@ -90,8 +90,11 @@ void AddressBook::LoadHosts ()
std::string addr = s.substr(pos);
Identity ident;
Base64ToByteStream (addr.c_str(), addr.length(), (uint8_t *)&ident, sizeof (ident));
m_Addresses[name] = CalculateIdentHash (ident);
if (!ident.FromBase64(addr)) {
LogPrint ("hosts.txt: ignore ", name);
continue;
}
m_Addresses[name] = ident.Hash();
numAddresses++;
}
}

View File

@ -6,6 +6,7 @@
#include <cryptopp/dsa.h>
#include "CryptoConst.h"
#include "Identity.h"
#include "base64.h"
namespace i2p
{
@ -17,6 +18,19 @@ namespace data
memcpy (publicKey, keys.publicKey, sizeof (publicKey) + sizeof (signingKey));
memset (certificate, 0, sizeof (certificate));
return *this;
}
bool Identity::FromBase64 (const std::string& s)
{
size_t count = Base64ToByteStream (s.c_str(), s.length(), reinterpret_cast<uint8_t*> (this), sizeof (Identity));
return count == sizeof(Identity);
}
IdentHash Identity::Hash()
{
IdentHash hash;
CryptoPP::SHA256().CalculateDigest(reinterpret_cast<uint8_t*>(&hash), reinterpret_cast<uint8_t*> (this), sizeof (Identity));
return hash;
}
PrivateKeys& PrivateKeys::operator=(const Keys& keys)

View File

@ -9,6 +9,8 @@ namespace i2p
{
namespace data
{
class IdentHash;
#pragma pack(1)
struct DHKeysPair // transient keys for transport sessions
@ -32,6 +34,8 @@ namespace data
uint8_t certificate[3];
Identity& operator=(const Keys& keys);
bool FromBase64(const std::string&);
IdentHash Hash();
};
struct PrivateKeys // for eepsites