diff options
| author | Bob Jamison <ishmalius@gmail.com> | 2008-04-13 19:06:55 +0000 |
|---|---|---|
| committer | ishmal <ishmal@users.sourceforge.net> | 2008-04-13 19:06:55 +0000 |
| commit | 590571f0e4303dda996d10241870d761f4f53e9c (patch) | |
| tree | 8c485eec4623443ef3de5abc3d9f8d1e8d697a9e /src | |
| parent | Make pedro dom list simpler (diff) | |
| download | inkscape-590571f0e4303dda996d10241870d761f4f53e9c.tar.gz inkscape-590571f0e4303dda996d10241870d761f4f53e9c.zip | |
Make fallback to iq auth in the odd situation of server saying it has streams v1.0, but doesnt handle sasl (server bug)
(bzr r5417)
Diffstat (limited to 'src')
| -rw-r--r-- | src/pedro/pedroutil.cpp | 39 | ||||
| -rw-r--r-- | src/pedro/pedroutil.h | 17 | ||||
| -rw-r--r-- | src/pedro/pedroxmpp.cpp | 24 | ||||
| -rw-r--r-- | src/pedro/pedroxmpp.h | 2 |
4 files changed, 60 insertions, 22 deletions
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,11 +185,16 @@ 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(); @@ -197,10 +202,20 @@ public: /** * */ + 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 */ virtual void finish(unsigned char *digest); 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 = "<iq type='set' id='auth%d'>" @@ -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("</stream:stream>"); Element *elem = parser.parse(recbuf); //elem->print(); @@ -2036,8 +2041,9 @@ bool XmppClient::createSession() if (useSasl) { - if (!saslAuthenticate()) + if (!saslAuthenticate(streamId)) return false; + fmt = "<stream:stream " "to='%s' " diff --git a/src/pedro/pedroxmpp.h b/src/pedro/pedroxmpp.h index 554cb76c6..7f927897f 100644 --- a/src/pedro/pedroxmpp.h +++ b/src/pedro/pedroxmpp.h @@ -1130,7 +1130,7 @@ private: bool saslPlainAuthenticate(); - bool saslAuthenticate(); + bool saslAuthenticate(const DOMString &streamId); bool iqAuthenticate(const DOMString &streamId); |
