pidgin.mxit: a1d8c4a9: Encrypt a message using transport-encryp...

andrew.victor at mxit.com andrew.victor at mxit.com
Sun Aug 14 16:50:42 EDT 2011


----------------------------------------------------------------------
Revision: a1d8c4a9d0690c456343f8fd7b178201a9ab5fad
Parent:   1b5e45245d72950657e22f873b57696ec2191f8c
Author:   andrew.victor at mxit.com
Date:     08/14/11 16:45:48
Branch:   im.pidgin.pidgin.mxit
URL: http://d.pidgin.im/viewmtn/revision/info/a1d8c4a9d0690c456343f8fd7b178201a9ab5fad

Changelog: 

Encrypt a message using transport-encryption.


Changes against parent 1b5e45245d72950657e22f873b57696ec2191f8c

  patched  libpurple/protocols/mxit/cipher.c
  patched  libpurple/protocols/mxit/cipher.h

-------------- next part --------------
============================================================
--- libpurple/protocols/mxit/cipher.c	e99a14de17a556650a28dfdc78bfe554221cde3d
+++ libpurple/protocols/mxit/cipher.c	13ce612237fb17843bd644e289fb1dbb710d9d51
@@ -109,7 +109,7 @@ char* mxit_encrypt_password( struct MXit
 
 
 /*------------------------------------------------------------------------
- * Decrypt a transport-layer encryptede message.
+ * Decrypt a transport-layer encrypted message.
  *
  *  @param session	The MXit session object
  *	@param message	The encrypted message data.
@@ -151,8 +151,6 @@ char* mxit_decrypt_message( struct MXitS
 	}
 	g_free( raw_message );
 
-	purple_debug_info( MXIT_PLUGIN_ID, "decrypted: '%s'\n", decoded->str );
-
 	/* check that the decrypted message starts with header: <mxit/> */
 	if ( strncmp( decoded->str, SECRET_HEADER, strlen( SECRET_HEADER ) != 0 ) ) {
 		g_string_free( decoded, TRUE );
@@ -171,3 +169,77 @@ char* mxit_decrypt_message( struct MXitS
 
 	return g_string_free( decoded, FALSE );
 }
+
+
+/*------------------------------------------------------------------------
+ * Encrypt a message using transport-layer encryption.
+ *
+ *  @param session	The MXit session object
+ *	@param message	The message data.
+ *  @return			The encrypted message.  Must be g_free'd when no longer needed.
+ */
+char* mxit_encrypt_message( struct MXitSession* session, char* message )
+{
+	char		key[64];
+	int			pwdlen		= strlen( session->acc->password );
+	char		exkey[512];
+	int			i;
+	GString*	decoded		= NULL;
+	GString*	encoded		= NULL;
+	gchar*		base64;
+
+	purple_debug_info( MXIT_PLUGIN_ID, "encrypt message: '%s'\n", message );
+
+	/* build the key - Client key, appended with last 8 characters of the PIN. (no padding) */
+	memset( key, 0x00, sizeof( key ) );
+	memcpy( key, session->clientkey, strlen( session->clientkey ) );
+	if ( pwdlen <= 8 )
+		strcat( key, session->acc->password );
+	else
+		strncat( key, session->acc->password + ( pwdlen - 8 ), 8 );
+	ExpandKey( (unsigned char*) key, (unsigned char*) exkey );
+
+	/* append encryption header */
+	decoded = g_string_sized_new( strlen( SECRET_HEADER ) + strlen( message ) );
+	g_string_append( decoded, SECRET_HEADER );
+	g_string_append( decoded, message );
+
+	/* add ISO10126 padding */
+	{
+		int blocks = ( decoded->len / 16 ) + 1;
+		int padding = ( blocks * 16 ) - decoded->len;
+
+		g_string_set_size( decoded, blocks * 16 );
+		decoded->str[decoded->len - 1] = padding;
+	}
+
+	/* encrypt each block */
+	encoded = g_string_sized_new( decoded->len );
+	for ( i = 0; i < decoded->len; i += 16 ) {
+		char	block[16];
+
+		Encrypt( (unsigned char*) decoded->str + i, (unsigned char*) exkey, (unsigned char*) block );
+		g_string_append_len( encoded, block, 16 );
+	}
+
+	/* now base64 encode the encrypted message */
+	base64 = purple_base64_encode( (unsigned char *) encoded->str, encoded->len );
+
+#if 0
+	/* and add optional header */
+	{
+		GString* tmp = g_string_sized_new( strlen( base64 ) + strlen( ENCRYPT_HEADER ) );
+		g_string_append( tmp, ENCRYPT_HEADER );
+		g_string_append( tmp, base64 );
+		g_free(base64);
+		base64 = g_string_free( tmp, FALSE );
+	}
+#endif
+
+	g_string_free( decoded, TRUE );
+	g_string_free( encoded, TRUE );
+
+	purple_debug_info( MXIT_PLUGIN_ID, "encrypted message: '%s'\n", base64 );
+
+	return base64;
+}
============================================================
--- libpurple/protocols/mxit/cipher.h	b1ae8268ab6a722286140d59e75a9fe10c580d25
+++ libpurple/protocols/mxit/cipher.h	4b0e421ff71088928a9ed3aeb09bb900cc487321
@@ -33,6 +33,6 @@ char* mxit_decrypt_message( struct MXitS
 char* mxit_encrypt_password( struct MXitSession* session );
 
 char* mxit_decrypt_message( struct MXitSession* session, char* message );
+char* mxit_encrypt_message( struct MXitSession* session, char* message );
 
-
 #endif		/* _MXIT_CIPHER_H_ */


More information about the Commits mailing list