GNUnet  0.11.x
Functions
SOCKS proxy

SOCKS proxy for connections. More...

Functions

int GNUNET_SOCKS_check_service (const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Check if a SOCKS proxy is required by a service. More...
 
struct GNUNET_CONNECTION_HandleGNUNET_SOCKS_do_connect (const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Try to connect to a service configured to use a SOCKS5 proxy. More...
 

Detailed Description

SOCKS proxy for connections.

Function Documentation

◆ GNUNET_SOCKS_check_service()

int GNUNET_SOCKS_check_service ( const char *  service_name,
const struct GNUNET_CONFIGURATION_Handle cfg 
)

Check if a SOCKS proxy is required by a service.

Do not use local service if a SOCKS proxy port is configured as this could deanonymize a user.

Parameters
service_namename of service to connect to
cfgconfiguration to use
Returns
GNUNET_YES if so, GNUNET_NO if not

Definition at line 593 of file socks.c.

References GNUNET_CONFIGURATION_have_value().

Referenced by GNUNET_SOCKS_do_connect(), and start_connect().

595 {
596  return GNUNET_CONFIGURATION_have_value (cfg, service_name, "SOCKSPORT") ||
597  GNUNET_CONFIGURATION_have_value (cfg, service_name, "SOCKSHOST");
598 }
int GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SOCKS_do_connect()

struct GNUNET_CONNECTION_Handle* GNUNET_SOCKS_do_connect ( const char *  service_name,
const struct GNUNET_CONFIGURATION_Handle cfg 
)

Try to connect to a service configured to use a SOCKS5 proxy.

Parameters
service_namename of service to connect to
cfgconfiguration to use
Returns
Connection handle that becomes usable when the handshake completes. NULL if SOCKS not configured or not configured properly

Definition at line 610 of file socks.c.

References _, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONNECTION_create_from_connect(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_free_non_null, GNUNET_OK, GNUNET_SOCKS_check_service(), GNUNET_SOCKS_init_handshake(), GNUNET_SOCKS_run_handshake(), GNUNET_SOCKS_set_handshake_destination(), GNUNET_YES, and LOG.

612 {
613  struct GNUNET_SOCKS_Handshake *ih;
614  struct GNUNET_CONNECTION_Handle *socks5; /* *proxied */
615  char *host0;
616  char *host1;
617  char *user;
618  char *pass;
619  unsigned long long port0;
620  unsigned long long port1;
621 
623  return NULL;
625  service_name,
626  "SOCKSPORT",
627  &port0))
628  port0 = 9050;
629  /* A typical Tor client should usually try port 9150 for the TBB too, but
630  * GNUnet can probably assume a system Tor installation. */
631  if ((port0 > 65535) || (port0 <= 0))
632  {
634  _ (
635  "Attempting to use invalid port %d as SOCKS proxy for service `%s'.\n"),
636  port0,
637  service_name);
638  return NULL;
639  }
641  service_name,
642  "PORT",
643  &port1)) ||
644  (port1 > 65535) || (port1 <= 0) ||
646  service_name,
647  "HOSTNAME",
648  &host1)))
649  {
651  _ (
652  "Attempting to proxy service `%s' to invalid port %d or hostname.\n"),
653  service_name,
654  port1);
655  return NULL;
656  }
657  /* Appeared to still work after host0 corrupted, so either test case is broken, or
658  this whole routine is not being called. */
660  service_name,
661  "SOCKSHOST",
662  &host0))
663  host0 = NULL;
665  (host0 != NULL) ? host0
666  : "127.0.0.1",
667  port0);
668  GNUNET_free_non_null (host0);
669 
670  /* Sets to NULL if they do not exist */
672  service_name,
673  "SOCKSUSER",
674  &user);
676  service_name,
677  "SOCKSPASS",
678  &pass);
679  ih = GNUNET_SOCKS_init_handshake (user, pass);
680  GNUNET_free_non_null (user);
681  GNUNET_free_non_null (pass);
682 
683  GNUNET_SOCKS_set_handshake_destination (ih, host1, port1);
684  GNUNET_free (host1);
685  return GNUNET_SOCKS_run_handshake (ih, socks5);
686 }
struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *hostname, uint16_t port)
Create a connection handle by (asynchronously) connecting to a host.
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
void GNUNET_SOCKS_set_handshake_destination(struct GNUNET_SOCKS_Handshake *ih, const char *host, uint16_t port)
Build request that the SOCKS5 proxy open a TCP/IP stream to the given host and port.
Definition: socks.c:523
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
int GNUNET_SOCKS_check_service(const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg)
Check if a SOCKS proxy is required by a service.
Definition: socks.c:593
#define LOG(kind,...)
Definition: socks.c:32
struct GNUNET_CONNECTION_Handle * GNUNET_SOCKS_run_handshake(struct GNUNET_SOCKS_Handshake *ih, struct GNUNET_CONNECTION_Handle *c)
Run a SOCKS5 handshake on an open but unused TCP connection.
Definition: socks.c:573
#define GNUNET_YES
Definition: gnunet_common.h:77
State of the SOCKS5 handshake.
Definition: socks.c:135
handle for a network connection
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_SOCKS_Handshake * GNUNET_SOCKS_init_handshake(const char *user, const char *pass)
Initialize a SOCKS5 handshake for authentication via username and password.
Definition: socks.c:459
Here is the call graph for this function: