summaryrefslogtreecommitdiff
path: root/protocols/JabberG/src/jabber_thread.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-12-02 17:08:53 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-12-02 17:08:53 +0300
commit51a49fa28205229010e9f4d29b7674889d97d8e2 (patch)
tree25b385da05a7d7db9066f47174fb13befc015401 /protocols/JabberG/src/jabber_thread.cpp
parent7e939a1efe055c425465de20489b4760b5e12374 (diff)
code cleaning
Diffstat (limited to 'protocols/JabberG/src/jabber_thread.cpp')
-rw-r--r--protocols/JabberG/src/jabber_thread.cpp46
1 files changed, 31 insertions, 15 deletions
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp
index b5b13ce4ec..77bad05c20 100644
--- a/protocols/JabberG/src/jabber_thread.cpp
+++ b/protocols/JabberG/src/jabber_thread.cpp
@@ -634,8 +634,15 @@ void CJabberProto::PerformAuthentication(ThreadData *info)
return;
}
+ // grab the safest mechanism and proceed
auto &auth = m_arAuthMechs[0];
- info->send(XmlNode("auth", ptrA(auth.getInitialRequest())) << XATTR("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl") << XATTR("mechanism", auth.getName()));
+
+ if (m_hasSasl2) {
+ XmlNode node("authenticate");
+ node << XATTR("xmlns", JABBER_FEAT_SASL2) << XATTR("mechanism", auth.getName()) << XCHILD("initial-response", auth.getInitialRequest());
+ info->send(node);
+ }
+ else info->send(XmlNode("auth", ptrA(auth.getInitialRequest())) << XATTR("xmlns", JABBER_FEAT_SASL) << XATTR("mechanism", auth.getName()));
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -756,7 +763,7 @@ void CJabberProto::OnProcessFailure(const TiXmlElement *node, ThreadData *info)
{
// failure xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"
const char *type = XmlGetAttr(node, "xmlns");
- if (!mir_strcmp(type, "urn:ietf:params:xml:ns:xmpp-sasl")) {
+ if (!mir_strcmp(type, JABBER_FEAT_SASL) || !mir_strcmp(type, JABBER_FEAT_SASL2)) {
m_arAuthMechs.remove(0L);
PerformAuthentication(info);
}
@@ -812,20 +819,28 @@ void CJabberProto::OnProcessSuccess(const TiXmlElement *node, ThreadData *info)
if ((type = XmlGetAttr(node, "xmlns")) == nullptr)
return;
- if (!mir_strcmp(type, "urn:ietf:params:xml:ns:xmpp-sasl")) {
- if (!m_arAuthMechs[0].validateLogin(node->GetText())) {
- info->send("</stream:stream>");
- return;
- }
+ const char *pszFinal;
+ if (!mir_strcmp(type, JABBER_FEAT_SASL))
+ pszFinal = node->GetText();
+ else if (!mir_strcmp(type, JABBER_FEAT_SASL2))
+ pszFinal = XmlGetChildText(node, "additional-data");
+ else {
+ debugLogA("Success: unknown action %s.", type);
+ return;
+ }
+
+ if (!pszFinal || !m_arAuthMechs[0].validateLogin(pszFinal)) {
+ info->send("</stream:stream>");
+ return;
+ }
- debugLogA("Success: Logged-in.");
- ptrA szNick(getUStringA("Nick"));
- if (!mir_strlen(szNick))
- setUString("Nick", info->conn.username);
+ debugLogA("Success: Logged-in.");
+ ptrA szNick(getUStringA("Nick"));
+ if (!mir_strlen(szNick))
+ setUString("Nick", info->conn.username);
+ if (!m_hasSasl2)
xmlStreamInitialize("after successful sasl");
- }
- else debugLogA("Success: unknown action %s.", type);
}
void CJabberProto::OnProcessChallenge(const TiXmlElement *node, ThreadData *info)
@@ -835,11 +850,12 @@ void CJabberProto::OnProcessChallenge(const TiXmlElement *node, ThreadData *info
return;
}
- if (mir_strcmp(XmlGetAttr(node, "xmlns"), "urn:ietf:params:xml:ns:xmpp-sasl"))
+ auto *xmlns = XmlGetAttr(node, "xmlns");
+ if (mir_strcmp(xmlns, JABBER_FEAT_SASL) && mir_strcmp(xmlns, JABBER_FEAT_SASL2))
return;
char *challenge = m_arAuthMechs[0].getChallenge(node->GetText());
- info->send(XmlNode("response", challenge) << XATTR("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl"));
+ info->send(XmlNode("response", challenge) << XATTR("xmlns", xmlns));
mir_free(challenge);
}