[CSE] Display menu for encrytp / decryot folders
authorTomaz Canabrava <tcanabrava@kde.org>
Thu, 24 Aug 2017 13:53:26 +0000 (15:53 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Wed, 18 Oct 2017 19:51:36 +0000 (21:51 +0200)
If the server supports client syde encryption, display
a menu on right click that should display encrypt and decrypt.
ideally it would show the encrypt if the folder is decrypted, and
decrypt if the folder is encrypted but currently there's no way
for the client to know that.

src/gui/accountsettings.cpp
src/gui/folder.h
src/libsync/account.cpp
src/libsync/account.h
src/libsync/connectionvalidator.cpp

index 23b28724444b5be7f6cd8612047beec7aa80bd0c..696a97f0a71138699673010cd6e1c511dcbde33a 100644 (file)
@@ -275,6 +275,23 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
             ac->setEnabled(false);
         }
 
+        qCInfo(lcAccountSettings) << "Display Client Side Encryption Options"
+            << accountsState()->account()->hasClientSideEncryption();
+
+            if (accountsState()->account()->hasClientSideEncryption()) {
+            ac = menu->addAction(tr("Encrypt"));
+            connect(ac, &QAction::triggered, [this, &index](bool triggered) {
+                Q_UNUSED(triggered);
+
+            });
+
+            ac = menu->addAction(tr("Decrypt"));
+            connect(ac, &QAction::triggered, [this, &index](bool triggered) {
+                Q_UNUSED(triggered);
+
+            });
+
+        }
         menu->exec(QCursor::pos());
 
         return;
@@ -701,6 +718,15 @@ void AccountSettings::slotAccountStateChanged()
             _toggleSignInOutAction->setText(tr("Log out"));
         }
     }
+
+    if (state == AccountState::State::Connected) {
+        /* TODO: We should probably do something better here.
+         * Verify if the user has a private key already uploaded to the server,
+         * if it has, do not offer to create one.
+         */
+        qCInfo(lcAccountSettings) << "Accout" << accountsState()->account()->displayName()
+            << "Client Side Encryption" << accountsState()->account()->hasClientSideEncryption();
+    }
 }
 
 void AccountSettings::slotLinkActivated(const QString &link)
index 7b503a6d60418e8207fdfd7e3362206c442f47f8..0ac050c0d4c18d8c2ededa0f1228349a9b72c2d9 100644 (file)
@@ -62,6 +62,8 @@ public:
     bool paused;
     /// whether the folder syncs hidden files
     bool ignoreHiddenFiles;
+    /// the folder has client side encryption
+    bool isClientSideEncrypted;
 
     /// Saves the folder definition, creating a new settings group.
     static void save(QSettings &settings, const FolderDefinition &folder);
index 0c2e44dbed20b6c5d00f81fe3adeb6877de4c1a8..dbe8b0019ad0c2e6739dc69323bd287fe0368415 100644 (file)
@@ -484,5 +484,14 @@ void Account::setNonShib(bool nonShib)
     }
 }
 
+bool Account::hasClientSideEncryption() const
+{
+    return _hasClientSideEncryption;
+}
+
+void Account::setHasClientSideEncryption(bool cse)
+{
+    _hasClientSideEncryption = cse;
+}
 
 } // namespace OCC
index aa100928718dfb0a7a8a4e63d4e9316b810dad04..e33d8baacdff8692222c56bbfde95d2393441c8e 100644 (file)
@@ -225,6 +225,9 @@ public:
     /// Called by network jobs on credential errors, emits invalidCredentials()
     void handleInvalidCredentials();
 
+    bool hasClientSideEncryption() const;
+    void setHasClientSideEncryption(bool cse);
+
 public slots:
     /// Used when forgetting credentials
     void clearQNAMCache();
@@ -275,6 +278,7 @@ private:
     QSharedPointer<QNetworkAccessManager> _am;
     QScopedPointer<AbstractCredentials> _credentials;
     bool _http2Supported = false;
+    bool _hasClientSideEncryption;
 
     /// Certificates that were explicitly rejected by the user
     QList<QSslCertificate> _rejectedCertificates;
index 75a2ff23fd7417a9a39cdd1b1a12a6f27d00b124..c0de1cb6cc771ada13fcf51b09aef9509842ac7c 100644 (file)
@@ -263,7 +263,7 @@ void ConnectionValidator::checkClientSideEncryption()
             }
         }
 
-        // _account->setHasClientSideEncryption(hasClientSideEncryption);
+        _account->setHasClientSideEncryption(hasClientSideEncryption);
     });
     job->start();
 }