comparison libpurple/protocols/jabber/si.c @ 25871:65cfc59858cf

propagate from branch 'im.pidgin.pidgin' (head d5bb29138cbe033bbfd8ec689203d73818765327) to branch 'im.pidgin.pidgin.next.minor' (head 35ee8e40db640867e5b9239030cdc326e7f0a005)
author Gary Kramlich <grim@reaperworld.com>
date Sat, 13 Dec 2008 05:45:27 +0000
parents 61e0924de04a
children e30e9779e7bf 0d7f02640e2b d7cdbee6d9be
comparison
equal deleted inserted replaced
25870:d9da15c9e2a1 25871:65cfc59858cf
21 */ 21 */
22 22
23 #include "internal.h" 23 #include "internal.h"
24 24
25 #include "blist.h" 25 #include "blist.h"
26 #include "cipher.h"
27 #include "debug.h" 26 #include "debug.h"
28 #include "ft.h" 27 #include "ft.h"
29 #include "request.h" 28 #include "request.h"
30 #include "network.h" 29 #include "network.h"
31 #include "notify.h" 30 #include "notify.h"
181 180
182 static void jabber_si_bytestreams_attempt_connect(PurpleXfer *xfer) 181 static void jabber_si_bytestreams_attempt_connect(PurpleXfer *xfer)
183 { 182 {
184 JabberSIXfer *jsx = xfer->data; 183 JabberSIXfer *jsx = xfer->data;
185 JabberBytestreamsStreamhost *streamhost; 184 JabberBytestreamsStreamhost *streamhost;
186 char *dstaddr, *p;
187 int i;
188 unsigned char hashval[20];
189 JabberID *dstjid; 185 JabberID *dstjid;
190 186
191 if(!jsx->streamhosts) { 187 if(!jsx->streamhosts) {
192 JabberIq *iq = jabber_iq_new(jsx->js, JABBER_IQ_ERROR); 188 JabberIq *iq = jabber_iq_new(jsx->js, JABBER_IQ_ERROR);
193 xmlnode *error, *inf; 189 xmlnode *error, *inf;
219 dstjid = jabber_id_new(xfer->who); 215 dstjid = jabber_id_new(xfer->who);
220 216
221 /* TODO: Deal with zeroconf */ 217 /* TODO: Deal with zeroconf */
222 218
223 if(dstjid != NULL && streamhost->host && streamhost->port > 0) { 219 if(dstjid != NULL && streamhost->host && streamhost->port > 0) {
220 char *dstaddr, *hash;
224 jsx->gpi = purple_proxy_info_new(); 221 jsx->gpi = purple_proxy_info_new();
225 purple_proxy_info_set_type(jsx->gpi, PURPLE_PROXY_SOCKS5); 222 purple_proxy_info_set_type(jsx->gpi, PURPLE_PROXY_SOCKS5);
226 purple_proxy_info_set_host(jsx->gpi, streamhost->host); 223 purple_proxy_info_set_host(jsx->gpi, streamhost->host);
227 purple_proxy_info_set_port(jsx->gpi, streamhost->port); 224 purple_proxy_info_set_port(jsx->gpi, streamhost->port);
228 225
232 jsx->js->user->resource, dstjid->node, dstjid->domain, dstjid->resource); 229 jsx->js->user->resource, dstjid->node, dstjid->domain, dstjid->resource);
233 else 230 else
234 dstaddr = g_strdup_printf("%s%s@%s/%s%s@%s/%s", jsx->stream_id, dstjid->node, dstjid->domain, dstjid->resource, 231 dstaddr = g_strdup_printf("%s%s@%s/%s%s@%s/%s", jsx->stream_id, dstjid->node, dstjid->domain, dstjid->resource,
235 jsx->js->user->node, jsx->js->user->domain, jsx->js->user->resource); 232 jsx->js->user->node, jsx->js->user->domain, jsx->js->user->resource);
236 233
237 purple_cipher_digest_region("sha1", (guchar *)dstaddr, strlen(dstaddr), 234 /* Per XEP-0065, the 'host' must be SHA1(SID + from JID + to JID) */
238 sizeof(hashval), hashval, NULL); 235 hash = jabber_calculate_data_sha1sum(dstaddr, strlen(dstaddr));
239 g_free(dstaddr);
240 dstaddr = g_malloc(41);
241 p = dstaddr;
242 for(i=0; i<20; i++, p+=2)
243 snprintf(p, 3, "%02x", hashval[i]);
244 236
245 jsx->connect_data = purple_proxy_connect_socks5(NULL, jsx->gpi, 237 jsx->connect_data = purple_proxy_connect_socks5(NULL, jsx->gpi,
246 dstaddr, 0, 238 hash, 0,
247 jabber_si_bytestreams_connect_cb, xfer); 239 jabber_si_bytestreams_connect_cb, xfer);
240 g_free(hash);
248 g_free(dstaddr); 241 g_free(dstaddr);
249 242
250 /* When selecting a streamhost, timeout after STREAMHOST_CONNECT_TIMEOUT seconds, otherwise it takes forever */ 243 /* When selecting a streamhost, timeout after STREAMHOST_CONNECT_TIMEOUT seconds, otherwise it takes forever */
251 if (xfer->type != PURPLE_XFER_SEND && jsx->connect_data != NULL) 244 if (xfer->type != PURPLE_XFER_SEND && jsx->connect_data != NULL)
252 jsx->connect_timeout = purple_timeout_add_seconds( 245 jsx->connect_timeout = purple_timeout_add_seconds(
359 jabber_si_xfer_bytestreams_send_read_again_cb(gpointer data, gint source, 352 jabber_si_xfer_bytestreams_send_read_again_cb(gpointer data, gint source,
360 PurpleInputCondition cond) 353 PurpleInputCondition cond)
361 { 354 {
362 PurpleXfer *xfer = data; 355 PurpleXfer *xfer = data;
363 JabberSIXfer *jsx = xfer->data; 356 JabberSIXfer *jsx = xfer->data;
364 int i;
365 char buffer[256]; 357 char buffer[256];
366 int len; 358 int len;
367 char *dstaddr, *p; 359 char *dstaddr, *hash;
368 unsigned char hashval[20];
369 const char *host; 360 const char *host;
370 361
371 purple_debug_info("jabber", "in jabber_si_xfer_bytestreams_send_read_again_cb\n"); 362 purple_debug_info("jabber", "in jabber_si_xfer_bytestreams_send_read_again_cb\n");
372 363
373 if(jsx->rxlen < 5) { 364 if(jsx->rxlen < 5) {
419 410
420 dstaddr = g_strdup_printf("%s%s@%s/%s%s", jsx->stream_id, 411 dstaddr = g_strdup_printf("%s%s@%s/%s%s", jsx->stream_id,
421 jsx->js->user->node, jsx->js->user->domain, 412 jsx->js->user->node, jsx->js->user->domain,
422 jsx->js->user->resource, xfer->who); 413 jsx->js->user->resource, xfer->who);
423 414
424 purple_cipher_digest_region("sha1", (guchar *)dstaddr, strlen(dstaddr), 415 /* Per XEP-0065, the 'host' must be SHA1(SID + from JID + to JID) */
425 sizeof(hashval), hashval, NULL); 416 hash = jabber_calculate_data_sha1sum(dstaddr, strlen(dstaddr));
426 g_free(dstaddr); 417
427 dstaddr = g_malloc(41); 418 if(jsx->rxqueue[4] != 40 || strncmp(hash, jsx->rxqueue+5, 40) ||
428 p = dstaddr;
429 for(i=0; i<20; i++, p+=2)
430 snprintf(p, 3, "%02x", hashval[i]);
431
432 if(jsx->rxqueue[4] != 40 || strncmp(dstaddr, jsx->rxqueue+5, 40) ||
433 jsx->rxqueue[45] != 0x00 || jsx->rxqueue[46] != 0x00) { 419 jsx->rxqueue[45] != 0x00 || jsx->rxqueue[46] != 0x00) {
434 purple_debug_error("jabber", "someone connected with the wrong info!\n"); 420 purple_debug_error("jabber", "someone connected with the wrong info!\n");
435 close(source); 421 close(source);
436 purple_xfer_cancel_remote(xfer); 422 purple_xfer_cancel_remote(xfer);
423 g_free(hash);
437 g_free(dstaddr); 424 g_free(dstaddr);
438 return; 425 return;
439 } 426 }
440 427
428 g_free(hash);
441 g_free(dstaddr); 429 g_free(dstaddr);
442 430
443 g_free(jsx->rxqueue); 431 g_free(jsx->rxqueue);
444 host = purple_network_get_my_ip(jsx->js->fd); 432 host = purple_network_get_my_ip(jsx->js->fd);
445 433