diff --git a/bin/jni/configurationmanager.i b/bin/jni/configurationmanager.i index fd2b7dd805a864a59d12c81367ac382dce794b70..4f54775462503f7e06257f694239dcecede63164 100644 --- a/bin/jni/configurationmanager.i +++ b/bin/jni/configurationmanager.i @@ -105,6 +105,8 @@ bool cancelMessage(const std::string& accountID, uint64_t id); void setIsComposing(const std::string& accountID, const std::string& conversationUri, bool isWriting); bool setMessageDisplayed(const std::string& accountID, const std::string& conversationUri, const std::string& messageId, int status); bool changeAccountPassword(const std::string& accountID, const std::string& password_old, const std::string& password_new); +bool isPasswordValid(const std::string& accountId, const std::string& password); +std::vector<uint8_t> getPasswordKey(const std::string& accountId, const std::string& password); bool lookupName(const std::string& account, const std::string& nameserver, const std::string& name); bool lookupAddress(const std::string& account, const std::string& nameserver, const std::string& address); diff --git a/src/client/configurationmanager.cpp b/src/client/configurationmanager.cpp index 3db4b7bde5a9df79a2ff66951dc67b5f112b9a55..289fc07dff7e1721bf726e0934abc8f897139bcd 100644 --- a/src/client/configurationmanager.cpp +++ b/src/client/configurationmanager.cpp @@ -251,9 +251,20 @@ sendRegister(const std::string& accountId, bool enable) bool isPasswordValid(const std::string& accountId, const std::string& password) { - return jami::Manager::instance().isPasswordValid(accountId, password); + if (auto acc = jami::Manager::instance().getAccount<JamiAccount>(accountId)) + return acc->isPasswordValid(password); + return false; +} + +std::vector<uint8_t> +getPasswordKey(const std::string& accountID, const std::string& password) +{ + if (auto acc = jami::Manager::instance().getAccount<JamiAccount>(accountID)) + return acc->getPasswordKey(password); + return {}; } + void registerAllAccounts() { diff --git a/src/jami/configurationmanager_interface.h b/src/jami/configurationmanager_interface.h index a4580eb8871d0989c73fdcf13c51f9820ffaeff2..4fa74f576d85c8e89d11a1ccbe159baa6b5ab044 100644 --- a/src/jami/configurationmanager_interface.h +++ b/src/jami/configurationmanager_interface.h @@ -82,6 +82,7 @@ LIBJAMI_PUBLIC bool changeAccountPassword(const std::string& accountID, const std::string& password_old, const std::string& password_new); LIBJAMI_PUBLIC bool isPasswordValid(const std::string& accountID, const std::string& password); +LIBJAMI_PUBLIC std::vector<uint8_t> getPasswordKey(const std::string& accountID, const std::string& password); LIBJAMI_PUBLIC bool lookupName(const std::string& account, const std::string& nameserver, diff --git a/src/jamidht/account_manager.h b/src/jamidht/account_manager.h index 3c8e10b578a40dff8dfeff61568c9b300bad447a..b2d79868226cfafcd5486c99c9e38bb72042ca5e 100644 --- a/src/jamidht/account_manager.h +++ b/src/jamidht/account_manager.h @@ -124,6 +124,7 @@ public: virtual void onSyncData(DeviceSync&& device, bool checkDevice = true); virtual bool isPasswordValid(const std::string& /*password*/) { return false; }; + virtual std::vector<uint8_t> getPasswordKey(const std::string& /*password*/) { return {}; }; dht::crypto::Identity loadIdentity(const std::string& accountId, const std::string& crt_path, diff --git a/src/jamidht/archive_account_manager.cpp b/src/jamidht/archive_account_manager.cpp index 0fc8c299aff6e8473126f5fad72c53026ed61357..0e90c1a2a29471f66b326714dc019b786ea400ce 100644 --- a/src/jamidht/archive_account_manager.cpp +++ b/src/jamidht/archive_account_manager.cpp @@ -651,6 +651,18 @@ ArchiveAccountManager::changePassword(const std::string& password_old, } } +std::vector<uint8_t> +ArchiveAccountManager::getPasswordKey(const std::string& password) +{ + try { + auto data = dhtnet::fileutils::loadFile(fileutils::getFullPath(path_, archivePath_)); + return dht::crypto::aesGetKey(data, password); + } catch (const std::exception& e) { + JAMI_ERR("Error loading archive: %s", e.what()); + } + return {}; +} + std::string generatePIN(size_t length = 16, size_t split = 8) { diff --git a/src/jamidht/archive_account_manager.h b/src/jamidht/archive_account_manager.h index 55d9b30aea073424d22f9df3ebacf3d9844bc8b1..03874a970552229bd43e4d708b54e996ef9fdccb 100644 --- a/src/jamidht/archive_account_manager.h +++ b/src/jamidht/archive_account_manager.h @@ -52,6 +52,7 @@ public: void startSync(const OnNewDeviceCb&, const OnDeviceAnnouncedCb& dcb = {}, bool publishPresence = true) override; bool changePassword(const std::string& password_old, const std::string& password_new) override; + virtual std::vector<uint8_t> getPasswordKey(const std::string& /*password*/) override; void syncDevices() override; diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp index 55546bd558b2f9d92ad9826c854a21e577de81b0..0479d1aa2042c34bab9f5bd6bb3f290b337fee8a 100644 --- a/src/jamidht/jamiaccount.cpp +++ b/src/jamidht/jamiaccount.cpp @@ -971,6 +971,13 @@ JamiAccount::isPasswordValid(const std::string& password) return accountManager_ and accountManager_->isPasswordValid(password); } +std::vector<uint8_t> +JamiAccount::getPasswordKey(const std::string& password) +{ + return accountManager_ ? accountManager_->getPasswordKey(password) : std::vector<uint8_t>(); +} + + void JamiAccount::addDevice(const std::string& password) { diff --git a/src/jamidht/jamiaccount.h b/src/jamidht/jamiaccount.h index 2747ce442b72c3c3dd2894881bead1fc74a95714..a0c31287f5c873df03b77bca005825dbc9215152 100644 --- a/src/jamidht/jamiaccount.h +++ b/src/jamidht/jamiaccount.h @@ -349,6 +349,7 @@ public: std::map<std::string, std::string> getKnownDevices() const; bool isPasswordValid(const std::string& password); + std::vector<uint8_t> getPasswordKey(const std::string& password); bool changeArchivePassword(const std::string& password_old, const std::string& password_new); diff --git a/src/manager.cpp b/src/manager.cpp index 2513bd4076000c903a7beba3589cf858d450b77e..4e5bce6f8180991b8b7b2dd93ba75863143969dc 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -2976,15 +2976,6 @@ Manager::sendRegister(const std::string& accountID, bool enable) acc->doUnregister(); } -bool -Manager::isPasswordValid(const std::string& accountID, const std::string& password) -{ - const auto acc = getAccount<JamiAccount>(accountID); - if (!acc) - return false; - return acc->isPasswordValid(password); -} - uint64_t Manager::sendTextMessage(const std::string& accountID, const std::string& to, diff --git a/src/manager.h b/src/manager.h index 24945a6a52d555879d86fd9d868383f0e83356aa..a0e822d8f1355625d48001773a9020a49160fe71 100644 --- a/src/manager.h +++ b/src/manager.h @@ -390,8 +390,6 @@ public: */ void sendRegister(const std::string& accountId, bool enable); - bool isPasswordValid(const std::string& accountID, const std::string& password); - uint64_t sendTextMessage(const std::string& accountID, const std::string& to, const std::map<std::string, std::string>& payloads,