aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-08-12 08:24:29 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-08-12 08:24:29 +0000
commitf312239c8cae0a2aa58edcdc0589479229c98b55 (patch)
treef777e7bdfcfdaba9aab80c5dd559d444553d921d /src
parent4e6d4908fdf5168fbd0ad4025f00a8d133622b4d (diff)
downloadqxmpp-f312239c8cae0a2aa58edcdc0589479229c98b55.tar.gz
make QXmppNonSASLAuthIq parsing/serialisation symetric
Diffstat (limited to 'src')
-rw-r--r--src/QXmppNonSASLAuth.cpp42
-rw-r--r--src/QXmppNonSASLAuth.h10
-rw-r--r--src/QXmppStream.cpp13
3 files changed, 27 insertions, 38 deletions
diff --git a/src/QXmppNonSASLAuth.cpp b/src/QXmppNonSASLAuth.cpp
index 7e33fa43..7fa1e9e8 100644
--- a/src/QXmppNonSASLAuth.cpp
+++ b/src/QXmppNonSASLAuth.cpp
@@ -30,17 +30,22 @@
#include "QXmppUtils.h"
QXmppNonSASLAuthIq::QXmppNonSASLAuthIq()
- : QXmppIq(QXmppIq::Set),
- m_useplaintext(false)
+ : QXmppIq(QXmppIq::Set)
{
}
+bool QXmppNonSASLAuthIq::isNonSASLAuthIq(const QDomElement &element)
+{
+ QDomElement queryElement = element.firstChildElement("query");
+ return queryElement.namespaceURI() == ns_auth;
+}
+
void QXmppNonSASLAuthIq::parseElementFromChild(const QDomElement &element)
{
QDomElement queryElement = element.firstChildElement("query");
m_username = queryElement.firstChildElement("username").text();
m_password = queryElement.firstChildElement("password").text();
- m_digest = queryElement.firstChildElement("digest").text();
+ m_digest = QByteArray::fromHex(queryElement.firstChildElement("digest").text().toAscii());
m_resource = queryElement.firstChildElement("resource").text();
}
@@ -50,18 +55,8 @@ void QXmppNonSASLAuthIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
writer->writeAttribute("xmlns", ns_auth);
if (!m_username.isEmpty())
writer->writeTextElement("username", m_username);
- if (!m_password.isEmpty())
- {
- if ( m_useplaintext )
- writer->writeTextElement("password", m_password);
- else
- {//SHA1(concat(sid, password)).
- QByteArray textSid = m_sid.toUtf8();
- QByteArray encodedPassword = m_password.toUtf8();
- QByteArray digest = QCryptographicHash::hash(textSid + encodedPassword, QCryptographicHash::Sha1 ).toHex();
- writer->writeTextElement("digest", digest);
- }
- }
+ if (!m_digest.isEmpty())
+ writer->writeTextElement("digest", m_digest.toHex());
if (!m_resource.isEmpty())
writer->writeTextElement("resource", m_resource);
writer->writeEndElement();
@@ -77,11 +72,16 @@ void QXmppNonSASLAuthIq::setUsername( const QString &username )
m_username = username;
}
-QString QXmppNonSASLAuthIq::digest() const
+QByteArray QXmppNonSASLAuthIq::digest() const
{
return m_digest;
}
+void QXmppNonSASLAuthIq::setDigest(const QString &streamId, const QString &password)
+{
+ m_digest = QCryptographicHash::hash(streamId.toUtf8() + password.toUtf8(), QCryptographicHash::Sha1);
+}
+
QString QXmppNonSASLAuthIq::password() const
{
return m_password;
@@ -102,13 +102,3 @@ void QXmppNonSASLAuthIq::setResource(const QString &resource)
m_resource = resource;
}
-void QXmppNonSASLAuthIq::setStreamId(const QString &sid)
-{
- m_sid = sid;
-}
-
-void QXmppNonSASLAuthIq::setUsePlainText(bool use)
-{
- m_useplaintext = use;
-}
-
diff --git a/src/QXmppNonSASLAuth.h b/src/QXmppNonSASLAuth.h
index 10dab42c..87017478 100644
--- a/src/QXmppNonSASLAuth.h
+++ b/src/QXmppNonSASLAuth.h
@@ -34,7 +34,8 @@ public:
QString username() const;
void setUsername(const QString &username);
- QString digest() const;
+ QByteArray digest() const;
+ void setDigest(const QString &streamId, const QString &password);
QString password() const;
void setPassword(const QString &password);
@@ -42,8 +43,7 @@ public:
QString resource() const;
void setResource(const QString &resource);
- void setStreamId(const QString &sid);
- void setUsePlainText( bool useplaintext );
+ static bool isNonSASLAuthIq(const QDomElement &element);
protected:
/// \cond
@@ -53,11 +53,9 @@ protected:
private:
QString m_username;
- QString m_digest;
+ QByteArray m_digest;
QString m_password;
QString m_resource;
- QString m_sid;
- bool m_useplaintext;
};
#endif // QXmppNonSASLAuth_H
diff --git a/src/QXmppStream.cpp b/src/QXmppStream.cpp
index d4625ba3..afa42351 100644
--- a/src/QXmppStream.cpp
+++ b/src/QXmppStream.cpp
@@ -653,8 +653,7 @@ void QXmppStream::parser(const QByteArray& data)
// xmpp connection made
emit xmppConnected();
}
- else if(nodeRecv.firstChildElement("query").
- namespaceURI() == ns_auth)
+ else if(QXmppNonSASLAuthIq::isNonSASLAuthIq(nodeRecv))
{
if(type == "result")
{
@@ -678,7 +677,8 @@ void QXmppStream::parser(const QByteArray& data)
plainText = false;
else
{
- //TODO Login error
+ warning("No supported Non-SASL Authentication mechanism available");
+ disconnect();
return;
}
sendNonSASLAuth(plainText);
@@ -814,10 +814,11 @@ void QXmppStream::sendNonSASLAuth(bool plainText)
QXmppNonSASLAuthIq authQuery;
authQuery.setType(QXmppIq::Set);
authQuery.setUsername(configuration().user());
- authQuery.setPassword(configuration().passwd());
+ if (plainText)
+ authQuery.setPassword(configuration().passwd());
+ else
+ authQuery.setDigest(d->streamId, configuration().passwd());
authQuery.setResource(configuration().resource());
- authQuery.setStreamId(d->streamId);
- authQuery.setUsePlainText(plainText);
d->nonSASLAuthId = authQuery.id();
sendPacket(authQuery);
}