diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-11-10 11:10:10 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-11-10 11:10:10 +0000 |
| commit | 83a329cbe139c9980167b9390fcabc1b851e1efc (patch) | |
| tree | 6e1d9db162d9a43be706fdd038ab0ea95c549ffd /src/QXmppSaslAuth.cpp | |
| parent | d6d0b4d7a57b9d36b868b49fb83bf6ddc301274b (diff) | |
| download | qxmpp-83a329cbe139c9980167b9390fcabc1b851e1efc.tar.gz | |
slightly refactor SASL auth to make QXmppSaslDigestMd5 class more generic
Diffstat (limited to 'src/QXmppSaslAuth.cpp')
| -rw-r--r-- | src/QXmppSaslAuth.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
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(); } |
