aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/connection.cpp127
-rw-r--r--lib/connection.h4
-rw-r--r--lib/events/keyverificationevent.h77
-rw-r--r--lib/keyverificationsession.cpp173
-rw-r--r--lib/keyverificationsession.h8
5 files changed, 198 insertions, 191 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 19fc484a..04cabf47 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -121,6 +121,7 @@ public:
QHash<QString, int> oneTimeKeysCount;
std::vector<std::unique_ptr<EncryptedEvent>> pendingEncryptedEvents;
void handleEncryptedToDeviceEvent(const EncryptedEvent& event);
+ bool processIfVerificationEvent(const Event &evt, bool encrypted);
// A map from SenderKey to vector of InboundSession
UnorderedMap<QString, std::vector<QOlmSessionPtr>> olmSessions;
@@ -988,68 +989,71 @@ void Connection::Private::consumeToDeviceEvents(Events&& toDeviceEvents)
pendingEncryptedEvents.push_back(std::move(event));
continue;
}
- switchOnType(*tdEvt,
- [this](const KeyVerificationRequestEvent& event) {
- auto session = new KeyVerificationSession(q->userId(),
- event, q, false);
- emit q->newKeyVerificationSession(session);
- }, [this](const KeyVerificationReadyEvent& event) {
- emit q->incomingKeyVerificationReady(event);
- }, [this](const KeyVerificationStartEvent& event) {
- emit q->incomingKeyVerificationStart(event);
- }, [this](const KeyVerificationAcceptEvent& event) {
- emit q->incomingKeyVerificationAccept(event);
- }, [this](const KeyVerificationKeyEvent& event) {
- emit q->incomingKeyVerificationKey(event);
- }, [this](const KeyVerificationMacEvent& event) {
- emit q->incomingKeyVerificationMac(event);
- }, [this](const KeyVerificationDoneEvent& event) {
- emit q->incomingKeyVerificationDone(event);
- }, [this](const KeyVerificationCancelEvent& event) {
- emit q->incomingKeyVerificationCancel(event);
- });
+ processIfVerificationEvent(*tdEvt, false);
}
}
#endif
}
#ifdef Quotient_E2EE_ENABLED
-void Connection::Private::handleEncryptedToDeviceEvent(const EncryptedEvent& event)
-{
- const auto [decryptedEvent, olmSessionId] = sessionDecryptMessage(event);
- if(!decryptedEvent) {
- qCWarning(E2EE) << "Failed to decrypt event" << event.id();
- return;
- }
-
- switchOnType(*decryptedEvent,
- [this, &event, olmSessionId = olmSessionId](const RoomKeyEvent& roomKeyEvent) {
- if (auto* detectedRoom = q->room(roomKeyEvent.roomId())) {
- detectedRoom->handleRoomKeyEvent(roomKeyEvent, event.senderId(), olmSessionId);
- } else {
- qCDebug(E2EE) << "Encrypted event room id" << roomKeyEvent.roomId()
- << "is not found at the connection" << q->objectName();
- }
- }, [this](const KeyVerificationRequestEvent& event) {
- emit q->newKeyVerificationSession(
- new KeyVerificationSession(q->userId(), event, q, true));
+bool Connection::Private::processIfVerificationEvent(const Event& evt,
+ bool encrypted)
+{
+ return switchOnType(evt,
+ [this, encrypted](const KeyVerificationRequestEvent& event) {
+ auto session =
+ new KeyVerificationSession(q->userId(), event, q, encrypted);
+ emit q->newKeyVerificationSession(session);
+ return true;
}, [this](const KeyVerificationReadyEvent& event) {
emit q->incomingKeyVerificationReady(event);
+ return true;
}, [this](const KeyVerificationStartEvent& event) {
emit q->incomingKeyVerificationStart(event);
+ return true;
}, [this](const KeyVerificationAcceptEvent& event) {
emit q->incomingKeyVerificationAccept(event);
+ return true;
}, [this](const KeyVerificationKeyEvent& event) {
emit q->incomingKeyVerificationKey(event);
+ return true;
}, [this](const KeyVerificationMacEvent& event) {
emit q->incomingKeyVerificationMac(event);
+ return true;
}, [this](const KeyVerificationDoneEvent& event) {
emit q->incomingKeyVerificationDone(event);
+ return true;
}, [this](const KeyVerificationCancelEvent& event) {
emit q->incomingKeyVerificationCancel(event);
- }, [](const Event& evt) {
+ return true;
+ }, false);
+}
+
+void Connection::Private::handleEncryptedToDeviceEvent(const EncryptedEvent& event)
+{
+ const auto [decryptedEvent, olmSessionId] = sessionDecryptMessage(event);
+ if(!decryptedEvent) {
+ qCWarning(E2EE) << "Failed to decrypt event" << event.id();
+ return;
+ }
+
+ if (processIfVerificationEvent(*decryptedEvent, true))
+ return;
+ switchOnType(*decryptedEvent,
+ [this, &event,
+ olmSessionId = olmSessionId](const RoomKeyEvent& roomKeyEvent) {
+ if (auto* detectedRoom = q->room(roomKeyEvent.roomId())) {
+ detectedRoom->handleRoomKeyEvent(roomKeyEvent, event.senderId(),
+ olmSessionId);
+ } else {
+ qCDebug(E2EE)
+ << "Encrypted event room id" << roomKeyEvent.roomId()
+ << "is not found at the connection" << q->objectName();
+ }
+ },
+ [](const Event& evt) {
qCWarning(E2EE) << "Skipping encrypted to_device event, type"
- << evt.matrixType();
+ << evt.matrixType();
});
}
#endif
@@ -2466,37 +2470,16 @@ void Connection::startKeyVerificationSession(const QString& deviceId)
emit newKeyVerificationSession(session);
}
-void Connection::sendToDevice(const QString& userId, const QString& deviceId,
- event_ptr_tt<Event> event, bool encrypted)
-{
- if (encrypted) {
- QJsonObject payloadJson = event->fullJson();
- payloadJson["recipient"] = userId;
- payloadJson["sender"] = user()->id();
- QJsonObject recipientObject;
- recipientObject["ed25519"] = edKeyForUserDevice(userId, deviceId);
- payloadJson["recipient_keys"] = recipientObject;
- QJsonObject senderObject;
- senderObject["ed25519"] = QString(olmAccount()->identityKeys().ed25519);
- payloadJson["keys"] = senderObject;
-
- auto cipherText = d->olmEncryptMessage(
- userId, deviceId,
- QJsonDocument(payloadJson).toJson(QJsonDocument::Compact));
- QJsonObject encryptedJson;
- encryptedJson[d->curveKeyForUserDevice(userId, deviceId)] =
- QJsonObject{ { "type", cipherText.first },
- { "body", QString(cipherText.second) },
- { "sender", this->userId() } };
- const auto& contentJson =
- EncryptedEvent(encryptedJson,
- olmAccount()->identityKeys().curve25519)
- .contentJson();
- sendToDevices(EncryptedEvent::TypeId,
- { { userId, { { deviceId, contentJson } } } });
- } else
- sendToDevices(event->matrixType(),
- { { userId, { { deviceId, event->contentJson() } } } });
+void Connection::sendToDevice(const QString& targetUserId,
+ const QString& targetDeviceId, Event event,
+ bool encrypted)
+{
+ const auto contentJson =
+ encrypted ? d->assembleEncryptedContent(event.fullJson(), targetUserId,
+ targetDeviceId)
+ : event.contentJson();
+ sendToDevices(encrypted ? EncryptedEvent::TypeId : event.type(),
+ { { targetUserId, { { targetDeviceId, contentJson } } } });
}
bool Connection::isVerifiedSession(const QString& megolmSessionId) const
diff --git a/lib/connection.h b/lib/connection.h
index 3a4ee798..5fdc525d 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -336,8 +336,8 @@ public:
bool hasOlmSession(const QString& user, const QString& deviceId) const;
// This assumes that an olm session already exists. If it doesn't, no message is sent.
- void sendToDevice(const QString& userId, const QString& deviceId,
- event_ptr_tt<Event> event, bool encrypted);
+ void sendToDevice(const QString& targetUserId, const QString& targetDeviceId,
+ Event event, bool encrypted);
/// Returns true if this megolm session comes from a verified device
bool isVerifiedSession(const QString& megolmSessionId) const;
diff --git a/lib/events/keyverificationevent.h b/lib/events/keyverificationevent.h
index cdbd5d74..f635d07b 100644
--- a/lib/events/keyverificationevent.h
+++ b/lib/events/keyverificationevent.h
@@ -18,6 +18,16 @@ public:
explicit KeyVerificationRequestEvent(const QJsonObject& obj)
: Event(TypeId, obj)
{}
+ KeyVerificationRequestEvent(const QString& transactionId,
+ const QString& fromDevice,
+ const QStringList& methods,
+ const QDateTime& timestamp)
+ : KeyVerificationRequestEvent(
+ basicJson(TypeId, { { "transaction_id"_ls, transactionId },
+ { "from_device"_ls, fromDevice },
+ { "methods"_ls, toJson(methods) },
+ { "timestamp"_ls, toJson(timestamp) } }))
+ {}
/// The device ID which is initiating the request.
QUO_CONTENT_GETTER(QString, fromDevice)
@@ -44,6 +54,14 @@ public:
explicit KeyVerificationReadyEvent(const QJsonObject& obj)
: Event(TypeId, obj)
{}
+ KeyVerificationReadyEvent(const QString& transactionId,
+ const QString& fromDevice,
+ const QStringList& methods)
+ : KeyVerificationReadyEvent(
+ basicJson(TypeId, { { "transaction_id"_ls, transactionId },
+ { "from_device"_ls, fromDevice },
+ { "methods"_ls, toJson(methods) } }))
+ {}
/// The device ID which is accepting the request.
QUO_CONTENT_GETTER(QString, fromDevice)
@@ -62,9 +80,23 @@ class QUOTIENT_API KeyVerificationStartEvent : public Event {
public:
DEFINE_EVENT_TYPEID("m.key.verification.start", KeyVerificationStartEvent)
- explicit KeyVerificationStartEvent(const QJsonObject &obj)
+ explicit KeyVerificationStartEvent(const QJsonObject& obj)
: Event(TypeId, obj)
{}
+ KeyVerificationStartEvent(const QString& transactionId,
+ const QString& fromDevice)
+ : KeyVerificationStartEvent(
+ basicJson(TypeId, { { "transaction_id"_ls, transactionId },
+ { "from_device"_ls, fromDevice },
+ { "method"_ls, SasV1Method },
+ { "hashes"_ls, QJsonArray{ "sha256"_ls } },
+ { "key_agreement_protocols"_ls,
+ QJsonArray{ "curve25519-hkdf-sha256"_ls } },
+ { "message_authentication_codes"_ls,
+ QJsonArray{ "hkdf-hmac-sha256"_ls } },
+ { "short_authentication_string"_ls,
+ QJsonArray{ "decimal"_ls, "emoji"_ls } } }))
+ {}
/// The device ID which is initiating the process.
QUO_CONTENT_GETTER(QString, fromDevice)
@@ -125,6 +157,18 @@ public:
explicit KeyVerificationAcceptEvent(const QJsonObject& obj)
: Event(TypeId, obj)
{}
+ KeyVerificationAcceptEvent(const QString& transactionId,
+ const QString& commitment)
+ : KeyVerificationAcceptEvent(basicJson(
+ TypeId, { { "transaction_id"_ls, transactionId },
+ { "method"_ls, SasV1Method },
+ { "key_agreement_protocol"_ls, "curve25519-hkdf-sha256" },
+ { "hash"_ls, "sha256" },
+ { "message_authentication_code"_ls, "hkdf-hmac-sha256" },
+ { "short_authentication_string"_ls,
+ QJsonArray{ "decimal"_ls, "emoji"_ls, } },
+ { "commitment"_ls, commitment } }))
+ {}
/// An opaque identifier for the verification process.
QUO_CONTENT_GETTER(QString, transactionId)
@@ -161,9 +205,18 @@ class QUOTIENT_API KeyVerificationCancelEvent : public Event {
public:
DEFINE_EVENT_TYPEID("m.key.verification.cancel", KeyVerificationCancelEvent)
- explicit KeyVerificationCancelEvent(const QJsonObject &obj)
+ explicit KeyVerificationCancelEvent(const QJsonObject& obj)
: Event(TypeId, obj)
{}
+ KeyVerificationCancelEvent(const QString& transactionId,
+ const QString& reason)
+ : KeyVerificationCancelEvent(
+ basicJson(TypeId, {
+ { "transaction_id"_ls, transactionId },
+ { "reason"_ls, reason },
+ { "code"_ls, reason } // Not a typo
+ }))
+ {}
/// An opaque identifier for the verification process.
QUO_CONTENT_GETTER(QString, transactionId)
@@ -183,9 +236,14 @@ class QUOTIENT_API KeyVerificationKeyEvent : public Event {
public:
DEFINE_EVENT_TYPEID("m.key.verification.key", KeyVerificationKeyEvent)
- explicit KeyVerificationKeyEvent(const QJsonObject &obj)
+ explicit KeyVerificationKeyEvent(const QJsonObject& obj)
: Event(TypeId, obj)
{}
+ KeyVerificationKeyEvent(const QString& transactionId, const QString& key)
+ : KeyVerificationKeyEvent(
+ basicJson(TypeId, { { "transaction_id"_ls, transactionId },
+ { "key"_ls, key } }))
+ {}
/// An opaque identifier for the verification process.
QUO_CONTENT_GETTER(QString, transactionId)
@@ -200,9 +258,16 @@ class QUOTIENT_API KeyVerificationMacEvent : public Event {
public:
DEFINE_EVENT_TYPEID("m.key.verification.mac", KeyVerificationMacEvent)
- explicit KeyVerificationMacEvent(const QJsonObject &obj)
+ explicit KeyVerificationMacEvent(const QJsonObject& obj)
: Event(TypeId, obj)
{}
+ KeyVerificationMacEvent(const QString& transactionId, const QString& keys,
+ const QJsonObject& mac)
+ : KeyVerificationMacEvent(
+ basicJson(TypeId, { { "transaction_id"_ls, transactionId },
+ { "keys"_ls, keys },
+ { "mac"_ls, mac } }))
+ {}
/// An opaque identifier for the verification process.
QUO_CONTENT_GETTER(QString, transactionId)
@@ -224,6 +289,10 @@ public:
explicit KeyVerificationDoneEvent(const QJsonObject& obj)
: Event(TypeId, obj)
{}
+ explicit KeyVerificationDoneEvent(const QString& transactionId)
+ : KeyVerificationDoneEvent(
+ basicJson(TypeId, { { "transaction_id"_ls, transactionId } }))
+ {}
/// The same transactionId as before
QUO_CONTENT_GETTER(QString, transactionId)
diff --git a/lib/keyverificationsession.cpp b/lib/keyverificationsession.cpp
index 1ee489ea..caf5071a 100644
--- a/lib/keyverificationsession.cpp
+++ b/lib/keyverificationsession.cpp
@@ -20,6 +20,19 @@
using namespace Quotient;
using namespace std::chrono;
+const QStringList supportedMethods = { SasV1Method };
+
+QStringList commonSupportedMethods(const QStringList& remoteMethods)
+{
+ QStringList result;
+ for (const auto& method : remoteMethods) {
+ if (supportedMethods.contains(method)) {
+ result += method;
+ }
+ }
+ return result;
+}
+
KeyVerificationSession::KeyVerificationSession(
QString remoteUserId, const KeyVerificationRequestEvent& event,
Connection* connection, bool encrypted)
@@ -93,7 +106,7 @@ void KeyVerificationSession::init(milliseconds timeout)
QTimer::singleShot(timeout, this, [this] { cancelVerification(TIMEOUT); });
- m_sas = olm_sas(new uint8_t[olm_sas_size()]);
+ m_sas = olm_sas(new std::byte[olm_sas_size()]);
auto randomSize = olm_create_sas_random_length(m_sas);
auto random = getRandom(randomSize);
olm_create_sas(m_sas, random.data(), randomSize);
@@ -104,7 +117,8 @@ void KeyVerificationSession::init(milliseconds timeout)
KeyVerificationSession::~KeyVerificationSession()
{
- delete[] reinterpret_cast<uint8_t*>(m_sas);
+ olm_clear_sas(m_sas);
+ delete[] reinterpret_cast<std::byte*>(m_sas);
}
void KeyVerificationSession::handleKey(const KeyVerificationKeyEvent& event)
@@ -160,18 +174,22 @@ void KeyVerificationSession::handleKey(const KeyVerificationKeyEvent& event)
emit keyReceived();
}
-QByteArray KeyVerificationSession::macInfo(bool verifying, const QString& key)
-{
- return (verifying ? "MATRIX_KEY_VERIFICATION_MAC%3%4%1%2%5%6"_ls : "MATRIX_KEY_VERIFICATION_MAC%1%2%3%4%5%6"_ls).arg(m_connection->userId()).arg(m_connection->deviceId()).arg(m_remoteUserId).arg(m_remoteDeviceId).arg(m_transactionId).arg(key).toLatin1();
-}
-
-QString KeyVerificationSession::calculateMac(const QString& input, bool verifying, const QString& keyId)
+QString KeyVerificationSession::calculateMac(const QString& input,
+ bool verifying,
+ const QString& keyId)
{
QByteArray inputBytes = input.toLatin1();
QByteArray outputBytes(olm_sas_mac_length(m_sas), '\0');
- olm_sas_calculate_mac(m_sas, inputBytes.data(), inputBytes.size(), macInfo(verifying, keyId).data(), macInfo(verifying, keyId).size(), outputBytes.data(), outputBytes.size());
- auto output = QString(outputBytes);
- return output.left(output.indexOf('='));
+ const auto macInfo =
+ (verifying ? "MATRIX_KEY_VERIFICATION_MAC%3%4%1%2%5%6"_ls
+ : "MATRIX_KEY_VERIFICATION_MAC%1%2%3%4%5%6"_ls)
+ .arg(m_connection->userId(), m_connection->deviceId(),
+ m_remoteUserId, m_remoteDeviceId, m_transactionId, keyId)
+ .toLatin1();
+ olm_sas_calculate_mac(m_sas, inputBytes.data(), inputBytes.size(),
+ macInfo.data(), macInfo.size(), outputBytes.data(),
+ outputBytes.size());
+ return QString::fromLatin1(outputBytes.data(), outputBytes.indexOf('='));
}
void KeyVerificationSession::sendMac()
@@ -184,56 +202,37 @@ void KeyVerificationSession::sendMac()
auto key = m_connection->olmAccount()->deviceKeys().keys[edKeyId];
mac[edKeyId] = calculateMac(key, false, edKeyId);
- auto event = makeEvent<KeyVerificationMacEvent>(QJsonObject {
- {"type", "m.key.verification.mac"},
- {"content", QJsonObject{
- {"transaction_id", m_transactionId},
- {"keys", keys},
- {"mac", mac},
- }}
- });
- m_connection->sendToDevice(m_remoteUserId, m_remoteDeviceId, std::move(event), m_encrypted);
+ m_connection->sendToDevice(m_remoteUserId, m_remoteDeviceId,
+ KeyVerificationMacEvent(m_transactionId, keys,
+ mac),
+ m_encrypted);
setState (macReceived ? DONE : WAITINGFORMAC);
}
void KeyVerificationSession::sendDone()
{
- auto event = makeEvent<KeyVerificationDoneEvent>(QJsonObject {
- {"type", "m.key.verification.done"},
- {"content", QJsonObject{
- {"transaction_id", m_transactionId},
- }}
- });
- m_connection->sendToDevice(m_remoteUserId, m_remoteDeviceId, std::move(event), m_encrypted);
+ m_connection->sendToDevice(m_remoteUserId, m_remoteDeviceId,
+ KeyVerificationDoneEvent(m_transactionId),
+ m_encrypted);
}
void KeyVerificationSession::sendKey()
{
QByteArray keyBytes(olm_sas_pubkey_length(m_sas), '\0');
olm_sas_get_pubkey(m_sas, keyBytes.data(), keyBytes.size());
- QString key = QString(keyBytes);
- auto event = makeEvent<KeyVerificationKeyEvent>(QJsonObject {
- {"type", "m.key.verification.key"},
- {"content", QJsonObject{
- {"transaction_id", m_transactionId},
- {"key", key},
- }}
- });
- m_connection->sendToDevice(m_remoteUserId, m_remoteDeviceId, std::move(event), m_encrypted);
+ m_connection->sendToDevice(m_remoteUserId, m_remoteDeviceId,
+ KeyVerificationKeyEvent(m_transactionId,
+ keyBytes),
+ m_encrypted);
}
void KeyVerificationSession::cancelVerification(Error error)
{
- auto event = makeEvent<KeyVerificationCancelEvent>(QJsonObject {
- {"type", "m.key.verification.cancel"},
- {"content", QJsonObject{
- {"code", errorToString(error)},
- {"reason", errorToString(error)},
- {"transaction_id", m_transactionId}
- }}
- });
- m_connection->sendToDevice(m_remoteUserId, m_remoteDeviceId, std::move(event), m_encrypted);
+ m_connection->sendToDevice(m_remoteUserId, m_remoteDeviceId,
+ KeyVerificationCancelEvent(m_transactionId,
+ errorToString(error)),
+ m_encrypted);
setState(CANCELED);
setError(error);
emit finished();
@@ -249,15 +248,11 @@ void KeyVerificationSession::sendReady()
return;
}
- auto event = makeEvent<KeyVerificationReadyEvent>(QJsonObject {
- {"type", "m.key.verification.ready"},
- {"content", QJsonObject {
- {"from_device", m_connection->deviceId()},
- {"methods", toJson(methods)},
- {"transaction_id", m_transactionId},
- }}
- });
- m_connection->sendToDevice(m_remoteUserId, m_remoteDeviceId, std::move(event), m_encrypted);
+ m_connection->sendToDevice(
+ m_remoteUserId, m_remoteDeviceId,
+ KeyVerificationReadyEvent(m_transactionId, m_connection->deviceId(),
+ methods),
+ m_encrypted);
setState(READY);
if (methods.size() == 1) {
@@ -268,20 +263,10 @@ void KeyVerificationSession::sendReady()
void KeyVerificationSession::sendStartSas()
{
startSentByUs = true;
- auto event = makeEvent<KeyVerificationStartEvent>(QJsonObject {
- {"type", "m.key.verification.start"},
- {"content", QJsonObject {
- {"from_device", m_connection->deviceId()},
- {"hashes", QJsonArray {"sha256"}},
- {"key_agreement_protocols", QJsonArray { "curve25519-hkdf-sha256" }},
- {"message_authentication_codes", QJsonArray { "hkdf-hmac-sha256" }},
- {"method", "m.sas.v1"},
- {"short_authentication_string", QJsonArray { "decimal", "emoji" }},
- {"transaction_id", m_transactionId},
- }}
- });
- m_startEvent = QJsonDocument(event->contentJson()).toJson(QJsonDocument::Compact);
- m_connection->sendToDevice(m_remoteUserId, m_remoteDeviceId, std::move(event), m_encrypted);
+ KeyVerificationStartEvent event(m_transactionId, m_connection->deviceId());
+ m_startEvent = QJsonDocument(event.contentJson()).toJson(QJsonDocument::Compact);
+ m_connection->sendToDevice(m_remoteUserId, m_remoteDeviceId,
+ std::move(event), m_encrypted);
setState(WAITINGFORACCEPT);
}
@@ -324,22 +309,10 @@ void KeyVerificationSession::handleStart(const KeyVerificationStartEvent& event)
auto commitment = QString(QCryptographicHash::hash((QString(publicKey) % canonicalEvent).toLatin1(), QCryptographicHash::Sha256).toBase64());
commitment = commitment.left(commitment.indexOf('='));
- auto acceptEvent = makeEvent<KeyVerificationAcceptEvent>(QJsonObject {
- {"type", "m.key.verification.accept"},
- {"content", QJsonObject {
- {"commitment", commitment},
- {"hash", "sha256"},
- {"key_agreement_protocol", "curve25519-hkdf-sha256"},
- {"message_authentication_code", "hkdf-hmac-sha256"},
- {"method", "m.sas.v1"},
- {"short_authentication_string", QJsonArray {
- "decimal",
- "emoji",
- }},
- {"transaction_id", m_transactionId},
- }}
- });
- m_connection->sendToDevice(m_remoteUserId, m_remoteDeviceId, std::move(acceptEvent), m_encrypted);
+ m_connection->sendToDevice(m_remoteUserId, m_remoteDeviceId,
+ KeyVerificationAcceptEvent(m_transactionId,
+ commitment),
+ m_encrypted);
setState(ACCEPTED);
}
@@ -417,17 +390,12 @@ QList<QVariantMap> KeyVerificationSession::sasEmojis() const
void KeyVerificationSession::sendRequest()
{
- QJsonArray methods = toJson(m_supportedMethods);
- auto event = makeEvent<KeyVerificationRequestEvent>(QJsonObject {
- {"type", "m.key.verification.request"},
- {"content", QJsonObject {
- {"from_device", m_connection->deviceId()},
- {"transaction_id", m_transactionId},
- {"methods", methods},
- {"timestamp", QDateTime::currentMSecsSinceEpoch()},
- }},
- });
- m_connection->sendToDevice(m_remoteUserId, m_remoteDeviceId, std::move(event), m_encrypted);
+ m_connection->sendToDevice(
+ m_remoteUserId, m_remoteDeviceId,
+ KeyVerificationRequestEvent(m_transactionId, m_connection->deviceId(),
+ supportedMethods,
+ QDateTime::currentDateTime()),
+ m_encrypted);
setState(WAITINGFORREADY);
}
@@ -453,7 +421,7 @@ void KeyVerificationSession::setError(Error error)
emit errorChanged();
}
-QString KeyVerificationSession::errorToString(Error error) const
+QString KeyVerificationSession::errorToString(Error error)
{
switch(error) {
case NONE:
@@ -485,7 +453,7 @@ QString KeyVerificationSession::errorToString(Error error) const
}
}
-KeyVerificationSession::Error KeyVerificationSession::stringToError(const QString& error) const
+KeyVerificationSession::Error KeyVerificationSession::stringToError(const QString& error)
{
if (error == "m.timeout"_ls) {
return REMOTE_TIMEOUT;
@@ -514,14 +482,3 @@ KeyVerificationSession::Error KeyVerificationSession::stringToError(const QStrin
}
return NONE;
}
-
-QStringList KeyVerificationSession::commonSupportedMethods(const QStringList& remoteMethods) const
-{
- QStringList result;
- for (const auto& method : remoteMethods) {
- if (m_supportedMethods.contains(method)) {
- result += method;
- }
- }
- return result;
-}
diff --git a/lib/keyverificationsession.h b/lib/keyverificationsession.h
index 2756fa0a..73c9384e 100644
--- a/lib/keyverificationsession.h
+++ b/lib/keyverificationsession.h
@@ -128,10 +128,8 @@ private:
void init(std::chrono::milliseconds timeout);
void setState(State state);
void setError(Error error);
- QStringList commonSupportedMethods(const QStringList& remoteSupportedMethods) const;
- QString errorToString(Error error) const;
- Error stringToError(const QString& error) const;
- QStringList m_supportedMethods = { "m.sas.v1"_ls };
+ static QString errorToString(Error error);
+ static Error stringToError(const QString& error);
QByteArray macInfo(bool verifying, const QString& key = "KEY_IDS"_ls);
QString calculateMac(const QString& input, bool verifying, const QString& keyId= "KEY_IDS"_ls);
@@ -139,4 +137,4 @@ private:
std::pair<QString, QString> emojiForCode(int code);
};
-}
+} // namespace Quotient