diff options
author | Tobias Fella <fella@posteo.de> | 2022-04-04 17:28:52 +0200 |
---|---|---|
committer | Tobias Fella <fella@posteo.de> | 2022-04-09 15:52:11 +0200 |
commit | 42abb01516ee4d3d0fe11ffddd47c7e76d786385 (patch) | |
tree | 54279dbabd142239cd23c0d35f3c8c33ab7086c1 /lib/connection.cpp | |
parent | fc3ad90a054e3c674127a0cdd385ddbb98cf2010 (diff) | |
download | libquotient-42abb01516ee4d3d0fe11ffddd47c7e76d786385.tar.gz libquotient-42abb01516ee4d3d0fe11ffddd47c7e76d786385.zip |
Check edKey when receiving an olm message
Diffstat (limited to 'lib/connection.cpp')
-rw-r--r-- | lib/connection.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index 45888bcb..1250eddf 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -322,9 +322,17 @@ public: << "in Olm plaintext"; return {}; } - //TODO make this do the check mentioned in the E2EE Implementation guide instead - if (decryptedEvent->fullJson()["keys"]["ed25519"].toString().isEmpty()) { - qCDebug(E2EE) << "Event does not contain an ed25519 key"; + + auto query = database->prepareQuery(QStringLiteral("SELECT edKey FROM tracked_devices WHERE curveKey=:curveKey;")); + query.bindValue(":curveKey", encryptedEvent.contentJson()["sender_key"].toString()); + database->execute(query); + if (!query.next()) { + qCWarning(E2EE) << "Received olm message from unknown device" << encryptedEvent.contentJson()["sender_key"].toString(); + return {}; + } + auto edKey = decryptedEvent->fullJson()["keys"]["ed25519"].toString(); + if (edKey.isEmpty() || query.value(QStringLiteral("edKey")).toString() != edKey) { + qCDebug(E2EE) << "Received olm message with invalid ed key"; return {}; } |