From a2a0f621357f677ae8ef1201e88b58bc9469500a Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 15 Apr 2020 18:01:01 -0400 Subject: [PATCH] multi crypto keys in i2cp.leaseSetEncType --- libi2pd/Destination.cpp | 50 ++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/libi2pd/Destination.cpp b/libi2pd/Destination.cpp index 30648a42..0bb71971 100644 --- a/libi2pd/Destination.cpp +++ b/libi2pd/Destination.cpp @@ -1,6 +1,9 @@ #include #include #include +#include +#include +#include #include "Crypto.h" #include "Log.h" #include "FS.h" @@ -839,25 +842,46 @@ namespace client 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 - auto encryptionKeyType = GetIdentity ()->GetCryptoKeyType (); // extract encryption type params for LS2 + std::set encryptionKeyTypes; if (GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2 && params) { auto it = params->find (I2CP_PARAM_LEASESET_ENCRYPTION_TYPE); if (it != params->end ()) - encryptionKeyType = std::stoi(it->second); + { + // comma-separated values + std::vector 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; + } + } + } } - - auto encryptionKey = new EncryptionKey (encryptionKeyType); - if (isPublic) - PersistTemporaryKeys (encryptionKey); - else - encryptionKey->GenerateKeys (); - encryptionKey->CreateDecryptor (); - if (encryptionKeyType == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD_RATCHET) - m_ECIESx25519EncryptionKey.reset (encryptionKey); - else - m_StandardEncryptionKey.reset (encryptionKey); + // if no param or valid crypto type use from identity + if (encryptionKeyTypes.empty ()) encryptionKeyTypes.insert (GetIdentity ()->GetCryptoKeyType ()); + + for (auto& it: encryptionKeyTypes) + { + auto encryptionKey = new EncryptionKey (it); + if (isPublic) + PersistTemporaryKeys (encryptionKey); // TODO: + else + encryptionKey->GenerateKeys (); + encryptionKey->CreateDecryptor (); + if (it == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD_RATCHET) + m_ECIESx25519EncryptionKey.reset (encryptionKey); + else + m_StandardEncryptionKey.reset (encryptionKey); + } if (isPublic) LogPrint (eLogInfo, "Destination: Local address ", GetIdentHash().ToBase32 (), " created");