From 83a329cbe139c9980167b9390fcabc1b851e1efc Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Wed, 10 Nov 2010 11:10:10 +0000 Subject: slightly refactor SASL auth to make QXmppSaslDigestMd5 class more generic --- src/QXmppSaslAuth.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/QXmppSaslAuth.cpp') diff --git a/src/QXmppSaslAuth.cpp b/src/QXmppSaslAuth.cpp index 89f4edd4..4a7453d8 100644 --- a/src/QXmppSaslAuth.cpp +++ b/src/QXmppSaslAuth.cpp @@ -79,6 +79,16 @@ void QXmppSaslDigestMd5::setNonce(const QByteArray &nonce) m_nonce = nonce; } +QByteArray QXmppSaslDigestMd5::qop() const +{ + return m_qop; +} + +void QXmppSaslDigestMd5::setQop(const QByteArray &qop) +{ + m_qop = qop; +} + QByteArray QXmppSaslDigestMd5::realm() const { return m_realm; @@ -113,6 +123,11 @@ QByteArray QXmppSaslDigestMd5::generateNonce() return nonce.toBase64(); } +/// Calculate digest response for use with XMPP/SASL. +/// +/// \param A2 +/// + QByteArray QXmppSaslDigestMd5::calculateDigest(const QByteArray &A2) const { const QByteArray a1 = m_username + ':' + m_realm + ':' + m_password; @@ -122,11 +137,21 @@ QByteArray QXmppSaslDigestMd5::calculateDigest(const QByteArray &A2) const if (!m_authzid.isEmpty()) ha1 += ':' + m_authzid; - QByteArray A1(ha1); + return calculateDigest(ha1, A2); +} + +/// Calculate generic digest response. +/// +/// \param A1 +/// \param A2 +/// + +QByteArray QXmppSaslDigestMd5::calculateDigest(const QByteArray &A1, const QByteArray &A2) const +{ QByteArray HA1 = QCryptographicHash::hash(A1, QCryptographicHash::Md5).toHex(); QByteArray HA2 = QCryptographicHash::hash(A2, QCryptographicHash::Md5).toHex(); QByteArray KD = HA1 + ':' + m_nonce + ':' + m_nc + ':' + m_cnonce + ':' - + "auth" + ':' + HA2; + + m_qop + ':' + HA2; return QCryptographicHash::hash(KD, QCryptographicHash::Md5).toHex(); } -- cgit v1.2.3