Fix remote wipe keychain storage (issue #1592)
authorMichael Schuster <michael@schuster.ms>
Fri, 29 Nov 2019 03:28:50 +0000 (04:28 +0100)
committerCamila Ayres <smayres@gmail.com>
Fri, 29 Nov 2019 12:53:52 +0000 (13:53 +0100)
The app password for the remote wipe was constantly being written in
WebFlowCredentials::slotFinished to the keychain, leading to unnecessary
write and log overhead on the system.

This fix introduces a check to only store the app password once in
a lifetime of the Account class. Also the method used to store the
password will be renamed from setAppPassword to writeAppPasswordOnce
to be more expressive.

Signed-off-by: Michael Schuster <michael@schuster.ms>
src/gui/creds/webflowcredentials.cpp
src/libsync/account.cpp
src/libsync/account.h

index 49c80e1ff751dcbaecca503135dbd6cf3c2aba35..e2dc10b352bb3593cf0dd84391bcb07943daf9d8 100644 (file)
@@ -420,7 +420,7 @@ void WebFlowCredentials::slotFinished(QNetworkReply *reply) {
         _credentialsValid = true;
 
         /// Used later for remote wipe
-        _account->setAppPassword(_password);
+        _account->writeAppPasswordOnce(_password);
     }
 }
 
index 32e58b2e438a05d4c048e3710526de8a47b68d0c..33032e3f874158abb6eab9f487d532c47ebe4106 100644 (file)
@@ -513,7 +513,10 @@ void Account::setNonShib(bool nonShib)
     }
 }
 
-void Account::setAppPassword(QString appPassword){
+void Account::writeAppPasswordOnce(QString appPassword){
+    if(_wroteAppPassword)
+        return;
+
     const QString kck = AbstractCredentials::keychainKey(
                 url().toString(),
                 davUser() + app_password,
@@ -524,8 +527,10 @@ void Account::setAppPassword(QString appPassword){
     job->setInsecureFallback(false);
     job->setKey(kck);
     job->setBinaryData(appPassword.toLatin1());
-    connect(job, &WritePasswordJob::finished, [](Job *) {
+    connect(job, &WritePasswordJob::finished, [this](Job *) {
         qCInfo(lcAccount) << "appPassword stored in keychain";
+
+        _wroteAppPassword = true;
     });
     job->start();
 }
index 1f3e46a96c0269adee11c262334adaf46bed64cf..2b843dca95645258dbc0c13268c8f7fec54254f7 100644 (file)
@@ -243,7 +243,7 @@ public:
 
     /// Used in RemoteWipe
     void retrieveAppPassword();
-    void setAppPassword(QString appPassword);
+    void writeAppPasswordOnce(QString appPassword);
     void deleteAppPassword();
 
 public slots:
@@ -319,6 +319,9 @@ private:
     QString _davPath; // defaults to value from theme, might be overwritten in brandings
     ClientSideEncryption _e2e;
 
+    /// Used in RemoteWipe
+    bool _wroteAppPassword = false;
+
     friend class AccountManager;
 };
 }