From d858e4ae6e0adeaad8d03b055883f411e6d19ab0 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Fri, 16 Sep 2022 19:08:02 +0200 Subject: Implement XEP-0448: Encryption for stateless file sharing parsing (#463) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://xmpp.org/extensions/xep-0448.html Co-authored-by: Jonah BrĂ¼chert --- tests/qxmppmessage/tst_qxmppmessage.cpp | 61 +++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'tests/qxmppmessage/tst_qxmppmessage.cpp') diff --git a/tests/qxmppmessage/tst_qxmppmessage.cpp b/tests/qxmppmessage/tst_qxmppmessage.cpp index 35bf2625..c9eaa786 100644 --- a/tests/qxmppmessage/tst_qxmppmessage.cpp +++ b/tests/qxmppmessage/tst_qxmppmessage.cpp @@ -6,6 +6,7 @@ #include "QXmppBitsOfBinaryContentId.h" #include "QXmppBitsOfBinaryDataList.h" +#include "QXmppEncryptedFileSource_p.h" #include "QXmppMessage.h" #include "QXmppMixInvitation.h" #include "QXmppTrustMessageElement.h" @@ -53,6 +54,7 @@ private slots: void testTrustMessageElement(); void testE2eeFallbackBody(); void testFileSharing(); + void testEncryptedFileSource(); }; void tst_QXmppMessage::testBasic_data() @@ -1186,5 +1188,64 @@ void tst_QXmppMessage::testFileSharing() serializePacket(message1, xml); } +void tst_QXmppMessage::testEncryptedFileSource() +{ + { + QByteArray xml( + "" + "SuRJ2agVm/pQbJQlPq/B23Xt1YOOJCcEGJA5HrcYOGQ=" + "T8RDMBaiqn6Ci4Nw" + "BgKI2gp2kNCRsARNvhFmw5kFf9BBo2pTbV2D8XHTMWI=" + "id4cnqqy9/ssfCkM4vYSkiXXrlE=" + "" + "" + "" + ""); + + QXmppEncryptedFileSource encryptedSource; + parsePacket(encryptedSource, xml); + QCOMPARE(encryptedSource.key(), QByteArray::fromBase64("SuRJ2agVm/pQbJQlPq/B23Xt1YOOJCcEGJA5HrcYOGQ=")); + QCOMPARE(encryptedSource.iv(), QByteArray::fromBase64("T8RDMBaiqn6Ci4Nw")); + QCOMPARE(encryptedSource.httpSources().front().url(), QUrl("https://download.montague.lit/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/encrypted.jpg")); + QCOMPARE(encryptedSource.cipher(), QXmppEncryptedFileSource::Aes256GcmNopadding); + QVERIFY(!encryptedSource.hashes().empty()); + serializePacket(encryptedSource, xml); + } + + { + QByteArray xml( + "" + "SuRJ2agVm/pQbJQlPq/B23Xt1YOOJCcEGJA5HrcYOGQ=" + "T8RDMBaiqn6Ci4Nw" + "BgKI2gp2kNCRsARNvhFmw5kFf9BBo2pTbV2D8XHTMWI=" + "id4cnqqy9/ssfCkM4vYSkiXXrlE=" + "" + "" + "" + ""); + + QXmppEncryptedFileSource encryptedSource; + parsePacket(encryptedSource, xml); + serializePacket(encryptedSource, xml); + } + + { + QByteArray xml( + "" + "SuRJ2agVm/pQbJQlPq/B23Xt1YOOJCcEGJA5HrcYOGQ=" + "T8RDMBaiqn6Ci4Nw" + "BgKI2gp2kNCRsARNvhFmw5kFf9BBo2pTbV2D8XHTMWI=" + "id4cnqqy9/ssfCkM4vYSkiXXrlE=" + "" + "" + "" + ""); + + QXmppEncryptedFileSource encryptedSource; + parsePacket(encryptedSource, xml); + serializePacket(encryptedSource, xml); + } +} + QTEST_MAIN(tst_QXmppMessage) #include "tst_qxmppmessage.moc" -- cgit v1.2.3