/soc/2013/ankitkv/gobjectification: 295cd5bf4c41: Refactored pro...
Ankit Vani
a at nevitus.org
Sat Jun 15 11:47:02 EDT 2013
Changeset: 295cd5bf4c41da0eac5676f169c4888ce8f820f6
Author: Ankit Vani <a at nevitus.org>
Date: 2013-06-15 20:21 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/295cd5bf4c41
Description:
Refactored protocols msn, myspace, oscar, simple, yahoo to use GObject-based PurpleCipher
diffstat:
libpurple/protocols/msn/directconn.c | 11 +-
libpurple/protocols/msn/msnutils.c | 14 +--
libpurple/protocols/msn/nexus.c | 111 ++++++++++++++-------------
libpurple/protocols/msn/notification.c | 12 +-
libpurple/protocols/msn/object.c | 18 ++--
libpurple/protocols/myspace/myspace.c | 38 +++------
libpurple/protocols/myspace/myspace.h | 5 +-
libpurple/protocols/oscar/clientlogin.c | 20 ++--
libpurple/protocols/oscar/family_auth.c | 24 ++---
libpurple/protocols/oscar/family_oservice.c | 22 ++--
libpurple/protocols/oscar/oscar.c | 12 +-
libpurple/protocols/simple/simple.c | 6 +-
libpurple/protocols/yahoo/libymsg.c | 12 +-
13 files changed, 149 insertions(+), 156 deletions(-)
diffs (truncated from 712 to 300 lines):
diff --git a/libpurple/protocols/msn/directconn.c b/libpurple/protocols/msn/directconn.c
--- a/libpurple/protocols/msn/directconn.c
+++ b/libpurple/protocols/msn/directconn.c
@@ -23,7 +23,7 @@
*/
#include "internal.h"
-#include "cipher.h"
+#include "ciphers/sha1.h"
#include "debug.h"
#include "msn.h"
@@ -44,11 +44,10 @@ msn_dc_calculate_nonce_hash(MsnDirectCon
guchar digest[20];
if (type == DC_NONCE_SHA1) {
- PurpleCipher *cipher = purple_ciphers_find_cipher("sha1");
- PurpleCipherContext *context = purple_cipher_context_new(cipher, NULL);
- purple_cipher_context_append(context, nonce, nonce_len);
- purple_cipher_context_digest(context, digest, sizeof(digest));
- purple_cipher_context_destroy(context);
+ PurpleCipher *cipher = purple_sha1_cipher_new();
+ purple_cipher_append(cipher, nonce, nonce_len);
+ purple_cipher_digest(cipher, digest, sizeof(digest));
+ g_object_unref(cipher);
} else if (type == DC_NONCE_PLAIN) {
memcpy(digest, nonce, nonce_len);
} else {
diff --git a/libpurple/protocols/msn/msnutils.c b/libpurple/protocols/msn/msnutils.c
--- a/libpurple/protocols/msn/msnutils.c
+++ b/libpurple/protocols/msn/msnutils.c
@@ -27,7 +27,7 @@
#include "msn.h"
#include "msnutils.h"
-#include "cipher.h"
+#include "ciphers/md5.h"
/**************************************************************************
* Util
@@ -543,7 +543,6 @@ void
msn_handle_chl(char *input, char *output)
{
PurpleCipher *cipher;
- PurpleCipherContext *context;
const guchar productKey[] = MSNP15_WLM_PRODUCT_KEY;
const guchar productID[] = MSNP15_WLM_PRODUCT_ID;
const char hexChars[] = "0123456789abcdef";
@@ -560,13 +559,12 @@ msn_handle_chl(char *input, char *output
int i;
/* Create the MD5 hash by using Purple MD5 algorithm */
- cipher = purple_ciphers_find_cipher("md5");
- context = purple_cipher_context_new(cipher, NULL);
+ cipher = purple_md5_cipher_new();
- purple_cipher_context_append(context, (guchar *)input, strlen(input));
- purple_cipher_context_append(context, productKey, sizeof(productKey) - 1);
- purple_cipher_context_digest(context, md5Hash, sizeof(md5Hash));
- purple_cipher_context_destroy(context);
+ purple_cipher_append(cipher, (guchar *)input, strlen(input));
+ purple_cipher_append(cipher, productKey, sizeof(productKey) - 1);
+ purple_cipher_digest(cipher, md5Hash, sizeof(md5Hash));
+ g_object_unref(cipher);
/* Split it into four integers */
md5Parts = (unsigned int *)md5Hash;
diff --git a/libpurple/protocols/msn/nexus.c b/libpurple/protocols/msn/nexus.c
--- a/libpurple/protocols/msn/nexus.c
+++ b/libpurple/protocols/msn/nexus.c
@@ -23,7 +23,6 @@
*/
#include "internal.h"
-#include "cipher.h"
#include "debug.h"
#include "msnutils.h"
@@ -31,6 +30,10 @@
#include "nexus.h"
#include "notification.h"
+#include "ciphers/des3.h"
+#include "ciphers/hmac.h"
+#include "ciphers/sha1.h"
+
/**************************************************************************
* Valid Ticket Tokens
**************************************************************************/
@@ -99,35 +102,36 @@ rps_create_key(const char *key, int key_
const guchar magic[] = "WS-SecureConversation";
const int magic_len = sizeof(magic) - 1;
- PurpleCipherContext *hmac;
+ PurpleCipher *hmac, *hash;
guchar hash1[20], hash2[20], hash3[20], hash4[20];
char *result;
- hmac = purple_cipher_context_new_by_name("hmac", NULL);
- purple_cipher_context_set_option(hmac, "hash", "sha1");
- purple_cipher_context_set_key(hmac, (guchar *)key, key_len);
+ hash = purple_sha1_cipher_new();
+ hmac = purple_hmac_cipher_new(hash);
+ purple_cipher_set_key(hmac, (guchar *)key, key_len);
- purple_cipher_context_append(hmac, magic, magic_len);
- purple_cipher_context_append(hmac, (guchar *)data, data_len);
- purple_cipher_context_digest(hmac, hash1, sizeof(hash1));
+ purple_cipher_append(hmac, magic, magic_len);
+ purple_cipher_append(hmac, (guchar *)data, data_len);
+ purple_cipher_digest(hmac, hash1, sizeof(hash1));
- purple_cipher_context_reset_state(hmac, NULL);
- purple_cipher_context_append(hmac, hash1, 20);
- purple_cipher_context_append(hmac, magic, magic_len);
- purple_cipher_context_append(hmac, (guchar *)data, data_len);
- purple_cipher_context_digest(hmac, hash2, sizeof(hash2));
+ purple_cipher_reset_state(hmac);
+ purple_cipher_append(hmac, hash1, 20);
+ purple_cipher_append(hmac, magic, magic_len);
+ purple_cipher_append(hmac, (guchar *)data, data_len);
+ purple_cipher_digest(hmac, hash2, sizeof(hash2));
- purple_cipher_context_reset_state(hmac, NULL);
- purple_cipher_context_append(hmac, hash1, 20);
- purple_cipher_context_digest(hmac, hash3, sizeof(hash3));
+ purple_cipher_reset_state(hmac);
+ purple_cipher_append(hmac, hash1, 20);
+ purple_cipher_digest(hmac, hash3, sizeof(hash3));
- purple_cipher_context_reset_state(hmac, NULL);
- purple_cipher_context_append(hmac, hash3, sizeof(hash3));
- purple_cipher_context_append(hmac, magic, magic_len);
- purple_cipher_context_append(hmac, (guchar *)data, data_len);
- purple_cipher_context_digest(hmac, hash4, sizeof(hash4));
+ purple_cipher_reset_state(hmac);
+ purple_cipher_append(hmac, hash3, sizeof(hash3));
+ purple_cipher_append(hmac, magic, magic_len);
+ purple_cipher_append(hmac, (guchar *)data, data_len);
+ purple_cipher_digest(hmac, hash4, sizeof(hash4));
- purple_cipher_context_destroy(hmac);
+ g_object_unref(hmac);
+ g_object_unref(hash);
result = g_malloc(24);
memcpy(result, hash2, sizeof(hash2));
@@ -139,21 +143,21 @@ rps_create_key(const char *key, int key_
static char *
des3_cbc(const char *key, const char *iv, const char *data, int len, gboolean decrypt)
{
- PurpleCipherContext *des3;
+ PurpleCipher *des3;
char *out;
- des3 = purple_cipher_context_new_by_name("des3", NULL);
- purple_cipher_context_set_key(des3, (guchar *)key, 24);
- purple_cipher_context_set_batch_mode(des3, PURPLE_CIPHER_BATCH_MODE_CBC);
- purple_cipher_context_set_iv(des3, (guchar *)iv, 8);
+ des3 = purple_des3_cipher_new();
+ purple_cipher_set_key(des3, (guchar *)key, 24);
+ purple_cipher_set_batch_mode(des3, PURPLE_CIPHER_BATCH_MODE_CBC);
+ purple_cipher_set_iv(des3, (guchar *)iv, 8);
out = g_malloc(len);
if (decrypt)
- purple_cipher_context_decrypt(des3, (guchar *)data, len, (guchar *)out, len);
+ purple_cipher_decrypt(des3, (guchar *)data, len, (guchar *)out, len);
else
- purple_cipher_context_encrypt(des3, (guchar *)data, len, (guchar *)out, len);
+ purple_cipher_encrypt(des3, (guchar *)data, len, (guchar *)out, len);
- purple_cipher_context_destroy(des3);
+ g_object_unref(des3);
return out;
}
@@ -168,7 +172,7 @@ msn_rps_encrypt(MsnNexus *nexus)
char usr_key_base[MSN_USER_KEY_SIZE], *usr_key;
const char magic1[] = "SESSION KEY HASH";
const char magic2[] = "SESSION KEY ENCRYPTION";
- PurpleCipherContext *hmac;
+ PurpleCipher *hmac, *hasher;
size_t len;
guchar *hash;
char *key1, *key2, *key3;
@@ -199,12 +203,13 @@ msn_rps_encrypt(MsnNexus *nexus)
key3 = rps_create_key(key1, key1_len, magic2, sizeof(magic2) - 1);
len = strlen(nexus->nonce);
- hmac = purple_cipher_context_new_by_name("hmac", NULL);
- purple_cipher_context_set_option(hmac, "hash", "sha1");
- purple_cipher_context_set_key(hmac, (guchar *)key2, 24);
- purple_cipher_context_append(hmac, (guchar *)nexus->nonce, len);
- purple_cipher_context_digest(hmac, hash, 20);
- purple_cipher_context_destroy(hmac);
+ hasher = purple_sha1_cipher_new();
+ hmac = purple_hmac_cipher_new(hasher);
+ purple_cipher_set_key(hmac, (guchar *)key2, 24);
+ purple_cipher_append(hmac, (guchar *)nexus->nonce, len);
+ purple_cipher_digest(hmac, hash, 20);
+ g_object_unref(hmac);
+ g_object_unref(hasher);
/* We need to pad this to 72 bytes, apparently */
nonce_fixed = g_malloc(len + 8);
@@ -508,8 +513,8 @@ msn_nexus_update_token(MsnNexus *nexus,
MsnSession *session = nexus->session;
MsnNexusUpdateData *ud;
MsnNexusUpdateCallback *update;
- PurpleCipherContext *sha1;
- PurpleCipherContext *hmac;
+ PurpleCipher *sha1;
+ PurpleCipher *hmac;
char *key;
@@ -560,7 +565,7 @@ msn_nexus_update_token(MsnNexus *nexus,
ud->nexus = nexus;
ud->id = id;
- sha1 = purple_cipher_context_new_by_name("sha1", NULL);
+ sha1 = purple_sha1_cipher_new();
domain = g_strdup_printf(MSN_SSO_RST_TEMPLATE,
id,
@@ -568,8 +573,8 @@ msn_nexus_update_token(MsnNexus *nexus,
ticket_domains[id][SSO_VALID_TICKET_POLICY] != NULL ?
ticket_domains[id][SSO_VALID_TICKET_POLICY] :
nexus->policy);
- purple_cipher_context_append(sha1, (guchar *)domain, strlen(domain));
- purple_cipher_context_digest(sha1, digest, 20);
+ purple_cipher_append(sha1, (guchar *)domain, strlen(domain));
+ purple_cipher_digest(sha1, digest, 20);
domain_b64 = purple_base64_encode(digest, 20);
now = time(NULL);
@@ -580,13 +585,13 @@ msn_nexus_update_token(MsnNexus *nexus,
timestamp = g_strdup_printf(MSN_SSO_TIMESTAMP_TEMPLATE,
now_str,
purple_utf8_strftime("%Y-%m-%dT%H:%M:%SZ", tm));
- purple_cipher_context_reset(sha1, NULL);
- purple_cipher_context_append(sha1, (guchar *)timestamp, strlen(timestamp));
- purple_cipher_context_digest(sha1, digest, 20);
+ purple_cipher_reset(sha1);
+ purple_cipher_append(sha1, (guchar *)timestamp, strlen(timestamp));
+ purple_cipher_digest(sha1, digest, 20);
timestamp_b64 = purple_base64_encode(digest, 20);
g_free(now_str);
- purple_cipher_context_destroy(sha1);
+ purple_cipher_reset(sha1);
signedinfo = g_strdup_printf(MSN_SSO_SIGNEDINFO_TEMPLATE,
id,
@@ -598,12 +603,14 @@ msn_nexus_update_token(MsnNexus *nexus,
nonce_b64 = purple_base64_encode((guchar *)&nonce, sizeof(nonce));
key = rps_create_key(nexus->secret, 24, (char *)nonce, sizeof(nonce));
- hmac = purple_cipher_context_new_by_name("hmac", NULL);
- purple_cipher_context_set_option(hmac, "hash", "sha1");
- purple_cipher_context_set_key(hmac, (guchar *)key, 24);
- purple_cipher_context_append(hmac, (guchar *)signedinfo, strlen(signedinfo));
- purple_cipher_context_digest(hmac, signature, 20);
- purple_cipher_context_destroy(hmac);
+ hmac = purple_hmac_cipher_new(sha1);
+ purple_cipher_set_key(hmac, (guchar *)key, 24);
+ purple_cipher_append(hmac, (guchar *)signedinfo, strlen(signedinfo));
+ purple_cipher_digest(hmac, signature, 20);
+
+ g_object_unref(hmac);
+ g_object_unref(sha1);
+
signature_b64 = purple_base64_encode(signature, 20);
request = g_strdup_printf(MSN_SSO_TOKEN_UPDATE_TEMPLATE,
diff --git a/libpurple/protocols/msn/notification.c b/libpurple/protocols/msn/notification.c
--- a/libpurple/protocols/msn/notification.c
+++ b/libpurple/protocols/msn/notification.c
@@ -23,7 +23,7 @@
*/
#include "internal.h"
-#include "cipher.h"
+#include "ciphers/md5.h"
#include "core.h"
#include "debug.h"
@@ -1394,7 +1394,7 @@ url_cmd(MsnCmdProc *cmdproc, MsnCommand
PurpleAccount *account;
const char *rru;
const char *url;
- PurpleCipherContext *cipher;
+ PurpleCipher *cipher;
gchar creds[33];
char *buf;
@@ -1415,10 +1415,10 @@ url_cmd(MsnCmdProc *cmdproc, MsnCommand
tmp_timestamp,
purple_connection_get_password(gc));
More information about the Commits
mailing list