diff --git a/libi2pd/Destination.cpp b/libi2pd/Destination.cpp index 318e7cbc..3a693980 100644 --- a/libi2pd/Destination.cpp +++ b/libi2pd/Destination.cpp @@ -777,12 +777,20 @@ namespace client m_DatagramDestination (nullptr), m_RefCounter (0), m_ReadyChecker(GetService()) { + i2p::data::CryptoKeyType keyType = GetIdentity ()->GetCryptoKeyType (); + // extract encryption type params for LS2 + if (GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2 && params) + { + auto it = params->find (I2CP_PARAM_LEASESET_ENCRYPTION_TYPE); + if (it != params->end ()) + keyType = std::stoi(it->second); + } + if (isPublic) - PersistTemporaryKeys (); + PersistTemporaryKeys (keyType); else - i2p::data::PrivateKeys::GenerateCryptoKeyPair(GetIdentity ()->GetCryptoKeyType (), - m_EncryptionPrivateKey, m_EncryptionPublicKey); - m_Decryptor = m_Keys.CreateDecryptor (m_EncryptionPrivateKey); + i2p::data::PrivateKeys::GenerateCryptoKeyPair (keyType, m_EncryptionPrivateKey, m_EncryptionPublicKey); + m_Decryptor = i2p::data::PrivateKeys::CreateDecryptor (keyType, m_EncryptionPrivateKey); if (isPublic) LogPrint (eLogInfo, "Destination: Local address ", GetIdentHash().ToBase32 (), " created"); @@ -1000,7 +1008,7 @@ namespace client return ret; } - void ClientDestination::PersistTemporaryKeys () + void ClientDestination::PersistTemporaryKeys (i2p::data::CryptoKeyType keyType) { std::string ident = GetIdentHash().ToBase32(); std::string path = i2p::fs::DataDirPath("destinations", (ident + ".dat")); @@ -1012,9 +1020,10 @@ namespace client return; } - LogPrint (eLogInfo, "Destination: Creating new temporary keys for address ", ident, ".b32.i2p"); - i2p::data::PrivateKeys::GenerateCryptoKeyPair(GetIdentity ()->GetCryptoKeyType (), - m_EncryptionPrivateKey, m_EncryptionPublicKey); + LogPrint (eLogInfo, "Destination: Creating new temporary keys of type ", (int)keyType, " for address ", ident, ".b32.i2p"); + memset (m_EncryptionPrivateKey, 0, 256); + memset (m_EncryptionPublicKey, 0, 256); + i2p::data::PrivateKeys::GenerateCryptoKeyPair (keyType, m_EncryptionPrivateKey, m_EncryptionPublicKey); std::ofstream f1 (path, std::ofstream::binary | std::ofstream::out); if (f1) { diff --git a/libi2pd/Destination.h b/libi2pd/Destination.h index c098708c..a2d20c16 100644 --- a/libi2pd/Destination.h +++ b/libi2pd/Destination.h @@ -54,6 +54,7 @@ namespace client const char I2CP_PARAM_OUTBOUND_NICKNAME[] = "outbound.nickname"; const char I2CP_PARAM_LEASESET_TYPE[] = "i2cp.leaseSetType"; const int DEFAULT_LEASESET_TYPE = 1; + const char I2CP_PARAM_LEASESET_ENCRYPTION_TYPE[] = "i2cp.leaseSetEncType"; // latency const char I2CP_PARAM_MIN_TUNNEL_LATENCY[] = "latency.min"; @@ -233,7 +234,7 @@ namespace client std::shared_ptr GetSharedFromThis () { return std::static_pointer_cast(shared_from_this ()); } - void PersistTemporaryKeys (); + void PersistTemporaryKeys (i2p::data::CryptoKeyType keyType); #ifdef I2LUA void ScheduleCheckForReady(ReadyPromise * p); void HandleCheckForReady(const boost::system::error_code & ecode, ReadyPromise * p); diff --git a/libi2pd_client/ClientContext.cpp b/libi2pd_client/ClientContext.cpp index ad561b19..c69e419e 100644 --- a/libi2pd_client/ClientContext.cpp +++ b/libi2pd_client/ClientContext.cpp @@ -375,6 +375,12 @@ namespace client return section.second.get (boost::property_tree::ptree::path_type (name, '/'), std::to_string (value)); } + template + std::string ClientContext::GetI2CPStringOption (const Section& section, const std::string& name, const std::string& value) const + { + return section.second.get (boost::property_tree::ptree::path_type (name, '/'), value); + } + template void ClientContext::ReadI2CPOptions (const Section& section, std::map& options) const { @@ -383,10 +389,12 @@ namespace client options[I2CP_PARAM_INBOUND_TUNNELS_QUANTITY] = GetI2CPOption (section, I2CP_PARAM_INBOUND_TUNNELS_QUANTITY, DEFAULT_INBOUND_TUNNELS_QUANTITY); options[I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY] = GetI2CPOption (section, I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY, DEFAULT_OUTBOUND_TUNNELS_QUANTITY); options[I2CP_PARAM_TAGS_TO_SEND] = GetI2CPOption (section, I2CP_PARAM_TAGS_TO_SEND, DEFAULT_TAGS_TO_SEND); - options[I2CP_PARAM_LEASESET_TYPE] = GetI2CPOption(section, I2CP_PARAM_LEASESET_TYPE, DEFAULT_LEASESET_TYPE); options[I2CP_PARAM_MIN_TUNNEL_LATENCY] = GetI2CPOption(section, I2CP_PARAM_MIN_TUNNEL_LATENCY, DEFAULT_MIN_TUNNEL_LATENCY); options[I2CP_PARAM_MAX_TUNNEL_LATENCY] = GetI2CPOption(section, I2CP_PARAM_MAX_TUNNEL_LATENCY, DEFAULT_MAX_TUNNEL_LATENCY); options[I2CP_PARAM_STREAMING_INITIAL_ACK_DELAY] = GetI2CPOption(section, I2CP_PARAM_STREAMING_INITIAL_ACK_DELAY, DEFAULT_INITIAL_ACK_DELAY); + options[I2CP_PARAM_LEASESET_TYPE] = GetI2CPOption(section, I2CP_PARAM_LEASESET_TYPE, DEFAULT_LEASESET_TYPE); + std::string encType = GetI2CPStringOption(section, I2CP_PARAM_LEASESET_ENCRYPTION_TYPE, ""); + if (encType.length () > 0) options[I2CP_PARAM_LEASESET_ENCRYPTION_TYPE] = encType; } void ClientContext::ReadI2CPOptionsFromConfig (const std::string& prefix, std::map& options) const diff --git a/libi2pd_client/ClientContext.h b/libi2pd_client/ClientContext.h index af9bebb2..71e052c3 100644 --- a/libi2pd_client/ClientContext.h +++ b/libi2pd_client/ClientContext.h @@ -93,6 +93,8 @@ namespace client template std::string GetI2CPOption (const Section& section, const std::string& name, const Type& value) const; template + std::string GetI2CPStringOption (const Section& section, const std::string& name, const std::string& value) const; // GetI2CPOption with string default value + template void ReadI2CPOptions (const Section& section, std::map& options) const; // for tunnels void ReadI2CPOptionsFromConfig (const std::string& prefix, std::map& options) const; // for HTTP and SOCKS proxy