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>
51 #define GNUNET_GNS_PROXY_PORT 7777
57 #define MAX_HTTP_URI_LENGTH 2048
69 #define IO_BUFFERSIZE CURL_MAX_WRITE_SIZE
76 #define SOCKS_BUFFERSIZE (256 + 32)
86 #define HTTPS_PORT 443
91 #define MAX_PEM_SIZE (10 * 1024)
96 #define MHD_CACHE_TIMEOUT GNUNET_TIME_relative_multiply ( \
97 GNUNET_TIME_UNIT_MINUTES, 5)
103 #define HTTP_HANDSHAKE_TIMEOUT GNUNET_TIME_relative_multiply ( \
104 GNUNET_TIME_UNIT_SECONDS, 15)
114 #define LOG_CURL_EASY(level, fun, rc) \
116 _ ("%s failed at %s:%d: `%s'\n"), \
120 curl_easy_strerror (rc))
128 #define SOCKS_VERSION_5 0x05
133 #define SOCKS_AUTH_NONE 0
315 gnutls_x509_privkey_t
key;
527 struct MHD_Connection *
con;
777 "Cleaning up socks request\n");
778 if (NULL != s5r->
curl)
781 "Cleaning up cURL handle\n");
784 curl_easy_cleanup (s5r->
curl);
790 MHD_resume_connection (s5r->
con);
792 curl_slist_free_all (s5r->
headers);
793 if (NULL != s5r->
hosts)
795 curl_slist_free_all (s5r->
hosts);
800 MHD_destroy_response (s5r->
response);
803 if (NULL != s5r->
rtask)
813 if (NULL != s5r->
wtask)
823 if (NULL != s5r->
sock)
825 if (SOCKS5_SOCKET_WITH_MHD <= s5r->
state)
837 for (
unsigned int i = 0; i < s5r->
num_danes; i++)
867 size_t bytes_to_copy;
876 "Pausing MHD download %s%s, not yet ready for download\n",
883 if ((0 == bytes_to_copy) &&
887 "Pausing MHD download %s%s, no data available\n",
890 if (NULL != s5r->
curl)
893 "Continuing CURL interaction for %s%s\n",
899 curl_easy_pause (s5r->
curl,
906 MHD_suspend_connection (s5r->
con);
911 if ((0 == bytes_to_copy) &&
915 "Completed MHD download %s%s\n",
918 return MHD_CONTENT_READER_END_OF_STREAM;
921 "Writing %llu/%llu bytes to %s%s\n",
922 (
unsigned long long) bytes_to_copy,
923 (
unsigned long long) s5r->
io_len,
930 &s5r->
io_buf[bytes_to_copy],
931 s5r->
io_len - bytes_to_copy);
932 s5r->
io_len -= bytes_to_copy;
933 if ((NULL != s5r->
curl) &&
937 "Continuing CURL interaction for %s%s\n",
941 curl_easy_pause (s5r->
curl,
944 return bytes_to_copy;
959 unsigned int cert_list_size;
960 const gnutls_datum_t *chainp;
961 const struct curl_tlssessioninfo *tlsinfo;
964 gnutls_x509_crt_t x509_cert;
970 "Checking X.509 certificate\n");
972 curl_easy_getinfo (s5r->
curl,
973 CURLINFO_TLS_SSL_PTR,
976 if (CURLSSLBACKEND_GNUTLS != tlsinfo->backend)
979 _ (
"Unsupported CURL TLS backend %d\n"),
983 chainp = gnutls_certificate_get_peers (tlsinfo->internals,
986 (0 == cert_list_size))
989 size =
sizeof(certdn);
991 gnutls_x509_crt_init (&x509_cert);
992 gnutls_x509_crt_import (x509_cert,
994 GNUTLS_X509_FMT_DER);
996 if (0 != (rc = gnutls_x509_crt_get_dn_by_oid (x509_cert,
997 GNUTLS_OID_X520_COMMON_NAME,
1004 _ (
"Failed to fetch CN from cert: %s\n"),
1005 gnutls_strerror (rc));
1006 gnutls_x509_crt_deinit (x509_cert);
1010 #if HAVE_GNUTLS_DANE
1013 dane_state_t dane_state;
1014 dane_query_t dane_query;
1018 if (0 != (rc = dane_state_init (&dane_state,
1019 #ifdef DANE_F_IGNORE_DNSSEC
1020 DANE_F_IGNORE_DNSSEC |
1022 DANE_F_IGNORE_LOCAL_RESOLVER)))
1025 _ (
"Failed to initialize DANE: %s\n"),
1026 dane_strerror (rc));
1027 gnutls_x509_crt_deinit (x509_cert);
1032 if (0 != (rc = dane_raw_tlsa (dane_state,
1040 _ (
"Failed to parse DANE record: %s\n"),
1041 dane_strerror (rc));
1042 dane_state_deinit (dane_state);
1043 gnutls_x509_crt_deinit (x509_cert);
1046 if (0 != (rc = dane_verify_crt_raw (dane_state,
1049 gnutls_certificate_type_get (
1050 tlsinfo->internals),
1056 _ (
"Failed to verify TLS connection using DANE: %s\n"),
1057 dane_strerror (rc));
1058 dane_query_deinit (dane_query);
1059 dane_state_deinit (dane_state);
1060 gnutls_x509_crt_deinit (x509_cert);
1067 "Failed DANE verification failed with GnuTLS verify status code: %u\n"),
1069 dane_query_deinit (dane_query);
1070 dane_state_deinit (dane_state);
1071 gnutls_x509_crt_deinit (x509_cert);
1074 dane_query_deinit (dane_query);
1075 dane_state_deinit (dane_state);
1083 if (NULL != s5r->
leho)
1087 if (0 == (rc = gnutls_x509_crt_check_hostname (x509_cert,
1092 "TLS certificate subject name (%s) does not match `%s': %d\n"),
1096 gnutls_x509_crt_deinit (x509_cert);
1107 gnutls_x509_crt_deinit (x509_cert);
1132 size_t bytes =
size * nmemb;
1134 const char *hdr_type;
1135 const char *cookie_domain;
1137 char *new_cookie_hdr;
1140 size_t delta_cdomain;
1145 "Receiving HTTP response header from CURL\n");
1156 hdr_type = strtok (ndup,
1158 if (NULL == hdr_type)
1163 hdr_val = strtok (NULL,
1165 if (NULL == hdr_val)
1170 if (
' ' == *hdr_val)
1174 new_cookie_hdr = NULL;
1175 if ((NULL != s5r->
leho) &&
1176 (0 == strcasecmp (hdr_type,
1177 MHD_HTTP_HEADER_SET_COOKIE)))
1181 + strlen (s5r->
domain) + 1);
1184 for (tok = strtok (hdr_val,
";"); NULL != tok; tok = strtok (NULL,
";"))
1186 if ((0 == strncasecmp (tok,
1188 strlen (
" domain"))) &&
1192 cookie_domain = tok + strlen (
" domain") + 1;
1193 if (strlen (cookie_domain) < strlen (s5r->
leho))
1195 delta_cdomain = strlen (s5r->
leho) - strlen (cookie_domain);
1196 if (0 == strcasecmp (cookie_domain,
1197 s5r->
leho + delta_cdomain))
1199 offset += sprintf (new_cookie_hdr + offset,
1205 else if (0 == strcmp (cookie_domain,
1208 offset += sprintf (new_cookie_hdr + offset,
1213 else if ((
'.' == cookie_domain[0]) &&
1214 (0 == strcmp (&cookie_domain[1],
1217 offset += sprintf (new_cookie_hdr + offset,
1223 _ (
"Cookie domain `%s' supplied by server is invalid\n"),
1229 offset += strlen (tok);
1230 new_cookie_hdr[offset++] =
';';
1232 hdr_val = new_cookie_hdr;
1233 hdr_val[offset] =
'\0';
1236 new_location = NULL;
1237 if (0 == strcasecmp (MHD_HTTP_HEADER_TRANSFER_ENCODING,
1243 if ((0 == strcasecmp (MHD_HTTP_HEADER_LOCATION,
1253 if (0 == strncmp (leho_host,
1255 strlen (leho_host)))
1263 hdr_val + strlen (leho_host));
1264 hdr_val = new_location;
1268 else if (0 == strcasecmp (MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
1278 if (0 == strncmp (leho_host,
1280 strlen (leho_host)))
1288 hdr_val = new_location;
1294 if (NULL != (tok = strchr (hdr_val,
'\n')))
1296 if (NULL != (tok = strchr (hdr_val,
'\r')))
1298 if (NULL != (tok = strchr (hdr_val,
'\t')))
1300 if (0 != strlen (hdr_val))
1303 "Adding header %s: %s to MHD response\n",
1333 double content_length;
1338 "Response already set!\n");
1343 curl_easy_getinfo (s5r->
curl,
1344 CURLINFO_RESPONSE_CODE,
1347 curl_easy_getinfo (s5r->
curl,
1348 CURLINFO_CONTENT_LENGTH_DOWNLOAD,
1351 "Creating MHD response with code %d and size %d for %s%s\n",
1353 (
int) content_length,
1357 s5r->
response = MHD_create_response_from_callback ((-1 == content_length)
1366 header = header->
next)
1368 if (0 == strcasecmp (header->type,
1369 MHD_HTTP_HEADER_CONTENT_LENGTH))
1371 if ((0 == strcasecmp (header->type,
1372 MHD_HTTP_HEADER_TRANSFER_ENCODING)) &&
1373 ((0 == strcasecmp (header->value,
1375 (0 == strcasecmp (header->value,
1379 MHD_add_response_header (s5r->
response,
1385 "Failed to add header `%s:%s'\n",
1396 MHD_resume_connection (s5r->
con);
1419 size_t total =
size * nmemb;
1422 "Receiving %ux%u bytes for `%s%s' from cURL to download\n",
1423 (
unsigned int)
size,
1424 (
unsigned int) nmemb,
1434 "Previous upload finished... starting DOWNLOAD.\n");
1444 "Pausing CURL download `%s%s', waiting for UPLOAD to finish\n",
1448 return CURL_WRITEFUNC_PAUSE;
1453 "Pausing CURL `%s%s' download, not enough space %llu %llu %llu\n",
1456 (
unsigned long long)
sizeof(s5r->
io_buf),
1457 (
unsigned long long) s5r->
io_len,
1458 (
unsigned long long) total);
1460 return CURL_WRITEFUNC_PAUSE;
1468 MHD_resume_connection (s5r->
con);
1472 "Received %llu bytes of payload via cURL from %s\n",
1473 (
unsigned long long) total,
1475 if (s5r->
io_len == total)
1502 "Receiving %ux%u bytes for `%s%s' from cURL to upload\n",
1503 (
unsigned int)
size,
1504 (
unsigned int) nmemb,
1508 if ((0 == s5r->
io_len) &&
1512 "Pausing CURL UPLOAD %s%s, need more data\n",
1515 return CURL_READFUNC_PAUSE;
1517 if ((0 == s5r->
io_len) &&
1524 curl_easy_pause (s5r->
curl,
1528 "Completed CURL UPLOAD %s%s\n",
1537 return CURL_READFUNC_ABORT;
1584 "Scheduling CURL interaction\n");
1594 if (CURLM_OK != (mret = curl_multi_fdset (
curl_multi,
1601 "%s failed at %s:%d: `%s'\n",
1602 "curl_multi_fdset", __FILE__, __LINE__,
1603 curl_multi_strerror (mret));
1654 struct CURLMsg *
msg;
1660 "Running CURL interaction\n");
1667 "Checking CURL multi status: %d\n",
1673 curl_easy_getinfo (
msg->easy_handle,
1689 switch (
msg->data.result)
1692 case CURLE_GOT_NOTHING:
1694 "CURL download %s%s completed.\n",
1697 if (NULL == s5r->response)
1705 MHD_resume_connection (s5r->con);
1713 "Download curl %s%s failed: %s\n",
1716 curl_easy_strerror (
msg->data.result));
1721 MHD_resume_connection (s5r->con);
1727 if (NULL == s5r->response)
1744 while (mret == CURLM_CALL_MULTI_PERFORM);
1745 if (CURLM_OK != mret)
1747 "%s failed at %s:%d: `%s'\n",
1748 "curl_multi_perform", __FILE__, __LINE__,
1749 curl_multi_strerror (mret));
1753 "Suspending cURL multi loop, no more events pending\n");
1783 enum MHD_ValueKind kind,
1790 if ((0 == strcasecmp (MHD_HTTP_HEADER_HOST,
1792 (NULL != s5r->
leho))
1799 "Adding HEADER `%s' to HTTP request\n",
1833 struct MHD_Connection *
con,
1837 const char *upload_data,
1838 size_t *upload_data_size,
1843 char ipstring[INET6_ADDRSTRLEN];
1844 char ipaddr[INET6_ADDRSTRLEN + 2];
1846 const struct sockaddr *sa;
1847 const struct sockaddr_in *s4;
1848 const struct sockaddr_in6 *s6;
1865 switch (sa->sa_family)
1869 if (NULL == inet_ntop (AF_INET,
1881 port = ntohs (s4->sin_port);
1886 if (NULL == inet_ntop (AF_INET6,
1898 port = ntohs (s6->sin6_port);
1910 s5r->
hosts = curl_slist_append (NULL,
1918 if (NULL == s5r->
curl)
1919 s5r->
curl = curl_easy_init ();
1920 if (NULL == s5r->
curl)
1921 return MHD_queue_response (con,
1924 curl_easy_setopt (s5r->
curl,
1925 CURLOPT_HEADERFUNCTION,
1927 curl_easy_setopt (s5r->
curl,
1930 curl_easy_setopt (s5r->
curl,
1931 CURLOPT_FOLLOWLOCATION,
1934 curl_easy_setopt (s5r->
curl,
1937 curl_easy_setopt (s5r->
curl,
1938 CURLOPT_CONNECTTIMEOUT,
1940 curl_easy_setopt (s5r->
curl,
1943 curl_easy_setopt (s5r->
curl,
1946 curl_easy_setopt (s5r->
curl,
1947 CURLOPT_HTTP_CONTENT_DECODING,
1949 curl_easy_setopt (s5r->
curl,
1952 curl_easy_setopt (s5r->
curl,
1955 curl_easy_setopt (s5r->
curl,
1963 if ((NULL != s5r->
leho) &&
1964 (NULL != s5r->
hosts))
1966 curl_easy_setopt (s5r->
curl,
1975 :
"https://%s:%d%s",
1987 :
"https://%s:%d%s",
1992 curl_easy_setopt (s5r->
curl,
1996 "Launching %s CURL interaction, fetching `%s'\n",
1997 (s5r->
is_gns) ?
"GNS" :
"DNS",
2000 if (0 == strcasecmp (meth,
2001 MHD_HTTP_METHOD_PUT))
2004 curl_easy_setopt (s5r->
curl,
2007 curl_easy_setopt (s5r->
curl,
2008 CURLOPT_WRITEFUNCTION,
2010 curl_easy_setopt (s5r->
curl,
2014 curl_easy_setopt (s5r->
curl,
2015 CURLOPT_READFUNCTION,
2017 curl_easy_setopt (s5r->
curl,
2022 long upload_size = 0;
2024 us = MHD_lookup_connection_value (con,
2026 MHD_HTTP_HEADER_CONTENT_LENGTH);
2027 if ((1 == sscanf (us,
2032 curl_easy_setopt (s5r->
curl,
2038 else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_POST))
2041 curl_easy_setopt (s5r->
curl,
2044 curl_easy_setopt (s5r->
curl,
2045 CURLOPT_WRITEFUNCTION,
2047 curl_easy_setopt (s5r->
curl,
2050 curl_easy_setopt (s5r->
curl,
2051 CURLOPT_READFUNCTION,
2053 curl_easy_setopt (s5r->
curl,
2061 us = MHD_lookup_connection_value (con,
2063 MHD_HTTP_HEADER_CONTENT_LENGTH);
2070 curl_easy_setopt (s5r->
curl,
2076 curl_easy_setopt (s5r->
curl,
2082 else if (0 == strcasecmp (meth,
2083 MHD_HTTP_METHOD_HEAD))
2086 curl_easy_setopt (s5r->
curl,
2090 else if (0 == strcasecmp (meth,
2091 MHD_HTTP_METHOD_OPTIONS))
2094 curl_easy_setopt (s5r->
curl,
2095 CURLOPT_CUSTOMREQUEST,
2097 curl_easy_setopt (s5r->
curl,
2098 CURLOPT_WRITEFUNCTION,
2100 curl_easy_setopt (s5r->
curl,
2104 else if (0 == strcasecmp (meth,
2105 MHD_HTTP_METHOD_GET))
2108 curl_easy_setopt (s5r->
curl,
2111 curl_easy_setopt (s5r->
curl,
2112 CURLOPT_WRITEFUNCTION,
2114 curl_easy_setopt (s5r->
curl,
2118 else if (0 == strcasecmp (meth,
2119 MHD_HTTP_METHOD_DELETE))
2122 curl_easy_setopt (s5r->
curl,
2123 CURLOPT_CUSTOMREQUEST,
2125 curl_easy_setopt (s5r->
curl,
2126 CURLOPT_WRITEFUNCTION,
2128 curl_easy_setopt (s5r->
curl,
2135 _ (
"Unsupported HTTP method `%s'\n"),
2137 curl_easy_cleanup (s5r->
curl);
2142 if (0 == strcasecmp (ver, MHD_HTTP_VERSION_1_0))
2144 curl_easy_setopt (s5r->
curl,
2145 CURLOPT_HTTP_VERSION,
2146 CURL_HTTP_VERSION_1_0);
2148 else if (0 == strcasecmp (ver, MHD_HTTP_VERSION_1_1))
2150 curl_easy_setopt (s5r->
curl,
2151 CURLOPT_HTTP_VERSION,
2152 CURL_HTTP_VERSION_1_1);
2156 curl_easy_setopt (s5r->
curl,
2157 CURLOPT_HTTP_VERSION,
2158 CURL_HTTP_VERSION_NONE);
2163 curl_easy_setopt (s5r->
curl,
2167 curl_easy_setopt (s5r->
curl,
2168 CURLOPT_SSL_VERIFYPEER,
2171 curl_easy_setopt (s5r->
curl,
2172 CURLOPT_SSL_VERIFYPEER,
2176 curl_easy_setopt (s5r->
curl,
2177 CURLOPT_SSL_VERIFYHOST,
2182 curl_easy_setopt (s5r->
curl,
2192 curl_easy_cleanup (s5r->
curl);
2196 MHD_get_connection_values (con,
2200 curl_easy_setopt (s5r->
curl,
2208 if (0 != *upload_data_size)
2211 "Processing %u bytes UPLOAD\n",
2212 (
unsigned int) *upload_data_size);
2217 curl_easy_setopt (s5r->
curl,
2218 CURLOPT_POSTFIELDSIZE,
2227 *upload_data_size -= left;
2232 curl_easy_pause (s5r->
curl,
2240 "Finished processing UPLOAD\n");
2246 "Waiting for HTTP response for %s%s...\n",
2249 MHD_suspend_connection (con);
2254 "Queueing response for %s%s with MHD\n",
2258 return MHD_queue_response (con,
2278 struct MHD_Connection *connection,
2280 enum MHD_RequestTerminationCode toe)
2286 if (MHD_REQUEST_TERMINATED_COMPLETED_OK != toe)
2288 "MHD encountered error handling request: %d\n",
2290 if (NULL != s5r->
curl)
2293 "Removing cURL handle (MHD interaction complete)\n");
2296 curl_slist_free_all (s5r->
headers);
2298 curl_easy_reset (s5r->
curl);
2306 MHD_destroy_response (s5r->
response);
2319 "Finished request for %s\n",
2340 struct MHD_Connection *connection,
2342 enum MHD_ConnectionNotificationCode cnc)
2345 const union MHD_ConnectionInfo *ci;
2350 case MHD_CONNECTION_NOTIFY_STARTED:
2352 ci = MHD_get_connection_info (connection,
2353 MHD_CONNECTION_INFO_CONNECTION_FD);
2359 sock = ci->connect_fd;
2365 "Context set...\n");
2373 case MHD_CONNECTION_NOTIFY_CLOSED:
2375 "Connection closed... cleaning up\n");
2380 "Connection stale!\n");
2410 struct MHD_Connection *connection)
2413 const union MHD_ConnectionInfo *ci;
2415 ci = MHD_get_connection_info (connection,
2416 MHD_CONNECTION_INFO_SOCKET_CONTEXT);
2423 s5r = ci->socket_context;
2424 if (NULL != s5r->
url)
2452 MHD_stop_daemon (hd->
daemon);
2506 MHD_UNSIGNED_LONG_LONG
timeout;
2514 MHD_get_fdset (hd->
daemon,
2523 haveto = MHD_get_timeout (hd->
daemon,
2525 if (MHD_YES == haveto)
2546 if ((MHD_YES != haveto) &&
2642 gnutls_datum_t key_data;
2647 if (NULL == key_data.data)
2649 ret = gnutls_x509_privkey_import (
key, &key_data,
2650 GNUTLS_X509_FMT_PEM);
2651 if (GNUTLS_E_SUCCESS !=
ret)
2654 _ (
"Unable to import private key from file `%s'\n"),
2671 const char*certfile)
2673 gnutls_datum_t cert_data;
2678 if (NULL == cert_data.data)
2680 ret = gnutls_x509_crt_import (crt,
2682 GNUTLS_X509_FMT_PEM);
2683 if (GNUTLS_E_SUCCESS !=
ret)
2686 _ (
"Unable to import certificate from `%s'\n"),
2703 unsigned int serial;
2704 size_t key_buf_size;
2705 size_t cert_buf_size;
2712 "Generating x.509 certificate for `%s'\n",
2718 gnutls_x509_crt_set_dn_by_oid (
request,
2719 GNUTLS_OID_X520_COUNTRY_NAME,
2723 gnutls_x509_crt_set_dn_by_oid (
request,
2724 GNUTLS_OID_X520_ORGANIZATION_NAME,
2727 strlen (
"GNU Name System"));
2728 gnutls_x509_crt_set_dn_by_oid (
request,
2729 GNUTLS_OID_X520_COMMON_NAME,
2733 gnutls_x509_crt_set_subject_alternative_name (
request,
2737 gnutls_x509_crt_set_version (
request,
2739 gnutls_rnd (GNUTLS_RND_NONCE,
2742 gnutls_x509_crt_set_serial (
request,
2745 etime = time (NULL);
2746 tm_data = localtime (&
etime);
2748 etime = mktime (tm_data);
2749 gnutls_x509_crt_set_activation_time (
request,
2752 etime = mktime (tm_data);
2753 gnutls_x509_crt_set_expiration_time (
request,
2755 gnutls_x509_crt_sign2 (
request,
2760 key_buf_size =
sizeof(pgc->
key);
2761 cert_buf_size =
sizeof(pgc->
cert);
2762 gnutls_x509_crt_export (
request,
2763 GNUTLS_X509_FMT_PEM,
2767 GNUTLS_X509_FMT_PEM,
2770 gnutls_x509_crt_deinit (
request);
2809 if ((NULL != hd->
domain) &&
2810 (0 == strcmp (hd->
domain, domain)))
2813 "Starting fresh MHD HTTPS instance for domain `%s'\n",
2820 hd->
daemon = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL
2821 | MHD_USE_NO_LISTEN_SOCKET
2822 | MHD_ALLOW_SUSPEND_RESUME,
2826 MHD_OPTION_CONNECTION_TIMEOUT, (
unsigned
2830 MHD_OPTION_NOTIFY_CONNECTION,
2834 MHD_OPTION_EXTERNAL_LOGGER,
2836 MHD_OPTION_HTTPS_MEM_KEY, pgc->
key,
2837 MHD_OPTION_HTTPS_MEM_CERT, pgc->
cert,
2882 const struct sockaddr *addr;
2895 _ (
"Failed to start HTTPS server for `%s'\n"),
2913 MHD_add_connection (hd->
daemon,
2919 _ (
"Failed to pass client to MHD\n"));
3020 if (NULL != s5r->
wtask)
3046 sizeof(
struct in_addr) +
sizeof(uint16_t));
3048 + sizeof(struct in_addr) + sizeof(uint16_t);
3049 if (NULL == s5r->
wtask)
3078 for (uint32_t i = 0; i <
rd_count; i++)
3085 struct sockaddr_in *in;
3087 if (
sizeof(
struct in_addr) != r->
data_size)
3099 in->sin_family = AF_INET;
3103 in->sin_port = htons (s5r->
port);
3104 #if HAVE_SOCKADDR_IN_SIN_LEN
3105 in->sin_len =
sizeof(*in);
3112 struct sockaddr_in6 *in;
3114 if (
sizeof(
struct in6_addr) != r->
data_size)
3129 in->sin6_family = AF_INET6;
3133 in->sin6_port = htons (s5r->
port);
3134 #if HAVE_SOCKADDR_IN_SIN_LEN
3135 in->sin6_len =
sizeof(*in);
3161 (ntohs (box->
protocol) != IPPROTO_TCP) ||
3188 "Name resolution failed to yield useful IP address.\n");
3244 "socks5 client disconnected.\n");
3254 "Processing %zu bytes of socks data in state %d\n",
3268 _ (
"Unsupported socks version %d\n"),
3300 _ (
"Unsupported socks command %d\n"),
3310 const struct in_addr *v4 = (
const struct in_addr *) &c_req[1];
3311 const uint16_t *
port = (
const uint16_t *) &v4[1];
3312 struct sockaddr_in *in;
3315 alen =
sizeof(
struct in_addr);
3317 + alen +
sizeof(uint16_t))
3320 in->sin_family = AF_INET;
3322 in->sin_port = *
port;
3323 #
if HAVE_SOCKADDR_IN_SIN_LEN
3324 in->sin_len =
sizeof(*in);
3332 const struct in6_addr *v6 = (
const struct in6_addr *) &c_req[1];
3333 const uint16_t *
port = (
const uint16_t *) &v6[1];
3334 struct sockaddr_in6 *in;
3337 alen =
sizeof(
struct in6_addr);
3339 + alen +
sizeof(uint16_t))
3342 in->sin6_family = AF_INET6;
3343 in->sin6_addr = *v6;
3344 in->sin6_port = *
port;
3345 #
if HAVE_SOCKADDR_IN_SIN_LEN
3346 in->sin6_len =
sizeof(*in);
3354 const uint8_t *dom_len;
3355 const char *dom_name;
3356 const uint16_t *
port;
3358 dom_len = (
const uint8_t *) &c_req[1];
3359 alen = *dom_len + 1;
3361 + alen +
sizeof(uint16_t))
3363 dom_name = (
const char *) &dom_len[1];
3364 port = (
const uint16_t *) &dom_name[*dom_len];
3368 "Requested connection is to %s:%d\n",
3386 _ (
"Unsupported socks address type %d\n"),
3394 + alen +
sizeof(uint16_t));
3446 else if (lsock ==
lsock6)
3463 "Got an inbound connection, waiting for data\n");
3489 "Shutting down...\n");
3498 MHD_resume_connection (s5r->con);
3542 gnutls_global_deinit ();
3555 struct sockaddr_in sa4;
3558 memset (&sa4, 0,
sizeof(sa4));
3559 sa4.sin_family = AF_INET;
3560 sa4.sin_port = htons (
port);
3561 sa4.sin_addr.s_addr =
address;
3562 #if HAVE_SOCKADDR_IN_SIN_LEN
3563 sa4.sin_len =
sizeof(sa4);
3572 (
const struct sockaddr *) &sa4,
3593 struct sockaddr_in6 sa6;
3596 memset (&sa6, 0,
sizeof(sa6));
3597 sa6.sin6_family = AF_INET6;
3598 sa6.sin6_port = htons (
port);
3600 #if HAVE_SOCKADDR_IN_SIN_LEN
3601 sa6.sin6_len =
sizeof(sa6);
3610 (
const struct sockaddr *) &sa6,
3633 const char *cfgfile,
3636 char*cafile_cfg = NULL;
3650 "Don't know what to bind to...\n");
3655 if (1 != inet_pton (AF_INET, addr_str, &
address))
3658 "Unable to parse address %s\n",
3672 "Don't know what to bind6 to...\n");
3677 if (1 != inet_pton (AF_INET6, addr_str, &
address6))
3680 "Unable to parse IPv6 address %s\n",
3688 if (NULL == (
curl_multi = curl_multi_init ()))
3691 "Failed to create cURL multi handle!\n");
3708 cafile = cafile_cfg;
3711 "Using `%s' as CA\n",
3714 gnutls_global_init ();
3726 _ (
"Failed to load X.509 key and certificate from `%s'\n"),
3730 gnutls_global_deinit ();
3738 "Unable to connect to GNS!\n");
3741 gnutls_global_deinit ();
3804 if (CURLSSLSET_OK != curl_global_sslset (CURLSSLBACKEND_GNUTLS,
3809 "cURL does not support the GnuTLS backend\n");
3812 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
3815 "cURL global init failed!\n");
3820 "Proxy listens on port %u\n",
3821 (
unsigned int)
port);
3825 hd->
daemon = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_NO_LISTEN_SOCKET
3826 | MHD_ALLOW_SUSPEND_RESUME,
3830 MHD_OPTION_CONNECTION_TIMEOUT, (
unsigned
3834 MHD_OPTION_NOTIFY_CONNECTION,
3868 "listen on specified port (default: 7777)"),
3882 static const char*page =
3883 "<html><head><title>gnunet-gns-proxy</title>"
3884 "</head><body>cURL fail</body></html>";
3895 = MHD_create_response_from_buffer (strlen (page),
3897 MHD_RESPMEM_PERSISTENT);
3903 _ (
"GNUnet GNS proxy"),
3905 &
run, NULL)) ? 0 : 1;
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
struct GNUNET_GETOPT_CommandLineOption options[]
struct GNUNET_MessageHeader * msg
#define GNUNET_GNSRECORD_TYPE_BOX
Boxed records (see TLSA/SRV handling in GNS)
#define GNUNET_GNSRECORD_TYPE_VPN
VPN resolution.
#define GNUNET_GNSRECORD_TYPE_LEHO
legacy hostnames
#define gettext_noop(String)
IPC messages between GNS API and GNS service.
static int ret
Return value of the commandline.
static int verify
Verify mode.
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
static uint64_t etime
Expiration string converted to numeric value.
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
struct GNUNET_HashCode key
The key used in the DHT.
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 void * mhd_log_callback(void *cls, const char *url, struct MHD_Connection *connection)
Function called when MHD first processes an incoming connection.
static struct Socks5Request * s5r_tail
DLL of active socks requests.
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 struct GNUNET_NETWORK_Handle * bind_v6()
Create an IPv6 listen socket bound to our port.
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 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 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_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 * load_file(const char *filename, unsigned int *size)
Read file in filename.
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.
static struct ProxyGNSCertificate * generate_gns_certificate(const char *name)
Generate new certificate for specific name.
#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 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 struct MhdHttpList * lookup_ssl_httpd(const char *domain)
Lookup (or create) an TLS MHD instance for a particular domain.
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 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 struct GNUNET_NETWORK_Handle * bind_v4()
Create an IPv4 listen socket bound to our port.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
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 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.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
library to make it easy to download JSON replies over HTTP
Identity service; implements identity management for GNUnet.
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.
void * GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr)
Cancel pending lookup request.
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 ...
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.
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#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.
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_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
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_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.
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_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_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...
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_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,...
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
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.
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.