diff --git a/libi2pd/Destination.cpp b/libi2pd/Destination.cpp index 3a693980..6f7ef8f0 100644 --- a/libi2pd/Destination.cpp +++ b/libi2pd/Destination.cpp @@ -777,20 +777,20 @@ namespace client m_DatagramDestination (nullptr), m_RefCounter (0), m_ReadyChecker(GetService()) { - i2p::data::CryptoKeyType keyType = GetIdentity ()->GetCryptoKeyType (); + m_EncryptionKeyType = 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); + m_EncryptionKeyType = std::stoi(it->second); } - if (isPublic) - PersistTemporaryKeys (keyType); + if (isPublic && m_EncryptionKeyType == GetIdentity ()->GetCryptoKeyType ()) // TODO: presist key type + PersistTemporaryKeys (); else - i2p::data::PrivateKeys::GenerateCryptoKeyPair (keyType, m_EncryptionPrivateKey, m_EncryptionPublicKey); - m_Decryptor = i2p::data::PrivateKeys::CreateDecryptor (keyType, m_EncryptionPrivateKey); + i2p::data::PrivateKeys::GenerateCryptoKeyPair (m_EncryptionKeyType, m_EncryptionPrivateKey, m_EncryptionPublicKey); + m_Decryptor = i2p::data::PrivateKeys::CreateDecryptor (m_EncryptionKeyType, m_EncryptionPrivateKey); if (isPublic) LogPrint (eLogInfo, "Destination: Local address ", GetIdentHash().ToBase32 (), " created"); @@ -1008,7 +1008,7 @@ namespace client return ret; } - void ClientDestination::PersistTemporaryKeys (i2p::data::CryptoKeyType keyType) + void ClientDestination::PersistTemporaryKeys () { std::string ident = GetIdentHash().ToBase32(); std::string path = i2p::fs::DataDirPath("destinations", (ident + ".dat")); @@ -1020,10 +1020,10 @@ namespace client return; } - LogPrint (eLogInfo, "Destination: Creating new temporary keys of type ", (int)keyType, " for address ", ident, ".b32.i2p"); + LogPrint (eLogInfo, "Destination: Creating new temporary keys of type for address ", ident, ".b32.i2p"); memset (m_EncryptionPrivateKey, 0, 256); memset (m_EncryptionPublicKey, 0, 256); - i2p::data::PrivateKeys::GenerateCryptoKeyPair (keyType, m_EncryptionPrivateKey, m_EncryptionPublicKey); + i2p::data::PrivateKeys::GenerateCryptoKeyPair (GetIdentity ()->GetCryptoKeyType (), m_EncryptionPrivateKey, m_EncryptionPublicKey); std::ofstream f1 (path, std::ofstream::binary | std::ofstream::out); if (f1) { @@ -1048,7 +1048,7 @@ namespace client // standard LS2 (type 3) assumed for now. TODO: implement others auto keyLen = m_Decryptor ? m_Decryptor->GetPublicKeyLen () : 256; leaseSet = new i2p::data::LocalLeaseSet2 (i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2, - GetIdentity (), GetIdentity ()->GetCryptoKeyType (), keyLen, m_EncryptionPublicKey, tunnels); + GetIdentity (), m_EncryptionKeyType, keyLen, m_EncryptionPublicKey, tunnels); // sign Sign (leaseSet->GetBuffer () - 1, leaseSet->GetBufferLen () - leaseSet->GetSignatureLen () + 1, leaseSet->GetSignature ()); // + leading store type } diff --git a/libi2pd/Destination.h b/libi2pd/Destination.h index a2d20c16..847ecb1a 100644 --- a/libi2pd/Destination.h +++ b/libi2pd/Destination.h @@ -234,7 +234,7 @@ namespace client std::shared_ptr GetSharedFromThis () { return std::static_pointer_cast(shared_from_this ()); } - void PersistTemporaryKeys (i2p::data::CryptoKeyType keyType); + void PersistTemporaryKeys (); #ifdef I2LUA void ScheduleCheckForReady(ReadyPromise * p); void HandleCheckForReady(const boost::system::error_code & ecode, ReadyPromise * p); @@ -243,6 +243,7 @@ namespace client i2p::data::PrivateKeys m_Keys; uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256]; + i2p::data::CryptoKeyType m_EncryptionKeyType; std::shared_ptr m_Decryptor; int m_StreamingAckDelay;