mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-29 04:07:49 +02:00
common LocalEncryptionKey to pass to loacl LeaseSet
This commit is contained in:
parent
9c46ff2449
commit
f6c93f7345
6 changed files with 43 additions and 34 deletions
|
@ -181,5 +181,21 @@ namespace crypto
|
|||
k.GetPrivateKey (priv);
|
||||
memcpy (pub, k.GetPublicKey (), 32);
|
||||
}
|
||||
|
||||
LocalEncryptionKey::LocalEncryptionKey (i2p::data::CryptoKeyType t): keyType(t)
|
||||
{
|
||||
pub.resize (GetCryptoPublicKeyLen (keyType));
|
||||
priv.resize (GetCryptoPrivateKeyLen (keyType));
|
||||
}
|
||||
|
||||
void LocalEncryptionKey::GenerateKeys ()
|
||||
{
|
||||
i2p::data::PrivateKeys::GenerateCryptoKeyPair (keyType, priv.data (), pub.data ());
|
||||
}
|
||||
|
||||
void LocalEncryptionKey::CreateDecryptor ()
|
||||
{
|
||||
decryptor = i2p::data::PrivateKeys::CreateDecryptor (keyType, priv.data ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -191,6 +191,17 @@ namespace crypto
|
|||
};
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct LocalEncryptionKey
|
||||
{
|
||||
std::vector<uint8_t> pub, priv;
|
||||
i2p::data::CryptoKeyType keyType;
|
||||
std::shared_ptr<CryptoKeyDecryptor> decryptor;
|
||||
|
||||
LocalEncryptionKey (i2p::data::CryptoKeyType t);
|
||||
void GenerateKeys ();
|
||||
void CreateDecryptor ();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1047,7 +1047,7 @@ namespace client
|
|||
|
||||
for (auto& it: encryptionKeyTypes)
|
||||
{
|
||||
auto encryptionKey = std::make_shared<EncryptionKey> (it);
|
||||
auto encryptionKey = std::make_shared<i2p::crypto::LocalEncryptionKey> (it);
|
||||
if (IsPublic ())
|
||||
PersistTemporaryKeys (encryptionKey);
|
||||
else
|
||||
|
@ -1405,7 +1405,7 @@ namespace client
|
|||
return ret;
|
||||
}
|
||||
|
||||
void ClientDestination::PersistTemporaryKeys (std::shared_ptr<EncryptionKey> keys)
|
||||
void ClientDestination::PersistTemporaryKeys (std::shared_ptr<i2p::crypto::LocalEncryptionKey> keys)
|
||||
{
|
||||
if (!keys) return;
|
||||
std::string ident = GetIdentHash().ToBase32();
|
||||
|
@ -1475,9 +1475,9 @@ namespace client
|
|||
else
|
||||
{
|
||||
// standard LS2 (type 3) first
|
||||
i2p::data::LocalLeaseSet2::KeySections keySections;
|
||||
i2p::data::LocalLeaseSet2::EncryptionKeys keySections;
|
||||
for (const auto& it: m_EncryptionKeys)
|
||||
keySections.push_back ({it.first, (uint16_t)it.second->pub.size (), it.second->pub.data ()} );
|
||||
keySections.push_back (it.second);
|
||||
|
||||
auto publishedTimestamp = i2p::util::GetSecondsSinceEpoch ();
|
||||
if (publishedTimestamp <= m_LastPublishedTimestamp)
|
||||
|
@ -1503,7 +1503,7 @@ namespace client
|
|||
|
||||
bool ClientDestination::Decrypt (const uint8_t * encrypted, uint8_t * data, i2p::data::CryptoKeyType preferredCrypto) const
|
||||
{
|
||||
std::shared_ptr<EncryptionKey> encryptionKey;
|
||||
std::shared_ptr<i2p::crypto::LocalEncryptionKey> encryptionKey;
|
||||
if (!m_EncryptionKeys.empty ())
|
||||
{
|
||||
if (m_EncryptionKeys.rbegin ()->first == preferredCrypto)
|
||||
|
|
|
@ -230,21 +230,6 @@ namespace client
|
|||
|
||||
class ClientDestination: public LeaseSetDestination
|
||||
{
|
||||
struct EncryptionKey
|
||||
{
|
||||
std::vector<uint8_t> pub, priv;
|
||||
i2p::data::CryptoKeyType keyType;
|
||||
std::shared_ptr<i2p::crypto::CryptoKeyDecryptor> decryptor;
|
||||
|
||||
EncryptionKey (i2p::data::CryptoKeyType t): keyType(t)
|
||||
{
|
||||
pub.resize (i2p::crypto::GetCryptoPublicKeyLen (keyType));
|
||||
priv.resize (i2p::crypto::GetCryptoPrivateKeyLen (keyType));
|
||||
}
|
||||
void GenerateKeys () { i2p::data::PrivateKeys::GenerateCryptoKeyPair (keyType, priv.data (), pub.data ()); };
|
||||
void CreateDecryptor () { decryptor = i2p::data::PrivateKeys::CreateDecryptor (keyType, priv.data ()); };
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
ClientDestination (boost::asio::io_context& service, const i2p::data::PrivateKeys& keys,
|
||||
|
@ -310,7 +295,7 @@ namespace client
|
|||
std::shared_ptr<ClientDestination> GetSharedFromThis () {
|
||||
return std::static_pointer_cast<ClientDestination>(shared_from_this ());
|
||||
}
|
||||
void PersistTemporaryKeys (std::shared_ptr<EncryptionKey> keys);
|
||||
void PersistTemporaryKeys (std::shared_ptr<i2p::crypto::LocalEncryptionKey> keys);
|
||||
void ReadAuthKey (const std::string& group, const std::map<std::string, std::string> * params);
|
||||
|
||||
template<typename Dest>
|
||||
|
@ -319,7 +304,7 @@ namespace client
|
|||
private:
|
||||
|
||||
i2p::data::PrivateKeys m_Keys;
|
||||
std::map<i2p::data::CryptoKeyType, std::shared_ptr<EncryptionKey> > m_EncryptionKeys; // last is most preferable
|
||||
std::map<i2p::data::CryptoKeyType, std::shared_ptr<i2p::crypto::LocalEncryptionKey> > m_EncryptionKeys; // last is most preferable
|
||||
i2p::data::CryptoKeyType m_PreferredCryptoType;
|
||||
|
||||
int m_StreamingAckDelay,m_StreamingOutboundSpeed, m_StreamingInboundSpeed, m_StreamingMaxConcurrentStreams;
|
||||
|
|
|
@ -848,7 +848,7 @@ namespace data
|
|||
}
|
||||
|
||||
LocalLeaseSet2::LocalLeaseSet2 (uint8_t storeType, const i2p::data::PrivateKeys& keys,
|
||||
const KeySections& encryptionKeys, const std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> >& tunnels,
|
||||
const EncryptionKeys& encryptionKeys, const std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> >& tunnels,
|
||||
bool isPublic, uint64_t publishedTimestamp, bool isPublishedEncrypted):
|
||||
LocalLeaseSet (keys.GetPublic (), nullptr, 0)
|
||||
{
|
||||
|
@ -858,7 +858,7 @@ namespace data
|
|||
if (num > MAX_NUM_LEASES) num = MAX_NUM_LEASES;
|
||||
size_t keySectionsLen = 0;
|
||||
for (const auto& it: encryptionKeys)
|
||||
keySectionsLen += 2/*key type*/ + 2/*key len*/ + it.keyLen/*key*/;
|
||||
keySectionsLen += 2/*key type*/ + 2/*key len*/ + it->pub.size()/*key*/;
|
||||
m_BufferLen = identity->GetFullLen () + 4/*published*/ + 2/*expires*/ + 2/*flag*/ + 2/*properties len*/ +
|
||||
1/*num keys*/ + keySectionsLen + 1/*num leases*/ + num*LEASE2_SIZE + keys.GetSignatureLen ();
|
||||
uint16_t flags = 0;
|
||||
|
@ -893,9 +893,9 @@ namespace data
|
|||
m_Buffer[offset] = encryptionKeys.size (); offset++; // 1 key
|
||||
for (const auto& it: encryptionKeys)
|
||||
{
|
||||
htobe16buf (m_Buffer + offset, it.keyType); offset += 2; // key type
|
||||
htobe16buf (m_Buffer + offset, it.keyLen); offset += 2; // key len
|
||||
memcpy (m_Buffer + offset, it.encryptionPublicKey, it.keyLen); offset += it.keyLen; // key
|
||||
htobe16buf (m_Buffer + offset, it->keyType); offset += 2; // key type
|
||||
htobe16buf (m_Buffer + offset, it->pub.size()); offset += 2; // key len
|
||||
memcpy (m_Buffer + offset, it->pub.data(), it->pub.size()); offset += it->pub.size(); // key
|
||||
}
|
||||
// leases
|
||||
uint32_t expirationTime = 0; // in seconds
|
||||
|
|
|
@ -12,12 +12,14 @@
|
|||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <memory>
|
||||
#include "Identity.h"
|
||||
#include "Timestamp.h"
|
||||
#include "I2PEndian.h"
|
||||
#include "Blinding.h"
|
||||
#include "CryptoKey.h"
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
|
@ -247,15 +249,10 @@ namespace data
|
|||
{
|
||||
public:
|
||||
|
||||
struct KeySection
|
||||
{
|
||||
uint16_t keyType, keyLen;
|
||||
const uint8_t * encryptionPublicKey;
|
||||
};
|
||||
typedef std::vector<KeySection> KeySections;
|
||||
typedef std::list<std::shared_ptr<const i2p::crypto::LocalEncryptionKey> > EncryptionKeys;
|
||||
|
||||
LocalLeaseSet2 (uint8_t storeType, const i2p::data::PrivateKeys& keys,
|
||||
const KeySections& encryptionKeys,
|
||||
const EncryptionKeys& encryptionKeys,
|
||||
const std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> >& tunnels,
|
||||
bool isPublic, uint64_t publishedTimestamp,
|
||||
bool isPublishedEncrypted = false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue