From: ishmal Date: Sun, 13 Apr 2008 19:06:55 +0000 (+0000) Subject: Make fallback to iq auth in the odd situation of server saying it has streams v1... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=59b195460be532890867125c402e2a9ba8a0f31e;p=inkscape.git Make fallback to iq auth in the odd situation of server saying it has streams v1.0, but doesnt handle sasl (server bug) --- diff --git a/src/pedro/pedroutil.cpp b/src/pedro/pedroutil.cpp index c9dbeaa81..c19498281 100644 --- a/src/pedro/pedroutil.cpp +++ b/src/pedro/pedroutil.cpp @@ -331,6 +331,12 @@ DOMString Sha1::hashHex(unsigned char *dataIn, int len) } +DOMString Sha1::hashHex(const DOMString &str) +{ + return hashHex((unsigned char *)str.c_str(), str.size()); +} + + void Sha1::init() { @@ -350,21 +356,32 @@ void Sha1::init() } -void Sha1::append(unsigned char *dataIn, int len) +void Sha1::append(unsigned char ch) { // Read the data into W and process blocks as they get full - for (int i = 0; i < len; i++) + W[lenW / 4] <<= 8; + W[lenW / 4] |= (unsigned long)ch; + if ((++lenW) % 64 == 0) { - W[lenW / 4] <<= 8; - W[lenW / 4] |= (unsigned long)dataIn[i]; - if ((++lenW) % 64 == 0) - { - hashblock(); - lenW = 0; - } - sizeLo += 8; - sizeHi += (sizeLo < 8); + hashblock(); + lenW = 0; } + sizeLo += 8; + sizeHi += (sizeLo < 8); +} + + +void Sha1::append(unsigned char *dataIn, int len) +{ + // Read the data into W and process blocks as they get full + for (int i = 0; i < len; i++) + append(dataIn[i]); +} + + +void Sha1::append(const DOMString &str) +{ + append((unsigned char *)str.c_str(), str.size()); } diff --git a/src/pedro/pedroutil.h b/src/pedro/pedroutil.h index d4577a5a4..b683080a1 100644 --- a/src/pedro/pedroutil.h +++ b/src/pedro/pedroutil.h @@ -185,20 +185,35 @@ public: /** * Static convenience method. This will fill a string with the hex - * codex string. + * coded string. */ static DOMString hashHex(unsigned char *dataIn, int len); + /** + * Static convenience method. + */ + static DOMString hashHex(const DOMString &str); + /** * Initialize the context (also zeroizes contents) */ virtual void init(); + /** + * + */ + virtual void append(unsigned char ch); + /** * */ virtual void append(unsigned char *dataIn, int len); + /** + * + */ + virtual void append(const DOMString &str); + /** * * @parm digest points to a bufer of 20 unsigned chars diff --git a/src/pedro/pedroxmpp.cpp b/src/pedro/pedroxmpp.cpp index 0dd78c5b8..0fa86a6c4 100644 --- a/src/pedro/pedroxmpp.cpp +++ b/src/pedro/pedroxmpp.cpp @@ -1505,7 +1505,7 @@ bool XmppClient::iqAuthenticate(const DOMString &streamId) //## Digest authentication DOMString digest = streamId; digest.append(password); - digest = Sha1::hashHex((unsigned char *)digest.c_str(), digest.size()); + digest = Sha1::hashHex(digest); //printf("digest:%s\n", digest.c_str()); fmt = "" @@ -1660,9 +1660,10 @@ bool XmppClient::saslMd5Authenticate() status("SASL recv nonce: '%s' realm:'%s'\n", nonce.c_str(), realm.c_str()); - char idBuf[10]; - snprintf(idBuf, 9, "%dsasl", msgId++); - DOMString cnonce = Sha1::hashHex((unsigned char *)idBuf, 7); + char idBuf[14]; + snprintf(idBuf, 13, "%dsasl", msgId++); + DOMString cnonceStr = idBuf; + DOMString cnonce = Sha1::hashHex(cnonceStr); DOMString authzid = username; authzid.append("@"); authzid.append(host); DOMString digest_uri = "xmpp/"; digest_uri.append(host); @@ -1729,7 +1730,7 @@ bool XmppClient::saslMd5Authenticate() return false; recbuf = readStanza(); - status("server says:: '%s'", recbuf.c_str()); + status("server says: '%s'", recbuf.c_str()); elem = parser.parse(recbuf); //elem->print(); //# Success or failure already? @@ -1835,8 +1836,9 @@ bool XmppClient::saslPlainAuthenticate() /** * Handshake with SASL, and use one of its offered mechanisms to * authenticate. + * @param streamId used for iq auth fallback is SASL not supported */ -bool XmppClient::saslAuthenticate() +bool XmppClient::saslAuthenticate(const DOMString &streamId) { Parser parser; @@ -1921,7 +1923,10 @@ bool XmppClient::saslAuthenticate() ElementList elems = elem->findElements("mechanism"); if (elems.size() < 1) { - error("login: no SASL mechanism offered by server"); + status("login: no SASL mechanism offered by server"); + //fall back to iq + if (iqAuthenticate(streamId)) + return true; return false; } bool md5Found = false; @@ -2023,7 +2028,7 @@ bool XmppClient::createSession() return false; DOMString recbuf = readStanza(); - //printf("received: '%s'\n", recbuf.c_str()); + status("RECV: '%s'\n", recbuf.c_str()); recbuf.append(""); Element *elem = parser.parse(recbuf); //elem->print(); @@ -2036,8 +2041,9 @@ bool XmppClient::createSession() if (useSasl) { - if (!saslAuthenticate()) + if (!saslAuthenticate(streamId)) return false; + fmt = "