Browse Source

Merge branch 'master' of https://github.com/orignal/i2pd

pull/60/head
orignal 10 years ago
parent
commit
654fe138a8
  1. 9
      AddressBook.cpp
  2. 14
      Identity.cpp
  3. 4
      Identity.h

9
AddressBook.cpp

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

14
Identity.cpp

@ -6,6 +6,7 @@
#include <cryptopp/dsa.h> #include <cryptopp/dsa.h>
#include "CryptoConst.h" #include "CryptoConst.h"
#include "Identity.h" #include "Identity.h"
#include "base64.h"
namespace i2p namespace i2p
{ {
@ -17,6 +18,19 @@ namespace data
memcpy (publicKey, keys.publicKey, sizeof (publicKey) + sizeof (signingKey)); memcpy (publicKey, keys.publicKey, sizeof (publicKey) + sizeof (signingKey));
memset (certificate, 0, sizeof (certificate)); memset (certificate, 0, sizeof (certificate));
return *this; 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) PrivateKeys& PrivateKeys::operator=(const Keys& keys)

4
Identity.h

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

Loading…
Cancel
Save