From e6a09b49c936180e6bd7ad9add6be658a21eb02e Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 7 Aug 2019 15:43:03 -0400 Subject: [PATCH] published encrypted flag --- libi2pd/Destination.cpp | 5 +++-- libi2pd/LeaseSet.cpp | 13 ++++++++++++- libi2pd/LeaseSet.h | 8 ++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/libi2pd/Destination.cpp b/libi2pd/Destination.cpp index 9355e75d..34ff374f 100644 --- a/libi2pd/Destination.cpp +++ b/libi2pd/Destination.cpp @@ -1180,9 +1180,10 @@ namespace client { // standard LS2 (type 3) first auto keyLen = m_Decryptor ? m_Decryptor->GetPublicKeyLen () : 256; + bool isPublishedEncrypted = GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_ENCRYPTED_LEASESET2; auto ls2 = std::make_shared (i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2, - m_Keys, m_EncryptionKeyType, keyLen, m_EncryptionPublicKey, tunnels, IsPublic ()); - if (GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_ENCRYPTED_LEASESET2) // encrypt if type 5 + m_Keys, m_EncryptionKeyType, keyLen, m_EncryptionPublicKey, tunnels, IsPublic (), isPublishedEncrypted); + if (isPublishedEncrypted) // encrypt if type 5 ls2 = std::make_shared (ls2, m_Keys, m_AuthType, m_AuthKeys); leaseSet = ls2; } diff --git a/libi2pd/LeaseSet.cpp b/libi2pd/LeaseSet.cpp index bc50e013..8cbb3341 100644 --- a/libi2pd/LeaseSet.cpp +++ b/libi2pd/LeaseSet.cpp @@ -303,6 +303,11 @@ namespace data } } if (flags & LEASESET2_FLAG_UNPUBLISHED_LEASESET) m_IsPublic = false; + if (flags & LEASESET2_FLAG_PUBLISHED_ENCRYPTED) + { + m_IsPublishedEncrypted = true; + m_IsPublic = true; + } // type specific part size_t s = 0; switch (m_StoreType) @@ -742,7 +747,8 @@ namespace data LocalLeaseSet2::LocalLeaseSet2 (uint8_t storeType, const i2p::data::PrivateKeys& keys, uint16_t keyType, uint16_t keyLen, const uint8_t * encryptionPublicKey, - std::vector > tunnels, bool isPublic): + std::vector > tunnels, + bool isPublic, bool isPublishedEncrypted): LocalLeaseSet (keys.GetPublic (), nullptr, 0) { auto identity = keys.GetPublic (); @@ -757,6 +763,11 @@ namespace data flags |= LEASESET2_FLAG_OFFLINE_KEYS; m_BufferLen += keys.GetOfflineSignature ().size (); } + if (isPublishedEncrypted) + { + flags |= LEASESET2_FLAG_PUBLISHED_ENCRYPTED; + isPublic = true; + } if (!isPublic) flags |= LEASESET2_FLAG_UNPUBLISHED_LEASESET; m_Buffer = new uint8_t[m_BufferLen + 1]; diff --git a/libi2pd/LeaseSet.h b/libi2pd/LeaseSet.h index b9979e00..2199ac32 100644 --- a/libi2pd/LeaseSet.h +++ b/libi2pd/LeaseSet.h @@ -82,6 +82,7 @@ namespace data virtual uint8_t GetOrigStoreType () const { return NETDB_STORE_TYPE_LEASESET; }; virtual uint32_t GetPublishedTimestamp () const { return 0; }; // should be set for LeaseSet2 only virtual std::shared_ptr GetTransientVerifier () const { return nullptr; }; + virtual bool IsPublishedEncrypted () const { return false; }; // implements RoutingDestination std::shared_ptr GetIdentity () const { return m_Identity; }; @@ -130,6 +131,7 @@ namespace data const uint16_t LEASESET2_FLAG_OFFLINE_KEYS = 0x0001; const uint16_t LEASESET2_FLAG_UNPUBLISHED_LEASESET = 0x0002; + const uint16_t LEASESET2_FLAG_PUBLISHED_ENCRYPTED = 0x0004; class LeaseSet2: public LeaseSet { @@ -141,6 +143,7 @@ namespace data uint8_t GetOrigStoreType () const { return m_OrigStoreType; }; uint32_t GetPublishedTimestamp () const { return m_PublishedTimestamp; }; bool IsPublic () const { return m_IsPublic; }; + bool IsPublishedEncrypted () const { return m_IsPublishedEncrypted; }; std::shared_ptr GetTransientVerifier () const { return m_TransientVerifier; }; void Update (const uint8_t * buf, size_t len, bool verifySignature); @@ -164,7 +167,7 @@ namespace data uint8_t m_StoreType, m_OrigStoreType; uint32_t m_PublishedTimestamp = 0; - bool m_IsPublic = true; + bool m_IsPublic = true, m_IsPublishedEncrypted = false; std::shared_ptr m_TransientVerifier; std::shared_ptr m_Encryptor; // for standardLS2 }; @@ -230,7 +233,8 @@ namespace data LocalLeaseSet2 (uint8_t storeType, const i2p::data::PrivateKeys& keys, uint16_t keyType, uint16_t keyLen, const uint8_t * encryptionPublicKey, - std::vector > tunnels, bool isPublic); + std::vector > tunnels, + bool isPublic, bool isPublishedEncrypted = false); LocalLeaseSet2 (uint8_t storeType, std::shared_ptr identity, const uint8_t * buf, size_t len); // from I2CP virtual ~LocalLeaseSet2 () { delete[] m_Buffer; };