Skip to content

Commit

Permalink
Add parameter 'keyOwnerJid' to trust storages' 'trustLevel()'
Browse files Browse the repository at this point in the history
  • Loading branch information
melvo authored and lnjX committed Mar 7, 2022
1 parent 76965a1 commit ebbf58a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/client/QXmppAtmManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ QFuture<void> QXmppAtmManager::handleMessage(const QXmppMessage &message)
const auto senderKey = e2eeMetadata ? e2eeMetadata->senderKey() : QByteArray();
const auto encryption = trustMessageElement->encryption();

auto future = m_trustStorage->trustLevel(encryption, senderKey);
auto future = m_trustStorage->trustLevel(encryption, senderJid, senderKey);
await(future, this, [=](const auto &&senderKeyTrustLevel) mutable {
const auto isSenderKeyAuthenticated = senderKeyTrustLevel == QXmppTrustStorage::Authenticated;

Expand Down
4 changes: 2 additions & 2 deletions src/client/QXmppTrustMemoryStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ QFuture<void> QXmppTrustMemoryStorage::setTrustLevel(const QString &encryption,
return makeReadyFuture();
}

QFuture<QXmppTrustStorage::TrustLevel> QXmppTrustMemoryStorage::trustLevel(const QString &encryption, const QByteArray &keyId)
QFuture<QXmppTrustStorage::TrustLevel> QXmppTrustMemoryStorage::trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId)
{
const auto keys = d->keys.values(encryption);
for (const auto &key : keys) {
if (key.id == keyId) {
if (key.id == keyId && key.ownerJid == keyOwnerJid) {
return makeReadyFuture(std::move(QXmppTrustStorage::TrustLevel(key.trustLevel)));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/QXmppTrustMemoryStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class QXMPP_EXPORT QXmppTrustMemoryStorage : virtual public QXmppTrustStorage

QFuture<void> setTrustLevel(const QString &encryption, const QMultiHash<QString, QByteArray> &keyIds, TrustLevel trustLevel) override;
QFuture<void> setTrustLevel(const QString &encryption, const QList<QString> &keyOwnerJids, TrustLevel oldTrustLevel, TrustLevel newTrustLevel) override;
QFuture<TrustLevel> trustLevel(const QString &encryption, const QByteArray &keyId) override;
QFuture<TrustLevel> trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) override;

QFuture<void> resetAll(const QString &encryption) override;
/// \endcond
Expand Down
3 changes: 2 additions & 1 deletion src/client/QXmppTrustStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,14 @@
///

///
/// \fn QXmppTrustStorage::trustLevel(const QString &encryption, const QByteArray &keyId)
/// \fn QXmppTrustStorage::trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId)
///
/// Returns the trust level of a key.
///
/// If the key is not stored, the trust in that key is undecided.
///
/// \param encryption encryption protocol namespace
/// \param keyOwnerJid key owner's bare JID
/// \param keyId ID of the key
///
/// \return the key's trust level
Expand Down
2 changes: 1 addition & 1 deletion src/client/QXmppTrustStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class QXMPP_EXPORT QXmppTrustStorage

virtual QFuture<void> setTrustLevel(const QString &encryption, const QMultiHash<QString, QByteArray> &keyIds, TrustLevel trustLevel) = 0;
virtual QFuture<void> setTrustLevel(const QString &encryption, const QList<QString> &keyOwnerJids, TrustLevel oldTrustLevel, TrustLevel newTrustLevel) = 0;
virtual QFuture<TrustLevel> trustLevel(const QString &encryption, const QByteArray &keyId) = 0;
virtual QFuture<TrustLevel> trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) = 0;

virtual QFuture<void> resetAll(const QString &encryption) = 0;
};
Expand Down
8 changes: 8 additions & 0 deletions tests/qxmppatmmanager/tst_qxmppatmmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,7 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsSoleOwnKeyDistrusted()
QVERIFY2(!unexpectedTrustMessageSentSpy.wait(UNEXPECTED_TRUST_MESSAGE_WAITING_TIMEOUT), "Unexpected trust message sent!");

auto futureTrustLevel = m_trustStorage->trustLevel(ns_omemo,
QStringLiteral("[email protected]"),
QByteArray::fromBase64(QByteArrayLiteral("RwyI/3m9l4wgju9JduFxb5MEJvBNRDfPfo1Ewhl1DEI=")));
QVERIFY(futureTrustLevel.isFinished());
auto result = futureTrustLevel.result();
Expand Down Expand Up @@ -2026,6 +2027,7 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsSoleContactKeyDistrusted()
QVERIFY2(!unexpectedTrustMessageSentSpy.wait(UNEXPECTED_TRUST_MESSAGE_WAITING_TIMEOUT), "Unexpected trust message sent!");

const auto futureTrustLevel = m_trustStorage->trustLevel(ns_omemo,
QStringLiteral("[email protected]"),
QByteArray::fromBase64(QByteArrayLiteral("+1VJvMLCGvkDquZ6mQZ+SS+gTbQ436BJUwFOoW0Ma1g=")));
QVERIFY(futureTrustLevel.isFinished());
const auto result = futureTrustLevel.result();
Expand All @@ -2035,18 +2037,21 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsSoleContactKeyDistrusted()
void tst_QXmppAtmManager::testMakeTrustDecisionsOwnKeysDone()
{
auto future = m_trustStorage->trustLevel(ns_omemo,
QStringLiteral("[email protected]"),
QByteArray::fromBase64(QByteArrayLiteral("0RcVsGk3LnpEFsqqztTzAgCDgVXlfa03paSqJFOOWOU=")));
QVERIFY(future.isFinished());
auto result = future.result();
QCOMPARE(result, QXmppTrustStorage::Authenticated);

future = m_trustStorage->trustLevel(ns_omemo,
QStringLiteral("[email protected]"),
QByteArray::fromBase64(QByteArrayLiteral("tYn/wcIOxBSoW4W1UfPr/zgbLipBK2KsFfC7F1bzut0=")));
QVERIFY(future.isFinished());
result = future.result();
QCOMPARE(result, QXmppTrustStorage::Authenticated);

future = m_trustStorage->trustLevel(ns_omemo,
QStringLiteral("[email protected]"),
QByteArray::fromBase64(QByteArrayLiteral("4iBsyJPVAfNWM/OgyA9fasOvkJ8K1/0wuYpwVGw4Q5M=")));
QVERIFY(future.isFinished());
result = future.result();
Expand All @@ -2056,18 +2061,21 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsOwnKeysDone()
void tst_QXmppAtmManager::testMakeTrustDecisionsContactKeysDone()
{
auto future = m_trustStorage->trustLevel(ns_omemo,
QStringLiteral("[email protected]"),
QByteArray::fromBase64(QByteArrayLiteral("+1VJvMLCGvkDquZ6mQZ+SS+gTbQ436BJUwFOoW0Ma1g=")));
QVERIFY(future.isFinished());
auto result = future.result();
QCOMPARE(result, QXmppTrustStorage::Authenticated);

future = m_trustStorage->trustLevel(ns_omemo,
QStringLiteral("[email protected]"),
QByteArray::fromBase64(QByteArrayLiteral("mzDeKTQBVm1cTmzF9DjCGKa14pDADZOVLT9Kh7CK7AM=")));
QVERIFY(future.isFinished());
result = future.result();
QCOMPARE(result, QXmppTrustStorage::Authenticated);

future = m_trustStorage->trustLevel(ns_omemo,
QStringLiteral("[email protected]"),
QByteArray::fromBase64(QByteArrayLiteral("8gBTC1fspYkO4akS6QKN+XFA9Nmf9NEIg7hjtlpTjII=")));
QVERIFY(future.isFinished());
result = future.result();
Expand Down
8 changes: 8 additions & 0 deletions tests/qxmpptrustmemorystorage/tst_qxmpptrustmemorystorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ void tst_QXmppTrustMemoryStorage::testTrustLevels()

auto future = m_trustStorage.trustLevel(
ns_omemo,
QStringLiteral("[email protected]"),
QByteArray::fromBase64(QByteArrayLiteral("AZ/cF4OrUOILKO1gQBf62pQevOhBJ2NyHnXLwM4FDZU=")));
QVERIFY(future.isFinished());
auto result = future.result();
Expand All @@ -538,13 +539,15 @@ void tst_QXmppTrustMemoryStorage::testTrustLevels()

future = m_trustStorage.trustLevel(
ns_omemo,
QStringLiteral("[email protected]"),
QByteArray::fromBase64(QByteArrayLiteral("AZ/cF4OrUOILKO1gQBf62pQevOhBJ2NyHnXLwM4FDZU=")));
QVERIFY(future.isFinished());
result = future.result();
QCOMPARE(result, QXmppTrustStorage::Authenticated);

future = m_trustStorage.trustLevel(
ns_omemo,
QStringLiteral("[email protected]"),
QByteArray::fromBase64(QByteArrayLiteral("9E51lG3vVmUn8CM7/AIcmIlLP2HPl6Ao0/VSf4VT/oA=")));
QVERIFY(future.isFinished());
result = future.result();
Expand All @@ -560,6 +563,7 @@ void tst_QXmppTrustMemoryStorage::testTrustLevels()

future = m_trustStorage.trustLevel(
ns_omemo,
QStringLiteral("[email protected]"),
QByteArray::fromBase64(QByteArrayLiteral("9w6oPjKyGSALd9gHq7sNOdOAkD5bHUVOKACNs89FjkA=")));
QVERIFY(future.isFinished());
result = future.result();
Expand All @@ -569,6 +573,7 @@ void tst_QXmppTrustMemoryStorage::testTrustLevels()
// The default value is returned.
future = m_trustStorage.trustLevel(
ns_omemo,
QStringLiteral("[email protected]"),
QByteArray::fromBase64(QByteArrayLiteral("WXL4EDfzUGbVPQWjT9pmBeiCpCBzYZv3lUAaj+UbPyE=")));
QVERIFY(future.isFinished());
result = future.result();
Expand All @@ -585,13 +590,15 @@ void tst_QXmppTrustMemoryStorage::testTrustLevels()

future = m_trustStorage.trustLevel(
ns_omemo,
QStringLiteral("[email protected]"),
QByteArray::fromBase64(QByteArrayLiteral("AZ/cF4OrUOILKO1gQBf62pQevOhBJ2NyHnXLwM4FDZU=")));
QVERIFY(future.isFinished());
result = future.result();
QCOMPARE(result, QXmppTrustStorage::ManuallyDistrusted);

future = m_trustStorage.trustLevel(
ns_omemo,
QStringLiteral("[email protected]"),
QByteArray::fromBase64(QByteArrayLiteral("9E51lG3vVmUn8CM7/AIcmIlLP2HPl6Ao0/VSf4VT/oA=")));
QVERIFY(future.isFinished());
result = future.result();
Expand All @@ -600,6 +607,7 @@ void tst_QXmppTrustMemoryStorage::testTrustLevels()
// Verify that the default trust level is returned for an unknown key.
future = m_trustStorage.trustLevel(
ns_omemo,
QStringLiteral("[email protected]"),
QByteArray::fromBase64(QByteArrayLiteral("wE06Gwf8f4DvDLFDoaCsGs8ibcUjf84WIOA2FAjPI3o=")));
QVERIFY(future.isFinished());
result = future.result();
Expand Down

0 comments on commit ebbf58a

Please sign in to comment.