|
|
@ -1,5 +1,5 @@ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2022, The PurpleI2P Project |
|
|
|
* Copyright (c) 2013-2023, The PurpleI2P Project |
|
|
|
* |
|
|
|
* |
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3 |
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3 |
|
|
|
* |
|
|
|
* |
|
|
@ -187,7 +187,6 @@ namespace data |
|
|
|
|
|
|
|
|
|
|
|
IdentityEx::~IdentityEx () |
|
|
|
IdentityEx::~IdentityEx () |
|
|
|
{ |
|
|
|
{ |
|
|
|
delete m_Verifier; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
IdentityEx& IdentityEx::operator=(const IdentityEx& other) |
|
|
|
IdentityEx& IdentityEx::operator=(const IdentityEx& other) |
|
|
@ -201,9 +200,8 @@ namespace data |
|
|
|
if (m_ExtendedLen > MAX_EXTENDED_BUFFER_SIZE) m_ExtendedLen = MAX_EXTENDED_BUFFER_SIZE; |
|
|
|
if (m_ExtendedLen > MAX_EXTENDED_BUFFER_SIZE) m_ExtendedLen = MAX_EXTENDED_BUFFER_SIZE; |
|
|
|
memcpy (m_ExtendedBuffer, other.m_ExtendedBuffer, m_ExtendedLen); |
|
|
|
memcpy (m_ExtendedBuffer, other.m_ExtendedBuffer, m_ExtendedLen); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
delete m_Verifier; |
|
|
|
|
|
|
|
m_Verifier = nullptr; |
|
|
|
m_Verifier = nullptr; |
|
|
|
|
|
|
|
CreateVerifier (); |
|
|
|
|
|
|
|
|
|
|
|
return *this; |
|
|
|
return *this; |
|
|
|
} |
|
|
|
} |
|
|
@ -212,11 +210,10 @@ namespace data |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_StandardIdentity = standard; |
|
|
|
m_StandardIdentity = standard; |
|
|
|
m_IdentHash = m_StandardIdentity.Hash (); |
|
|
|
m_IdentHash = m_StandardIdentity.Hash (); |
|
|
|
|
|
|
|
|
|
|
|
m_ExtendedLen = 0; |
|
|
|
m_ExtendedLen = 0; |
|
|
|
|
|
|
|
|
|
|
|
delete m_Verifier; |
|
|
|
|
|
|
|
m_Verifier = nullptr; |
|
|
|
m_Verifier = nullptr; |
|
|
|
|
|
|
|
CreateVerifier (); |
|
|
|
|
|
|
|
|
|
|
|
return *this; |
|
|
|
return *this; |
|
|
|
} |
|
|
|
} |
|
|
@ -249,8 +246,8 @@ namespace data |
|
|
|
m_ExtendedLen = 0; |
|
|
|
m_ExtendedLen = 0; |
|
|
|
SHA256(buf, GetFullLen (), m_IdentHash); |
|
|
|
SHA256(buf, GetFullLen (), m_IdentHash); |
|
|
|
|
|
|
|
|
|
|
|
delete m_Verifier; |
|
|
|
|
|
|
|
m_Verifier = nullptr; |
|
|
|
m_Verifier = nullptr; |
|
|
|
|
|
|
|
CreateVerifier (); |
|
|
|
|
|
|
|
|
|
|
|
return GetFullLen (); |
|
|
|
return GetFullLen (); |
|
|
|
} |
|
|
|
} |
|
|
@ -286,7 +283,6 @@ namespace data |
|
|
|
|
|
|
|
|
|
|
|
size_t IdentityEx::GetSigningPublicKeyLen () const |
|
|
|
size_t IdentityEx::GetSigningPublicKeyLen () const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!m_Verifier) CreateVerifier (); |
|
|
|
|
|
|
|
if (m_Verifier) |
|
|
|
if (m_Verifier) |
|
|
|
return m_Verifier->GetPublicKeyLen (); |
|
|
|
return m_Verifier->GetPublicKeyLen (); |
|
|
|
return 128; |
|
|
|
return 128; |
|
|
@ -301,7 +297,6 @@ namespace data |
|
|
|
|
|
|
|
|
|
|
|
size_t IdentityEx::GetSigningPrivateKeyLen () const |
|
|
|
size_t IdentityEx::GetSigningPrivateKeyLen () const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!m_Verifier) CreateVerifier (); |
|
|
|
|
|
|
|
if (m_Verifier) |
|
|
|
if (m_Verifier) |
|
|
|
return m_Verifier->GetPrivateKeyLen (); |
|
|
|
return m_Verifier->GetPrivateKeyLen (); |
|
|
|
return GetSignatureLen ()/2; |
|
|
|
return GetSignatureLen ()/2; |
|
|
@ -309,14 +304,12 @@ namespace data |
|
|
|
|
|
|
|
|
|
|
|
size_t IdentityEx::GetSignatureLen () const |
|
|
|
size_t IdentityEx::GetSignatureLen () const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!m_Verifier) CreateVerifier (); |
|
|
|
|
|
|
|
if (m_Verifier) |
|
|
|
if (m_Verifier) |
|
|
|
return m_Verifier->GetSignatureLen (); |
|
|
|
return m_Verifier->GetSignatureLen (); |
|
|
|
return i2p::crypto::DSA_SIGNATURE_LENGTH; |
|
|
|
return i2p::crypto::DSA_SIGNATURE_LENGTH; |
|
|
|
} |
|
|
|
} |
|
|
|
bool IdentityEx::Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const |
|
|
|
bool IdentityEx::Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!m_Verifier) CreateVerifier (); |
|
|
|
|
|
|
|
if (m_Verifier) |
|
|
|
if (m_Verifier) |
|
|
|
return m_Verifier->Verify (buf, len, signature); |
|
|
|
return m_Verifier->Verify (buf, len, signature); |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -373,9 +366,10 @@ namespace data |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void IdentityEx::CreateVerifier () const |
|
|
|
void IdentityEx::CreateVerifier () |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!m_Verifier) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_Verifier) return; // don't create again
|
|
|
|
|
|
|
|
auto verifier = CreateVerifier (GetSigningKeyType ()); |
|
|
|
auto verifier = CreateVerifier (GetSigningKeyType ()); |
|
|
|
if (verifier) |
|
|
|
if (verifier) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -393,32 +387,8 @@ namespace data |
|
|
|
delete[] signingKey; |
|
|
|
delete[] signingKey; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
UpdateVerifier (verifier); |
|
|
|
m_Verifier.reset (verifier); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void IdentityEx::UpdateVerifier (i2p::crypto::Verifier * verifier) const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
bool del = false; |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::lock_guard<std::mutex> l(m_VerifierMutex); |
|
|
|
|
|
|
|
if (!m_Verifier) |
|
|
|
|
|
|
|
m_Verifier = verifier; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
del = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (del) |
|
|
|
|
|
|
|
delete verifier; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void IdentityEx::DropVerifier () const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
i2p::crypto::Verifier * verifier; |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::lock_guard<std::mutex> l(m_VerifierMutex); |
|
|
|
|
|
|
|
verifier = m_Verifier; |
|
|
|
|
|
|
|
m_Verifier = nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
delete verifier; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<i2p::crypto::CryptoKeyEncryptor> IdentityEx::CreateEncryptor (CryptoKeyType keyType, const uint8_t * key) |
|
|
|
std::shared_ptr<i2p::crypto::CryptoKeyEncryptor> IdentityEx::CreateEncryptor (CryptoKeyType keyType, const uint8_t * key) |
|
|
|