| 296 generate_response_value(JabberID *jid, const char *passwd, const char *nonce, |
296 generate_response_value(JabberID *jid, const char *passwd, const char *nonce, |
| 297 const char *cnonce, const char *a2, const char *realm) |
297 const char *cnonce, const char *a2, const char *realm) |
| 298 { |
298 { |
| 299 md5_state_t ctx; |
299 md5_state_t ctx; |
| 300 md5_byte_t result[16]; |
300 md5_byte_t result[16]; |
| 301 |
301 size_t a1len; |
| 302 char *x, *y, *a1, *ha1, *ha2, *kd, *z; |
302 |
| 303 |
303 char *x, *a1, *ha1, *ha2, *kd, *z, *convnode, *convpasswd; |
| 304 x = g_strdup_printf("%s:%s:%s", jid->node, realm, passwd); |
304 |
| |
305 if((convnode = g_convert(jid->node, strlen(jid->node), "iso-8859-1", "utf-8", |
| |
306 NULL, NULL, NULL)) == NULL) { |
| |
307 convnode = g_strdup(jid->node); |
| |
308 } |
| |
309 if((convpasswd = g_convert(passwd, strlen(passwd), "iso-8859-1", "utf-8", |
| |
310 NULL, NULL, NULL)) == NULL) { |
| |
311 convpasswd = g_strdup(passwd); |
| |
312 } |
| |
313 |
| |
314 x = g_strdup_printf("%s:%s:%s", convnode, realm, convpasswd); |
| 305 md5_init(&ctx); |
315 md5_init(&ctx); |
| 306 md5_append(&ctx, x, strlen(x)); |
316 md5_append(&ctx, x, strlen(x)); |
| 307 md5_finish(&ctx, result); |
317 md5_finish(&ctx, result); |
| 308 |
318 |
| 309 y = g_strndup(result, 16); |
319 a1 = g_strdup_printf("xxxxxxxxxxxxxxxx:%s:%s", nonce, cnonce); |
| 310 |
320 a1len = strlen(a1); |
| 311 a1 = g_strdup_printf("%s:%s:%s", y, nonce, cnonce); |
321 g_memmove(a1, result, 16); |
| 312 |
322 |
| 313 md5_init(&ctx); |
323 md5_init(&ctx); |
| 314 md5_append(&ctx, a1, strlen(a1)); |
324 md5_append(&ctx, a1, a1len); |
| 315 md5_finish(&ctx, result); |
325 md5_finish(&ctx, result); |
| 316 |
326 |
| 317 ha1 = gaim_base16_encode(result, 16); |
327 ha1 = gaim_base16_encode(result, 16); |
| 318 |
328 |
| 319 md5_init(&ctx); |
329 md5_init(&ctx); |