From 93046d414e60b47447d91638c5f74503f8eef81b Mon Sep 17 00:00:00 2001 From: Tiziano Bacocco Date: Tue, 28 Feb 2023 23:38:10 +0100 Subject: [PATCH 1/2] Some server implementations like the one in use by www.ilportaledellautomobilista.it are broken and fail if Password is passed before Username Also Sending Nonce and Created to those implementations will cause authentication to fail Signed-off-by: Tiziano Bacocco --- src/KDSoapClient/KDSoapAuthentication.cpp | 32 ++++++++++++++++------- src/KDSoapClient/KDSoapAuthentication.h | 8 ++++++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/KDSoapClient/KDSoapAuthentication.cpp b/src/KDSoapClient/KDSoapAuthentication.cpp index 40394f6c..ff82cb57 100644 --- a/src/KDSoapClient/KDSoapAuthentication.cpp +++ b/src/KDSoapClient/KDSoapAuthentication.cpp @@ -28,6 +28,7 @@ class KDSoapAuthentication::Private bool useWSUsernameToken = false; QDateTime overrideWSUsernameCreatedTime; QByteArray overrideWSUsernameNonce; + bool omitNonceCreatedFromUsernameToken = false; }; KDSoapAuthentication::KDSoapAuthentication() @@ -104,6 +105,16 @@ bool KDSoapAuthentication::useWSUsernameToken() const return d->useWSUsernameToken; } +void KDSoapAuthentication::setOmitNonceCreatedFromUsernameToken(bool omitNonceCreatedFromUsernameToken) +{ + d->omitNonceCreatedFromUsernameToken = omitNonceCreatedFromUsernameToken; +} + +bool KDSoapAuthentication::omitNonceCreatedFromUsernameToken() const +{ + return d->omitNonceCreatedFromUsernameToken; +} + QDateTime KDSoapAuthentication::overrideWSUsernameCreatedTime() const { return d->overrideWSUsernameCreatedTime; @@ -162,13 +173,18 @@ void KDSoapAuthentication::writeWSUsernameTokenHeader(QXmlStreamWriter &writer) writer.writeStartElement(securityExtentionNS, QLatin1String("Security")); writer.writeStartElement(securityExtentionNS, QLatin1String("UsernameToken")); + if ( !d->omitNonceCreatedFromUsernameToken ) { + writer.writeStartElement(securityExtentionNS, QLatin1String("Nonce")); + writer.writeCharacters(QString::fromLatin1(nonce.toBase64().constData())); + writer.writeEndElement(); + + writer.writeStartElement(securityUtilityNS, QLatin1String("Created")); + writer.writeCharacters(timestamp); + writer.writeEndElement(); + } - writer.writeStartElement(securityExtentionNS, QLatin1String("Nonce")); - writer.writeCharacters(QString::fromLatin1(nonce.toBase64().constData())); - writer.writeEndElement(); - - writer.writeStartElement(securityUtilityNS, QLatin1String("Created")); - writer.writeCharacters(timestamp); + writer.writeStartElement(securityExtentionNS, QLatin1String("Username")); + writer.writeCharacters(d->user); writer.writeEndElement(); writer.writeStartElement(securityExtentionNS, QLatin1String("Password")); @@ -185,10 +201,6 @@ void KDSoapAuthentication::writeWSUsernameTokenHeader(QXmlStreamWriter &writer) } writer.writeEndElement(); - writer.writeStartElement(securityExtentionNS, QLatin1String("Username")); - writer.writeCharacters(d->user); - writer.writeEndElement(); - writer.writeEndElement(); writer.writeEndElement(); } diff --git a/src/KDSoapClient/KDSoapAuthentication.h b/src/KDSoapClient/KDSoapAuthentication.h index 8b7b15c4..e874690a 100644 --- a/src/KDSoapClient/KDSoapAuthentication.h +++ b/src/KDSoapClient/KDSoapAuthentication.h @@ -87,6 +87,14 @@ class KDSOAP_EXPORT KDSoapAuthentication */ bool useWSUsernameToken() const; + /** + * Workaround some broken implementations like on some italian institutions + * Remove Nonce and Created from UsernameToken + */ + void setOmitNonceCreatedFromUsernameToken(bool omitNonceCreatedFromUsernameToken); + + bool omitNonceCreatedFromUsernameToken() const; + /** * Sets the created time used during WS-UsernameToken authentication * This is useful for devices with an incorrect time and during testing From ea2ae8dcdc131af8036e99af3bb043fa10cc2314 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 28 Feb 2023 22:56:18 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/KDSoapClient/KDSoapAuthentication.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/KDSoapClient/KDSoapAuthentication.cpp b/src/KDSoapClient/KDSoapAuthentication.cpp index ff82cb57..db2f909e 100644 --- a/src/KDSoapClient/KDSoapAuthentication.cpp +++ b/src/KDSoapClient/KDSoapAuthentication.cpp @@ -173,7 +173,7 @@ void KDSoapAuthentication::writeWSUsernameTokenHeader(QXmlStreamWriter &writer) writer.writeStartElement(securityExtentionNS, QLatin1String("Security")); writer.writeStartElement(securityExtentionNS, QLatin1String("UsernameToken")); - if ( !d->omitNonceCreatedFromUsernameToken ) { + if (!d->omitNonceCreatedFromUsernameToken) { writer.writeStartElement(securityExtentionNS, QLatin1String("Nonce")); writer.writeCharacters(QString::fromLatin1(nonce.toBase64().constData())); writer.writeEndElement();