diff --git a/bin/dbus/cx.ring.Ring.ConfigurationManager.xml b/bin/dbus/cx.ring.Ring.ConfigurationManager.xml index 6fbbb4b241075d6e44a5e1dae9d302343ec278f5..7d8068a01af4eb00985a5a5bacd4736134035ad4 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 ca4ce39330e95e463b733dcad220feede3dae551..2b4c0f4039e99dc48340ceac9660bf4ecf5e368e 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 018a4ef6bd115080027f43b0185d338018580b11..6c92831c20b36f1354cd8d424cd4a46b4e866e78 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 f3fd51ec1f63ff4f07c11b8c8b944a3504f262c3..790d8aba3ad1981bbe75250d338c3d2519148ddf 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 013c1806bd9e6b571e0f1328c292bd9d0f8ae2eb..dbc3ba9c5f49135fab54bd07a0ef40a090e0e974 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 a7fc815ec4277332a7518a1b20a81de246548ad0..301ae8b9a5c99d11e3315730703d25c72fc7e647 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 6b26238c5d0e8a5d1f4d72b415bb2021561678ff..472259cb3789e0828ebc538cf5c99d38729c19ad 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