[libgdata] core: Use GHmac instead of HMAC from liboauth



commit 95033d02d73a9d7b6e95d4e201c7f53c60b048af
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun Oct 23 11:24:40 2011 +0100

    core: Use GHmac instead of HMAC from liboauth
    
    This moves us one step closer to dropping the liboauth dependency.
    
    This bumps our GLib dependency to 2.30.0.

 configure.ac                    |    2 +-
 gdata/gdata-oauth1-authorizer.c |   15 ++++++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 5f743eb..0e56919 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,7 +31,7 @@ AC_PATH_PROG([GLIB_GENMARSHAL],[glib-genmarshal])
 AC_PATH_PROG([GLIB_MKENUMS],[glib-mkenums])
 
 # Requirements
-GLIB_REQS=2.19.0
+GLIB_REQS=2.30.0
 GIO_REQS=2.17.3
 SOUP_REQS=2.26.1
 OAUTH_REQS=0.9.4
diff --git a/gdata/gdata-oauth1-authorizer.c b/gdata/gdata-oauth1-authorizer.c
index 42513a4..4b56c41 100644
--- a/gdata/gdata-oauth1-authorizer.c
+++ b/gdata/gdata-oauth1-authorizer.c
@@ -146,6 +146,8 @@
 #include "gdata-oauth1-authorizer.h"
 #include "gdata-private.h"
 
+#define HMAC_SHA1_LEN 20 /* bytes, raw */
+
 static void authorizer_init (GDataAuthorizerInterface *iface);
 static void dispose (GObject *object);
 static void finalize (GObject *object);
@@ -434,6 +436,9 @@ sign_message (GDataOAuth1Authorizer *self, SoupMessage *message, const gchar *to
 	char *nonce;
 	gboolean is_first = TRUE;
 	GTimeVal time_val;
+	guchar signature_buf[HMAC_SHA1_LEN];
+	gsize signature_buf_len;
+	GHmac *signature_hmac;
 
 	g_return_if_fail (GDATA_IS_OAUTH1_AUTHORIZER (self));
 	g_return_if_fail (SOUP_IS_MESSAGE (message));
@@ -539,7 +544,15 @@ sign_message (GDataOAuth1Authorizer *self, SoupMessage *message, const gchar *to
 	}
 
 	/* Create the signature as described here: http://tools.ietf.org/html/rfc5849#section-3.4.2 */
-	signature = oauth_sign_hmac_sha1 (signature_base_string->str, secret_string->str);
+	signature_hmac = g_hmac_new (G_CHECKSUM_SHA1, (const guchar*) secret_string->str, secret_string->len);
+	g_hmac_update (signature_hmac, (const guchar*) signature_base_string->str, signature_base_string->len);
+
+	signature_buf_len = G_N_ELEMENTS (signature_buf);
+	g_hmac_get_digest (signature_hmac, signature_buf, &signature_buf_len);
+
+	g_hmac_unref (signature_hmac);
+
+	signature = g_base64_encode (signature_buf, signature_buf_len);
 
 	/*g_debug ("Signing message using Signature Base String: â%sâ and key â%sâ using method â%sâ to give signature: â%sâ.",
 	         signature_base_string->str, secret_string->str, signature_method, signature);*/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]