comparison src/protocols/yahoo/yahoo.c @ 10687:b256ce6b85b8

[gaim-migrate @ 12235] grim says this is really fixed this time. committer: Tailor Script <tailor@pidgin.im>
author Etan Reisner <pidgin@unreliablesource.net>
date Sat, 12 Mar 2005 01:10:37 +0000
parents 72a5babfa8b4
children c4cb90065e1d
comparison
equal deleted inserted replaced
10686:212946f774c0 10687:b256ce6b85b8
956 956
957 cipher = gaim_ciphers_find_cipher("md5"); 957 cipher = gaim_ciphers_find_cipher("md5");
958 context = gaim_cipher_context_new(cipher, NULL); 958 context = gaim_cipher_context_new(cipher, NULL);
959 959
960 gaim_cipher_context_append(context, pass, strlen(pass)); 960 gaim_cipher_context_append(context, pass, strlen(pass));
961 gaim_cipher_context_digest(context, NULL, digest); 961 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
962 962
963 to_y64(password_hash, digest, 16); 963 to_y64(password_hash, digest, 16);
964 964
965 crypt_result = yahoo_crypt(pass, "$1$_2S43d5f$"); 965 crypt_result = yahoo_crypt(pass, "$1$_2S43d5f$");
966 966
967 gaim_cipher_context_reset(context, NULL); 967 gaim_cipher_context_reset(context, NULL);
968 gaim_cipher_context_append(context, crypt_result, strlen(crypt_result)); 968 gaim_cipher_context_append(context, crypt_result, strlen(crypt_result));
969 gaim_cipher_context_digest(context, NULL, digest); 969 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
970 to_y64(crypt_hash, digest, 16); 970 to_y64(crypt_hash, digest, 16);
971 971
972 switch (sv) { 972 switch (sv) {
973 case 1: 973 case 1:
974 case 6: 974 case 6:
1010 break; 1010 break;
1011 } 1011 }
1012 1012
1013 gaim_cipher_context_reset(context, NULL); 1013 gaim_cipher_context_reset(context, NULL);
1014 gaim_cipher_context_append(context, hash_string_p, strlen(hash_string_p)); 1014 gaim_cipher_context_append(context, hash_string_p, strlen(hash_string_p));
1015 gaim_cipher_context_digest(context, NULL, digest); 1015 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
1016 to_y64(result6, digest, 16); 1016 to_y64(result6, digest, 16);
1017 1017
1018 gaim_cipher_context_reset(context, NULL); 1018 gaim_cipher_context_reset(context, NULL);
1019 gaim_cipher_context_append(context, hash_string_c, strlen(hash_string_c)); 1019 gaim_cipher_context_append(context, hash_string_c, strlen(hash_string_c));
1020 gaim_cipher_context_digest(context, NULL, digest); 1020 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
1021 gaim_cipher_context_destroy(context); 1021 gaim_cipher_context_destroy(context);
1022 to_y64(result96, digest, 16); 1022 to_y64(result96, digest, 16);
1023 1023
1024 pack = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, YAHOO_STATUS_AVAILABLE, 0); 1024 pack = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, YAHOO_STATUS_AVAILABLE, 0);
1025 yahoo_packet_hash(pack, "ssss", 0, name, 6, result6, 96, result96, 1, name); 1025 yahoo_packet_hash(pack, "ssss", 0, name, 6, result6, 96, result96, 1, name);
1242 test[2] = y; 1242 test[2] = y;
1243 1243
1244 gaim_cipher_context_reset(md5_ctx, NULL); 1244 gaim_cipher_context_reset(md5_ctx, NULL);
1245 gaim_cipher_context_append(md5_ctx, magic_key_char, 4); 1245 gaim_cipher_context_append(md5_ctx, magic_key_char, 4);
1246 gaim_cipher_context_append(md5_ctx, test, 3); 1246 gaim_cipher_context_append(md5_ctx, test, 3);
1247 gaim_cipher_context_digest(md5_ctx, NULL, md5_digest); 1247 gaim_cipher_context_digest(md5_ctx, sizeof(md5_digest),
1248 md5_digest, NULL);
1248 1249
1249 if (!memcmp(md5_digest, comparison_src+4, 16)) { 1250 if (!memcmp(md5_digest, comparison_src+4, 16)) {
1250 leave = 1; 1251 leave = 1;
1251 break; 1252 break;
1252 } 1253 }
1273 } 1274 }
1274 1275
1275 /* Get password and crypt hashes as per usual. */ 1276 /* Get password and crypt hashes as per usual. */
1276 gaim_cipher_context_reset(md5_ctx, NULL); 1277 gaim_cipher_context_reset(md5_ctx, NULL);
1277 gaim_cipher_context_append(md5_ctx, pass, strlen(pass)); 1278 gaim_cipher_context_append(md5_ctx, pass, strlen(pass));
1278 gaim_cipher_context_digest(md5_ctx, NULL, md5_digest); 1279 gaim_cipher_context_digest(md5_ctx, sizeof(md5_digest),
1280 md5_digest, NULL);
1279 to_y64(password_hash, md5_digest, 16); 1281 to_y64(password_hash, md5_digest, 16);
1280 1282
1281 crypt_result = yahoo_crypt(pass, "$1$_2S43d5f$"); 1283 crypt_result = yahoo_crypt(pass, "$1$_2S43d5f$");
1282 gaim_cipher_context_reset(md5_ctx, NULL); 1284 gaim_cipher_context_reset(md5_ctx, NULL);
1283 gaim_cipher_context_append(md5_ctx, crypt_result, strlen(crypt_result)); 1285 gaim_cipher_context_append(md5_ctx, crypt_result, strlen(crypt_result));
1284 gaim_cipher_context_digest(md5_ctx, NULL, md5_digest); 1286 gaim_cipher_context_digest(md5_ctx, sizeof(md5_digest),
1287 md5_digest, NULL);
1285 to_y64(crypt_hash, md5_digest, 16); 1288 to_y64(crypt_hash, md5_digest, 16);
1286 1289
1287 /* Our first authentication response is based off of the password hash. */ 1290 /* Our first authentication response is based off of the password hash. */
1288 for (x = 0; x < (int)strlen(password_hash); x++) 1291 for (x = 0; x < (int)strlen(password_hash); x++)
1289 pass_hash_xor1[cnt++] = password_hash[x] ^ 0x36; 1292 pass_hash_xor1[cnt++] = password_hash[x] ^ 0x36;
1306 1309
1307 gaim_cipher_context_append(sha1_ctx1, pass_hash_xor1, 64); 1310 gaim_cipher_context_append(sha1_ctx1, pass_hash_xor1, 64);
1308 if (y >= 3) 1311 if (y >= 3)
1309 gaim_cipher_context_set_option(sha1_ctx1, "sizeLo", GINT_TO_POINTER(0x1ff)); 1312 gaim_cipher_context_set_option(sha1_ctx1, "sizeLo", GINT_TO_POINTER(0x1ff));
1310 gaim_cipher_context_append(sha1_ctx1, magic_key_char, 4); 1313 gaim_cipher_context_append(sha1_ctx1, magic_key_char, 4);
1311 gaim_cipher_context_digest(sha1_ctx1, NULL, digest1); 1314 gaim_cipher_context_digest(sha1_ctx1, sizeof(digest1), digest1, NULL);
1312 1315
1313 /* 1316 /*
1314 * The second context gets the password hash XORed with 0x5c plus the SHA-1 digest 1317 * The second context gets the password hash XORed with 0x5c plus the SHA-1 digest
1315 * of the first context. 1318 * of the first context.
1316 */ 1319 */
1317 1320
1318 gaim_cipher_context_append(sha1_ctx2, pass_hash_xor2, 64); 1321 gaim_cipher_context_append(sha1_ctx2, pass_hash_xor2, 64);
1319 gaim_cipher_context_append(sha1_ctx2, digest1, 20); 1322 gaim_cipher_context_append(sha1_ctx2, digest1, 20);
1320 gaim_cipher_context_digest(sha1_ctx2, NULL, digest2); 1323 gaim_cipher_context_digest(sha1_ctx2, sizeof(digest2), digest2, NULL);
1321 1324
1322 /* 1325 /*
1323 * Now that we have digest2, use it to fetch characters from an alphabet to construct 1326 * Now that we have digest2, use it to fetch characters from an alphabet to construct
1324 * our first authentication response. 1327 * our first authentication response.
1325 */ 1328 */
1396 * The first context gets the password hash XORed with 0x36 plus a magic value 1399 * The first context gets the password hash XORed with 0x36 plus a magic value
1397 * which we previously extrapolated from our challenge. 1400 * which we previously extrapolated from our challenge.
1398 */ 1401 */
1399 1402
1400 gaim_cipher_context_append(sha1_ctx1, crypt_hash_xor1, 64); 1403 gaim_cipher_context_append(sha1_ctx1, crypt_hash_xor1, 64);
1401 if (y >= 3) 1404 if (y >= 3) {
1402 gaim_cipher_context_set_option(sha1_ctx1, "sizeLo", GINT_TO_POINTER(0x1ff)); 1405 gaim_cipher_context_set_option(sha1_ctx1, "sizeLo",
1406 GINT_TO_POINTER(0x1ff));
1407 }
1403 gaim_cipher_context_append(sha1_ctx1, magic_key_char, 4); 1408 gaim_cipher_context_append(sha1_ctx1, magic_key_char, 4);
1404 gaim_cipher_context_digest(sha1_ctx1, NULL, digest1); 1409 gaim_cipher_context_digest(sha1_ctx1, sizeof(digest1), digest1, NULL);
1405 1410
1406 /* 1411 /*
1407 * The second context gets the password hash XORed with 0x5c plus the SHA-1 digest 1412 * The second context gets the password hash XORed with 0x5c plus the SHA-1 digest
1408 * of the first context. 1413 * of the first context.
1409 */ 1414 */
1410 1415
1411 gaim_cipher_context_append(sha1_ctx2, crypt_hash_xor2, 64); 1416 gaim_cipher_context_append(sha1_ctx2, crypt_hash_xor2, 64);
1412 gaim_cipher_context_append(sha1_ctx2, digest1, 20); 1417 gaim_cipher_context_append(sha1_ctx2, digest1, 20);
1413 gaim_cipher_context_digest(sha1_ctx2, NULL, digest2); 1418 gaim_cipher_context_digest(sha1_ctx2, sizeof(digest2), digest2, NULL);
1414 1419
1415 /* 1420 /*
1416 * Now that we have digest2, use it to fetch characters from an alphabet to construct 1421 * Now that we have digest2, use it to fetch characters from an alphabet to construct
1417 * our first authentication response. 1422 * our first authentication response.
1418 */ 1423 */
2181 2186
2182 cipher = gaim_ciphers_find_cipher("md5"); 2187 cipher = gaim_ciphers_find_cipher("md5");
2183 context = gaim_cipher_context_new(cipher, NULL); 2188 context = gaim_cipher_context_new(cipher, NULL);
2184 2189
2185 gaim_cipher_context_append(context, pass, strlen(pass)); 2190 gaim_cipher_context_append(context, pass, strlen(pass));
2186 gaim_cipher_context_digest(context, NULL, digest); 2191 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
2187 for (i = 0; i < 16; ++i) { 2192 for (i = 0; i < 16; ++i) {
2188 g_snprintf(hashp, 3, "%02x", digest[i]); 2193 g_snprintf(hashp, 3, "%02x", digest[i]);
2189 hashp += 2; 2194 hashp += 2;
2190 } 2195 }
2191 2196
2192 chal = g_strconcat(md5, g_hash_table_lookup(hash, ".challenge"), NULL); 2197 chal = g_strconcat(md5, g_hash_table_lookup(hash, ".challenge"), NULL);
2193 gaim_cipher_context_reset(context, NULL); 2198 gaim_cipher_context_reset(context, NULL);
2194 gaim_cipher_context_append(context, chal, strlen(chal)); 2199 gaim_cipher_context_append(context, chal, strlen(chal));
2195 gaim_cipher_context_digest(context, NULL, digest); 2200 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
2196 hashp = md5; 2201 hashp = md5;
2197 for (i = 0; i < 16; ++i) { 2202 for (i = 0; i < 16; ++i) {
2198 g_snprintf(hashp, 3, "%02x", digest[i]); 2203 g_snprintf(hashp, 3, "%02x", digest[i]);
2199 hashp += 2; 2204 hashp += 2;
2200 } 2205 }
2202 * I dunno why this is here and commented out.. but in case it's needed 2207 * I dunno why this is here and commented out.. but in case it's needed
2203 * I updated it.. 2208 * I updated it..
2204 2209
2205 gaim_cipher_context_reset(context, NULL); 2210 gaim_cipher_context_reset(context, NULL);
2206 gaim_cipher_context_append(context, md5, strlen(md5)); 2211 gaim_cipher_context_append(context, md5, strlen(md5));
2207 gaim_cipher_context_digest(context, NULL, digest); 2212 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
2208 hashp = md5; 2213 hashp = md5;
2209 for (i = 0; i < 16; ++i) { 2214 for (i = 0; i < 16; ++i) {
2210 g_snprintf(hashp, 3, "%02x", digest[i]); 2215 g_snprintf(hashp, 3, "%02x", digest[i]);
2211 hashp += 2; 2216 hashp += 2;
2212 } 2217 }