Update our E2E API requirement
authorKevin Ottens <kevin.ottens@nextcloud.com>
Wed, 15 Jul 2020 13:26:45 +0000 (15:26 +0200)
committerKevin Ottens <ervin@ipsquad.net>
Wed, 15 Jul 2020 16:39:29 +0000 (18:39 +0200)
Now that we adjusted our protocol to follow the slightly updated server
API, let's make sure we don't try to talk to a server with an older API.

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/libsync/capabilities.cpp

index 190edfe77a88270f52c4884d0657e4cf50f58668..78035fa8cb0e27b3adbe5a06522d0897a82848c7 100644 (file)
@@ -87,9 +87,35 @@ bool Capabilities::shareResharing() const
 bool Capabilities::clientSideEncryptionAvailable() const
 {
     auto it = _capabilities.constFind(QStringLiteral("end-to-end-encryption"));
-    if (it != _capabilities.constEnd())
-        return (*it).toMap().value(QStringLiteral("enabled"), false).toBool();
-    return false;
+    if (it == _capabilities.constEnd()) {
+        return false;
+    }
+
+    const auto properties = (*it).toMap();
+    const auto enabled = properties.value(QStringLiteral("enabled"), false).toBool();
+    if (!enabled) {
+        return false;
+    }
+
+    const auto version = properties.value(QStringLiteral("api-version"), "1.0").toByteArray();
+    qCInfo(lcServerCapabilities) << "E2EE API version:" << version;
+    const auto splittedVersion = version.split('.');
+
+    bool ok = false;
+    const auto major = !splittedVersion.isEmpty() ? splittedVersion.at(0).toInt(&ok) : 0;
+    if (!ok) {
+        qCWarning(lcServerCapabilities) << "Didn't understand version scheme (major), E2EE disabled";
+        return false;
+    }
+
+    ok = false;
+    const auto minor = splittedVersion.size() > 1 ? splittedVersion.at(1).toInt(&ok) : 0;
+    if (!ok) {
+        qCWarning(lcServerCapabilities) << "Didn't understand version scheme (minor), E2EE disabled";
+        return false;
+    }
+
+    return major == 1 && minor >= 1;
 }
 
 bool Capabilities::notificationsAvailable() const