aboutsummaryrefslogtreecommitdiff
path: root/lib/connection.cpp
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-06-01 10:08:00 +0200
committerGitHub <noreply@github.com>2022-06-01 10:08:00 +0200
commit6c735f9f55b936e9de1497c2f5896f0a018d4227 (patch)
treefccc042d6af708ddf0d540ea1166e8ae68365ecb /lib/connection.cpp
parent49b0d191ab8917c61b28da3cfeaf1d28c143d5c8 (diff)
parentcd442611b19ec4a438d0847bf09b7bca99b494d3 (diff)
downloadlibquotient-6c735f9f55b936e9de1497c2f5896f0a018d4227.tar.gz
libquotient-6c735f9f55b936e9de1497c2f5896f0a018d4227.zip
#554: Fix update-api jobs
Diffstat (limited to 'lib/connection.cpp')
-rw-r--r--lib/connection.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 102fb16d..7885718f 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -376,7 +376,7 @@ public:
const QByteArray& message) const;
bool createOlmSession(const QString& targetUserId,
const QString& targetDeviceId,
- const QJsonObject& oneTimeKeyObject);
+ const OneTimeKeys &oneTimeKeyObject);
QString curveKeyForUserDevice(const QString& userId,
const QString& device) const;
QString edKeyForUserDevice(const QString& userId,
@@ -2306,7 +2306,7 @@ std::pair<QOlmMessage::Type, QByteArray> Connection::Private::olmEncryptMessage(
bool Connection::Private::createOlmSession(const QString& targetUserId,
const QString& targetDeviceId,
- const QJsonObject& oneTimeKeyObject)
+ const OneTimeKeys& oneTimeKeyObject)
{
static QOlmUtility verifier;
qDebug(E2EE) << "Creating a new session for" << targetUserId
@@ -2316,17 +2316,23 @@ bool Connection::Private::createOlmSession(const QString& targetUserId,
<< targetDeviceId;
return false;
}
- auto signedOneTimeKey = oneTimeKeyObject.constBegin()->toObject();
+ auto* signedOneTimeKey =
+ std::get_if<SignedOneTimeKey>(&*oneTimeKeyObject.begin());
+ if (!signedOneTimeKey) {
+ qWarning(E2EE) << "No signed one time key for" << targetUserId
+ << targetDeviceId;
+ return false;
+ }
// Verify contents of signedOneTimeKey - for that, drop `signatures` and
// `unsigned` and then verify the object against the respective signature
const auto signature =
- signedOneTimeKey.take("signatures"_ls)[targetUserId]["ed25519:"_ls % targetDeviceId]
- .toString()
+ signedOneTimeKey
+ ->signatures[targetUserId]["ed25519:"_ls % targetDeviceId]
.toLatin1();
- signedOneTimeKey.remove("unsigned"_ls);
if (!verifier.ed25519Verify(
edKeyForUserDevice(targetUserId, targetDeviceId).toLatin1(),
- QJsonDocument(signedOneTimeKey).toJson(QJsonDocument::Compact),
+ QJsonDocument(toJson(SignedOneTimeKey { signedOneTimeKey->key, {} }))
+ .toJson(QJsonDocument::Compact),
signature)) {
qWarning(E2EE) << "Failed to verify one-time-key signature for" << targetUserId
<< targetDeviceId << ". Skipping this device.";
@@ -2336,7 +2342,7 @@ bool Connection::Private::createOlmSession(const QString& targetUserId,
curveKeyForUserDevice(targetUserId, targetDeviceId);
auto session =
QOlmSession::createOutboundSession(olmAccount.get(), recipientCurveKey,
- signedOneTimeKey["key"].toString());
+ signedOneTimeKey->key);
if (!session) {
qCWarning(E2EE) << "Failed to create olm session for "
<< recipientCurveKey << session.error();