From 19333d5697c7d9c1b6aa52c396f6f6e197376c86 Mon Sep 17 00:00:00 2001 From: cpubug Date: Mon, 7 Apr 2014 21:47:40 +0400 Subject: [PATCH 1/3] load Ident from base64 string --- Identity.cpp | 7 +++++++ Identity.h | 1 + 2 files changed, 8 insertions(+) diff --git a/Identity.cpp b/Identity.cpp index 387eef50..652dc1e1 100644 --- a/Identity.cpp +++ b/Identity.cpp @@ -6,6 +6,7 @@ #include #include "CryptoConst.h" #include "Identity.h" +#include "base64.h" namespace i2p { @@ -17,6 +18,12 @@ 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 (this), sizeof (Identity)); + return count == sizeof(Identity); } PrivateKeys& PrivateKeys::operator=(const Keys& keys) diff --git a/Identity.h b/Identity.h index 1dafdef4..19e5a007 100644 --- a/Identity.h +++ b/Identity.h @@ -32,6 +32,7 @@ namespace data uint8_t certificate[3]; Identity& operator=(const Keys& keys); + bool FromBase64(const std::string&); }; struct PrivateKeys // for eepsites From a82bd628c1635d97ceea48308665295314d51bb2 Mon Sep 17 00:00:00 2001 From: cpubug Date: Mon, 7 Apr 2014 22:01:24 +0400 Subject: [PATCH 2/3] compute IdentHash in Identity method --- Identity.cpp | 7 +++++++ Identity.h | 3 +++ 2 files changed, 10 insertions(+) diff --git a/Identity.cpp b/Identity.cpp index 652dc1e1..435c0c9b 100644 --- a/Identity.cpp +++ b/Identity.cpp @@ -24,6 +24,13 @@ namespace data { size_t count = Base64ToByteStream (s.c_str(), s.length(), reinterpret_cast (this), sizeof (Identity)); return count == sizeof(Identity); + } + + IdentHash Identity::Hash() + { + IdentHash hash; + CryptoPP::SHA256().CalculateDigest(reinterpret_cast(&hash), reinterpret_cast (this), sizeof (Identity)); + return hash; } PrivateKeys& PrivateKeys::operator=(const Keys& keys) diff --git a/Identity.h b/Identity.h index 19e5a007..902153dc 100644 --- a/Identity.h +++ b/Identity.h @@ -9,6 +9,8 @@ namespace i2p { namespace data { + class IdentHash; + #pragma pack(1) struct DHKeysPair // transient keys for transport sessions @@ -33,6 +35,7 @@ namespace data Identity& operator=(const Keys& keys); bool FromBase64(const std::string&); + IdentHash Hash(); }; struct PrivateKeys // for eepsites From 8725599d96d9b358a8ba7d4931a6a33fdbe3f50e Mon Sep 17 00:00:00 2001 From: cpubug Date: Mon, 7 Apr 2014 22:04:29 +0400 Subject: [PATCH 3/3] improve hosts.txt loading --- AddressBook.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/AddressBook.cpp b/AddressBook.cpp index 75ca5761..dfd788bf 100644 --- a/AddressBook.cpp +++ b/AddressBook.cpp @@ -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++; } }