summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4a54613)
raw | patch | inline | side by side (parent: 4a54613)
author | ishmal <ishmal@users.sourceforge.net> | |
Sun, 13 Apr 2008 19:06:55 +0000 (19:06 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Sun, 13 Apr 2008 19:06:55 +0000 (19:06 +0000) |
src/pedro/pedroutil.cpp | patch | blob | history | |
src/pedro/pedroutil.h | patch | blob | history | |
src/pedro/pedroxmpp.cpp | patch | blob | history | |
src/pedro/pedroxmpp.h | patch | blob | history |
index c9dbeaa812587440ae62409a9aa13a2425802649..c19498281842148d203fb89b6fc2c5c10ccced4a 100644 (file)
--- a/src/pedro/pedroutil.cpp
+++ b/src/pedro/pedroutil.cpp
}
+DOMString Sha1::hashHex(const DOMString &str)
+{
+ return hashHex((unsigned char *)str.c_str(), str.size());
+}
+
+
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 d4577a5a4a5ebbc7edd3916c900a14b99123edaa..b683080a189a7c8d2c53884ef1a02ddc8e4d01e1 100644 (file)
--- a/src/pedro/pedroutil.h
+++ b/src/pedro/pedroutil.h
/**
* 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
index 0dd78c5b89ffb4a512e33fc892787d19fdbd04d3..0fa86a6c41e27572255b07362e18b47d6bac08a3 100644 (file)
--- a/src/pedro/pedroxmpp.cpp
+++ b/src/pedro/pedroxmpp.cpp
//## 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'>"
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);
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?
/**
* 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;
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;
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();
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 554cb76c666ae16a2b23a3b6e4bfe7997233f7f6..7f927897fb8f5228018961467eed2626eb7272a4 100644 (file)
--- a/src/pedro/pedroxmpp.h
+++ b/src/pedro/pedroxmpp.h
bool saslPlainAuthenticate();
- bool saslAuthenticate();
+ bool saslAuthenticate(const DOMString &streamId);
bool iqAuthenticate(const DOMString &streamId);