Blame SOURCES/SASL-fix-facebook-mechanism.patch

6ab996
From 761a83d9e7408d0e47e8c279052b93f8d9edb511 Mon Sep 17 00:00:00 2001
6ab996
From: Xavier Claessens <xavier.claessens@collabora.co.uk>
6ab996
Date: Thu, 31 Oct 2013 13:39:21 -0400
6ab996
Subject: [PATCH] SASL: fix facebook mechanism
6ab996
6ab996
libsoup was escaping '_' and '.' in the challenge response but the
6ab996
facebook server is not expecting that.
6ab996
6ab996
https://bugzilla.gnome.org/show_bug.cgi?id=707747
6ab996
---
6ab996
 libempathy/empathy-sasl-mechanisms.c | 33 +++++++++++++++++----------------
6ab996
 1 file changed, 17 insertions(+), 16 deletions(-)
6ab996
6ab996
diff --git a/libempathy/empathy-sasl-mechanisms.c b/libempathy/empathy-sasl-mechanisms.c
6ab996
index ffb3aa4..05a2de9 100644
6ab996
--- a/libempathy/empathy-sasl-mechanisms.c
6ab996
+++ b/libempathy/empathy-sasl-mechanisms.c
6ab996
@@ -156,8 +156,7 @@ facebook_new_challenge_cb (TpChannel *channel,
6ab996
   GSimpleAsyncResult *result = user_data;
6ab996
   FacebookData *data;
6ab996
   GHashTable *h;
6ab996
-  GHashTable *params;
6ab996
-  gchar *response;
6ab996
+  GString *response_string;
6ab996
   GArray *response_array;
6ab996
 
6ab996
   DEBUG ("new challenge: %s", challenge->data);
6ab996
@@ -166,27 +165,29 @@ facebook_new_challenge_cb (TpChannel *channel,
6ab996
 
6ab996
   h = soup_form_decode (challenge->data);
6ab996
 
6ab996
-  /* See https://developers.facebook.com/docs/chat/#platauth */
6ab996
-  params = g_hash_table_new (g_str_hash, g_str_equal);
6ab996
-  g_hash_table_insert (params, "method", g_hash_table_lookup (h, "method"));
6ab996
-  g_hash_table_insert (params, "nonce", g_hash_table_lookup (h, "nonce"));
6ab996
-  g_hash_table_insert (params, "access_token", data->access_token);
6ab996
-  g_hash_table_insert (params, "api_key", data->client_id);
6ab996
-  g_hash_table_insert (params, "call_id", "0");
6ab996
-  g_hash_table_insert (params, "v", "1.0");
6ab996
-
6ab996
-  response = soup_form_encode_hash (params);
6ab996
-  DEBUG ("Response: %s", response);
6ab996
+  /* See https://developers.facebook.com/docs/chat/#platauth.
6ab996
+   * We don't use soup_form_encode() here because it would escape parameters
6ab996
+   * and facebook server is not expecting that and would reject the response. */
6ab996
+  response_string = g_string_new ("v=1.0&call_id=0");
6ab996
+  g_string_append (response_string, "&access_token=");
6ab996
+  g_string_append_uri_escaped (response_string, data->access_token, NULL, TRUE);
6ab996
+  g_string_append (response_string, "&api_key=");
6ab996
+  g_string_append_uri_escaped (response_string, data->client_id, NULL, TRUE);
6ab996
+  g_string_append (response_string, "&method=");
6ab996
+  g_string_append_uri_escaped (response_string, g_hash_table_lookup (h, "method"), NULL, TRUE);
6ab996
+  g_string_append (response_string, "&nonce=");
6ab996
+  g_string_append_uri_escaped (response_string, g_hash_table_lookup (h, "nonce"), NULL, TRUE);
6ab996
+
6ab996
+  DEBUG ("Response: %s", response_string->str);
6ab996
 
6ab996
   response_array = g_array_new (FALSE, FALSE, sizeof (gchar));
6ab996
-  g_array_append_vals (response_array, response, strlen (response));
6ab996
+  g_array_append_vals (response_array, response_string->str, response_string->len);
6ab996
 
6ab996
   tp_cli_channel_interface_sasl_authentication_call_respond (data->channel, -1,
6ab996
       response_array, generic_cb, g_object_ref (result), g_object_unref, NULL);
6ab996
 
6ab996
   g_hash_table_unref (h);
6ab996
-  g_hash_table_unref (params);
6ab996
-  g_free (response);
6ab996
+  g_string_free (response_string, TRUE);
6ab996
   g_array_unref (response_array);
6ab996
 }
6ab996
 
6ab996
-- 
6ab996
1.8.3.2