aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTobias Fella <fella@posteo.de>2022-09-06 21:35:27 +0200
committerTobias Fella <fella@posteo.de>2022-09-06 21:35:27 +0200
commitecf6b855b0fc8cbe16d34b67ae1dca7bd9b69948 (patch)
tree5e091f5c114cecd1082d45fb17361438a39f3624 /lib
parent66127730592eadf9ee717a53a521ac2ec14f1051 (diff)
downloadlibquotient-ecf6b855b0fc8cbe16d34b67ae1dca7bd9b69948.tar.gz
libquotient-ecf6b855b0fc8cbe16d34b67ae1dca7bd9b69948.zip
Add autotest for key verification and fix several edge-cases
Diffstat (limited to 'lib')
-rw-r--r--lib/keyverificationsession.cpp15
-rw-r--r--lib/keyverificationsession.h7
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/keyverificationsession.cpp b/lib/keyverificationsession.cpp
index 44a085fe..24fc08e1 100644
--- a/lib/keyverificationsession.cpp
+++ b/lib/keyverificationsession.cpp
@@ -154,7 +154,7 @@ EmojiEntry emojiForCode(int code, const QString& language)
void KeyVerificationSession::handleKey(const KeyVerificationKeyEvent& event)
{
- if (state() != WAITINGFORKEY && state() != WAITINGFORVERIFICATION) {
+ if (state() != WAITINGFORKEY && state() != ACCEPTED) {
cancelVerification(UNEXPECTED_MESSAGE);
return;
}
@@ -176,7 +176,6 @@ void KeyVerificationSession::handleKey(const KeyVerificationKeyEvent& event)
} else {
sendKey();
}
- setState(WAITINGFORVERIFICATION);
std::string key(olm_sas_pubkey_length(m_sas), '\0');
olm_sas_get_pubkey(m_sas, key.data(), key.size());
@@ -214,6 +213,7 @@ void KeyVerificationSession::handleKey(const KeyVerificationKeyEvent& event)
emit sasEmojisChanged();
emit keyReceived();
+ setState(WAITINGFORVERIFICATION);
}
QString KeyVerificationSession::calculateMac(const QString& input,
@@ -314,6 +314,10 @@ void KeyVerificationSession::sendStartSas()
void KeyVerificationSession::handleReady(const KeyVerificationReadyEvent& event)
{
+ if (state() == ACCEPTED) {
+ // It's possible to receive ready and start in the same sync, in which case start might be handled before ready.
+ return;
+ }
if (state() != WAITINGFORREADY) {
cancelVerification(UNEXPECTED_MESSAGE);
return;
@@ -334,7 +338,7 @@ void KeyVerificationSession::handleReady(const KeyVerificationReadyEvent& event)
void KeyVerificationSession::handleStart(const KeyVerificationStartEvent& event)
{
- if (state() != READY) {
+ if (state() != READY && state() != WAITINGFORREADY) {
cancelVerification(UNEXPECTED_MESSAGE);
return;
}
@@ -510,3 +514,8 @@ KeyVerificationSession::Error KeyVerificationSession::stringToError(const QStrin
}
return NONE;
}
+
+QString KeyVerificationSession::remoteDeviceId() const
+{
+ return m_remoteDeviceId;
+}
diff --git a/lib/keyverificationsession.h b/lib/keyverificationsession.h
index aa0295cb..31f63453 100644
--- a/lib/keyverificationsession.h
+++ b/lib/keyverificationsession.h
@@ -19,6 +19,11 @@ struct QUOTIENT_API EmojiEntry {
Q_GADGET
Q_PROPERTY(QString emoji MEMBER emoji CONSTANT)
Q_PROPERTY(QString description MEMBER description CONSTANT)
+
+public:
+ bool operator==(const EmojiEntry& rhs) const {
+ return emoji == rhs.emoji && description == rhs.description;
+ }
};
/** A key verification session. Listen for incoming sessions by connecting to Connection::newKeyVerificationSession.
@@ -93,6 +98,8 @@ public:
Error error() const;
+ QString remoteDeviceId() const;
+
public Q_SLOTS:
void sendRequest();
void sendReady();