Parcourir la source

[cse] Start to fetch the basics to fetch the key from the server

Tomaz Canabrava il y a 8 ans
Parent
commit
29b64640fa

+ 8 - 0
src/libsync/account.cpp

@@ -19,7 +19,9 @@
 #include "creds/abstractcredentials.h"
 #include "capabilities.h"
 #include "theme.h"
+
 #include "common/asserts.h"
+#include "clientsideencryption.h"
 
 #include <QLoggingCategory>
 #include <QNetworkReply>
@@ -39,6 +41,7 @@ Q_LOGGING_CATEGORY(lcAccount, "sync.account", QtInfoMsg)
 Account::Account(QObject *parent)
     : QObject(parent)
     , _capabilities(QVariantMap())
+    , _encryption(new ClientSideEncryption(this))
     , _davPath(Theme::instance()->webDavPath())
 {
     qRegisterMetaType<AccountPtr>("AccountPtr");
@@ -482,4 +485,9 @@ void Account::setNonShib(bool nonShib)
     }
 }
 
+ClientSideEncryption *Account::cse() const
+{
+    return _encryption;
+}
+
 } // namespace OCC

+ 3 - 0
src/libsync/account.h

@@ -31,6 +31,7 @@
 #include "common/utility.h"
 #include <memory>
 #include "capabilities.h"
+#include "clientsideencryption.h"
 
 class QSettings;
 class QNetworkReply;
@@ -225,6 +226,7 @@ public:
     /// Called by network jobs on credential errors, emits invalidCredentials()
     void handleInvalidCredentials();
 
+    ClientSideEncryption *cse() const;
 public slots:
     /// Used when forgetting credentials
     void clearQNAMCache();
@@ -274,6 +276,7 @@ private:
     QuotaInfo *_quotaInfo;
     QSharedPointer<QNetworkAccessManager> _am;
     QScopedPointer<AbstractCredentials> _credentials;
+    ClientSideEncryption *_encryption;
     bool _http2Supported = false;
 
     /// Certificates that were explicitly rejected by the user

+ 31 - 1
src/libsync/clientsideencryption.cpp

@@ -1,4 +1,34 @@
 #include "clientsideencryption.h"
+#include "account.h"
+#include "capabilities.h"
+
+#include <QDebug>
+#include <QLoggingCategory>
+
+namespace OCC
+{
+
+Q_LOGGING_CATEGORY(lcCse, "sync.connectionvalidator", QtInfoMsg)
+
+QString baseUrl = QStringLiteral("ocs/v2.php/apps/client_side_encryption/api/v1/");
+
+ClientSideEncryption::ClientSideEncryption(Account *parent) : _account(parent)
+{
+}
+
+void OCC::ClientSideEncryption::initialize()
+{
+    if (!_account->capabilities().clientSideEncryptionAvaliable()) {
+        qCInfo(lcCse()) << "No client side encryption, do not initialize anything.";
+        emit initializationFinished();
+    }
+
+    fetchPrivateKey();
+}
+
+void ClientSideEncryption::fetchPrivateKey()
+{
+    qCInfo(lcCse()) << "Client side encryption enabled, trying to retrieve the key.";
+}
 
-namespace ClientSideEncryption {
 }

+ 20 - 2
src/libsync/clientsideencryption.h

@@ -2,9 +2,27 @@
 #define CLIENTSIDEENCRYPTION_H
 
 #include <QString>
+#include <QObject>
+
+namespace OCC {
+
+class Account;
+
+class ClientSideEncryption : public QObject {
+    Q_OBJECT
+public:
+    ClientSideEncryption(OCC::Account *parent);
+    void initialize();
+
+    void fetchPrivateKey();
+signals:
+    void initializationFinished();
+
+private:
+    OCC::Account *_account;
+    bool isInitialized = false;
+};
 
-namespace ClientSideEncryption {
-    QString baseUrl = QStringLiteral("ocs/v2.php/apps/client_side_encryption/api/v1/");
 }
 
 #endif

+ 5 - 0
src/libsync/connectionvalidator.cpp

@@ -326,6 +326,11 @@ void ConnectionValidator::slotUserFetched(const QJsonDocument &json)
 void ConnectionValidator::slotAvatarImage(const QImage &img)
 {
     _account->setAvatar(img);
+    connect(_account->cse(), &ClientSideEncryption::initializationFinished, this, &ConnectionValidator::reportConnected);
+    _account->cse()->initialize();
+}
+
+void ConnectionValidator::reportConnected() {
     reportResult(Connected);
 }
 

+ 6 - 1
src/libsync/connectionvalidator.h

@@ -65,7 +65,11 @@ namespace OCC {
                                       |
   +-----------------------------------+
   |
-  +-> fetchUser
+  +-> Client Side Encryption Checks --+
+                                      |
+    +---------------------------------+
+    |
+  fetchUser
         PropfindJob
         |
         +-> slotUserFetched
@@ -126,6 +130,7 @@ protected slots:
     void slotAvatarImage(const QImage &img);
 
 private:
+    void reportConnected();
     void reportResult(Status status);
     void checkServerCapabilities();
     void fetchUser();