Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some server implementations like the one in use by … #255

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions src/KDSoapClient/KDSoapAuthentication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class KDSoapAuthentication::Private
bool useWSUsernameToken = false;
QDateTime overrideWSUsernameCreatedTime;
QByteArray overrideWSUsernameNonce;
bool omitNonceCreatedFromUsernameToken = false;
};

KDSoapAuthentication::KDSoapAuthentication()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand All @@ -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();
}
8 changes: 8 additions & 0 deletions src/KDSoapClient/KDSoapAuthentication.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down