Skip to content

Commit

Permalink
KeyVerificationSession: be more vigilant with the received commitment
Browse files Browse the repository at this point in the history
The commitment is now checked to actually be valid base64 as we receive
it. Also, it is stored as QByteArray now - thanks to QString and
QByteArray having the same layout (3 pointers + alignment) we can get
away with this without breaking ABI compat.
  • Loading branch information
KitsuneRal committed Nov 20, 2024
1 parent efd12a6 commit 9e8d10a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions Quotient/keyverificationsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ void KeyVerificationSession::handleEvent(const KeyVerificationEvent& baseEvent)
cancelVerification(UNKNOWN_METHOD);
return false;
}
m_commitment = event.commitment();
m_commitment = event.commitment().toLatin1();
if (!QByteArray::fromBase64Encoding(m_commitment,
QByteArray::AbortOnBase64DecodingErrors)) {
cancelVerification(INVALID_MESSAGE);
return false;
}
sendKey();
setState(WAITINGFORKEY);
return true;
Expand Down Expand Up @@ -228,12 +233,10 @@ void KeyVerificationSession::handleKey(const KeyVerificationKeyEvent& event)
olm_sas_set_their_key(olmData, eventKey.data(), unsignedSize(eventKey));

if (startSentByUs) {
const auto paddedCommitment =
const auto unpaddedCommitment =
QCryptographicHash::hash((event.key() % m_startEvent).toLatin1(),
QCryptographicHash::Sha256)
.toBase64();
const QLatin1String unpaddedCommitment(paddedCommitment.constData(),
QString::fromLatin1(paddedCommitment).indexOf(u'='));
.toBase64(QByteArray::OmitTrailingEquals);
if (unpaddedCommitment != m_commitment) {
qCWarning(E2EE) << "Commitment mismatch; aborting verification";
cancelVerification(MISMATCHED_COMMITMENT);
Expand Down
2 changes: 1 addition & 1 deletion Quotient/keyverificationsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public Q_SLOTS:
State m_state = INCOMING;
Error m_error = NONE;
QString m_startEvent{};
QString m_commitment{};
QByteArray m_commitment{};
bool macReceived = false;
bool m_verified = false;
QString m_pendingEdKeyId{};
Expand Down

0 comments on commit 9e8d10a

Please sign in to comment.