proxy advertises only SASL PLAIN mechanism if it is supported by server
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 9 Dec 2006 01:33:11 +0000 (01:33 +0000)
committerThadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
Sat, 9 Dec 2006 01:33:11 +0000 (01:33 +0000)
If server supports SASL PLAIN mechanism, instead of advertising all
supported mechanisms to client, the proxy advertises only PLAIN. This
way, client is forced to use PLAIN. If server does not support or
allow use of PLAIN mechanism, proxy announces all of them. In the
future, it will announce only PLAIN and use whichever mechanism is
safer in the path from proxy to server.

jabber_server.c

index 728aab4..96641ac 100644 (file)
@@ -61,6 +61,44 @@ void jabber_server_tls_filter (iks* node)
     }
 }
 
+void jabber_server_sasl_filter (iks* node)
+{
+  iks* sasl;
+  GString* mechs = NULL;
+  gboolean plain = FALSE;
+  if (g_str_equal (iks_name (node), "stream:features"))
+    {
+      sasl = iks_find (node, "mechanisms");
+      if (sasl && g_str_equal (iks_find_attrib (sasl, "xmlns"),
+                              "urn:ietf:params:xml:ns:xmpp-sasl"))
+       {
+         mechs = g_string_sized_new (256);
+         iks* mech;
+         for (mech = iks_child (sasl); mech != NULL; mech = iks_next (mech))
+           {
+             char* mech_name;
+             mech_name = iks_cdata (iks_child (mech));
+             if (g_str_equal (mech_name, "PLAIN"))
+               plain = TRUE;
+             mechs = g_string_append (mechs, mech_name);
+             mechs = g_string_append_c (mechs, ' ');
+           }
+         g_debug ("Mechanisms supported by server: %s", mechs->str);
+         g_string_free (mechs, TRUE);
+         if (plain)
+           {
+             for (mech = iks_child (sasl); mech != NULL; mech = iks_next (mech))
+               {
+                 char* mech_name;
+                 mech_name = iks_cdata (iks_child (mech));
+                 if (!g_str_equal (mech_name, "PLAIN"))
+                   iks_hide (mech);
+               }
+           }
+       }
+    }
+}
+
 int jabber_server_parser (gpointer data, int type, iks* node)
 {
   net_hook_t* hook;
@@ -76,6 +114,7 @@ int jabber_server_parser (gpointer data, int type, iks* node)
       break;
     case IKS_NODE_NORMAL:
       jabber_server_tls_filter (node);
+      jabber_server_sasl_filter (node);
       buffer = g_string_new (iks_string (iks_stack (node), node));
       gnet_conn_write (hook->peer->conn, buffer->str, buffer->len);
       g_string_free (buffer, TRUE);