comparison libpurple/protocols/mxit/cipher.c @ 32672:3828a61c44da

A boring and large patch so I can merge heads.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Fri, 23 Dec 2011 08:21:58 +0000
parents 2754bbe70ac1
children
comparison
equal deleted inserted replaced
32671:0e69949b3e61 32672:3828a61c44da
77 * @return The transport-layer crypto key. 77 * @return The transport-layer crypto key.
78 */ 78 */
79 static char* transport_layer_key( struct MXitSession* session ) 79 static char* transport_layer_key( struct MXitSession* session )
80 { 80 {
81 static char key[16 + 1]; 81 static char key[16 + 1];
82 int passlen = strlen( session->acc->password ); 82 const char* password = purple_account_get_password( session->acc );
83 int passlen = strlen( password );
83 84
84 /* initialize with initial key */ 85 /* initialize with initial key */
85 g_strlcpy( key, INITIAL_KEY, sizeof( key ) ); 86 g_strlcpy( key, INITIAL_KEY, sizeof( key ) );
86 87
87 /* client key (8 bytes) */ 88 /* client key (8 bytes) */
88 memcpy( key, session->clientkey, strlen( session->clientkey ) ); 89 memcpy( key, session->clientkey, strlen( session->clientkey ) );
89 90
90 /* add last 8 characters of the PIN (no padding if less characters) */ 91 /* add last 8 characters of the PIN (no padding if less characters) */
91 if ( passlen <= 8 ) 92 if ( passlen <= 8 )
92 memcpy( key + 8, session->acc->password, passlen ); 93 memcpy( key + 8, password, passlen );
93 else 94 else
94 memcpy( key + 8, session->acc->password + ( passlen - 8 ), 8 ); 95 memcpy( key + 8, password + ( passlen - 8 ), 8 );
95 96
96 return key; 97 return key;
97 } 98 }
98 99
99 100
122 memcpy( key, session->clientkey, strlen( session->clientkey ) ); 123 memcpy( key, session->clientkey, strlen( session->clientkey ) );
123 ExpandKey( (unsigned char*) key, (unsigned char*) exkey ); 124 ExpandKey( (unsigned char*) key, (unsigned char*) exkey );
124 125
125 /* build the secret data to be encrypted: SECRET_HEADER + password */ 126 /* build the secret data to be encrypted: SECRET_HEADER + password */
126 pass = g_string_new( SECRET_HEADER ); 127 pass = g_string_new( SECRET_HEADER );
127 g_string_append( pass, session->acc->password ); 128 g_string_append( pass, purple_account_get_password( session->acc) );
128 padding_add( pass ); /* add ISO10126 padding */ 129 padding_add( pass ); /* add ISO10126 padding */
129 130
130 /* now encrypt the secret. we encrypt each block separately (ECB mode) */ 131 /* now encrypt the secret. we encrypt each block separately (ECB mode) */
131 for ( i = 0; i < pass->len; i += 16 ) 132 for ( i = 0; i < pass->len; i += 16 )
132 Encrypt( (unsigned char*) pass->str + i, (unsigned char*) exkey, (unsigned char*) encrypted + i ); 133 Encrypt( (unsigned char*) pass->str + i, (unsigned char*) exkey, (unsigned char*) encrypted + i );