From 1267dce401c0013b75ba811daaab8d94030aa301 Mon Sep 17 00:00:00 2001 From: Adrien Beraud <adrien.beraud@savoirfairelinux.com> Date: Tue, 5 Sep 2017 17:20:06 +0200 Subject: [PATCH] ringaccount: allow to change archive password Add a method to change a Ring account archive password. The method is blocking and returns a boolean indicating if the operation succeeded. Note that the change won't be transferred to other devices connected to the same account unless they are initialized after the change, from the device where the password was changed. Change-Id: Ide36bf407f75178e0019ab5dab511a79139b844c --- bin/dbus/cx.ring.Ring.ConfigurationManager.xml | 17 +++++++++++++++++ bin/dbus/dbusconfigurationmanager.cpp | 6 ++++++ bin/dbus/dbusconfigurationmanager.h | 1 + src/client/configurationmanager.cpp | 8 ++++++++ src/dring/configurationmanager_interface.h | 1 + src/ringdht/ringaccount.cpp | 13 +++++++++++++ src/ringdht/ringaccount.h | 5 +++-- 7 files changed, 49 insertions(+), 2 deletions(-) diff --git a/bin/dbus/cx.ring.Ring.ConfigurationManager.xml b/bin/dbus/cx.ring.Ring.ConfigurationManager.xml index 6fbbb4b241..7d8068a01a 100644 --- a/bin/dbus/cx.ring.Ring.ConfigurationManager.xml +++ b/bin/dbus/cx.ring.Ring.ConfigurationManager.xml @@ -256,6 +256,23 @@ </arg> </method> + <method name="changeAccountPassword" tp:name-for-bindings="changeAccountPassword"> + <tp:docstring> + Change the Ring account archive password. + </tp:docstring> + <arg type="s" name="accountID" direction="in"> + </arg> + <arg type="s" name="oldPassword" direction="in"> + </arg> + <arg type="s" name="newPassword" direction="in"> + </arg> + <arg type="b" name="success" direction="out"> + <tp:docstring> + True if the operation was successful. + </tp:docstring> + </arg> + </method> + <method name="lookupName" tp:name-for-bindings="lookupName"> <tp:docstring> Performs name lookup with RingNS protocol for the specified account (if any) or using the default nameserver. diff --git a/bin/dbus/dbusconfigurationmanager.cpp b/bin/dbus/dbusconfigurationmanager.cpp index ca4ce39330..2b4c0f4039 100644 --- a/bin/dbus/dbusconfigurationmanager.cpp +++ b/bin/dbus/dbusconfigurationmanager.cpp @@ -92,6 +92,12 @@ DBusConfigurationManager::getKnownRingDevices(const std::string& accountID) -> d return DRing::getKnownRingDevices(accountID); } +auto +DBusConfigurationManager::changeAccountPassword(const std::string& accountID, const std::string& password_old, const std::string& password_new) -> decltype(DRing::changeAccountPassword(accountID, password_old, password_new)) +{ + return DRing::changeAccountPassword(accountID, password_old, password_new); +} + auto DBusConfigurationManager::lookupName(const std::string& account, const std::string& nameserver, const std::string& name) -> decltype(DRing::lookupName(account, nameserver, name)) { diff --git a/bin/dbus/dbusconfigurationmanager.h b/bin/dbus/dbusconfigurationmanager.h index 018a4ef6bd..6c92831c20 100644 --- a/bin/dbus/dbusconfigurationmanager.h +++ b/bin/dbus/dbusconfigurationmanager.h @@ -66,6 +66,7 @@ class DBusConfigurationManager : bool exportOnRing(const std::string& accountID, const std::string& password); bool revokeDevice(const std::string& accountID, const std::string& password, const std::string& device); std::map<std::string, std::string> getKnownRingDevices(const std::string& accountID); + bool changeAccountPassword(const std::string& accountID, const std::string& password_old, const std::string& password_new); 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); bool registerName(const std::string& account, const std::string& password, const std::string& name); diff --git a/src/client/configurationmanager.cpp b/src/client/configurationmanager.cpp index f3fd51ec1f..790d8aba3a 100644 --- a/src/client/configurationmanager.cpp +++ b/src/client/configurationmanager.cpp @@ -299,6 +299,14 @@ getKnownRingDevices(const std::string& accountId) return {}; } +bool +changeAccountPassword(const std::string& accountID, const std::string& password_old, const std::string& password_new) +{ + if (auto acc = ring::Manager::instance().getAccount<ring::RingAccount>(accountID)) + return acc->changeArchivePassword(password_old, password_new); + return false; +} + /* contacts */ void addContact(const std::string& accountId, const std::string& uri) diff --git a/src/dring/configurationmanager_interface.h b/src/dring/configurationmanager_interface.h index 013c1806bd..dbc3ba9c5f 100644 --- a/src/dring/configurationmanager_interface.h +++ b/src/dring/configurationmanager_interface.h @@ -52,6 +52,7 @@ std::string addAccount(const std::map<std::string, std::string>& details); bool exportOnRing(const std::string& accountID, const std::string& password); bool revokeDevice(const std::string& accountID, const std::string& password, const std::string& deviceID); std::map<std::string, std::string> getKnownRingDevices(const std::string& accountID); +bool changeAccountPassword(const std::string& accountID, const std::string& password_old, const std::string& password_new); 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/ringdht/ringaccount.cpp b/src/ringdht/ringaccount.cpp index a7fc815ec4..301ae8b9a5 100644 --- a/src/ringdht/ringaccount.cpp +++ b/src/ringdht/ringaccount.cpp @@ -926,6 +926,19 @@ RingAccount::saveArchive(AccountArchive& archive, const std::string& pwd) } } +bool +RingAccount::changeArchivePassword(const std::string& password_old, const std::string& password_new) +{ + auto path = fileutils::getFullPath(idPath_, archivePath_); + try { + AccountArchive(path, password_old).save(path, password_new); + } catch (const std::exception& ex) { + RING_ERR("[Account %s] Can't change archive password: %s", getAccountID().c_str(), ex.what()); + return false; + } + return true; +} + std::pair<std::vector<uint8_t>, dht::InfoHash> RingAccount::computeKeys(const std::string& password, const std::string& pin, bool previous) { diff --git a/src/ringdht/ringaccount.h b/src/ringdht/ringaccount.h index 6b26238c5d..472259cb37 100644 --- a/src/ringdht/ringaccount.h +++ b/src/ringdht/ringaccount.h @@ -288,12 +288,13 @@ class RingAccount : public SIPAccountBase { void sendTrustRequestConfirm(const dht::InfoHash& to); virtual void sendTextMessage(const std::string& to, const std::map<std::string, std::string>& payloads, uint64_t id) override; + /* Devices */ void addDevice(const std::string& password); - bool revokeDevice(const std::string& password, const std::string& device); - std::map<std::string, std::string> getKnownDevices() const; + bool changeArchivePassword(const std::string& password_old, const std::string& password_new); + void connectivityChanged() override; // overloaded methods -- GitLab