mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-05-25 16:45:35 +02:00
common code for offline signatures
This commit is contained in:
parent
f5f4190803
commit
2cac9b03ff
4 changed files with 57 additions and 62 deletions
libi2pd
|
@ -8,6 +8,7 @@
|
|||
#include <memory>
|
||||
#include "Identity.h"
|
||||
#include "Timestamp.h"
|
||||
#include "I2PEndian.h"
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
|
@ -77,7 +78,8 @@ namespace data
|
|||
bool operator== (const LeaseSet& other) const
|
||||
{ return m_BufferLen == other.m_BufferLen && !memcmp (m_Buffer, other.m_Buffer, m_BufferLen); };
|
||||
virtual uint8_t GetStoreType () const { return NETDB_STORE_TYPE_LEASESET; };
|
||||
|
||||
virtual std::shared_ptr<const i2p::crypto::Verifier> GetTransientVerifier () const { return nullptr; };
|
||||
|
||||
// implements RoutingDestination
|
||||
std::shared_ptr<const IdentityEx> GetIdentity () const { return m_Identity; };
|
||||
void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx) const;
|
||||
|
@ -128,8 +130,9 @@ namespace data
|
|||
|
||||
LeaseSet2 (uint8_t storeType, const uint8_t * buf, size_t len, bool storeLeases = true);
|
||||
uint8_t GetStoreType () const { return m_StoreType; };
|
||||
std::shared_ptr<const i2p::crypto::Verifier> GetTransientVerifier () const { return m_TransientVerifier; };
|
||||
void Update (const uint8_t * buf, size_t len, bool verifySignature);
|
||||
|
||||
|
||||
// implements RoutingDestination
|
||||
void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx) const;
|
||||
|
||||
|
@ -148,9 +151,31 @@ namespace data
|
|||
private:
|
||||
|
||||
uint8_t m_StoreType;
|
||||
std::shared_ptr<i2p::crypto::Verifier> m_TransientVerifier;
|
||||
std::shared_ptr<i2p::crypto::CryptoKeyEncryptor> m_Encryptor; // for standardLS2
|
||||
};
|
||||
|
||||
// also called from Streaming.cpp
|
||||
template<typename Verifier>
|
||||
std::shared_ptr<i2p::crypto::Verifier> ProcessOfflineSignature (const Verifier& verifier, const uint8_t * buf, size_t len, size_t& offset)
|
||||
{
|
||||
if (offset + 6 >= len) return nullptr;
|
||||
const uint8_t * signedData = buf + offset;
|
||||
uint32_t expiresTimestamp = bufbe32toh (buf + offset); offset += 4; // expires timestamp
|
||||
if (expiresTimestamp < i2p::util::GetSecondsSinceEpoch ()) return nullptr;
|
||||
uint16_t keyType = bufbe16toh (buf + offset); offset += 2;
|
||||
std::shared_ptr<i2p::crypto::Verifier> transientVerifier (i2p::data::IdentityEx::CreateVerifier (keyType));
|
||||
if (!transientVerifier) return nullptr;
|
||||
auto keyLen = transientVerifier->GetPublicKeyLen ();
|
||||
if (offset + keyLen >= len) return nullptr;
|
||||
transientVerifier->SetPublicKey (buf + offset); offset += keyLen;
|
||||
if (offset + verifier->GetSignatureLen () >= len) return nullptr;
|
||||
if (!verifier->Verify (signedData, keyLen + 6, buf + offset)) return nullptr;
|
||||
offset += verifier->GetSignatureLen ();
|
||||
return transientVerifier;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
class LocalLeaseSet
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue