| 225 x = xmlnode_new_child(query, "resource"); |
224 x = xmlnode_new_child(query, "resource"); |
| 226 xmlnode_insert_data(x, js->user->resource, -1); |
225 xmlnode_insert_data(x, js->user->resource, -1); |
| 227 |
226 |
| 228 x = xmlnode_new_child(query, "digest"); |
227 x = xmlnode_new_child(query, "digest"); |
| 229 s = g_strdup_printf("%s%s", js->stream_id, pw); |
228 s = g_strdup_printf("%s%s", js->stream_id, pw); |
| 230 shaBlock((unsigned char *)s, strlen(s), hashval); |
229 |
| |
230 gaim_cipher_digest_region("sha1", (guint8 *)s, strlen(s), |
| |
231 hashval, NULL); |
| |
232 |
| 231 p = h; |
233 p = h; |
| 232 for(i=0; i<20; i++, p+=2) |
234 for(i=0; i<20; i++, p+=2) |
| 233 snprintf(p, 3, "%02x", hashval[i]); |
235 snprintf(p, 3, "%02x", hashval[i]); |
| 234 xmlnode_insert_data(x, h, -1); |
236 xmlnode_insert_data(x, h, -1); |
| 235 g_free(s); |
237 g_free(s); |
| 298 |
300 |
| 299 static unsigned char* |
301 static unsigned char* |
| 300 generate_response_value(JabberID *jid, const char *passwd, const char *nonce, |
302 generate_response_value(JabberID *jid, const char *passwd, const char *nonce, |
| 301 const char *cnonce, const char *a2, const char *realm) |
303 const char *cnonce, const char *a2, const char *realm) |
| 302 { |
304 { |
| 303 md5_state_t ctx; |
305 GaimCipher *cipher; |
| 304 md5_byte_t result[16]; |
306 GaimCipherContext *context; |
| |
307 guint8 result[16]; |
| 305 size_t a1len; |
308 size_t a1len; |
| 306 |
309 |
| 307 unsigned char *x, *a1, *ha1, *ha2, *kd, *z, *convnode, *convpasswd; |
310 unsigned char *x, *a1, *ha1, *ha2, *kd, *z, *convnode, *convpasswd; |
| 308 |
311 |
| 309 if((convnode = g_convert(jid->node, strlen(jid->node), "iso-8859-1", "utf-8", |
312 if((convnode = g_convert(jid->node, strlen(jid->node), "iso-8859-1", "utf-8", |
| 313 if((convpasswd = g_convert(passwd, strlen(passwd), "iso-8859-1", "utf-8", |
316 if((convpasswd = g_convert(passwd, strlen(passwd), "iso-8859-1", "utf-8", |
| 314 NULL, NULL, NULL)) == NULL) { |
317 NULL, NULL, NULL)) == NULL) { |
| 315 convpasswd = g_strdup(passwd); |
318 convpasswd = g_strdup(passwd); |
| 316 } |
319 } |
| 317 |
320 |
| |
321 cipher = gaim_ciphers_find_cipher("md5"); |
| |
322 context = gaim_cipher_context_new(cipher, NULL); |
| |
323 |
| 318 x = g_strdup_printf("%s:%s:%s", convnode, realm, convpasswd); |
324 x = g_strdup_printf("%s:%s:%s", convnode, realm, convpasswd); |
| 319 md5_init(&ctx); |
325 gaim_cipher_context_append(context, x, strlen(x)); |
| 320 md5_append(&ctx, x, strlen(x)); |
326 gaim_cipher_context_digest(context, NULL, result); |
| 321 md5_finish(&ctx, result); |
|
| 322 |
327 |
| 323 a1 = g_strdup_printf("xxxxxxxxxxxxxxxx:%s:%s", nonce, cnonce); |
328 a1 = g_strdup_printf("xxxxxxxxxxxxxxxx:%s:%s", nonce, cnonce); |
| 324 a1len = strlen(a1); |
329 a1len = strlen(a1); |
| 325 g_memmove(a1, result, 16); |
330 g_memmove(a1, result, 16); |
| 326 |
331 |
| 327 md5_init(&ctx); |
332 gaim_cipher_context_reset(context, NULL); |
| 328 md5_append(&ctx, a1, a1len); |
333 gaim_cipher_context_append(context, a1, a1len); |
| 329 md5_finish(&ctx, result); |
334 gaim_cipher_context_digest(context, NULL, result); |
| 330 |
335 |
| 331 ha1 = gaim_base16_encode(result, 16); |
336 ha1 = gaim_base16_encode(result, 16); |
| 332 |
337 |
| 333 md5_init(&ctx); |
338 gaim_cipher_context_reset(context, NULL); |
| 334 md5_append(&ctx, a2, strlen(a2)); |
339 gaim_cipher_context_append(context, a2, strlen(a2)); |
| 335 md5_finish(&ctx, result); |
340 gaim_cipher_context_digest(context, NULL, result); |
| 336 |
341 |
| 337 ha2 = gaim_base16_encode(result, 16); |
342 ha2 = gaim_base16_encode(result, 16); |
| 338 |
343 |
| 339 kd = g_strdup_printf("%s:%s:00000001:%s:auth:%s", ha1, nonce, cnonce, ha2); |
344 kd = g_strdup_printf("%s:%s:00000001:%s:auth:%s", ha1, nonce, cnonce, ha2); |
| 340 |
345 |
| 341 md5_init(&ctx); |
346 gaim_cipher_context_reset(context, NULL); |
| 342 md5_append(&ctx, kd, strlen(kd)); |
347 gaim_cipher_context_append(context, kd, strlen(kd)); |
| 343 md5_finish(&ctx, result); |
348 gaim_cipher_context_digest(context, NULL, result); |
| |
349 gaim_cipher_context_destroy(context); |
| 344 |
350 |
| 345 z = gaim_base16_encode(result, 16); |
351 z = gaim_base16_encode(result, 16); |
| 346 |
352 |
| 347 g_free(convnode); |
353 g_free(convnode); |
| 348 g_free(convpasswd); |
354 g_free(convpasswd); |