31#include <microhttpd.h>
34#include <gnutls/gnutls.h>
35#include <gnutls/x509.h>
36#include <gnutls/abstract.h>
37#include <gnutls/crypto.h>
39#include <gnutls/dane.h>
49#define GNUNET_GNS_PROXY_PORT 7777
55#define MAX_HTTP_URI_LENGTH 2048
67#define IO_BUFFERSIZE CURL_MAX_WRITE_SIZE
74#define SOCKS_BUFFERSIZE (256 + 32)
89#define MAX_PEM_SIZE (10 * 1024)
94#define MHD_CACHE_TIMEOUT GNUNET_TIME_relative_multiply ( \
95 GNUNET_TIME_UNIT_MINUTES, 5)
101#define HTTP_HANDSHAKE_TIMEOUT GNUNET_TIME_relative_multiply ( \
102 GNUNET_TIME_UNIT_SECONDS, 15)
112#define LOG_CURL_EASY(level, fun, rc) \
114 _ ("%s failed at %s:%d: `%s'\n"), \
118 curl_easy_strerror (rc))
126#define SOCKS_VERSION_5 0x05
131#define SOCKS_AUTH_NONE 0
313 gnutls_x509_privkey_t
key;
525 struct MHD_Connection *
con;
775 "Cleaning up socks request\n");
776 if (NULL != s5r->
curl)
779 "Cleaning up cURL handle\n");
782 curl_easy_cleanup (s5r->
curl);
788 MHD_resume_connection (s5r->
con);
790 curl_slist_free_all (s5r->
headers);
791 if (NULL != s5r->
hosts)
793 curl_slist_free_all (s5r->
hosts);
798 MHD_destroy_response (s5r->
response);
801 if (NULL != s5r->
rtask)
811 if (NULL != s5r->
wtask)
821 if (NULL != s5r->
sock)
823 if (SOCKS5_SOCKET_WITH_MHD <= s5r->
state)
835 for (
unsigned int i = 0; i < s5r->
num_danes; i++)
865 size_t bytes_to_copy;
874 "Pausing MHD download %s%s, not yet ready for download\n",
881 if ((0 == bytes_to_copy) &&
885 "Pausing MHD download %s%s, no data available\n",
888 if (NULL != s5r->
curl)
891 "Continuing CURL interaction for %s%s\n",
897 curl_easy_pause (s5r->
curl,
904 MHD_suspend_connection (s5r->
con);
909 if ((0 == bytes_to_copy) &&
913 "Completed MHD download %s%s\n",
916 return MHD_CONTENT_READER_END_OF_STREAM;
919 "Writing %llu/%llu bytes to %s%s\n",
920 (
unsigned long long) bytes_to_copy,
921 (
unsigned long long) s5r->
io_len,
928 &s5r->
io_buf[bytes_to_copy],
929 s5r->
io_len - bytes_to_copy);
930 s5r->
io_len -= bytes_to_copy;
931 if ((NULL != s5r->
curl) &&
935 "Continuing CURL interaction for %s%s\n",
939 curl_easy_pause (s5r->
curl,
942 return bytes_to_copy;
957 unsigned int cert_list_size;
958 const gnutls_datum_t *chainp;
959 const struct curl_tlssessioninfo *tlsinfo;
962 gnutls_x509_crt_t x509_cert;
968 "Checking X.509 certificate\n");
970 curl_easy_getinfo (s5r->
curl,
971 CURLINFO_TLS_SSL_PTR,
974 if (CURLSSLBACKEND_GNUTLS != tlsinfo->backend)
977 _ (
"Unsupported CURL TLS backend %d\n"),
981 chainp = gnutls_certificate_get_peers (tlsinfo->internals,
984 (0 == cert_list_size))
987 size =
sizeof(certdn);
989 gnutls_x509_crt_init (&x509_cert);
990 gnutls_x509_crt_import (x509_cert,
992 GNUTLS_X509_FMT_DER);
994 if (0 != (rc = gnutls_x509_crt_get_dn_by_oid (x509_cert,
995 GNUTLS_OID_X520_COMMON_NAME,
1002 _ (
"Failed to fetch CN from cert: %s\n"),
1003 gnutls_strerror (rc));
1004 gnutls_x509_crt_deinit (x509_cert);
1011 dane_state_t dane_state;
1012 dane_query_t dane_query;
1016 if (0 != (rc = dane_state_init (&dane_state,
1017#ifdef DANE_F_IGNORE_DNSSEC
1018 DANE_F_IGNORE_DNSSEC |
1020 DANE_F_IGNORE_LOCAL_RESOLVER)))
1023 _ (
"Failed to initialize DANE: %s\n"),
1024 dane_strerror (rc));
1025 gnutls_x509_crt_deinit (x509_cert);
1030 if (0 != (rc = dane_raw_tlsa (dane_state,
1038 _ (
"Failed to parse DANE record: %s\n"),
1039 dane_strerror (rc));
1040 dane_state_deinit (dane_state);
1041 gnutls_x509_crt_deinit (x509_cert);
1044 if (0 != (rc = dane_verify_crt_raw (dane_state,
1047 gnutls_certificate_type_get (
1048 tlsinfo->internals),
1054 _ (
"Failed to verify TLS connection using DANE: %s\n"),
1055 dane_strerror (rc));
1056 dane_query_deinit (dane_query);
1057 dane_state_deinit (dane_state);
1058 gnutls_x509_crt_deinit (x509_cert);
1065 "Failed DANE verification failed with GnuTLS verify status code: %u\n"),
1067 dane_query_deinit (dane_query);
1068 dane_state_deinit (dane_state);
1069 gnutls_x509_crt_deinit (x509_cert);
1072 dane_query_deinit (dane_query);
1073 dane_state_deinit (dane_state);
1081 if (NULL != s5r->
leho)
1085 if (0 == (rc = gnutls_x509_crt_check_hostname (x509_cert,
1090 "TLS certificate subject name (%s) does not match `%s': %d\n"),
1094 gnutls_x509_crt_deinit (x509_cert);
1105 gnutls_x509_crt_deinit (x509_cert);
1130 size_t bytes =
size * nmemb;
1132 const char *hdr_type;
1133 const char *cookie_domain;
1135 char *new_cookie_hdr;
1138 size_t delta_cdomain;
1143 "Receiving HTTP response header from CURL\n");
1154 hdr_type = strtok (ndup,
1156 if (NULL == hdr_type)
1161 hdr_val = strtok (NULL,
1163 if (NULL == hdr_val)
1168 if (
' ' == *hdr_val)
1172 new_cookie_hdr = NULL;
1173 if ((NULL != s5r->
leho) &&
1174 (0 == strcasecmp (hdr_type,
1175 MHD_HTTP_HEADER_SET_COOKIE)))
1179 + strlen (s5r->
domain) + 1);
1182 for (tok = strtok (hdr_val,
";"); NULL != tok; tok = strtok (NULL,
";"))
1184 if ((0 == strncasecmp (tok,
1186 strlen (
" domain"))) &&
1190 cookie_domain = tok + strlen (
" domain") + 1;
1191 if (strlen (cookie_domain) < strlen (s5r->
leho))
1193 delta_cdomain = strlen (s5r->
leho) - strlen (cookie_domain);
1194 if (0 == strcasecmp (cookie_domain,
1195 s5r->
leho + delta_cdomain))
1197 offset += sprintf (new_cookie_hdr + offset,
1203 else if (0 == strcmp (cookie_domain,
1206 offset += sprintf (new_cookie_hdr + offset,
1211 else if ((
'.' == cookie_domain[0]) &&
1212 (0 == strcmp (&cookie_domain[1],
1215 offset += sprintf (new_cookie_hdr + offset,
1221 _ (
"Cookie domain `%s' supplied by server is invalid\n"),
1227 offset += strlen (tok);
1228 new_cookie_hdr[offset++] =
';';
1230 hdr_val = new_cookie_hdr;
1231 hdr_val[offset] =
'\0';
1234 new_location = NULL;
1235 if (0 == strcasecmp (MHD_HTTP_HEADER_TRANSFER_ENCODING,
1241 if ((0 == strcasecmp (MHD_HTTP_HEADER_LOCATION,
1251 if (0 == strncmp (leho_host,
1253 strlen (leho_host)))
1261 hdr_val + strlen (leho_host));
1262 hdr_val = new_location;
1266 else if (0 == strcasecmp (MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
1276 if (0 == strncmp (leho_host,
1278 strlen (leho_host)))
1286 hdr_val = new_location;
1292 if (NULL != (tok = strchr (hdr_val,
'\n')))
1294 if (NULL != (tok = strchr (hdr_val,
'\r')))
1296 if (NULL != (tok = strchr (hdr_val,
'\t')))
1298 if (0 != strlen (hdr_val))
1301 "Adding header %s: %s to MHD response\n",
1331 double content_length;
1336 "Response already set!\n");
1341 curl_easy_getinfo (s5r->
curl,
1342 CURLINFO_RESPONSE_CODE,
1345 curl_easy_getinfo (s5r->
curl,
1346 CURLINFO_CONTENT_LENGTH_DOWNLOAD_T,
1349 "Creating MHD response with code %d and size %d for %s%s\n",
1351 (
int) content_length,
1355 s5r->
response = MHD_create_response_from_callback ((-1 == content_length)
1364 header = header->
next)
1366 if (0 == strcasecmp (header->type,
1367 MHD_HTTP_HEADER_CONTENT_LENGTH))
1369 if ((0 == strcasecmp (header->type,
1370 MHD_HTTP_HEADER_TRANSFER_ENCODING)) &&
1371 ((0 == strcasecmp (header->value,
1373 (0 == strcasecmp (header->value,
1377 MHD_add_response_header (s5r->
response,
1383 "Failed to add header `%s:%s'\n",
1394 MHD_resume_connection (s5r->
con);
1417 size_t total =
size * nmemb;
1420 "Receiving %ux%u bytes for `%s%s' from cURL to download\n",
1421 (
unsigned int)
size,
1422 (
unsigned int) nmemb,
1432 "Previous upload finished... starting DOWNLOAD.\n");
1442 "Pausing CURL download `%s%s', waiting for UPLOAD to finish\n",
1446 return CURL_WRITEFUNC_PAUSE;
1451 "Pausing CURL `%s%s' download, not enough space %llu %llu %llu\n",
1454 (
unsigned long long)
sizeof(s5r->
io_buf),
1455 (
unsigned long long) s5r->
io_len,
1456 (
unsigned long long) total);
1458 return CURL_WRITEFUNC_PAUSE;
1466 MHD_resume_connection (s5r->
con);
1470 "Received %llu bytes of payload via cURL from %s\n",
1471 (
unsigned long long) total,
1473 if (s5r->
io_len == total)
1496 size_t len =
size * nmemb;
1500 "Receiving %ux%u bytes for `%s%s' from cURL to upload\n",
1501 (
unsigned int)
size,
1502 (
unsigned int) nmemb,
1506 if ((0 == s5r->
io_len) &&
1510 "Pausing CURL UPLOAD %s%s, need more data\n",
1513 return CURL_READFUNC_PAUSE;
1515 if ((0 == s5r->
io_len) &&
1522 curl_easy_pause (s5r->
curl,
1526 "Completed CURL UPLOAD %s%s\n",
1535 return CURL_READFUNC_ABORT;
1582 "Scheduling CURL interaction\n");
1592 if (CURLM_OK != (mret = curl_multi_fdset (
curl_multi,
1599 "%s failed at %s:%d: `%s'\n",
1600 "curl_multi_fdset", __FILE__, __LINE__,
1601 curl_multi_strerror (mret));
1652 struct CURLMsg *
msg;
1658 "Running CURL interaction\n");
1665 "Checking CURL multi status: %d\n",
1671 curl_easy_getinfo (
msg->easy_handle,
1687 switch (
msg->data.result)
1690 case CURLE_GOT_NOTHING:
1692 "CURL download %s%s completed.\n",
1695 if (NULL == s5r->response)
1703 MHD_resume_connection (s5r->con);
1711 "Download curl %s%s failed: %s\n",
1714 curl_easy_strerror (
msg->data.result));
1719 MHD_resume_connection (s5r->con);
1725 if (NULL == s5r->response)
1742 while (mret == CURLM_CALL_MULTI_PERFORM);
1743 if (CURLM_OK != mret)
1745 "%s failed at %s:%d: `%s'\n",
1746 "curl_multi_perform", __FILE__, __LINE__,
1747 curl_multi_strerror (mret));
1751 "Suspending cURL multi loop, no more events pending\n");
1781 enum MHD_ValueKind kind,
1788 if ((0 == strcasecmp (MHD_HTTP_HEADER_HOST,
1790 (NULL != s5r->
leho))
1797 "Adding HEADER `%s' to HTTP request\n",
1831 struct MHD_Connection *
con,
1835 const char *upload_data,
1836 size_t *upload_data_size,
1841 char ipstring[INET6_ADDRSTRLEN];
1842 char ipaddr[INET6_ADDRSTRLEN + 2];
1844 const struct sockaddr *sa;
1845 const struct sockaddr_in *s4;
1846 const struct sockaddr_in6 *s6;
1863 switch (sa->sa_family)
1867 if (NULL == inet_ntop (AF_INET,
1879 port_tmp = ntohs (s4->sin_port);
1884 if (NULL == inet_ntop (AF_INET6,
1896 port_tmp = ntohs (s6->sin6_port);
1908 s5r->
hosts = curl_slist_append (NULL,
1914 port_tmp = s5r->
port;
1916 if (NULL == s5r->
curl)
1917 s5r->
curl = curl_easy_init ();
1918 if (NULL == s5r->
curl)
1919 return MHD_queue_response (con,
1922 curl_easy_setopt (s5r->
curl,
1923 CURLOPT_HEADERFUNCTION,
1925 curl_easy_setopt (s5r->
curl,
1928 curl_easy_setopt (s5r->
curl,
1929 CURLOPT_FOLLOWLOCATION,
1932 curl_easy_setopt (s5r->
curl,
1935 curl_easy_setopt (s5r->
curl,
1936 CURLOPT_CONNECTTIMEOUT,
1938 curl_easy_setopt (s5r->
curl,
1941 curl_easy_setopt (s5r->
curl,
1944 curl_easy_setopt (s5r->
curl,
1945 CURLOPT_HTTP_CONTENT_DECODING,
1947 curl_easy_setopt (s5r->
curl,
1950 curl_easy_setopt (s5r->
curl,
1953 curl_easy_setopt (s5r->
curl,
1961 if ((NULL != s5r->
leho) &&
1962 (NULL != s5r->
hosts))
1964 curl_easy_setopt (s5r->
curl,
1973 :
"https://%s:%d%s",
1985 :
"https://%s:%d%s",
1990 curl_easy_setopt (s5r->
curl,
1994 "Launching %s CURL interaction, fetching `%s'\n",
1995 (s5r->
is_gns) ?
"GNS" :
"DNS",
1998 if (0 == strcasecmp (meth,
1999 MHD_HTTP_METHOD_PUT))
2002 curl_easy_setopt (s5r->
curl,
2005 curl_easy_setopt (s5r->
curl,
2006 CURLOPT_WRITEFUNCTION,
2008 curl_easy_setopt (s5r->
curl,
2012 curl_easy_setopt (s5r->
curl,
2013 CURLOPT_READFUNCTION,
2015 curl_easy_setopt (s5r->
curl,
2020 long upload_size = 0;
2022 us = MHD_lookup_connection_value (con,
2024 MHD_HTTP_HEADER_CONTENT_LENGTH);
2025 if ((1 == sscanf (us,
2030 curl_easy_setopt (s5r->
curl,
2036 else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_POST))
2039 curl_easy_setopt (s5r->
curl,
2042 curl_easy_setopt (s5r->
curl,
2043 CURLOPT_WRITEFUNCTION,
2045 curl_easy_setopt (s5r->
curl,
2048 curl_easy_setopt (s5r->
curl,
2049 CURLOPT_READFUNCTION,
2051 curl_easy_setopt (s5r->
curl,
2059 us = MHD_lookup_connection_value (con,
2061 MHD_HTTP_HEADER_CONTENT_LENGTH);
2068 curl_easy_setopt (s5r->
curl,
2074 curl_easy_setopt (s5r->
curl,
2080 else if (0 == strcasecmp (meth,
2081 MHD_HTTP_METHOD_HEAD))
2084 curl_easy_setopt (s5r->
curl,
2088 else if (0 == strcasecmp (meth,
2089 MHD_HTTP_METHOD_OPTIONS))
2092 curl_easy_setopt (s5r->
curl,
2093 CURLOPT_CUSTOMREQUEST,
2095 curl_easy_setopt (s5r->
curl,
2096 CURLOPT_WRITEFUNCTION,
2098 curl_easy_setopt (s5r->
curl,
2102 else if (0 == strcasecmp (meth,
2103 MHD_HTTP_METHOD_GET))
2106 curl_easy_setopt (s5r->
curl,
2109 curl_easy_setopt (s5r->
curl,
2110 CURLOPT_WRITEFUNCTION,
2112 curl_easy_setopt (s5r->
curl,
2116 else if (0 == strcasecmp (meth,
2117 MHD_HTTP_METHOD_DELETE))
2120 curl_easy_setopt (s5r->
curl,
2121 CURLOPT_CUSTOMREQUEST,
2123 curl_easy_setopt (s5r->
curl,
2124 CURLOPT_WRITEFUNCTION,
2126 curl_easy_setopt (s5r->
curl,
2133 _ (
"Unsupported HTTP method `%s'\n"),
2135 curl_easy_cleanup (s5r->
curl);
2140 if (0 == strcasecmp (ver, MHD_HTTP_VERSION_1_0))
2142 curl_easy_setopt (s5r->
curl,
2143 CURLOPT_HTTP_VERSION,
2144 CURL_HTTP_VERSION_1_0);
2146 else if (0 == strcasecmp (ver, MHD_HTTP_VERSION_1_1))
2148 curl_easy_setopt (s5r->
curl,
2149 CURLOPT_HTTP_VERSION,
2150 CURL_HTTP_VERSION_1_1);
2154 curl_easy_setopt (s5r->
curl,
2155 CURLOPT_HTTP_VERSION,
2156 CURL_HTTP_VERSION_NONE);
2161 curl_easy_setopt (s5r->
curl,
2165 curl_easy_setopt (s5r->
curl,
2166 CURLOPT_SSL_VERIFYPEER,
2169 curl_easy_setopt (s5r->
curl,
2170 CURLOPT_SSL_VERIFYPEER,
2174 curl_easy_setopt (s5r->
curl,
2175 CURLOPT_SSL_VERIFYHOST,
2180 curl_easy_setopt (s5r->
curl,
2190 curl_easy_cleanup (s5r->
curl);
2194 MHD_get_connection_values (con,
2198 curl_easy_setopt (s5r->
curl,
2206 if (0 != *upload_data_size)
2209 "Processing %u bytes UPLOAD\n",
2210 (
unsigned int) *upload_data_size);
2215 curl_easy_setopt (s5r->
curl,
2216 CURLOPT_POSTFIELDSIZE,
2225 *upload_data_size -= left;
2230 curl_easy_pause (s5r->
curl,
2238 "Finished processing UPLOAD\n");
2244 "Waiting for HTTP response for %s%s...\n",
2247 MHD_suspend_connection (con);
2252 "Queueing response for %s%s with MHD\n",
2256 return MHD_queue_response (con,
2276 struct MHD_Connection *connection,
2278 enum MHD_RequestTerminationCode toe)
2284 if (MHD_REQUEST_TERMINATED_COMPLETED_OK != toe)
2286 "MHD encountered error handling request: %d\n",
2288 if (NULL != s5r->
curl)
2291 "Removing cURL handle (MHD interaction complete)\n");
2294 curl_slist_free_all (s5r->
headers);
2296 curl_easy_reset (s5r->
curl);
2304 MHD_destroy_response (s5r->
response);
2317 "Finished request for %s\n",
2338 struct MHD_Connection *connection,
2340 enum MHD_ConnectionNotificationCode cnc)
2343 const union MHD_ConnectionInfo *ci;
2348 case MHD_CONNECTION_NOTIFY_STARTED:
2350 ci = MHD_get_connection_info (connection,
2351 MHD_CONNECTION_INFO_CONNECTION_FD);
2357 sock = ci->connect_fd;
2363 "Context set...\n");
2371 case MHD_CONNECTION_NOTIFY_CLOSED:
2373 "Connection closed... cleaning up\n");
2378 "Connection stale!\n");
2408 struct MHD_Connection *connection)
2411 const union MHD_ConnectionInfo *ci;
2413 ci = MHD_get_connection_info (connection,
2414 MHD_CONNECTION_INFO_SOCKET_CONTEXT);
2421 s5r = ci->socket_context;
2422 if (NULL != s5r->
url)
2450 MHD_stop_daemon (hd->
daemon);
2504 MHD_UNSIGNED_LONG_LONG
timeout;
2512 MHD_get_fdset (hd->
daemon,
2521 haveto = MHD_get_timeout (hd->
daemon,
2523 if (MHD_YES == haveto)
2544 if ((MHD_YES != haveto) &&
2640 gnutls_datum_t key_data;
2645 if (NULL == key_data.data)
2647 ret = gnutls_x509_privkey_import (
key, &key_data,
2648 GNUTLS_X509_FMT_PEM);
2649 if (GNUTLS_E_SUCCESS !=
ret)
2652 _ (
"Unable to import private key from file `%s'\n"),
2669 const char*certfile)
2671 gnutls_datum_t cert_data;
2676 if (NULL == cert_data.data)
2678 ret = gnutls_x509_crt_import (crt,
2680 GNUTLS_X509_FMT_PEM);
2681 if (GNUTLS_E_SUCCESS !=
ret)
2684 _ (
"Unable to import certificate from `%s'\n"),
2701 unsigned int serial;
2702 size_t key_buf_size;
2703 size_t cert_buf_size;
2710 "Generating x.509 certificate for `%s'\n",
2716 gnutls_x509_crt_set_dn_by_oid (
request,
2717 GNUTLS_OID_X520_COUNTRY_NAME,
2721 gnutls_x509_crt_set_dn_by_oid (
request,
2722 GNUTLS_OID_X520_ORGANIZATION_NAME,
2725 strlen (
"GNU Name System"));
2726 gnutls_x509_crt_set_dn_by_oid (
request,
2727 GNUTLS_OID_X520_COMMON_NAME,
2731 gnutls_x509_crt_set_subject_alternative_name (
request,
2735 gnutls_x509_crt_set_version (
request,
2737 gnutls_rnd (GNUTLS_RND_NONCE,
2740 gnutls_x509_crt_set_serial (
request,
2743 etime = time (NULL);
2744 tm_data = localtime (&
etime);
2746 etime = mktime (tm_data);
2747 gnutls_x509_crt_set_activation_time (
request,
2750 etime = mktime (tm_data);
2751 gnutls_x509_crt_set_expiration_time (
request,
2753 gnutls_x509_crt_sign2 (
request,
2758 key_buf_size =
sizeof(pgc->
key);
2759 cert_buf_size =
sizeof(pgc->
cert);
2760 gnutls_x509_crt_export (
request,
2761 GNUTLS_X509_FMT_PEM,
2765 GNUTLS_X509_FMT_PEM,
2768 gnutls_x509_crt_deinit (
request);
2807 if ((NULL != hd->
domain) &&
2808 (0 == strcmp (hd->
domain, domain)))
2811 "Starting fresh MHD HTTPS instance for domain `%s'\n",
2818 hd->
daemon = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL
2819 | MHD_USE_NO_LISTEN_SOCKET
2820 | MHD_ALLOW_SUSPEND_RESUME,
2824 MHD_OPTION_CONNECTION_TIMEOUT, (
unsigned
2828 MHD_OPTION_NOTIFY_CONNECTION,
2832 MHD_OPTION_EXTERNAL_LOGGER,
2834 MHD_OPTION_HTTPS_MEM_KEY, pgc->
key,
2835 MHD_OPTION_HTTPS_MEM_CERT, pgc->
cert,
2880 const struct sockaddr *addr;
2893 _ (
"Failed to start HTTPS server for `%s'\n"),
2911 MHD_add_connection (hd->
daemon,
2917 _ (
"Failed to pass client to MHD\n"));
3018 if (NULL != s5r->
wtask)
3044 sizeof(
struct in_addr) +
sizeof(uint16_t));
3046 + sizeof(struct in_addr) + sizeof(uint16_t);
3047 if (NULL == s5r->
wtask)
3076 for (uint32_t i = 0; i <
rd_count; i++)
3083 struct sockaddr_in *in;
3085 if (
sizeof(
struct in_addr) != r->
data_size)
3097 in->sin_family = AF_INET;
3101 in->sin_port = htons (s5r->
port);
3102#if HAVE_SOCKADDR_IN_SIN_LEN
3103 in->sin_len =
sizeof(*in);
3110 struct sockaddr_in6 *in;
3112 if (
sizeof(
struct in6_addr) != r->
data_size)
3127 in->sin6_family = AF_INET6;
3131 in->sin6_port = htons (s5r->
port);
3132#if HAVE_SOCKADDR_IN_SIN_LEN
3133 in->sin6_len =
sizeof(*in);
3159 (ntohs (box->
protocol) != IPPROTO_TCP) ||
3186 "Name resolution failed to yield useful IP address.\n");
3242 "socks5 client disconnected.\n");
3252 "Processing %zu bytes of socks data in state %d\n",
3266 _ (
"Unsupported socks version %d\n"),
3298 _ (
"Unsupported socks command %d\n"),
3308 const struct in_addr *v4 = (
const struct in_addr *) &c_req[1];
3309 const uint16_t *v4port = (
const uint16_t *) &v4[1];
3310 struct sockaddr_in *in;
3312 s5r->
port = ntohs (*v4port);
3313 alen =
sizeof(
struct in_addr);
3315 + alen +
sizeof(uint16_t))
3318 in->sin_family = AF_INET;
3320 in->sin_port = *v4port;
3321#
if HAVE_SOCKADDR_IN_SIN_LEN
3322 in->sin_len =
sizeof(*in);
3330 const struct in6_addr *v6 = (
const struct in6_addr *) &c_req[1];
3331 const uint16_t *v6port = (
const uint16_t *) &v6[1];
3332 struct sockaddr_in6 *in;
3334 s5r->
port = ntohs (*v6port);
3335 alen =
sizeof(
struct in6_addr);
3337 + alen +
sizeof(uint16_t))
3340 in->sin6_family = AF_INET6;
3341 in->sin6_addr = *v6;
3342 in->sin6_port = *v6port;
3343#
if HAVE_SOCKADDR_IN_SIN_LEN
3344 in->sin6_len =
sizeof(*in);
3352 const uint8_t *dom_len;
3353 const char *dom_name;
3354 const uint16_t *dport;
3356 dom_len = (
const uint8_t *) &c_req[1];
3357 alen = *dom_len + 1;
3359 + alen +
sizeof(uint16_t))
3361 dom_name = (
const char *) &dom_len[1];
3362 dport = (
const uint16_t *) &dom_name[*dom_len];
3366 "Requested connection is to %s:%d\n",
3371 s5r->
port = ntohs (*dport);
3384 _ (
"Unsupported socks address type %d\n"),
3392 + alen +
sizeof(uint16_t));
3444 else if (lsock ==
lsock6)
3461 "Got an inbound connection, waiting for data\n");
3487 "Shutting down...\n");
3496 MHD_resume_connection (s5r->con);
3540 gnutls_global_deinit ();
3553 struct sockaddr_in sa4;
3556 memset (&sa4, 0,
sizeof(sa4));
3557 sa4.sin_family = AF_INET;
3558 sa4.sin_port = htons (
port);
3559 sa4.sin_addr.s_addr =
address;
3560#if HAVE_SOCKADDR_IN_SIN_LEN
3561 sa4.sin_len =
sizeof(sa4);
3570 (
const struct sockaddr *) &sa4,
3591 struct sockaddr_in6 sa6;
3594 memset (&sa6, 0,
sizeof(sa6));
3595 sa6.sin6_family = AF_INET6;
3596 sa6.sin6_port = htons (
port);
3598#if HAVE_SOCKADDR_IN_SIN_LEN
3599 sa6.sin6_len =
sizeof(sa6);
3608 (
const struct sockaddr *) &sa6,
3631 const char *cfgfile,
3634 char*cafile_cfg = NULL;
3648 "Don't know what to bind to...\n");
3653 if (1 != inet_pton (AF_INET, addr_str, &
address))
3656 "Unable to parse address %s\n",
3670 "Don't know what to bind6 to...\n");
3675 if (1 != inet_pton (AF_INET6, addr_str, &
address6))
3678 "Unable to parse IPv6 address %s\n",
3686 if (NULL == (
curl_multi = curl_multi_init ()))
3689 "Failed to create cURL multi handle!\n");
3706 cafile = cafile_cfg;
3709 "Using `%s' as CA\n",
3712 gnutls_global_init ();
3724 _ (
"Failed to load X.509 key and certificate from `%s'\n"),
3728 gnutls_global_deinit ();
3736 "Unable to connect to GNS!\n");
3739 gnutls_global_deinit ();
3802 if (CURLSSLSET_OK != curl_global_sslset (CURLSSLBACKEND_GNUTLS,
3807 "cURL does not support the GnuTLS backend\n");
3810 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
3813 "cURL global init failed!\n");
3818 "Proxy listens on port %u\n",
3819 (
unsigned int)
port);
3823 hd->
daemon = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_NO_LISTEN_SOCKET
3824 | MHD_ALLOW_SUSPEND_RESUME,
3828 MHD_OPTION_CONNECTION_TIMEOUT, (
unsigned
3832 MHD_OPTION_NOTIFY_CONNECTION,
3866 "listen on specified port (default: 7777)"),
3880 static const char*page =
3881 "<html><head><title>gnunet-gns-proxy</title>"
3882 "</head><body>cURL fail</body></html>";
3893 = MHD_create_response_from_buffer (strlen (page),
3895 MHD_RESPMEM_PERSISTENT);
3901 _ (
"GNUnet GNS proxy"),
3903 &
run, NULL)) ? 0 : 1;
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
struct GNUNET_GETOPT_CommandLineOption options[]
struct GNUNET_MessageHeader * msg
#define gettext_noop(String)
static int verify
Verify mode.
static int ret
Final status code.
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
struct GNUNET_HashCode key
The key used in the DHT.
static void cleanup(void *cls)
Disconnect and shutdown.
static struct GNUNET_FS_Handle * ctx
static struct MhdHttpList * mhd_httpd_tail
DLL for http/https daemons.
static void do_s5r_read(void *cls)
Read data from incoming Socks5 connection.
static struct ProxyCA proxy_ca
The CA for X.509 certificate generation.
static struct Socks5Request * s5r_tail
DLL of active socks requests.
static void * load_file(const char *filename, unsigned int *size)
Read file in filename.
static int create_mhd_response_from_s5r(struct Socks5Request *s5r)
Create an MHD response object in s5r matching the information we got from curl.
static size_t curl_download_cb(void *ptr, size_t size, size_t nmemb, void *ctx)
Handle response payload data from cURL.
static struct GNUNET_GNS_Handle * gns_handle
Handle to the GNS service.
static void signal_socks_success(struct Socks5Request *s5r)
Return a server response message indicating success.
#define SOCKS_AUTH_NONE
Flag to set for 'no authentication'.
#define GNUNET_GNS_PROXY_PORT
Default Socks5 listen port.
static struct GNUNET_NETWORK_Handle * bind_v4()
Create an IPv4 listen socket bound to our port.
static CURLM * curl_multi
The cURL multi handle.
Socks5Commands
Commands in Socks5.
@ SOCKS5_CMD_UDP_PORT
Establish UDP port binding.
@ SOCKS5_CMD_TCP_STREAM
Establish TCP/IP stream.
@ SOCKS5_CMD_TCP_PORT
Establish TCP port binding.
#define MAX_PEM_SIZE
Largest allowed size for a PEM certificate.
static struct GNUNET_NETWORK_Handle * bind_v6()
Create an IPv6 listen socket bound to our port.
static int disable_v6
Disable IPv6.
static char * cafile_opt
The CA file (pem) to use for the proxy CA.
static struct GNUNET_NETWORK_Handle * lsock6
The listen socket of the proxy for IPv6.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
SocksPhase
The socks phases.
@ SOCKS5_SOCKET_UPLOAD_STARTED
We've started receiving upload data from MHD.
@ SOCKS5_SOCKET_WITH_MHD
Socket has been passed to MHD, do not close it anymore.
@ SOCKS5_SOCKET_DOWNLOAD_STARTED
We've finished uploading data via CURL and can now download.
@ SOCKS5_RESOLVING
We are currently resolving the destination.
@ SOCKS5_INIT
We're waiting to get the client hello.
@ SOCKS5_SOCKET_DOWNLOAD_DONE
We've finished receiving download data from cURL.
@ SOCKS5_WRITE_THEN_CLEANUP
Finish writing the write buffer, then clean up.
@ SOCKS5_DATA_TRANSFER
We're in transfer mode.
@ SOCKS5_REQUEST
We're waiting to get the initial request.
@ SOCKS5_SOCKET_UPLOAD_DONE
We've finished receiving upload data from MHD.
#define SOCKS_VERSION_5
Which SOCKS version do we speak?
static MHD_RESULT create_response(void *cls, struct MHD_Connection *con, const char *url, const char *meth, const char *ver, const char *upload_data, size_t *upload_data_size, void **con_cls)
Main MHD callback for handling requests.
static size_t curl_check_hdr(void *buffer, size_t size, size_t nmemb, void *cls)
We're getting an HTTP response header from cURL.
static struct GNUNET_NETWORK_Handle * lsock4
The listen socket of the proxy for IPv4.
static void clear_from_s5r_rbuf(struct Socks5Request *s5r, size_t len)
Remove the first len bytes from the beginning of the read buffer.
static struct in6_addr address6
The IPv6 address to bind to.
static int load_key_from_file(gnutls_x509_privkey_t key, const char *keyfile)
Load PEM key from file.
#define HTTPS_PORT
Port for HTTPS.
static void do_shutdown(void *cls)
Task run on shutdown.
static void mhd_error_log_callback(void *cls, const char *fm, va_list ap)
Function called by MHD with errors, suppresses them all.
static int con_val_iter(void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
Read HTTP request header field from the request.
static void * mhd_log_callback(void *cls, const char *url, struct MHD_Connection *connection)
Function called when MHD first processes an incoming connection.
static void mhd_completed_cb(void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe)
Function called when MHD decides that we are done with a request.
#define SOCKS_BUFFERSIZE
Size of the read/write buffers for Socks.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run.
static uint16_t port
The port the proxy is running on (default 7777)
static void do_httpd(void *cls)
Task run whenever HTTP server operations are pending.
static void curl_download_prepare()
Ask cURL for the select() sets and schedule cURL operations.
static struct MhdHttpList * httpd
Daemon for HTTP (we have one per X.509 certificate, and then one for all HTTP connections; this is th...
Socks5AddressType
Address types in Socks5.
@ SOCKS5_AT_DOMAINNAME
IPv4 address.
@ SOCKS5_AT_IPV4
IPv4 address.
@ SOCKS5_AT_IPV6
IPv6 address.
static ssize_t mhd_content_cb(void *cls, uint64_t pos, char *buf, size_t max)
Callback for MHD response generation.
#define MAX_DANES
Maximum number of DANE records we support per domain name (and port and protocol).
static void kill_httpd_task(void *cls)
Task run whenever HTTP server is idle for too long.
static struct MhdHttpList * mhd_httpd_head
DLL for http/https daemons.
Socks5StatusCode
Status codes in Socks5 response.
@ SOCKS5_STATUS_CONNECTION_NOT_ALLOWED_BY_RULE
@ SOCKS5_STATUS_CONNECTION_REFUSED_BY_HOST
@ SOCKS5_STATUS_ADDRESS_TYPE_NOT_SUPPORTED
@ SOCKS5_STATUS_HOST_UNREACHABLE
@ SOCKS5_STATUS_TTL_EXPIRED
@ SOCKS5_STATUS_GENERAL_FAILURE
@ SOCKS5_STATUS_COMMAND_NOT_SUPPORTED
@ SOCKS5_STATUS_REQUEST_GRANTED
@ SOCKS5_STATUS_NETWORK_UNREACHABLE
static void curl_task_download(void *cls)
Task that is run when we are ready to receive more data from curl.
static struct MhdHttpList * lookup_ssl_httpd(const char *domain)
Lookup (or create) an TLS MHD instance for a particular domain.
static struct GNUNET_SCHEDULER_Task * curl_download_task
The cURL download task (curl multi API).
static size_t curl_upload_cb(void *buf, size_t size, size_t nmemb, void *cls)
cURL callback for uploaded (PUT/POST) data.
static void do_accept(void *cls)
Accept new incoming connections.
static void kill_httpd(struct MhdHttpList *hd)
Kill the given MHD daemon.
static int load_cert_from_file(gnutls_x509_crt_t crt, const char *certfile)
Load cert from file.
static void do_write(void *cls)
Write data from buffer to socks5 client, then continue with state machine.
static void handle_gns_result(void *cls, int tld, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Process GNS results for target domain.
static struct Socks5Request * s5r_head
DLL of active socks requests.
static int check_ssl_certificate(struct Socks5Request *s5r)
Check that the website has presented us with a valid X.509 certificate.
#define MHD_CACHE_TIMEOUT
After how long do we clean up unused MHD TLS instances?
int main(int argc, char *const *argv)
The main function for gnunet-gns-proxy.
static void run_mhd_now(struct MhdHttpList *hd)
Run MHD now, we have extra data ready for the callback.
#define HTTP_HANDSHAKE_TIMEOUT
After how long do we clean up Socks5 handles that failed to show any activity with their respective M...
static void cleanup_s5r(struct Socks5Request *s5r)
Clean up s5r handles.
static in_addr_t address
The address to bind to.
static void signal_socks_failure(struct Socks5Request *s5r, enum Socks5StatusCode sc)
Return a server response message indicating a failure to the client.
static void timeout_s5r_handshake(void *cls)
Task run when a Socks5Request somehow fails to be associated with an MHD connection (e....
static void mhd_connection_cb(void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_ConnectionNotificationCode cnc)
Function called when MHD connection is opened or closed.
#define IO_BUFFERSIZE
Size of the buffer for the data upload / download.
static struct GNUNET_SCHEDULER_Task * ltask6
The listen task ID for IPv6.
static struct GNUNET_SCHEDULER_Task * ltask4
The listen task ID for IPv4.
static struct MHD_Response * curl_failure_response
Response we return on cURL failures.
static void schedule_httpd(struct MhdHttpList *hd)
Schedule MHD.
static struct ProxyGNSCertificate * generate_gns_certificate(const char *name)
Generate new certificate for specific name.
static void setup_data_transfer(struct Socks5Request *s5r)
We're done with the Socks5 protocol, now we need to pass the connection data through to the final des...
static char * name
Name (label) of the records to list.
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static char * value
Value of the record to add/remove.
static uint64_t etime
Expiration string converted to numeric value.
static struct GNUNET_NETWORK_Handle * ls
Listen socket for STUN processing.
enum State state
current state of profiling
static struct GNUNET_FS_SearchContext * sc
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
library to make it easy to download JSON replies over HTTP
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue 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.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_DNSPARSER_TYPE_TLSA
#define GNUNET_DNSPARSER_TYPE_A
#define GNUNET_DNSPARSER_TYPE_AAAA
#define GNUNET_DNSPARSER_MAX_NAME_LENGTH
Maximum length of a name in DNS.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint16(char shortName, const char *name, const char *argumentHelp, const char *description, uint16_t *val)
Allow user to specify an uint16_t.
void GNUNET_GNS_disconnect(struct GNUNET_GNS_Handle *handle)
Shutdown connection with the GNS service.
struct GNUNET_GNS_LookupWithTldRequest * GNUNET_GNS_lookup_with_tld(struct GNUNET_GNS_Handle *handle, const char *name, uint32_t type, enum GNUNET_GNS_LocalOptions options, GNUNET_GNS_LookupResultProcessor2 proc, void *proc_cls)
Perform an asynchronous lookup operation on the GNS, determining the zone using the TLD of the given ...
void * GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr)
Cancel pending lookup request.
struct GNUNET_GNS_Handle * GNUNET_GNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the connection with the GNS service.
@ GNUNET_GNS_LO_LOCAL_MASTER
For the rightmost label, only look in the cache (it is our local namestore), for the others,...
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_SCHEDULER_PRIORITY_DEFAULT
Run with the default priority (normal P2P operations).
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_free_nz(ptr)
Wrapper around free.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
struct sockaddr * GNUNET_NETWORK_get_addr(const struct GNUNET_NETWORK_Handle *desc)
Return the sockaddr for this network handle.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_accept(const struct GNUNET_NETWORK_Handle *desc, struct sockaddr *address, socklen_t *address_len)
Accept a new connection on a socket.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
socklen_t GNUNET_NETWORK_get_addrlen(const struct GNUNET_NETWORK_Handle *desc)
Return sockaddr length for this network handle.
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
void GNUNET_NETWORK_fdset_copy_native(struct GNUNET_NETWORK_FDSet *to, const fd_set *from, int nfds)
Copy a native fd set into the GNUnet representation.
ssize_t GNUNET_NETWORK_socket_recv(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length)
Read data from a connected socket (always non-blocking).
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
void GNUNET_NETWORK_socket_free_memory_only_(struct GNUNET_NETWORK_Handle *desc)
Only free memory of a socket, keep the file descriptor untouched.
ssize_t GNUNET_NETWORK_socket_send(const struct GNUNET_NETWORK_Handle *desc, const void *buffer, size_t length)
Send data (always non-blocking).
enum GNUNET_GenericReturnValue GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Check whether a socket is part of the fd set.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_select(enum GNUNET_SCHEDULER_Priority prio, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when any of the specified file descriptor set...
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
@ MHD_HTTP_INTERNAL_SERVER_ERROR
Internal Server Error [RFC7231, Section 6.6.1].
static unsigned int size
Size of the "table".
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
#define GNUNET_GNSRECORD_TYPE_BOX
Box record.
#define GNUNET_GNSRECORD_TYPE_VPN
VPN resolution.
#define GNUNET_GNSRECORD_TYPE_LEHO
GNS legacy hostname.
Definition of a command line option.
Record type used to box up SRV and TLSA records.
uint32_t record_type
GNS record type of the boxed record.
uint16_t service
Service of the boxed record (aka port number), in NBO.
uint16_t protocol
Protocol of the boxed record (6 = TCP, 17 = UDP, etc.).
uint32_t record_type
Type of the GNS/DNS record.
const void * data
Binary value stored in the DNS record.
size_t data_size
Number of bytes in data.
Connection to the GNS service.
Handle to a lookup request.
collection of IO descriptors
Context information passed to each scheduler task.
const struct GNUNET_NETWORK_FDSet * read_ready
Set of file descriptors ready for reading; note that additional bits may be set that were not in the ...
Entry in list of pending tasks.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
A structure for all running Httpds.
struct MhdHttpList * prev
DLL for httpds.
struct GNUNET_SCHEDULER_Task * httpd_task
The task ID.
struct ProxyGNSCertificate * proxy_cert
Optional proxy certificate used.
char * domain
the domain name to server (only important for TLS)
struct MhdHttpList * next
DLL for httpds.
struct MHD_Daemon * daemon
The daemon handle.
int is_ssl
is this an ssl daemon?
A structure for CA cert/key.
gnutls_x509_privkey_t key
The private key.
gnutls_x509_crt_t cert
The certificate.
Structure for GNS certificates.
char cert[(10 *1024)]
The certificate as PEM.
char key[(10 *1024)]
The private key as PEM.
Client hello in Socks5 protocol.
uint8_t version
Should be SOCKS_VERSION_5.
uint8_t num_auth_methods
How many authentication methods does the client support.
Client socks request in Socks5 protocol.
uint8_t version
Should be SOCKS_VERSION_5.
uint8_t resvd
Reserved, always zero.
uint8_t command
Command code, we only uspport SOCKS5_CMD_TCP_STREAM.
uint8_t addr_type
Address type, an enum Socks5AddressType.
A structure for socks requests.
int suspended
Did we suspend MHD processing?
struct GNUNET_SCHEDULER_Task * rtask
Client socket read task.
CURL * curl
Handle to cURL.
size_t io_len
Number of bytes already in the IO buffer.
struct MHD_Response * response
MHD response object for this request.
struct Socks5Request * next
DLL.
enum SocksPhase state
The socks state.
struct HttpResponseHeader * header_head
Headers from response.
int is_tls
This is (probably) a TLS connection.
struct HttpResponseHeader * header_tail
Headers from response.
char * domain
the domain name to server (only important for TLS)
char * url
The URL to fetch.
size_t rbuf_len
Number of bytes already in read buffer.
int is_gns
Was the hostname resolved via GNS?
uint16_t port
Desired destination port.
int ssl_checked
X.509 Certificate status.
struct GNUNET_GNS_LookupWithTldRequest * gns_lookup
Handle to GNS lookup, during SOCKS5_RESOLVING phase.
int dane_data_len[32+1]
Number of bytes in dane_data.
struct GNUNET_SCHEDULER_Task * timeout_task
Timeout task.
struct MHD_Connection * con
MHD connection for this request.
char rbuf[(256+32)]
Read buffer.
char wbuf[(256+32)]
Write buffer.
unsigned int num_danes
Number of entries used in dane_data_len and dane_data.
char * leho
DNS Legacy Host Name as given by GNS, NULL if not given.
struct curl_slist * hosts
DNS->IP mappings resolved through GNS.
int curl_paused
Did we pause CURL processing?
struct sockaddr_storage destination_address
Once known, what's the target address for the connection?
struct curl_slist * headers
HTTP request headers for the curl request.
struct MhdHttpList * hd
MHD HTTP instance handling this request, NULL for none.
char * dane_data[32+1]
Payload of the DANE records encountered.
char io_buf[CURL_MAX_WRITE_SIZE]
Buffer we use for moving data between MHD and curl (in both directions).
unsigned int response_code
HTTP response code to give to MHD for the response.
struct GNUNET_SCHEDULER_Task * wtask
Client socket write task.
struct Socks5Request * prev
DLL.
size_t wbuf_len
Number of bytes already in write buffer.
struct GNUNET_NETWORK_Handle * sock
The client socket.
Server hello in Socks5 protocol.
uint8_t version
Should be SOCKS_VERSION_5.
uint8_t auth_method
Chosen authentication method, for us always SOCKS_AUTH_NONE, which skips the authentication step.
Server response to client requests in Socks5 protocol.
uint8_t reply
Status code, an enum Socks5StatusCode
uint8_t version
Should be SOCKS_VERSION_5.
uint8_t addr_type
Address type, an enum Socks5AddressType.
uint8_t reserved
Always zero.