From bb9f20419c794e4555860e6aeb097229653d5dc9 Mon Sep 17 00:00:00 2001 From: Melvin Keskin Date: Tue, 7 Mar 2023 23:22:06 +0100 Subject: EME: Always send encryption name as fallback Since QXmpp does not differentiate between different EME versions receiving clients support, it is better to always send the encryption name. It ensures that a name is displayed by the receiving client even if it does not support the latest EME version introducing a new encryption. --- src/base/QXmppMessage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/base') diff --git a/src/base/QXmppMessage.cpp b/src/base/QXmppMessage.cpp index c0923d22..9527f5ed 100644 --- a/src/base/QXmppMessage.cpp +++ b/src/base/QXmppMessage.cpp @@ -1659,7 +1659,7 @@ void QXmppMessage::serializeExtensions(QXmlStreamWriter *writer, QXmpp::SceMode writer->writeStartElement(QStringLiteral("encryption")); writer->writeDefaultNamespace(ns_eme); writer->writeAttribute(QStringLiteral("namespace"), d->encryptionMethod); - helperToXmlAddAttribute(writer, QStringLiteral("name"), d->encryptionName); + helperToXmlAddAttribute(writer, QStringLiteral("name"), encryptionName()); writer->writeEndElement(); } -- cgit v1.2.3 From 7bfb39fe1eb853a95929c16a2692cbb648d7387c Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Tue, 14 Mar 2023 23:17:55 +0100 Subject: Client: Don't fill empty 'to' attributes of outgoing IQs --- src/base/QXmppStream.cpp | 4 ++-- src/base/QXmppStream.h | 2 +- src/client/QXmppOutgoingClient.cpp | 7 ++----- 3 files changed, 5 insertions(+), 8 deletions(-) (limited to 'src/base') diff --git a/src/base/QXmppStream.cpp b/src/base/QXmppStream.cpp index 428e8e55..a4921a43 100644 --- a/src/base/QXmppStream.cpp +++ b/src/base/QXmppStream.cpp @@ -208,7 +208,7 @@ QXmppTask QXmppStream::send(QXmppPacket &&packet, bool &writt /// /// \since QXmpp 1.5 /// -QXmppTask QXmppStream::sendIq(QXmppIq &&iq) +QXmppTask QXmppStream::sendIq(QXmppIq &&iq, const QString &to) { using namespace QXmpp; @@ -223,7 +223,7 @@ QXmppTask QXmppStream::sendIq(QXmppIq &&iq) iq.setId(QXmppUtils::generateStanzaUuid()); } - return sendIq(QXmppPacket(iq), iq.id(), iq.to()); + return sendIq(QXmppPacket(iq), iq.id(), to); } /// diff --git a/src/base/QXmppStream.h b/src/base/QXmppStream.h index 55dc7967..a7584366 100644 --- a/src/base/QXmppStream.h +++ b/src/base/QXmppStream.h @@ -47,7 +47,7 @@ public: QXmppTask send(QXmppPacket &&); using IqResult = std::variant; - QXmppTask sendIq(QXmppIq &&); + QXmppTask sendIq(QXmppIq &&, const QString &to); QXmppTask sendIq(QXmppPacket &&, const QString &id, const QString &to); void cancelOngoingIqs(); bool hasIqId(const QString &id) const; diff --git a/src/client/QXmppOutgoingClient.cpp b/src/client/QXmppOutgoingClient.cpp index 20e88b9c..53c02e41 100644 --- a/src/client/QXmppOutgoingClient.cpp +++ b/src/client/QXmppOutgoingClient.cpp @@ -328,11 +328,8 @@ bool QXmppOutgoingClient::isStreamResumed() const /// QXmppTask QXmppOutgoingClient::sendIq(QXmppIq &&iq) { - // always set a to address (the QXmppStream needs this for matching) - if (iq.to().isEmpty()) { - iq.setTo(d->config.domain()); - } - return QXmppStream::sendIq(std::move(iq)); + auto to = iq.to(); + return QXmppStream::sendIq(std::move(iq), to.isEmpty() ? d->config.domain() : to); } void QXmppOutgoingClient::_q_socketDisconnected() -- cgit v1.2.3 From 67d75d5adc5915b5fb83fc1578b35724dae6185b Mon Sep 17 00:00:00 2001 From: Melvin Keskin Date: Thu, 16 Mar 2023 21:57:47 +0100 Subject: Stream: IQ handling: Accept responses without 'from' attribute (#556) See https://xmpp.org/rfcs/rfc6120.html#stanzas-attributes-from-c2s point 3 --- src/base/QXmppStream.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/base') diff --git a/src/base/QXmppStream.cpp b/src/base/QXmppStream.cpp index a4921a43..4e7c7276 100644 --- a/src/base/QXmppStream.cpp +++ b/src/base/QXmppStream.cpp @@ -481,10 +481,18 @@ bool QXmppStream::handleIqResponse(const QDomElement &stanza) return false; } - if (auto itr = d->runningIqs.find(stanza.attribute(QStringLiteral("id"))); + const auto id = stanza.attribute(QStringLiteral("id")); + if (auto itr = d->runningIqs.find(id); itr != d->runningIqs.end()) { - if (stanza.attribute("from") != itr.value().jid) { - warning(QStringLiteral("Received IQ response to one of our requests from wrong sender. Ignoring.")); + const auto expectedFrom = itr.value().jid; + // Check that the sender of the response matches the recipient of the request. + // Stanzas coming from the server on behalf of the user's account must have no "from" + // attribute or have it set to the user's bare JID. + // If 'from' is empty, the IQ has been sent by the server. In this case we don't need to + // do the check as we trust the server anyways. + if (const auto from = stanza.attribute("from"); !from.isEmpty() && from != expectedFrom) { + warning(QStringLiteral("Ignored received IQ response to request '%1' because of wrong sender '%2' instead of expected sender '%3'") + .arg(id, from, expectedFrom)); return false; } -- cgit v1.2.3