Mercurial > pidgin
comparison libpurple/protocols/myspace/myspace.c @ 16400:9c9c627dbbfe
Use Purple Cipher API for RC4.
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Wed, 25 Apr 2007 03:46:17 +0000 |
parents | 70c069168459 |
children | 10d2958bd632 |
comparison
equal
deleted
inserted
replaced
16399:18d766d252f3 | 16400:9c9c627dbbfe |
---|---|
52 #include "plugin.h" | 52 #include "plugin.h" |
53 #include "version.h" | 53 #include "version.h" |
54 #include "cipher.h" /* for SHA-1 */ | 54 #include "cipher.h" /* for SHA-1 */ |
55 #include "util.h" /* for base64 */ | 55 #include "util.h" /* for base64 */ |
56 #include "debug.h" /* for purple_debug_info */ | 56 #include "debug.h" /* for purple_debug_info */ |
57 | |
58 #include "crypt-rc4.h" /* TODO: use rc4 */ | |
59 | 57 |
60 #define MSIM_STATUS_ONLINE "online" | 58 #define MSIM_STATUS_ONLINE "online" |
61 #define MSIM_STATUS_AWAY "away" | 59 #define MSIM_STATUS_AWAY "away" |
62 #define MSIM_STATUS_OFFLINE "offline" | 60 #define MSIM_STATUS_OFFLINE "offline" |
63 #define MSIM_STATUS_INVISIBLE "invisible" | 61 #define MSIM_STATUS_INVISIBLE "invisible" |
255 */ | 253 */ |
256 static gchar* msim_compute_login_response(guchar nonce[2*NONCE_HALF_SIZE], gchar* email, gchar* password) | 254 static gchar* msim_compute_login_response(guchar nonce[2*NONCE_HALF_SIZE], gchar* email, gchar* password) |
257 { | 255 { |
258 PurpleCipherContext *key_context; | 256 PurpleCipherContext *key_context; |
259 PurpleCipher *sha1; | 257 PurpleCipher *sha1; |
260 rc4_state_struct rc4; | 258 PurpleCipherContext *rc4; |
261 guchar hash_pw[HASH_SIZE]; | 259 guchar hash_pw[HASH_SIZE]; |
262 guchar key[HASH_SIZE]; | 260 guchar key[HASH_SIZE]; |
263 gchar* password_utf16le; | 261 gchar* password_utf16le; |
264 guchar* data; | 262 guchar* data; |
263 guchar* data_out; | |
265 gchar* response; | 264 gchar* response; |
266 int i, data_len; | 265 int i; |
266 size_t data_len, data_out_len; | |
267 | 267 |
268 //memset(nonce, 0, NONCE_HALF_SIZE); | 268 //memset(nonce, 0, NONCE_HALF_SIZE); |
269 //memset(nonce + NONCE_HALF_SIZE, 1, NONCE_HALF_SIZE); | 269 //memset(nonce + NONCE_HALF_SIZE, 1, NONCE_HALF_SIZE); |
270 | 270 |
271 /* Convert ASCII password to UTF16 little endian */ | 271 /* Convert ASCII password to UTF16 little endian */ |
304 printf("%.2x ", key[i]); | 304 printf("%.2x ", key[i]); |
305 } | 305 } |
306 printf("\n"); | 306 printf("\n"); |
307 #endif | 307 #endif |
308 | 308 |
309 rc4 = purple_cipher_context_new_by_name("rc4", NULL); | |
310 | |
309 /* Note: 'key' variable is 0x14 bytes (from SHA-1 hash), | 311 /* Note: 'key' variable is 0x14 bytes (from SHA-1 hash), |
310 * but only first 0x10 used for the RC4 key. */ | 312 * but only first 0x10 used for the RC4 key. */ |
311 crypt_rc4_init(&rc4, key, 0x10); | 313 purple_cipher_context_set_option(rc4, "key_len", (gpointer)0x10); |
314 purple_cipher_context_set_key(rc4, key); | |
312 | 315 |
313 /* TODO: obtain IPs of network interfaces. This is not immediately | 316 /* TODO: obtain IPs of network interfaces. This is not immediately |
314 * important because you can still connect and perform basic | 317 * important because you can still connect and perform basic |
315 * functions of the protocol. There is also a high chance that the addreses | 318 * functions of the protocol. There is also a high chance that the addreses |
316 * are RFC1918 private, so the servers couldn't do anything with them | 319 * are RFC1918 private, so the servers couldn't do anything with them |
324 memcpy(data, nonce, NONCE_HALF_SIZE); | 327 memcpy(data, nonce, NONCE_HALF_SIZE); |
325 memcpy(data + NONCE_HALF_SIZE, email, strlen(email)); | 328 memcpy(data + NONCE_HALF_SIZE, email, strlen(email)); |
326 memcpy(data + NONCE_HALF_SIZE + strlen(email), | 329 memcpy(data + NONCE_HALF_SIZE + strlen(email), |
327 /* IP addresses of network interfaces */ | 330 /* IP addresses of network interfaces */ |
328 "\x00\x00\x00\x00\x05\x7f\x00\x00\x01\x00\x00\x00\x00\x0a\x00\x00\x40\xc0\xa8\x58\x01\xc0\xa8\x3c\x01", 25); | 331 "\x00\x00\x00\x00\x05\x7f\x00\x00\x01\x00\x00\x00\x00\x0a\x00\x00\x40\xc0\xa8\x58\x01\xc0\xa8\x3c\x01", 25); |
329 crypt_rc4(&rc4, data, data_len); | 332 // crypt_rc4(&rc4, data, data_len); |
330 | 333 |
331 response = purple_base64_encode(data, data_len); | 334 data_out = g_new0(guchar, data_len); |
335 purple_cipher_context_encrypt(rc4, (const guchar*)data, | |
336 data_len, data_out, &data_out_len); | |
337 g_assert(data_out_len == data_len); | |
338 purple_cipher_context_destroy(rc4); | |
339 | |
340 response = purple_base64_encode(data_out, data_out_len); | |
341 g_free(data_out); | |
332 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE | 342 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE |
333 printf("response=<%s>\n", response); | 343 printf("response=<%s>\n", response); |
334 #endif | 344 #endif |
335 | 345 |
336 return response; | 346 return response; |