diff options
Diffstat (limited to 'src/util/socks.c')
-rw-r--r-- | src/util/socks.c | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/src/util/socks.c b/src/util/socks.c index 3fa18cca9..cc59858dd 100644 --- a/src/util/socks.c +++ b/src/util/socks.c | |||
@@ -105,7 +105,7 @@ unsigned char * SOCK5_proto_string(unsigned char * b, const char * s) | |||
105 | /** | 105 | /** |
106 | * State of the SOCKS5 handshake. | 106 | * State of the SOCKS5 handshake. |
107 | */ | 107 | */ |
108 | struct GNUNET_SOCKS_Handshake | 108 | struct GNUNET_SOCKS_Handshake |
109 | { | 109 | { |
110 | 110 | ||
111 | /** | 111 | /** |
@@ -124,7 +124,7 @@ struct GNUNET_SOCKS_Handshake | |||
124 | struct GNUNET_CONNECTION_TransmitHandle *th; | 124 | struct GNUNET_CONNECTION_TransmitHandle *th; |
125 | 125 | ||
126 | /** | 126 | /** |
127 | * Our stage in the SOCKS5 handshake | 127 | * Our stage in the SOCKS5 handshake |
128 | */ | 128 | */ |
129 | int step; | 129 | int step; |
130 | 130 | ||
@@ -199,7 +199,7 @@ SOCKS5_handshake_step (struct GNUNET_SOCKS_Handshake *ih) | |||
199 | GNUNET_assert (SOCKS5_step_done > ih->step && ih->step >= 0); | 199 | GNUNET_assert (SOCKS5_step_done > ih->step && ih->step >= 0); |
200 | switch (ih->step) { | 200 | switch (ih->step) { |
201 | case SOCKS5_step_greet: /* SOCKS5 server's greeting */ | 201 | case SOCKS5_step_greet: /* SOCKS5 server's greeting */ |
202 | if (b[0] != 5) | 202 | if (b[0] != 5) |
203 | { | 203 | { |
204 | LOG (GNUNET_ERROR_TYPE_ERROR, | 204 | LOG (GNUNET_ERROR_TYPE_ERROR, |
205 | "Not a SOCKS5 server\n"); | 205 | "Not a SOCKS5 server\n"); |
@@ -234,7 +234,7 @@ SOCKS5_handshake_step (struct GNUNET_SOCKS_Handshake *ih) | |||
234 | b += 2; | 234 | b += 2; |
235 | break; | 235 | break; |
236 | case SOCKS5_step_cmd: /* SOCKS5 server's responce to command */ | 236 | case SOCKS5_step_cmd: /* SOCKS5 server's responce to command */ |
237 | if (b[0] != 5) | 237 | if (b[0] != 5) |
238 | { | 238 | { |
239 | LOG (GNUNET_ERROR_TYPE_ERROR, | 239 | LOG (GNUNET_ERROR_TYPE_ERROR, |
240 | "SOCKS5 protocol error\n"); | 240 | "SOCKS5 protocol error\n"); |
@@ -271,11 +271,11 @@ SOCKS5_handshake_step (struct GNUNET_SOCKS_Handshake *ih) | |||
271 | ih->instart = b; | 271 | ih->instart = b; |
272 | SOCKS5_handshake_done (ih); | 272 | SOCKS5_handshake_done (ih); |
273 | return; | 273 | return; |
274 | case SOCKS5_step_done: | 274 | case SOCKS5_step_done: |
275 | GNUNET_assert (0); | 275 | GNUNET_assert (0); |
276 | } | 276 | } |
277 | ih->instart = b; | 277 | ih->instart = b; |
278 | /* Do not reschedule the sender unless we're done reading. | 278 | /* Do not reschedule the sender unless we're done reading. |
279 | * I imagine this lets us avoid ever cancelling the transmit handle. */ | 279 | * I imagine this lets us avoid ever cancelling the transmit handle. */ |
280 | register_sender (ih); | 280 | register_sender (ih); |
281 | } | 281 | } |
@@ -289,7 +289,7 @@ SOCKS5_handshake_step (struct GNUNET_SOCKS_Handshake *ih) | |||
289 | * @param handler_cls closure for @a handler | 289 | * @param handler_cls closure for @a handler |
290 | */ | 290 | */ |
291 | void | 291 | void |
292 | reciever (void *cls, | 292 | reciever (void *cls, |
293 | const void *buf, size_t available, | 293 | const void *buf, size_t available, |
294 | const struct sockaddr * addr, | 294 | const struct sockaddr * addr, |
295 | socklen_t addrlen, int errCode) | 295 | socklen_t addrlen, int errCode) |
@@ -330,7 +330,7 @@ register_reciever (struct GNUNET_SOCKS_Handshake *ih, int want) | |||
330 | */ | 330 | */ |
331 | 331 | ||
332 | size_t | 332 | size_t |
333 | transmit_ready (void *cls, | 333 | transmit_ready (void *cls, |
334 | size_t size, | 334 | size_t size, |
335 | void *buf) | 335 | void *buf) |
336 | { | 336 | { |
@@ -345,23 +345,28 @@ transmit_ready (void *cls, | |||
345 | * GNUNET_CONNECTION_notify_transmit_ready() can schedule : | 345 | * GNUNET_CONNECTION_notify_transmit_ready() can schedule : |
346 | * transmit_timeout() - DNS still working | 346 | * transmit_timeout() - DNS still working |
347 | * connect_error() - DNS done but no socket? | 347 | * connect_error() - DNS done but no socket? |
348 | * transmit_ready() - scheduler shutdown or timeout, or signal_transmit_error() | 348 | * transmit_ready() - scheduler shutdown or timeout, or signal_transmit_error() |
349 | * We'd need to dig into the scheduler to guess at the reason, as | 349 | * We'd need to dig into the scheduler to guess at the reason, as |
350 | * connection.c tells us nothing itself, but mostly its timouts. | 350 | * connection.c tells us nothing itself, but mostly its timouts. |
351 | * Initially, we'll simply ignore this and leave massive timeouts, but | 351 | * Initially, we'll simply ignore this and leave massive timeouts, but |
352 | * maybe that should change for error handling pruposes. It appears that | 352 | * maybe that should change for error handling pruposes. It appears that |
353 | * successful operations, including DNS resolution, do not use this. */ | 353 | * successful operations, including DNS resolution, do not use this. */ |
354 | if (NULL==buf) | 354 | if (NULL == buf) |
355 | { | 355 | { |
356 | enum GNUNET_SCHEDULER_Reason reason = GNUNET_SCHEDULER_get_reason (); | 356 | const struct GNUNET_SCHEDULER_TaskContext *tc; |
357 | if (0 != (reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 357 | |
358 | tc = GNUNET_SCHEDULER_get_task_context (); | ||
359 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
358 | return 0; | 360 | return 0; |
359 | if (0 != (reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) { | 361 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) { |
360 | if (0==ih->step) { | 362 | if (0==ih->step) |
363 | { | ||
361 | LOG (GNUNET_ERROR_TYPE_WARNING, | 364 | LOG (GNUNET_ERROR_TYPE_WARNING, |
362 | "Timeout contacting SOCKS server, retrying indefinitely, but probably hopeless.\n"); | 365 | "Timeout contacting SOCKS server, retrying indefinitely, but probably hopeless.\n"); |
363 | register_sender (ih); | 366 | register_sender (ih); |
364 | } else { | 367 | } |
368 | else | ||
369 | { | ||
365 | LOG (GNUNET_ERROR_TYPE_ERROR, | 370 | LOG (GNUNET_ERROR_TYPE_ERROR, |
366 | "Timeout during mid SOCKS handshake (step %u), probably not a SOCKS server.\n", | 371 | "Timeout during mid SOCKS handshake (step %u), probably not a SOCKS server.\n", |
367 | ih->step); | 372 | ih->step); |
@@ -418,7 +423,7 @@ register_sender (struct GNUNET_SOCKS_Handshake *ih) | |||
418 | /** | 423 | /** |
419 | * Initialize a SOCKS5 handshake for authentication via username and | 424 | * Initialize a SOCKS5 handshake for authentication via username and |
420 | * password. Tor uses SOCKS username and password authentication to assign | 425 | * password. Tor uses SOCKS username and password authentication to assign |
421 | * programs unique circuits. | 426 | * programs unique circuits. |
422 | * | 427 | * |
423 | * @param user username for the proxy | 428 | * @param user username for the proxy |
424 | * @param pass password for the proxy | 429 | * @param pass password for the proxy |
@@ -435,7 +440,7 @@ GNUNET_SOCKS_init_handshake (const char *user, const char *pass) | |||
435 | unsigned char * n = b++; | 440 | unsigned char * n = b++; |
436 | *n = 1; /* Number of authentication methods */ | 441 | *n = 1; /* Number of authentication methods */ |
437 | /* We support no authentication even when requesting authentication, | 442 | /* We support no authentication even when requesting authentication, |
438 | * but this appears harmless, given the way that Tor uses authentication. | 443 | * but this appears harmless, given the way that Tor uses authentication. |
439 | * And some SOCKS5 servers might require this. */ | 444 | * And some SOCKS5 servers might require this. */ |
440 | *(b++) = SOCKS5_AUTH_NOAUTH; | 445 | *(b++) = SOCKS5_AUTH_NOAUTH; |
441 | if (NULL != user) { | 446 | if (NULL != user) { |
@@ -445,7 +450,7 @@ GNUNET_SOCKS_init_handshake (const char *user, const char *pass) | |||
445 | /* There is no apperent reason to support authentication methods beyond | 450 | /* There is no apperent reason to support authentication methods beyond |
446 | * username and password since afaik Tor does not support them. */ | 451 | * username and password since afaik Tor does not support them. */ |
447 | 452 | ||
448 | /* We authenticate with an empty username and password if the server demands | 453 | /* We authenticate with an empty username and password if the server demands |
449 | * them but we do not have any. */ | 454 | * them but we do not have any. */ |
450 | if (user == NULL) | 455 | if (user == NULL) |
451 | user = ""; | 456 | user = ""; |
@@ -466,7 +471,7 @@ GNUNET_SOCKS_init_handshake (const char *user, const char *pass) | |||
466 | 471 | ||
467 | 472 | ||
468 | /** | 473 | /** |
469 | * Initialize a SOCKS5 handshake without authentication, thereby possibly | 474 | * Initialize a SOCKS5 handshake without authentication, thereby possibly |
470 | * sharing a Tor circuit with another process. | 475 | * sharing a Tor circuit with another process. |
471 | * | 476 | * |
472 | * @return Valid SOCKS5 hanbdshake handle | 477 | * @return Valid SOCKS5 hanbdshake handle |
@@ -480,11 +485,11 @@ GNUNET_SOCKS_init_handshake_noauth () | |||
480 | 485 | ||
481 | /** | 486 | /** |
482 | * Build request that the SOCKS5 proxy open a TCP/IP stream to the given host | 487 | * Build request that the SOCKS5 proxy open a TCP/IP stream to the given host |
483 | * and port. | 488 | * and port. |
484 | * | 489 | * |
485 | * @param ih SOCKS5 handshake | 490 | * @param ih SOCKS5 handshake |
486 | * @param hostname | 491 | * @param hostname |
487 | * @param port | 492 | * @param port |
488 | */ | 493 | */ |
489 | void | 494 | void |
490 | GNUNET_SOCKS_set_handshake_destination (struct GNUNET_SOCKS_Handshake *ih, | 495 | GNUNET_SOCKS_set_handshake_destination (struct GNUNET_SOCKS_Handshake *ih, |
@@ -529,7 +534,7 @@ GNUNET_SOCKS_set_handshake_destination (struct GNUNET_SOCKS_Handshake *ih, | |||
529 | * @param c open unused connection, consumed here. | 534 | * @param c open unused connection, consumed here. |
530 | * @return Connection handle that becomes usable when the SOCKS5 handshake completes. | 535 | * @return Connection handle that becomes usable when the SOCKS5 handshake completes. |
531 | */ | 536 | */ |
532 | struct GNUNET_CONNECTION_Handle * | 537 | struct GNUNET_CONNECTION_Handle * |
533 | GNUNET_SOCKS_run_handshake(struct GNUNET_SOCKS_Handshake *ih, | 538 | GNUNET_SOCKS_run_handshake(struct GNUNET_SOCKS_Handshake *ih, |
534 | struct GNUNET_CONNECTION_Handle *c) | 539 | struct GNUNET_CONNECTION_Handle *c) |
535 | { | 540 | { |
@@ -580,7 +585,7 @@ GNUNET_SOCKS_do_connect (const char *service_name, | |||
580 | if (GNUNET_OK != | 585 | if (GNUNET_OK != |
581 | GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "SOCKSPORT", &port0)) | 586 | GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "SOCKSPORT", &port0)) |
582 | port0 = 9050; | 587 | port0 = 9050; |
583 | /* A typical Tor client should usually try port 9150 for the TBB too, but | 588 | /* A typical Tor client should usually try port 9150 for the TBB too, but |
584 | * GUNNet can probably assume a system Tor instalation. */ | 589 | * GUNNet can probably assume a system Tor instalation. */ |
585 | if (GNUNET_OK != | 590 | if (GNUNET_OK != |
586 | GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "SOCKSHOST", &host0)) | 591 | GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "SOCKSHOST", &host0)) |