changeset 31617:504a65e03514

Remove some struct packing from code that does login. I think this is the cause of the broken login on PPC. Refs #14132.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Fri, 20 May 2011 22:29:29 +0000
parents 3268f7da72c6
children 3e53f6871805
files libpurple/protocols/msn/nexus.c libpurple/protocols/msn/nexus.h
diffstat 2 files changed, 23 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/nexus.c	Fri May 20 04:19:13 2011 +0000
+++ b/libpurple/protocols/msn/nexus.c	Fri May 20 22:29:29 2011 +0000
@@ -26,6 +26,7 @@
 #include "cipher.h"
 #include "debug.h"
 
+#include "msnutils.h"
 #include "soap.h"
 #include "nexus.h"
 #include "notification.h"
@@ -165,42 +166,46 @@
 	return out;
 }
 
+#define MSN_USER_KEY_SIZE (7*4 + 8 + 20 + 72)
 #define CRYPT_MODE_CBC 1
 #define CIPHER_TRIPLE_DES 0x6603
 #define HASH_SHA1 0x8004
 static char *
 msn_rps_encrypt(MsnNexus *nexus)
 {
-	MsnUsrKey *usr_key;
+	char usr_key_base[MSN_USER_KEY_SIZE], *usr_key;
 	const char magic1[] = "SESSION KEY HASH";
 	const char magic2[] = "SESSION KEY ENCRYPTION";
 	PurpleCipherContext *hmac;
 	size_t len;
-	guchar hash[20];
+	guchar *hash;
 	char *key1, *key2, *key3;
 	gsize key1_len;
-	int *iv;
+	const char *iv;
 	char *nonce_fixed;
 	char *cipher;
 	char *response;
 
-	usr_key = g_malloc(sizeof(MsnUsrKey));
-	usr_key->size = GUINT32_TO_LE(28);
-	usr_key->crypt_mode = GUINT32_TO_LE(CRYPT_MODE_CBC);
-	usr_key->cipher_type = GUINT32_TO_LE(CIPHER_TRIPLE_DES);
-	usr_key->hash_type = GUINT32_TO_LE(HASH_SHA1);
-	usr_key->iv_len = GUINT32_TO_LE(8);
-	usr_key->hash_len = GUINT32_TO_LE(20);
-	usr_key->cipher_len = GUINT32_TO_LE(72);
+	usr_key = &usr_key_base[0];
+	/* Header */
+	msn_push32le(usr_key, 28);                  /* Header size */
+	msn_push32le(usr_key, CRYPT_MODE_CBC);      /* Crypt mode */
+	msn_push32le(usr_key, CIPHER_TRIPLE_DES);   /* Cipher type */
+	msn_push32le(usr_key, HASH_SHA1);           /* Hash type */
+	msn_push32le(usr_key, 8);                   /* IV size */
+	msn_push32le(usr_key, 20);                  /* Hash size */
+	msn_push32le(usr_key, 72);                  /* Cipher size */
+	/* Data */
+	iv = usr_key;
+	msn_push32le(usr_key, rand());
+	msn_push32le(usr_key, rand());
+	hash = (guchar *)usr_key;
+	usr_key += 20;  /* Remaining is cipher data */
 
 	key1 = (char *)purple_base64_decode((const char *)nexus->tokens[MSN_AUTH_MESSENGER].secret, &key1_len);
 	key2 = rps_create_key(key1, key1_len, magic1, sizeof(magic1) - 1);
 	key3 = rps_create_key(key1, key1_len, magic2, sizeof(magic2) - 1);
 
-	iv = (int *)usr_key->iv;
-	iv[0] = rand();
-	iv[1] = rand();
-
 	len = strlen(nexus->nonce);
 	hmac = purple_cipher_context_new_by_name("hmac", NULL);
 	purple_cipher_context_set_option(hmac, "hash", "sha1");
@@ -213,20 +218,17 @@
 	nonce_fixed = g_malloc(len + 8);
 	memcpy(nonce_fixed, nexus->nonce, len);
 	memset(nonce_fixed + len, 0x08, 8);
-	cipher = des3_cbc(key3, usr_key->iv, nonce_fixed, len + 8, FALSE);
+	cipher = des3_cbc(key3, iv, nonce_fixed, len + 8, FALSE);
 	g_free(nonce_fixed);
 
-	memcpy(usr_key->hash, hash, 20);
-	memcpy(usr_key->cipher, cipher, 72);
+	memcpy(usr_key, cipher, 72);
 
 	g_free(key1);
 	g_free(key2);
 	g_free(key3);
 	g_free(cipher);
 
-	response = purple_base64_encode((guchar *)usr_key, sizeof(MsnUsrKey));
-
-	g_free(usr_key);
+	response = purple_base64_encode((guchar *)usr_key_base, MSN_USER_KEY_SIZE);
 
 	return response;
 }
--- a/libpurple/protocols/msn/nexus.h	Fri May 20 04:19:13 2011 +0000
+++ b/libpurple/protocols/msn/nexus.h	Fri May 20 22:29:29 2011 +0000
@@ -28,7 +28,6 @@
 
 typedef struct _MsnNexus MsnNexus;
 typedef struct _MsnTicketToken MsnTicketToken;
-typedef struct _MsnUsrKey MsnUsrKey;
 
 /* Index into ticket_tokens in nexus.c Keep updated! */
 typedef enum
@@ -189,21 +188,6 @@
 	"</Body>"\
 "</Envelope>"
 
-struct _MsnUsrKey
-{
-	int size; /* 28. Does not count data */
-	int crypt_mode; /* CRYPT_MODE_CBC (1) */
-	int cipher_type; /* TripleDES (0x6603) */
-	int hash_type; /* SHA1 (0x8004) */
-	int iv_len;    /* 8 */
-	int hash_len;  /* 20 */
-	int cipher_len; /* 72 */
-	/* Data */
-	char iv[8];
-	char hash[20];
-	char cipher[72];
-};
-
 struct _MsnTicketToken {
 	GHashTable *token;
 	char *secret;