pidgin: b8354dfc: Remove some struct packing from code tha...

qulogic at pidgin.im qulogic at pidgin.im
Fri May 20 18:35:41 EDT 2011


----------------------------------------------------------------------
Revision: b8354dfc19eecdfd2aecfdb2685fbd78b9010587
Parent:   c5ff15b5ec091a257bfe57b1a21de743d77bd723
Author:   qulogic at pidgin.im
Date:     05/20/11 18:29:29
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/b8354dfc19eecdfd2aecfdb2685fbd78b9010587

Changelog: 

Remove some struct packing from code that does login. I think this is
the cause of the broken login on PPC.

Refs #14132.

Changes against parent c5ff15b5ec091a257bfe57b1a21de743d77bd723

  patched  libpurple/protocols/msn/nexus.c
  patched  libpurple/protocols/msn/nexus.h

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/nexus.c	58bfa96db1c7bba42bf2d6bf0ab4f099b0ca294a
+++ libpurple/protocols/msn/nexus.c	3fdfb40d70dba287aa7341a5f69c9ffb57b2ff92
@@ -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 @@ des3_cbc(const char *key, const char *iv
 	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,21 +218,18 @@ msn_rps_encrypt(MsnNexus *nexus)
 	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));
+	response = purple_base64_encode((guchar *)usr_key_base, MSN_USER_KEY_SIZE);
 
-	g_free(usr_key);
-
 	return response;
 }
 
============================================================
--- libpurple/protocols/msn/nexus.h	08edca2e593ae8f002c790743d682e697249a509
+++ libpurple/protocols/msn/nexus.h	92b1fe81d4a1a034bca325881ffe9bf1cf7e0418
@@ -28,7 +28,6 @@ typedef struct _MsnTicketToken MsnTicket
 
 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 @@ typedef enum
 	"</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;


More information about the Commits mailing list