[network/ruqola] src/core/encryption: Store password

Laurent Montel <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 1d732719e822e4b3ca2552821b35717ce103452b by Laurent Montel.
Committed on 04/08/2026 at 05:58.
Pushed by mlaurent into branch 'master'.

Store password

M  +24   -1    src/core/encryption/e2ekeymanager.cpp
M  +7    -0    src/core/encryption/e2ekeymanager.h

https://invent.kde.org/network/ruqola/-/commit/1d732719e822e4b3ca2552821b35717ce103452b

diff --git a/src/core/encryption/e2ekeymanager.cpp b/src/core/encryption/e2ekeymanager.cpp
index 3272b50a16..49872b5b1b 100644
--- a/src/core/encryption/e2ekeymanager.cpp
+++ b/src/core/encryption/e2ekeymanager.cpp
@@ -18,12 +18,13 @@
 #include "rocketchataccountsettings.h"
 #include "ruqola_encryption_debug.h"
 #include "ruqolaserverconfig.h"
+#include <qt6keychain/keychain.h>
 
 #include <QByteArray>
 #include <QJsonDocument>
 #include <QJsonObject>
 #include <QJsonValue>
-
+using namespace QKeychain;
 using namespace Qt::Literals::StringLiterals;
 
 // https://docs.rocket.chat/docs/end-to-end-encryption-specifications
@@ -154,6 +155,7 @@ bool E2eKeyManager::decodeEncryptionKey(const QString &password)
     mDecodedPrivateKey = privateKeyPem;
     setStatus(Status::KeyDecrypted);
     Q_EMIT decodeEncryptionKeyDone();
+    storePassword(password);
     return true;
 #else
     Q_UNUSED(password)
@@ -161,6 +163,27 @@ bool E2eKeyManager::decodeEncryptionKey(const QString &password)
 #endif
 }
 
+QString E2eKeyManager::passwordKeyIdentifier() const
+{
+    return mAccount->accountName() + u"-encrypted"_s;
+}
+
+void E2eKeyManager::storePassword(const QString &password)
+{
+    auto writeJob = new WritePasswordJob(u"Ruqola"_s);
+    connect(writeJob, &Job::finished, this, &E2eKeyManager::slotPasswordWritten);
+    writeJob->setKey(passwordKeyIdentifier());
+    writeJob->setTextData(password);
+    writeJob->start();
+}
+
+void E2eKeyManager::slotPasswordWritten(QKeychain::Job *baseJob)
+{
+    if (baseJob->error()) {
+        qCWarning(RUQOLA_ENCRYPTION_LOG) << "Error writing password using QKeychain:" << baseJob->errorString();
+    }
+}
+
 void E2eKeyManager::postponeDecryption()
 {
     setStatus(Status::DecryptionPostponned);
diff --git a/src/core/encryption/e2ekeymanager.h b/src/core/encryption/e2ekeymanager.h
index 81e4223a8e..b8fa42960f 100644
--- a/src/core/encryption/e2ekeymanager.h
+++ b/src/core/encryption/e2ekeymanager.h
@@ -9,6 +9,10 @@
 
 #include <QObject>
 class RocketChatAccount;
+namespace QKeychain
+{
+class Job;
+}
 class LIBRUQOLACORE_EXPORT E2eKeyManager : public QObject
 {
     Q_OBJECT
@@ -56,6 +60,9 @@ Q_SIGNALS:
 private:
     LIBRUQOLACORE_NO_EXPORT void verifyExistingKey(const QJsonObject &json);
     LIBRUQOLACORE_NO_EXPORT bool startUploadGeneratedKey(const QByteArray &publicKey, const QByteArray &encryptedPrivateKey);
+    LIBRUQOLACORE_NO_EXPORT void storePassword(const QString &password);
+    LIBRUQOLACORE_NO_EXPORT void slotPasswordWritten(QKeychain::Job *baseJob);
+    [[nodiscard]] LIBRUQOLACORE_NO_EXPORT QString passwordKeyIdentifier() const;
     Status mStatus = Status::Unknown;
     QString mGeneratedPassword;
     QByteArray mDecodedPrivateKey;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.