From f4798d05e7e1d7773fadf2d77c2ea11ff648cee0 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 15 Apr 2020 22:04:18 -0400 Subject: [PATCH] persist multi encryption keys --- libi2pd/Destination.cpp | 15 +++++++++++---- libi2pd/Destination.h | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/libi2pd/Destination.cpp b/libi2pd/Destination.cpp index 0bb71971..1473d41f 100644 --- a/libi2pd/Destination.cpp +++ b/libi2pd/Destination.cpp @@ -867,13 +867,18 @@ namespace client } } // if no param or valid crypto type use from identity - if (encryptionKeyTypes.empty ()) encryptionKeyTypes.insert (GetIdentity ()->GetCryptoKeyType ()); + bool isSingleKey = false; + if (encryptionKeyTypes.empty ()) + { + isSingleKey = true; + encryptionKeyTypes.insert (GetIdentity ()->GetCryptoKeyType ()); + } for (auto& it: encryptionKeyTypes) { auto encryptionKey = new EncryptionKey (it); if (isPublic) - PersistTemporaryKeys (encryptionKey); // TODO: + PersistTemporaryKeys (encryptionKey, isSingleKey); else encryptionKey->GenerateKeys (); encryptionKey->CreateDecryptor (); @@ -1119,10 +1124,12 @@ namespace client return ret; } - void ClientDestination::PersistTemporaryKeys (EncryptionKey * keys) + void ClientDestination::PersistTemporaryKeys (EncryptionKey * keys, bool isSingleKey) { + if (!keys) return; std::string ident = GetIdentHash().ToBase32(); - std::string path = i2p::fs::DataDirPath("destinations", (ident + ".dat")); + std::string path = i2p::fs::DataDirPath("destinations", + isSingleKey ? (ident + ".dat") : (ident + "." + std::to_string (keys->keyType) + ".dat")); std::ifstream f(path, std::ifstream::binary); if (f) { diff --git a/libi2pd/Destination.h b/libi2pd/Destination.h index 4d51877b..8c423d77 100644 --- a/libi2pd/Destination.h +++ b/libi2pd/Destination.h @@ -256,7 +256,7 @@ namespace client std::shared_ptr GetSharedFromThis () { return std::static_pointer_cast(shared_from_this ()); } - void PersistTemporaryKeys (EncryptionKey * keys); + void PersistTemporaryKeys (EncryptionKey * keys, bool isSingleKey); void ReadAuthKey (const std::string& group, const std::map * params); private: