/soc/2013/ankitkv/gobjectification: 7ed9e7b31bad: Merged default...

Ankit Vani a at nevitus.org
Wed Apr 2 22:36:31 EDT 2014


Changeset: 7ed9e7b31bad88ee60542c57a0f5af6b6ad56991
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2014-04-03 08:06 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/7ed9e7b31bad

Description:

Merged default branch

diffstat:

 libpurple/ciphers/aescipher.c                  |  102 +++++-
 libpurple/plugins/tcl/tcl_glib.c               |    3 +-
 libpurple/protocols/bonjour/bonjour_ft.c       |    7 +-
 libpurple/protocols/bonjour/jabber.c           |   46 +-
 libpurple/protocols/gg/resolver-purple.c       |   20 +-
 libpurple/protocols/irc/dcc_send.c             |    4 +-
 libpurple/protocols/jabber/disco.c             |   14 +-
 libpurple/protocols/jabber/google/jingleinfo.c |   14 +-
 libpurple/protocols/msn/directconn.c           |   12 +-
 libpurple/protocols/msn/msnutils.c             |   54 ++-
 libpurple/protocols/msn/p2p.c                  |    8 +-
 libpurple/protocols/msn/slpcall.c              |   18 +-
 libpurple/protocols/msn/tlv.c                  |    2 +-
 libpurple/protocols/msn/tlv.h                  |    2 +-
 libpurple/protocols/mxit/Makefile.am           |    6 +-
 libpurple/protocols/mxit/actions.c             |    2 +-
 libpurple/protocols/mxit/aes.c                 |  405 -------------------------
 libpurple/protocols/mxit/aes.h                 |   39 --
 libpurple/protocols/mxit/cipher.c              |  272 +++-------------
 libpurple/protocols/mxit/cipher.h              |   29 +-
 libpurple/protocols/mxit/client.c              |   13 +-
 libpurple/protocols/mxit/login.c               |    2 +-
 libpurple/protocols/yahoo/ymsg.c               |    2 +-
 23 files changed, 281 insertions(+), 795 deletions(-)

diffs (truncated from 1626 to 300 lines):

diff --git a/libpurple/ciphers/aescipher.c b/libpurple/ciphers/aescipher.c
--- a/libpurple/ciphers/aescipher.c
+++ b/libpurple/ciphers/aescipher.c
@@ -58,6 +58,7 @@ typedef struct {
 	guchar key[32];
 	guint key_size;
 	gboolean failure;
+	PurpleCipherBatchMode batch_mode;
 } PurpleAESCipherPrivate;
 
 /******************************************************************************
@@ -82,7 +83,8 @@ static GParamSpec *properties[PROP_LAST]
 
 typedef gboolean (*purple_aes_cipher_crypt_func)(
 	const guchar *input, guchar *output, size_t len,
-	guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size);
+	guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size,
+	PurpleCipherBatchMode batch_mode);
 
 static void
 purple_aes_cipher_reset(PurpleCipher *cipher)
@@ -232,11 +234,32 @@ purple_aes_cipher_gnutls_crypt_init(guch
 
 static gboolean
 purple_aes_cipher_gnutls_encrypt(const guchar *input, guchar *output, size_t len,
-	guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size)
+	guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size,
+	PurpleCipherBatchMode batch_mode)
 {
 	gnutls_cipher_hd_t handle;
 	int ret;
 
+	/* We have to simulate ECB mode, which is not supported by GnuTLS. */
+	if (batch_mode == PURPLE_CIPHER_BATCH_MODE_ECB) {
+		size_t i;
+		for (i = 0; i < len / PURPLE_AES_BLOCK_SIZE; i++) {
+			int offset = i * PURPLE_AES_BLOCK_SIZE;
+			guchar iv_local[PURPLE_AES_BLOCK_SIZE];
+			gboolean succ;
+
+			memcpy(iv_local, iv, sizeof(iv_local));
+			succ = purple_aes_cipher_gnutls_encrypt(
+				input + offset, output + offset,
+				PURPLE_AES_BLOCK_SIZE,
+				iv_local, key, key_size,
+				PURPLE_CIPHER_BATCH_MODE_CBC);
+			if (!succ)
+				return FALSE;
+		}
+		return TRUE;
+	}
+
 	handle = purple_aes_cipher_gnutls_crypt_init(iv, key, key_size);
 	if (handle == NULL)
 		return FALSE;
@@ -255,11 +278,32 @@ purple_aes_cipher_gnutls_encrypt(const g
 
 static gboolean
 purple_aes_cipher_gnutls_decrypt(const guchar *input, guchar *output, size_t len,
-	guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size)
+	guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size,
+	PurpleCipherBatchMode batch_mode)
 {
 	gnutls_cipher_hd_t handle;
 	int ret;
 
+	/* We have to simulate ECB mode, which is not supported by GnuTLS. */
+	if (batch_mode == PURPLE_CIPHER_BATCH_MODE_ECB) {
+		size_t i;
+		for (i = 0; i < len / PURPLE_AES_BLOCK_SIZE; i++) {
+			int offset = i * PURPLE_AES_BLOCK_SIZE;
+			guchar iv_local[PURPLE_AES_BLOCK_SIZE];
+			gboolean succ;
+
+			memcpy(iv_local, iv, sizeof(iv_local));
+			succ = purple_aes_cipher_gnutls_decrypt(
+				input + offset, output + offset,
+				PURPLE_AES_BLOCK_SIZE,
+				iv_local, key, key_size,
+				PURPLE_CIPHER_BATCH_MODE_CBC);
+			if (!succ)
+				return FALSE;
+		}
+		return TRUE;
+	}
+
 	handle = purple_aes_cipher_gnutls_crypt_init(iv, key, key_size);
 	if (handle == NULL)
 		return FALSE;
@@ -305,10 +349,9 @@ purple_aes_cipher_nss_cleanup(PurpleAESC
 static gboolean
 purple_aes_cipher_nss_crypt(const guchar *input, guchar *output, size_t len,
 	guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size,
-	CK_ATTRIBUTE_TYPE operation)
+	CK_ATTRIBUTE_TYPE operation, CK_MECHANISM_TYPE cipher_mech)
 {
 	PurpleAESCipherNSSContext context;
-	CK_MECHANISM_TYPE cipher_mech = CKM_AES_CBC;
 	SECItem key_item, iv_item;
 	SECStatus ret;
 	int outlen = 0;
@@ -385,28 +428,41 @@ purple_aes_cipher_nss_crypt(const guchar
 	outlen += outlen_tmp;
 	if (outlen != (int)len) {
 		purple_debug_error("cipher-aes",
-			"resulting length doesn't match: %d (expected: %lu)\n",
-			outlen, len);
+			"resulting length doesn't match: %d (expected: %"
+			G_GSIZE_FORMAT ")\n", outlen, len);
 		return FALSE;
 	}
 
 	return TRUE;
 }
 
+static CK_MECHANISM_TYPE
+purple_aes_cipher_nss_batch_mode(PurpleCipherBatchMode batch_mode)
+{
+	switch (batch_mode) {
+		case PURPLE_CIPHER_BATCH_MODE_CBC:
+			return CKM_AES_CBC;
+		case PURPLE_CIPHER_BATCH_MODE_ECB:
+			return CKM_AES_ECB;
+	}
+}
+
 static gboolean
 purple_aes_cipher_nss_encrypt(const guchar *input, guchar *output, size_t len,
-	guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size)
+	guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size,
+	PurpleCipherBatchMode batch_mode)
 {
 	return purple_aes_cipher_nss_crypt(input, output, len, iv, key, key_size,
-		CKA_ENCRYPT);
+		CKA_ENCRYPT, purple_aes_cipher_nss_batch_mode(batch_mode));
 }
 
 static gboolean
 purple_aes_cipher_nss_decrypt(const guchar *input, guchar *output, size_t len,
-	guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size)
+	guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size,
+	PurpleCipherBatchMode batch_mode)
 {
 	return purple_aes_cipher_nss_crypt(input, output, len, iv, key, key_size,
-		CKA_DECRYPT);
+		CKA_DECRYPT, purple_aes_cipher_nss_batch_mode(batch_mode));
 }
 
 #endif /* PURPLE_AES_USE_NSS */
@@ -427,7 +483,8 @@ purple_aes_cipher_encrypt(PurpleCipher *
 	input_padded = purple_aes_cipher_pad_pkcs7(input, in_len, &out_len);
 
 	if (out_len > out_size) {
-		purple_debug_error("cipher-aes", "Output buffer too small\n");
+		purple_debug_error("cipher-aes",
+			"Output buffer too small (%d > %d)", out_len, out_size);
 		memset(input_padded, 0, out_len);
 		g_free(input_padded);
 		return -1;
@@ -443,7 +500,7 @@ purple_aes_cipher_encrypt(PurpleCipher *
 #endif
 
 	succ = encrypt_func(input_padded, output, out_len, priv->iv,
-		priv->key, priv->key_size);
+		priv->key, priv->key_size, priv->batch_mode);
 
 	memset(input_padded, 0, out_len);
 	g_free(input_padded);
@@ -488,7 +545,7 @@ purple_aes_cipher_decrypt(PurpleCipher *
 #endif
 
 	succ = decrypt_func(input, output, in_len, priv->iv, priv->key,
-		priv->key_size);
+		priv->key_size, priv->batch_mode);
 
 	if (!succ) {
 		memset(output, 0, in_len);
@@ -518,18 +575,24 @@ purple_aes_cipher_set_batch_mode(PurpleC
 {
 	PurpleAESCipherPrivate *priv = PURPLE_AES_CIPHER_GET_PRIVATE(cipher);
 
-	if (mode != PURPLE_CIPHER_BATCH_MODE_CBC) {
+	if (mode != PURPLE_CIPHER_BATCH_MODE_CBC &&
+		mode != PURPLE_CIPHER_BATCH_MODE_ECB)
+	{
 		purple_debug_error("cipher-aes", "unsupported batch mode\n");
 		priv->failure = TRUE;
 	}
 
+	priv->batch_mode = mode;
+
 	g_object_notify_by_pspec(G_OBJECT(cipher), properties[PROP_BATCH_MODE]);
 }
 
 static PurpleCipherBatchMode
 purple_aes_cipher_get_batch_mode(PurpleCipher *cipher)
 {
-	return PURPLE_CIPHER_BATCH_MODE_CBC;
+	PurpleAESCipherPrivate *priv = PURPLE_AES_CIPHER_GET_PRIVATE(cipher);
+
+	return priv->batch_mode;
 }
 
 static size_t
@@ -605,9 +668,10 @@ purple_aes_cipher_class_init(PurpleAESCi
 
 	g_type_class_add_private(klass, sizeof(PurpleAESCipherPrivate));
 
-	properties[PROP_BATCH_MODE] = g_param_spec_enum("batch-mode", "batch-mode",
-							  "batch-mode", PURPLE_TYPE_CIPHER_BATCH_MODE, 0,
-							  G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+	properties[PROP_BATCH_MODE] = g_param_spec_enum("batch-mode",
+		"batch-mode", "batch-mode", PURPLE_TYPE_CIPHER_BATCH_MODE,
+		PURPLE_CIPHER_BATCH_MODE_CBC,
+		G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
 
 	properties[PROP_IV] = g_param_spec_string("iv", "iv", "iv", NULL,
 								G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
diff --git a/libpurple/plugins/tcl/tcl_glib.c b/libpurple/plugins/tcl/tcl_glib.c
--- a/libpurple/plugins/tcl/tcl_glib.c
+++ b/libpurple/plugins/tcl/tcl_glib.c
@@ -224,7 +224,8 @@ static gboolean tcl_file_callback(GIOCha
 		return TRUE;
 
 	tfh->pending |= mask;
-	fev = (struct tcl_file_event *)ckalloc(sizeof(struct tcl_file_event));
+	/* ckalloc returns memory "suitably aligned for any use" */
+	fev = (gpointer)ckalloc(sizeof(struct tcl_file_event));
 	memset(fev, 0, sizeof(struct tcl_file_event));
 	fev->header.proc = tcl_file_event_callback;
 	fev->fd = tfh->fd;
diff --git a/libpurple/protocols/bonjour/bonjour_ft.c b/libpurple/protocols/bonjour/bonjour_ft.c
--- a/libpurple/protocols/bonjour/bonjour_ft.c
+++ b/libpurple/protocols/bonjour/bonjour_ft.c
@@ -541,6 +541,7 @@ xep_cmp_addr(const char *host, const cha
 {
 #if defined(AF_INET6) && defined(HAVE_GETADDRINFO)
 	struct addrinfo hint, *res = NULL;
+	common_sockaddr_t addr;
 	int ret;
 
 	memset(&hint, 0, sizeof(hint));
@@ -550,9 +551,11 @@ xep_cmp_addr(const char *host, const cha
 	ret = getaddrinfo(host, NULL, &hint, &res);
 	if(ret)
 		goto out;
+	memcpy(&addr, res->ai_addr, sizeof(addr));
 
-	if(res->ai_family != AF_INET6 ||
-	   !IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *)res->ai_addr)->sin6_addr)) {
+	if (res->ai_family != AF_INET6 ||
+		!IN6_IS_ADDR_LINKLOCAL(&addr.in6.sin6_addr))
+	{
 		freeaddrinfo(res);
 		goto out;
 	}
diff --git a/libpurple/protocols/bonjour/jabber.c b/libpurple/protocols/bonjour/jabber.c
--- a/libpurple/protocols/bonjour/jabber.c
+++ b/libpurple/protocols/bonjour/jabber.c
@@ -705,14 +705,14 @@ static void
 }
 
 static int
-start_serversocket_listening(int port, int socket, struct sockaddr *addr, size_t addr_size, gboolean ip6, gboolean allow_port_fallback)
+start_serversocket_listening(int port, int socket, common_sockaddr_t *addr, size_t addr_size, gboolean ip6, gboolean allow_port_fallback)
 {
 	int ret_port = port;
 
 	purple_debug_info("bonjour", "Attempting to bind IPv%d socket to port %d.\n", ip6 ? 6 : 4, port);
 
 	/* Try to use the specified port - if it isn't available, use a random port */
-	if (bind(socket, addr, addr_size) != 0) {
+	if (bind(socket, &addr->sa, addr_size) != 0) {
 
 		purple_debug_info("bonjour", "Unable to bind to specified "
 				"port %i: %s\n", port, g_strerror(errno));
@@ -723,12 +723,12 @@ start_serversocket_listening(int port, i
 		}
 #ifdef PF_INET6
 		if (ip6)
-			((struct sockaddr_in6 *) addr)->sin6_port = 0;
+			addr->in6.sin6_port = 0;
 		else
 #endif
-		((struct sockaddr_in *) addr)->sin_port = 0;
+			addr->in.sin_port = 0;
 
-		if (bind(socket, addr, addr_size) != 0) {
+		if (bind(socket, &addr->sa, addr_size) != 0) {
 			purple_debug_error("bonjour", "Unable to bind IPv%d socket to port: %s\n", ip6 ? 6 : 4, g_strerror(errno));
 			return -1;
 		}
@@ -774,16 +774,17 @@ bonjour_jabber_start(BonjourJabber *jdat
 
 #ifdef PF_INET6
 	if (jdata->socket6 != -1) {
-		struct sockaddr_in6 addr6;
+		common_sockaddr_t addr6;
 #ifdef IPV6_V6ONLY
 		int on = 1;



More information about the Commits mailing list