Skip to content

Commit

Permalink
use published timestamp for blinding
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Apr 12, 2019
1 parent 5d5cd71 commit 6cc6849
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
21 changes: 13 additions & 8 deletions libi2pd/LeaseSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,21 @@ namespace data
SHA256_Final (hash, &ctx);
}

i2p::data::IdentHash BlindedPublicKey::GetStoreHash () const
i2p::data::IdentHash BlindedPublicKey::GetStoreHash (const char * date) const
{
i2p::data::IdentHash hash;
if (m_BlindedSigType == i2p::data::SIGNING_KEY_TYPE_REDDSA_SHA512_ED25519 ||
m_BlindedSigType == SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519)
{
char date[9];
i2p::util::GetCurrentDate (date);
uint8_t blinded[32];
GetBlindedKey (date, blinded);
if (date)
GetBlindedKey (date, blinded);
else
{
char currentDate[9];
i2p::util::GetCurrentDate (currentDate);
GetBlindedKey (currentDate, blinded);
}
auto stA1 = htobe16 (m_BlindedSigType);
SHA256_CTX ctx;
SHA256_Init (&ctx);
Expand Down Expand Up @@ -605,7 +610,7 @@ namespace data
{
// verify blinding
char date[9];
i2p::util::GetCurrentDate (date);
i2p::util::GetDateString (m_PublishedTimestamp, date);
uint8_t blinded[32];
key->GetBlindedKey (date, blinded);
if (memcmp (blindedPublicKey, blinded, 32))
Expand Down Expand Up @@ -862,15 +867,15 @@ namespace data
m_Buffer = new uint8_t[m_BufferLen + 1];
m_Buffer[0] = NETDB_STORE_TYPE_ENCRYPTED_LEASESET2;
BlindedPublicKey blindedKey (ls->GetIdentity ());
auto timestamp = i2p::util::GetSecondsSinceEpoch ();
char date[9];
i2p::util::GetCurrentDate (date);
i2p::util::GetDateString (timestamp, date);
uint8_t blindedPriv[32], blindedPub[32];
blindedKey.BlindPrivateKey (keys.GetSigningPrivateKey (), date, blindedPriv, blindedPub);
std::unique_ptr<i2p::crypto::Signer> blindedSigner (i2p::data::PrivateKeys::CreateSigner (blindedKeyType, blindedPriv));
auto offset = 1;
htobe16buf (m_Buffer + offset, blindedKeyType); offset += 2; // Blinded Public Key Sig Type
memcpy (m_Buffer + offset, blindedPub, 32); offset += 32; // Blinded Public Key
auto timestamp = i2p::util::GetSecondsSinceEpoch ();
htobe32buf (m_Buffer + offset, timestamp); offset += 4; // published timestamp (seconds)
auto nextMidnight = (timestamp/86400LL + 1)*86400LL; // 86400 = 24*3600 seconds
auto expirationTime = ls->GetExpirationTime ()/1000LL;
Expand Down Expand Up @@ -906,7 +911,7 @@ namespace data
// signature
blindedSigner->Sign (m_Buffer, offset, m_Buffer + offset);
// store hash
m_StoreHash = blindedKey.GetStoreHash ();
m_StoreHash = blindedKey.GetStoreHash (date);
}

LocalEncryptedLeaseSet2::LocalEncryptedLeaseSet2 (std::shared_ptr<const IdentityEx> identity, const uint8_t * buf, size_t len):
Expand Down
2 changes: 1 addition & 1 deletion libi2pd/LeaseSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace data
void GetSubcredential (const uint8_t * blinded, size_t len, uint8_t * subcredential) const; // 32 bytes
void GetBlindedKey (const char * date, uint8_t * blindedKey) const; // blinded key 32 bytes, date is 8 chars "YYYYMMDD"
void BlindPrivateKey (const uint8_t * priv, const char * date, uint8_t * blindedPriv, uint8_t * blindedPub) const; // blinded key 32 bytes, date is 8 chars "YYYYMMDD"
i2p::data::IdentHash GetStoreHash () const;
i2p::data::IdentHash GetStoreHash (const char * date = nullptr) const; // date is 8 chars "YYYYMMDD", use current if null

private:

Expand Down
8 changes: 7 additions & 1 deletion libi2pd/Timestamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,13 @@ namespace util

void GetCurrentDate (char * date)
{
time_t t = time (nullptr);
GetDateString (GetSecondsSinceEpoch (), date);
}

void GetDateString (uint64_t timestamp, char * date)
{
using clock = std::chrono::system_clock;
auto t = clock::to_time_t (clock::time_point (std::chrono::seconds(timestamp)));
struct tm tm;
#ifdef _WIN32
gmtime_s(&tm, &t);
Expand Down
1 change: 1 addition & 0 deletions libi2pd/Timestamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace util
uint64_t GetSecondsSinceEpoch ();

void GetCurrentDate (char * date); // returns date as YYYYMMDD string, 9 bytes
void GetDateString (uint64_t timestamp, char * date); // timestap is seconds since epoch, returns date as YYYYMMDD string, 9 bytes

class NTPTimeSync
{
Expand Down

0 comments on commit 6cc6849

Please sign in to comment.