mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-24 06:04:16 +00:00
implement Decrypt for all local destination
This commit is contained in:
parent
60aa459dfc
commit
c5f784719d
@ -711,6 +711,7 @@ namespace client
|
|||||||
else
|
else
|
||||||
i2p::data::PrivateKeys::GenerateCryptoKeyPair(GetIdentity ()->GetCryptoKeyType (),
|
i2p::data::PrivateKeys::GenerateCryptoKeyPair(GetIdentity ()->GetCryptoKeyType (),
|
||||||
m_EncryptionPrivateKey, m_EncryptionPublicKey);
|
m_EncryptionPrivateKey, m_EncryptionPublicKey);
|
||||||
|
m_Decryptor = m_Keys.CreateDecryptor (m_EncryptionPrivateKey);
|
||||||
if (isPublic)
|
if (isPublic)
|
||||||
LogPrint (eLogInfo, "Destination: Local address ", GetIdentHash().ToBase32 (), " created");
|
LogPrint (eLogInfo, "Destination: Local address ", GetIdentHash().ToBase32 (), " created");
|
||||||
}
|
}
|
||||||
@ -952,5 +953,12 @@ namespace client
|
|||||||
if (m_DatagramDestination) m_DatagramDestination->CleanUp ();
|
if (m_DatagramDestination) m_DatagramDestination->CleanUp ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClientDestination::Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const
|
||||||
|
{
|
||||||
|
if (m_Decryptor)
|
||||||
|
m_Decryptor->Decrypt (encrypted, data, ctx);
|
||||||
|
else
|
||||||
|
LogPrint (eLogError, "Destinations: decryptor is not set");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,6 +206,7 @@ namespace client
|
|||||||
|
|
||||||
// implements LocalDestination
|
// implements LocalDestination
|
||||||
const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; };
|
const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; };
|
||||||
|
void Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const;
|
||||||
std::shared_ptr<const i2p::data::IdentityEx> GetIdentity () const { return m_Keys.GetPublic (); };
|
std::shared_ptr<const i2p::data::IdentityEx> GetIdentity () const { return m_Keys.GetPublic (); };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -228,6 +229,7 @@ namespace client
|
|||||||
|
|
||||||
i2p::data::PrivateKeys m_Keys;
|
i2p::data::PrivateKeys m_Keys;
|
||||||
uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256];
|
uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256];
|
||||||
|
std::shared_ptr<i2p::crypto::CryptoKeyDecryptor> m_Decryptor;
|
||||||
|
|
||||||
std::shared_ptr<i2p::stream::StreamingDestination> m_StreamingDestination; // default
|
std::shared_ptr<i2p::stream::StreamingDestination> m_StreamingDestination; // default
|
||||||
std::map<uint16_t, std::shared_ptr<i2p::stream::StreamingDestination> > m_StreamingDestinationsByPorts;
|
std::map<uint16_t, std::shared_ptr<i2p::stream::StreamingDestination> > m_StreamingDestinationsByPorts;
|
||||||
|
@ -587,7 +587,13 @@ namespace data
|
|||||||
std::shared_ptr<i2p::crypto::CryptoKeyDecryptor> PrivateKeys::CreateDecryptor (const uint8_t * key) const
|
std::shared_ptr<i2p::crypto::CryptoKeyDecryptor> PrivateKeys::CreateDecryptor (const uint8_t * key) const
|
||||||
{
|
{
|
||||||
if (!key) key = m_PrivateKey; // use privateKey
|
if (!key) key = m_PrivateKey; // use privateKey
|
||||||
switch (m_Public->GetCryptoKeyType ())
|
return CreateDecryptor (m_Public->GetCryptoKeyType (), key);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<i2p::crypto::CryptoKeyDecryptor> PrivateKeys::CreateDecryptor (CryptoKeyType cryptoType, const uint8_t * key)
|
||||||
|
{
|
||||||
|
if (!key) return nullptr;
|
||||||
|
switch (cryptoType)
|
||||||
{
|
{
|
||||||
case CRYPTO_KEY_TYPE_ELGAMAL:
|
case CRYPTO_KEY_TYPE_ELGAMAL:
|
||||||
return std::make_shared<i2p::crypto::ElGamalDecryptor>(key);
|
return std::make_shared<i2p::crypto::ElGamalDecryptor>(key);
|
||||||
@ -596,9 +602,9 @@ namespace data
|
|||||||
return std::make_shared<i2p::crypto::ECIESP256Decryptor>(key);
|
return std::make_shared<i2p::crypto::ECIESP256Decryptor>(key);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LogPrint (eLogError, "Identity: Unknown crypto key type ", (int)m_Public->GetCryptoKeyType ());
|
LogPrint (eLogError, "Identity: Unknown crypto key type ", (int)cryptoType);
|
||||||
};
|
};
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrivateKeys PrivateKeys::CreateRandomKeys (SigningKeyType type, CryptoKeyType cryptoType)
|
PrivateKeys PrivateKeys::CreateRandomKeys (SigningKeyType type, CryptoKeyType cryptoType)
|
||||||
|
@ -150,6 +150,7 @@ namespace data
|
|||||||
|
|
||||||
std::shared_ptr<i2p::crypto::CryptoKeyDecryptor> CreateDecryptor (const uint8_t * key) const;
|
std::shared_ptr<i2p::crypto::CryptoKeyDecryptor> CreateDecryptor (const uint8_t * key) const;
|
||||||
|
|
||||||
|
static std::shared_ptr<i2p::crypto::CryptoKeyDecryptor> CreateDecryptor (CryptoKeyType cryptoType, const uint8_t * key);
|
||||||
static PrivateKeys CreateRandomKeys (SigningKeyType type = SIGNING_KEY_TYPE_DSA_SHA1, CryptoKeyType cryptoType = CRYPTO_KEY_TYPE_ELGAMAL);
|
static PrivateKeys CreateRandomKeys (SigningKeyType type = SIGNING_KEY_TYPE_DSA_SHA1, CryptoKeyType cryptoType = CRYPTO_KEY_TYPE_ELGAMAL);
|
||||||
static void GenerateCryptoKeyPair (CryptoKeyType type, uint8_t * priv, uint8_t * pub); // priv and pub are 256 bytes long
|
static void GenerateCryptoKeyPair (CryptoKeyType type, uint8_t * priv, uint8_t * pub); // priv and pub are 256 bytes long
|
||||||
|
|
||||||
@ -202,7 +203,8 @@ namespace data
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~LocalDestination() {};
|
virtual ~LocalDestination() {};
|
||||||
virtual const uint8_t * GetEncryptionPrivateKey () const = 0;
|
virtual const uint8_t * GetEncryptionPrivateKey () const = 0; // deprecated
|
||||||
|
virtual void Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const = 0;
|
||||||
virtual std::shared_ptr<const IdentityEx> GetIdentity () const = 0;
|
virtual std::shared_ptr<const IdentityEx> GetIdentity () const = 0;
|
||||||
|
|
||||||
const IdentHash& GetIdentHash () const { return GetIdentity ()->GetIdentHash (); };
|
const IdentHash& GetIdentHash () const { return GetIdentity ()->GetIdentHash (); };
|
||||||
|
@ -28,6 +28,7 @@ namespace i2p
|
|||||||
m_StartupTime = i2p::util::GetSecondsSinceEpoch ();
|
m_StartupTime = i2p::util::GetSecondsSinceEpoch ();
|
||||||
if (!Load ())
|
if (!Load ())
|
||||||
CreateNewRouter ();
|
CreateNewRouter ();
|
||||||
|
m_Decryptor = m_Keys.CreateDecryptor (nullptr);
|
||||||
UpdateRouterInfo ();
|
UpdateRouterInfo ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,4 +479,10 @@ namespace i2p
|
|||||||
{
|
{
|
||||||
return i2p::util::GetSecondsSinceEpoch () - m_StartupTime;
|
return i2p::util::GetSecondsSinceEpoch () - m_StartupTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RouterContext::Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const
|
||||||
|
{
|
||||||
|
if (m_Decryptor)
|
||||||
|
m_Decryptor->Decrypt (encrypted, data, ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,8 @@ namespace i2p
|
|||||||
|
|
||||||
// implements LocalDestination
|
// implements LocalDestination
|
||||||
std::shared_ptr<const i2p::data::IdentityEx> GetIdentity () const { return m_Keys.GetPublic (); };
|
std::shared_ptr<const i2p::data::IdentityEx> GetIdentity () const { return m_Keys.GetPublic (); };
|
||||||
const uint8_t * GetEncryptionPrivateKey () const { return m_Keys.GetPrivateKey (); };
|
const uint8_t * GetEncryptionPrivateKey () const { return m_Keys.GetPrivateKey (); }; // deprecated
|
||||||
|
void Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const;
|
||||||
const uint8_t * GetEncryptionPublicKey () const { return GetIdentity ()->GetStandardIdentity ().publicKey; };
|
const uint8_t * GetEncryptionPublicKey () const { return GetIdentity ()->GetStandardIdentity ().publicKey; };
|
||||||
void Sign (const uint8_t * buf, int len, uint8_t * signature) const { m_Keys.Sign (buf, len, signature); };
|
void Sign (const uint8_t * buf, int len, uint8_t * signature) const { m_Keys.Sign (buf, len, signature); };
|
||||||
void SetLeaseSetUpdated () {};
|
void SetLeaseSetUpdated () {};
|
||||||
@ -115,6 +116,7 @@ namespace i2p
|
|||||||
|
|
||||||
i2p::data::RouterInfo m_RouterInfo;
|
i2p::data::RouterInfo m_RouterInfo;
|
||||||
i2p::data::PrivateKeys m_Keys;
|
i2p::data::PrivateKeys m_Keys;
|
||||||
|
std::shared_ptr<i2p::crypto::CryptoKeyDecryptor> m_Decryptor;
|
||||||
uint64_t m_LastUpdateTime;
|
uint64_t m_LastUpdateTime;
|
||||||
bool m_AcceptsTunnels, m_IsFloodfill;
|
bool m_AcceptsTunnels, m_IsFloodfill;
|
||||||
uint64_t m_StartupTime; // in seconds since epoch
|
uint64_t m_StartupTime; // in seconds since epoch
|
||||||
|
@ -31,6 +31,15 @@ namespace client
|
|||||||
void I2CPDestination::SetEncryptionPrivateKey (const uint8_t * key)
|
void I2CPDestination::SetEncryptionPrivateKey (const uint8_t * key)
|
||||||
{
|
{
|
||||||
memcpy (m_EncryptionPrivateKey, key, 256);
|
memcpy (m_EncryptionPrivateKey, key, 256);
|
||||||
|
m_Decryptor = i2p::data::PrivateKeys::CreateDecryptor (m_Identity->GetCryptoKeyType (), m_EncryptionPrivateKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
void I2CPDestination::Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const
|
||||||
|
{
|
||||||
|
if (m_Decryptor)
|
||||||
|
m_Decryptor->Decrypt (encrypted, data, ctx);
|
||||||
|
else
|
||||||
|
LogPrint (eLogError, "I2CP: decryptor is not set");
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2CPDestination::HandleDataMessage (const uint8_t * buf, size_t len)
|
void I2CPDestination::HandleDataMessage (const uint8_t * buf, size_t len)
|
||||||
|
@ -71,7 +71,8 @@ namespace client
|
|||||||
void SendMsgTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint32_t nonce); // called from I2CPSession
|
void SendMsgTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint32_t nonce); // called from I2CPSession
|
||||||
|
|
||||||
// implements LocalDestination
|
// implements LocalDestination
|
||||||
const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; };
|
const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; }; // deprecated
|
||||||
|
void Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const;
|
||||||
std::shared_ptr<const i2p::data::IdentityEx> GetIdentity () const { return m_Identity; };
|
std::shared_ptr<const i2p::data::IdentityEx> GetIdentity () const { return m_Identity; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -91,6 +92,7 @@ namespace client
|
|||||||
std::shared_ptr<I2CPSession> m_Owner;
|
std::shared_ptr<I2CPSession> m_Owner;
|
||||||
std::shared_ptr<const i2p::data::IdentityEx> m_Identity;
|
std::shared_ptr<const i2p::data::IdentityEx> m_Identity;
|
||||||
uint8_t m_EncryptionPrivateKey[256];
|
uint8_t m_EncryptionPrivateKey[256];
|
||||||
|
std::shared_ptr<i2p::crypto::CryptoKeyDecryptor> m_Decryptor;
|
||||||
uint64_t m_LeaseSetExpirationTime;
|
uint64_t m_LeaseSetExpirationTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user