use published timestamp for blinding

This commit is contained in:
orignal 2019-04-12 14:05:07 -04:00
parent 5d5cd71714
commit 6cc6849ccc
4 changed files with 22 additions and 10 deletions

View file

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

View file

@ -144,7 +144,7 @@ namespace data
void GetSubcredential (const uint8_t * blinded, size_t len, uint8_t * subcredential) const; // 32 bytes 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 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" 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: private:

View file

@ -182,7 +182,13 @@ namespace util
void GetCurrentDate (char * date) 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; struct tm tm;
#ifdef _WIN32 #ifdef _WIN32
gmtime_s(&tm, &t); gmtime_s(&tm, &t);

View file

@ -16,6 +16,7 @@ namespace util
uint64_t GetSecondsSinceEpoch (); uint64_t GetSecondsSinceEpoch ();
void GetCurrentDate (char * date); // returns date as YYYYMMDD string, 9 bytes 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 class NTPTimeSync
{ {