Browse Source

multi crypto keys in i2cp.leaseSetEncType

pull/1515/head
orignal 5 years ago
parent
commit
a2a0f62135
  1. 50
      libi2pd/Destination.cpp

50
libi2pd/Destination.cpp

@ -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
auto encryptionKey = new EncryptionKey (encryptionKeyType); if (encryptionKeyTypes.empty ()) encryptionKeyTypes.insert (GetIdentity ()->GetCryptoKeyType ());
if (isPublic)
PersistTemporaryKeys (encryptionKey); for (auto& it: encryptionKeyTypes)
else {
encryptionKey->GenerateKeys (); auto encryptionKey = new EncryptionKey (it);
encryptionKey->CreateDecryptor (); if (isPublic)
if (encryptionKeyType == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD_RATCHET) PersistTemporaryKeys (encryptionKey); // TODO:
m_ECIESx25519EncryptionKey.reset (encryptionKey); else
else encryptionKey->GenerateKeys ();
m_StandardEncryptionKey.reset (encryptionKey); encryptionKey->CreateDecryptor ();
if (it == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD_RATCHET)
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…
Cancel
Save