mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
multi crypto keys in i2cp.leaseSetEncType
This commit is contained in:
parent
d923f0e01b
commit
a2a0f62135
|
@ -1,6 +1,9 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <set>
|
||||||
|
#include <vector>
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
#include "Crypto.h"
|
#include "Crypto.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "FS.h"
|
#include "FS.h"
|
||||||
|
@ -839,25 +842,46 @@ namespace client
|
||||||
if (keys.IsOfflineSignature () && GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_LEASESET)
|
if (keys.IsOfflineSignature () && GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_LEASESET)
|
||||||
SetLeaseSetType (i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2); // offline keys can be published with LS2 only
|
SetLeaseSetType (i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2); // offline keys can be published with LS2 only
|
||||||
|
|
||||||
auto encryptionKeyType = GetIdentity ()->GetCryptoKeyType ();
|
|
||||||
// extract encryption type params for LS2
|
// extract encryption type params for LS2
|
||||||
|
std::set<i2p::data::CryptoKeyType> encryptionKeyTypes;
|
||||||
if (GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2 && params)
|
if (GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2 && params)
|
||||||
{
|
{
|
||||||
auto it = params->find (I2CP_PARAM_LEASESET_ENCRYPTION_TYPE);
|
auto it = params->find (I2CP_PARAM_LEASESET_ENCRYPTION_TYPE);
|
||||||
if (it != params->end ())
|
if (it != params->end ())
|
||||||
encryptionKeyType = std::stoi(it->second);
|
{
|
||||||
|
// comma-separated values
|
||||||
|
std::vector<std::string> values;
|
||||||
|
boost::split(values, it->second, boost::is_any_of(","));
|
||||||
|
for (auto& it1: values)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
encryptionKeyTypes.insert (std::stoi(it1));
|
||||||
|
}
|
||||||
|
catch (std::exception& ex)
|
||||||
|
{
|
||||||
|
LogPrint (eLogInfo, "Destination: Unexpected crypto type ", it1, ". ", ex.what ());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// if no param or valid crypto type use from identity
|
||||||
|
if (encryptionKeyTypes.empty ()) encryptionKeyTypes.insert (GetIdentity ()->GetCryptoKeyType ());
|
||||||
|
|
||||||
auto encryptionKey = new EncryptionKey (encryptionKeyType);
|
for (auto& it: encryptionKeyTypes)
|
||||||
if (isPublic)
|
{
|
||||||
PersistTemporaryKeys (encryptionKey);
|
auto encryptionKey = new EncryptionKey (it);
|
||||||
else
|
if (isPublic)
|
||||||
encryptionKey->GenerateKeys ();
|
PersistTemporaryKeys (encryptionKey); // TODO:
|
||||||
encryptionKey->CreateDecryptor ();
|
else
|
||||||
if (encryptionKeyType == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD_RATCHET)
|
encryptionKey->GenerateKeys ();
|
||||||
m_ECIESx25519EncryptionKey.reset (encryptionKey);
|
encryptionKey->CreateDecryptor ();
|
||||||
else
|
if (it == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD_RATCHET)
|
||||||
m_StandardEncryptionKey.reset (encryptionKey);
|
m_ECIESx25519EncryptionKey.reset (encryptionKey);
|
||||||
|
else
|
||||||
|
m_StandardEncryptionKey.reset (encryptionKey);
|
||||||
|
}
|
||||||
|
|
||||||
if (isPublic)
|
if (isPublic)
|
||||||
LogPrint (eLogInfo, "Destination: Local address ", GetIdentHash().ToBase32 (), " created");
|
LogPrint (eLogInfo, "Destination: Local address ", GetIdentHash().ToBase32 (), " created");
|
||||||
|
|
Loading…
Reference in a new issue