Skip to content

Commit

Permalink
Update our E2E API requirement
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Kevin Ottens authored and er-vin committed Jul 15, 2020
1 parent 15f9eee commit f46276d
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/libsync/capabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f46276d

Please sign in to comment.