aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-01-25 20:52:55 +0100
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-01-25 20:52:55 +0100
commit7f666b4467ae5f530e904675df3f28886f4202fa (patch)
tree7bceb77a3b5de5fc8ec48bf8211d8bcd239f08fb /src
parent92d1fd704da83c27e9aac3d385b8dd6cf0c18a8a (diff)
downloadgnunet-7f666b4467ae5f530e904675df3f28886f4202fa.tar.gz
gnunet-7f666b4467ae5f530e904675df3f28886f4202fa.zip
Fix #5514; Add test for GNS Proxy and DANE; Fix TLS connections on ports != 443 through proxy
Diffstat (limited to 'src')
-rw-r--r--src/gns/Makefile.am11
-rw-r--r--src/gns/gnunet-gns-proxy-setup-ca45
-rw-r--r--src/gns/gnunet-gns-proxy.c62
-rw-r--r--src/gns/test_gns_proxy.c402
-rw-r--r--src/gns/test_gns_proxy.conf28
-rwxr-xr-xsrc/gns/test_proxy.sh53
6 files changed, 369 insertions, 232 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index e0497b11e..1abc57d57 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -155,6 +155,12 @@ if HAVE_GNUTLS_DANE
155gnunet_gns_proxy_LDADD += -lgnutls-dane 155gnunet_gns_proxy_LDADD += -lgnutls-dane
156endif 156endif
157 157
158test_gns_proxy_SOURCES = \
159 test_gns_proxy.c
160test_gns_proxy_LDADD = -lmicrohttpd $(LIB_GNURL) -lgnutls \
161 $(top_builddir)/src/util/libgnunetutil.la \
162 $(GN_LIBINTL)
163
158gnunet_gns_helper_service_w32_SOURCES = \ 164gnunet_gns_helper_service_w32_SOURCES = \
159 gnunet-gns-helper-service-w32.c 165 gnunet-gns-helper-service-w32.c
160gnunet_gns_helper_service_w32_LDADD = \ 166gnunet_gns_helper_service_w32_LDADD = \
@@ -232,6 +238,8 @@ libgnunet_plugin_block_gns_la_LIBADD = \
232libgnunet_plugin_block_gns_la_LDFLAGS = \ 238libgnunet_plugin_block_gns_la_LDFLAGS = \
233 $(GN_PLUGIN_LDFLAGS) 239 $(GN_PLUGIN_LDFLAGS)
234 240
241check_PROGRAMS = \
242 test_gns_proxy
235 243
236check_SCRIPTS = \ 244check_SCRIPTS = \
237 test_gns_lookup.sh \ 245 test_gns_lookup.sh \
@@ -248,7 +256,8 @@ check_SCRIPTS = \
248 test_gns_rel_expiration.sh\ 256 test_gns_rel_expiration.sh\
249 test_gns_soa_lookup.sh\ 257 test_gns_soa_lookup.sh\
250 test_gns_revocation.sh\ 258 test_gns_revocation.sh\
251 test_gns_cname_lookup.sh 259 test_gns_cname_lookup.sh \
260 test_proxy.sh
252 261
253if ENABLE_TEST_RUN 262if ENABLE_TEST_RUN
254if HAVE_SQLITE 263if HAVE_SQLITE
diff --git a/src/gns/gnunet-gns-proxy-setup-ca b/src/gns/gnunet-gns-proxy-setup-ca
index 52f4b012b..7c1d58dc2 100644
--- a/src/gns/gnunet-gns-proxy-setup-ca
+++ b/src/gns/gnunet-gns-proxy-setup-ca
@@ -5,12 +5,6 @@
5 5
6# TODO: We should sed the real paths to the binaries involved here. 6# TODO: We should sed the real paths to the binaries involved here.
7 7
8if ! which certutil > /dev/null
9then
10 echo "'certutil' command not found. Please install it."
11 exit 1
12fi
13
14if ! which openssl > /dev/null 8if ! which openssl > /dev/null
15then 9then
16 echo "'openssl' command not found. Please install it." 10 echo "'openssl' command not found. Please install it."
@@ -50,24 +44,29 @@ openssl rsa -passin pass:"GNU Name System" -in $GNSCAKY -out $GNSCANO
50echo "Making private key available to gnunet-gns-proxy" 44echo "Making private key available to gnunet-gns-proxy"
51cat $GNSCERT $GNSCANO > $GNS_CA_CERT_PEM 45cat $GNSCERT $GNSCANO > $GNS_CA_CERT_PEM
52 46
53echo "Importing CA into browsers" 47if ! which certutil > /dev/null
54for f in ~/.mozilla/firefox/*.*/ 48then
55do 49 echo "'certutil' command not found. Not importing into browsers."
56 if [ -d $f ]; then 50else
57 echo "Importing CA info Firefox at $f" 51 echo "Importing CA into browsers"
58# delete old certificate (if any) 52 for f in ~/.mozilla/firefox/*.*/
59 certutil -D -n "GNS Proxy CA" -d "$f" >/dev/null 2>/dev/null 53 do
60# add new certificate 54 if [ -d $f ]; then
61 certutil -A -n "GNS Proxy CA" -t CT,, -d "$f" < $GNSCERT 55 echo "Importing CA info Firefox at $f"
62 fi 56 # delete old certificate (if any)
63done 57 certutil -D -n "GNS Proxy CA" -d "$f" >/dev/null 2>/dev/null
58 # add new certificate
59 certutil -A -n "GNS Proxy CA" -t CT,, -d "$f" < $GNSCERT
60 fi
61 done
64 62
65if [ -d ~/.pki/nssdb/ ]; then 63 if [ -d ~/.pki/nssdb/ ]; then
66 echo "Importing CA into Chrome at ~/.pki/nssdb/" 64 echo "Importing CA into Chrome at ~/.pki/nssdb/"
67# delete old certificate (if any) 65 # delete old certificate (if any)
68 certutil -D -n "GNS Proxy CA" -d ~/.pki/nssdb/ >/dev/null 2>/dev/null 66 certutil -D -n "GNS Proxy CA" -d ~/.pki/nssdb/ >/dev/null 2>/dev/null
69# add new certificate 67 # add new certificate
70 certutil -A -n "GNS Proxy CA" -t CT,, -d ~/.pki/nssdb/ < $GNSCERT 68 certutil -A -n "GNS Proxy CA" -t CT,, -d ~/.pki/nssdb/ < $GNSCERT
69 fi
71fi 70fi
72 71
73echo "Cleaning up." 72echo "Cleaning up."
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index 7e0dec722..385524a18 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -642,6 +642,11 @@ struct Socks5Request
642 int is_gns; 642 int is_gns;
643 643
644 /** 644 /**
645 * This is (probably) a TLS connection
646 */
647 int is_tls;
648
649 /**
645 * Did we suspend MHD processing? 650 * Did we suspend MHD processing?
646 */ 651 */
647 int suspended; 652 int suspended;
@@ -1138,7 +1143,8 @@ curl_check_hdr (void *buffer,
1138 "Receiving HTTP response header from CURL\n"); 1143 "Receiving HTTP response header from CURL\n");
1139 /* first, check TLS certificate */ 1144 /* first, check TLS certificate */
1140 if ( (GNUNET_YES != s5r->ssl_checked) && 1145 if ( (GNUNET_YES != s5r->ssl_checked) &&
1141 (HTTPS_PORT == s5r->port)) 1146 (GNUNET_YES == s5r->is_tls))
1147 //(HTTPS_PORT == s5r->port))
1142 { 1148 {
1143 if (GNUNET_OK != check_ssl_certificate (s5r)) 1149 if (GNUNET_OK != check_ssl_certificate (s5r))
1144 return 0; 1150 return 0;
@@ -1237,7 +1243,7 @@ curl_check_hdr (void *buffer,
1237 char *leho_host; 1243 char *leho_host;
1238 1244
1239 GNUNET_asprintf (&leho_host, 1245 GNUNET_asprintf (&leho_host,
1240 (HTTPS_PORT != s5r->port) 1246 (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port)
1241 ? "http://%s" 1247 ? "http://%s"
1242 : "https://%s", 1248 : "https://%s",
1243 s5r->leho); 1249 s5r->leho);
@@ -1247,7 +1253,7 @@ curl_check_hdr (void *buffer,
1247 { 1253 {
1248 GNUNET_asprintf (&new_location, 1254 GNUNET_asprintf (&new_location,
1249 "%s%s%s", 1255 "%s%s%s",
1250 (HTTPS_PORT != s5r->port) 1256 (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port)
1251 ? "http://" 1257 ? "http://"
1252 : "https://", 1258 : "https://",
1253 s5r->domain, 1259 s5r->domain,
@@ -1262,7 +1268,7 @@ curl_check_hdr (void *buffer,
1262 char *leho_host; 1268 char *leho_host;
1263 1269
1264 GNUNET_asprintf (&leho_host, 1270 GNUNET_asprintf (&leho_host,
1265 (HTTPS_PORT != s5r->port) 1271 (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port)
1266 ? "http://%s" 1272 ? "http://%s"
1267 : "https://%s", 1273 : "https://%s",
1268 s5r->leho); 1274 s5r->leho);
@@ -1272,7 +1278,7 @@ curl_check_hdr (void *buffer,
1272 { 1278 {
1273 GNUNET_asprintf (&new_location, 1279 GNUNET_asprintf (&new_location,
1274 "%s%s", 1280 "%s%s",
1275 (HTTPS_PORT != s5r->port) 1281 (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port)
1276 ? "http://" 1282 ? "http://"
1277 : "https://", 1283 : "https://",
1278 s5r->domain); 1284 s5r->domain);
@@ -1923,7 +1929,7 @@ create_response (void *cls,
1923 if (s5r->is_gns) 1929 if (s5r->is_gns)
1924 { 1930 {
1925 GNUNET_asprintf (&curlurl, 1931 GNUNET_asprintf (&curlurl,
1926 (HTTPS_PORT != s5r->port) 1932 (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port)
1927 ? "http://%s:%d%s" 1933 ? "http://%s:%d%s"
1928 : "https://%s:%d%s", 1934 : "https://%s:%d%s",
1929 (NULL != s5r->leho) 1935 (NULL != s5r->leho)
@@ -1935,7 +1941,7 @@ create_response (void *cls,
1935 else 1941 else
1936 { 1942 {
1937 GNUNET_asprintf (&curlurl, 1943 GNUNET_asprintf (&curlurl,
1938 (HTTPS_PORT != s5r->port) 1944 (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port)
1939 ? "http://%s:%d%s" 1945 ? "http://%s:%d%s"
1940 : "https://%s:%d%s", 1946 : "https://%s:%d%s",
1941 s5r->domain, 1947 s5r->domain,
@@ -2109,7 +2115,7 @@ create_response (void *cls,
2109 CURL_HTTP_VERSION_NONE); 2115 CURL_HTTP_VERSION_NONE);
2110 } 2116 }
2111 2117
2112 if (HTTPS_PORT == s5r->port) 2118 if (GNUNET_YES == s5r->is_tls) //(HTTPS_PORT == s5r->port)
2113 { 2119 {
2114 curl_easy_setopt (s5r->curl, 2120 curl_easy_setopt (s5r->curl,
2115 CURLOPT_USE_SSL, 2121 CURLOPT_USE_SSL,
@@ -2828,29 +2834,25 @@ setup_data_transfer (struct Socks5Request *s5r)
2828 socklen_t len; 2834 socklen_t len;
2829 char *domain; 2835 char *domain;
2830 2836
2831 switch (s5r->port) 2837 if (GNUNET_YES == s5r->is_tls)
2832 { 2838 {
2833 case HTTPS_PORT: 2839 GNUNET_asprintf (&domain,
2834 GNUNET_asprintf (&domain, 2840 "%s",
2835 "%s", 2841 s5r->domain);
2836 s5r->domain); 2842 hd = lookup_ssl_httpd (domain);
2837 hd = lookup_ssl_httpd (domain); 2843 if (NULL == hd)
2838 if (NULL == hd) 2844 {
2839 { 2845 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2840 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2846 _("Failed to start HTTPS server for `%s'\n"),
2841 _("Failed to start HTTPS server for `%s'\n"), 2847 s5r->domain);
2842 s5r->domain); 2848 cleanup_s5r (s5r);
2843 cleanup_s5r (s5r); 2849 GNUNET_free (domain);
2844 GNUNET_free (domain); 2850 return;
2845 return; 2851 }
2846 } 2852 } else {
2847 break;
2848 case HTTP_PORT:
2849 default:
2850 domain = NULL; 2853 domain = NULL;
2851 GNUNET_assert (NULL != httpd); 2854 GNUNET_assert (NULL != httpd);
2852 hd = httpd; 2855 hd = httpd;
2853 break;
2854 } 2856 }
2855 fd = GNUNET_NETWORK_get_fd (s5r->sock); 2857 fd = GNUNET_NETWORK_get_fd (s5r->sock);
2856 addr = GNUNET_NETWORK_get_addr (s5r->sock); 2858 addr = GNUNET_NETWORK_get_addr (s5r->sock);
@@ -3102,6 +3104,7 @@ handle_gns_result (void *cls,
3102 GNUNET_break (0); /* MAX_DANES too small */ 3104 GNUNET_break (0); /* MAX_DANES too small */
3103 break; 3105 break;
3104 } 3106 }
3107 s5r->is_tls = GNUNET_YES; /* This should be TLS */
3105 s5r->dane_data_len[s5r->num_danes] 3108 s5r->dane_data_len[s5r->num_danes]
3106 = r->data_size - sizeof (struct GNUNET_GNSRECORD_BoxRecord); 3109 = r->data_size - sizeof (struct GNUNET_GNSRECORD_BoxRecord);
3107 s5r->dane_data[s5r->num_danes] 3110 s5r->dane_data[s5r->num_danes]
@@ -3293,12 +3296,13 @@ do_s5r_read (void *cls)
3293 s5r->domain = GNUNET_strndup (dom_name, 3296 s5r->domain = GNUNET_strndup (dom_name,
3294 *dom_len); 3297 *dom_len);
3295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3296 "Requested connection is to http%s://%s:%d\n", 3299 "Requested connection is to %s:%d\n",
3297 (HTTPS_PORT == s5r->port) ? "s" : "", 3300 //(HTTPS_PORT == s5r->port) ? "s" : "",
3298 s5r->domain, 3301 s5r->domain,
3299 ntohs (*port)); 3302 ntohs (*port));
3300 s5r->state = SOCKS5_RESOLVING; 3303 s5r->state = SOCKS5_RESOLVING;
3301 s5r->port = ntohs (*port); 3304 s5r->port = ntohs (*port);
3305 s5r->is_tls = (HTTPS_PORT == s5r->port) ? GNUNET_YES : GNUNET_NO;
3302 s5r->gns_lookup = GNUNET_GNS_lookup_with_tld (gns_handle, 3306 s5r->gns_lookup = GNUNET_GNS_lookup_with_tld (gns_handle,
3303 s5r->domain, 3307 s5r->domain,
3304 GNUNET_DNSPARSER_TYPE_A, 3308 GNUNET_DNSPARSER_TYPE_A,
diff --git a/src/gns/test_gns_proxy.c b/src/gns/test_gns_proxy.c
index ea61a89d5..75fe95617 100644
--- a/src/gns/test_gns_proxy.c
+++ b/src/gns/test_gns_proxy.c
@@ -30,13 +30,15 @@
30#include <gnurl/curl.h> 30#include <gnurl/curl.h>
31#endif 31#endif
32#include <microhttpd.h> 32#include <microhttpd.h>
33#include "gnunet_namestore_service.h" 33#include "gnunet_util_lib.h"
34#include "gnunet_gns_service.h" 34#include "gnutls/x509.h"
35#include "gnunet_testing_lib.h"
36#include "gnunet_os_lib.h"
37 35
38#define PORT 8080 36/**
39#define TEST_DOMAIN "www.gnu" 37 * Largest allowed size for a PEM certificate.
38 */
39#define MAX_PEM_SIZE (10 * 1024)
40
41#define TEST_DOMAIN "www.test"
40 42
41#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) 43#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
42 44
@@ -45,7 +47,6 @@
45 */ 47 */
46static int global_ret; 48static int global_ret;
47 49
48static struct GNUNET_NAMESTORE_Handle *namestore;
49 50
50static struct MHD_Daemon *mhd; 51static struct MHD_Daemon *mhd;
51 52
@@ -61,7 +62,15 @@ static char *url;
61 62
62static struct GNUNET_OS_Process *proxy_proc; 63static struct GNUNET_OS_Process *proxy_proc;
63 64
64static char* tmp_cfgfile; 65static char* cafile_opt;
66
67static char* cafile_srv;
68
69static uint16_t port;
70
71static gnutls_x509_crt_t proxy_cert;
72
73static gnutls_x509_privkey_t proxy_key;
65 74
66struct CBC 75struct CBC
67{ 76{
@@ -71,6 +80,101 @@ struct CBC
71 80
72static struct CBC cbc; 81static struct CBC cbc;
73 82
83/**
84 * Read file in filename
85 *
86 * @param filename file to read
87 * @param size pointer where filesize is stored
88 * @return NULL on error
89 */
90static void*
91load_file (const char* filename,
92 unsigned int* size)
93{
94 void *buffer;
95 uint64_t fsize;
96
97 if (GNUNET_OK !=
98 GNUNET_DISK_file_size (filename,
99 &fsize,
100 GNUNET_YES,
101 GNUNET_YES))
102 return NULL;
103 if (fsize > MAX_PEM_SIZE)
104 return NULL;
105 *size = (unsigned int) fsize;
106 buffer = GNUNET_malloc (*size);
107 if (fsize !=
108 GNUNET_DISK_fn_read (filename,
109 buffer,
110 (size_t) fsize))
111 {
112 GNUNET_free (buffer);
113 return NULL;
114 }
115 return buffer;
116}
117
118/**
119 * Load PEM key from file
120 *
121 * @param key where to store the data
122 * @param keyfile path to the PEM file
123 * @return #GNUNET_OK on success
124 */
125static int
126load_key_from_file (gnutls_x509_privkey_t key,
127 const char* keyfile)
128{
129 gnutls_datum_t key_data;
130 int ret;
131
132 key_data.data = load_file (keyfile,
133 &key_data.size);
134 if (NULL == key_data.data)
135 return GNUNET_SYSERR;
136 ret = gnutls_x509_privkey_import (key, &key_data,
137 GNUTLS_X509_FMT_PEM);
138 if (GNUTLS_E_SUCCESS != ret)
139 {
140 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
141 _("Unable to import private key from file `%s'\n"),
142 keyfile);
143 }
144 GNUNET_free_non_null (key_data.data);
145 return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK;
146}
147
148/**
149 * Load cert from file
150 *
151 * @param crt struct to store data in
152 * @param certfile path to pem file
153 * @return #GNUNET_OK on success
154 */
155static int
156load_cert_from_file (gnutls_x509_crt_t crt,
157 const char* certfile)
158{
159 gnutls_datum_t cert_data;
160 int ret;
161
162 cert_data.data = load_file (certfile,
163 &cert_data.size);
164 if (NULL == cert_data.data)
165 return GNUNET_SYSERR;
166 ret = gnutls_x509_crt_import (crt,
167 &cert_data,
168 GNUTLS_X509_FMT_PEM);
169 if (GNUTLS_E_SUCCESS != ret)
170 {
171 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
172 _("Unable to import certificate from `%s'\n"),
173 certfile);
174 }
175 GNUNET_free_non_null (cert_data.data);
176 return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK;
177}
74 178
75static size_t 179static size_t
76copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx) 180copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx)
@@ -112,8 +216,11 @@ mhd_ahc (void *cls,
112 MHD_RESPMEM_MUST_COPY); 216 MHD_RESPMEM_MUST_COPY);
113 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 217 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
114 MHD_destroy_response (response); 218 MHD_destroy_response (response);
115 if (ret == MHD_NO) 219 if (ret == MHD_NO) {
220 global_ret = 1;
116 abort (); 221 abort ();
222 }
223 global_ret = 0;
117 return ret; 224 return ret;
118} 225}
119 226
@@ -138,13 +245,6 @@ do_shutdown ()
138 } 245 }
139 GNUNET_free_non_null (url); 246 GNUNET_free_non_null (url);
140 247
141 if (NULL != tmp_cfgfile)
142 {
143 if (0 != remove (tmp_cfgfile))
144 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "remove", tmp_cfgfile);
145 GNUNET_free (tmp_cfgfile);
146 tmp_cfgfile = NULL;
147 }
148 if (NULL != proxy_proc) 248 if (NULL != proxy_proc)
149 { 249 {
150 (void) GNUNET_OS_process_kill (proxy_proc, SIGKILL); 250 (void) GNUNET_OS_process_kill (proxy_proc, SIGKILL);
@@ -198,12 +298,12 @@ curl_main ()
198 { 298 {
199 if (msg->data.result != CURLE_OK) 299 if (msg->data.result != CURLE_OK)
200 { 300 {
201 fprintf (stderr, 301 fprintf (stderr,
202 "%s failed at %s:%d: `%s'\n", 302 "%s failed at %s:%d: `%s'\n",
203 "curl_multi_perform", 303 "curl_multi_perform",
204 __FILE__, 304 __FILE__,
205 __LINE__, curl_easy_strerror (msg->data.result)); 305 __LINE__, curl_easy_strerror (msg->data.result));
206 global_ret = 1; 306 global_ret = 1;
207 } 307 }
208 } 308 }
209 curl_multi_remove_handle (multi, curl); 309 curl_multi_remove_handle (multi, curl);
@@ -232,17 +332,17 @@ curl_main ()
232 else 332 else
233 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, (unsigned int) timeout); 333 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, (unsigned int) timeout);
234 GNUNET_NETWORK_fdset_copy_native (&nrs, 334 GNUNET_NETWORK_fdset_copy_native (&nrs,
235 &rs, 335 &rs,
236 max + 1); 336 max + 1);
237 GNUNET_NETWORK_fdset_copy_native (&nws, 337 GNUNET_NETWORK_fdset_copy_native (&nws,
238 &ws, 338 &ws,
239 max + 1); 339 max + 1);
240 curl_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 340 curl_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
241 delay, 341 delay,
242 &nrs, 342 &nrs,
243 &nws, 343 &nws,
244 &curl_task, 344 &curl_task,
245 NULL); 345 NULL);
246} 346}
247 347
248 348
@@ -250,33 +350,30 @@ static void
250start_curl (void *cls) 350start_curl (void *cls)
251{ 351{
252 GNUNET_asprintf (&url, 352 GNUNET_asprintf (&url,
253 "http://%s:%d/hello_world", 353 "https://%s:%d/hello_world",
254 TEST_DOMAIN, PORT); 354 TEST_DOMAIN, port);
255 curl = curl_easy_init (); 355 curl = curl_easy_init ();
256 curl_easy_setopt (curl, CURLOPT_URL, url); 356 curl_easy_setopt (curl, CURLOPT_URL, url);
357 //curl_easy_setopt (curl, CURLOPT_URL, "https://127.0.0.1:8443/hello_world");
257 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, &copy_buffer); 358 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, &copy_buffer);
258 curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc); 359 curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc);
259 curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1); 360 curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1);
260 curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L); 361 curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L);
261 curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 15L); 362 curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 15L);
262 curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1); 363 curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1);
364 curl_easy_setopt (curl, CURLOPT_CAINFO, cafile_opt);
365 //curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0L);
366 //curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0L);
263 curl_easy_setopt (curl, CURLOPT_PROXY, "socks5h://127.0.0.1:7777"); 367 curl_easy_setopt (curl, CURLOPT_PROXY, "socks5h://127.0.0.1:7777");
264 368
265 multi = curl_multi_init (); 369 multi = curl_multi_init ();
266 GNUNET_assert (multi != NULL); 370 GNUNET_assert (multi != NULL);
267 GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl)); 371 GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl));
268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Beginning HTTP download from `%s'\n", url); 372 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Beginning HTTP download from `%s'\n", url);
269 curl_main (); 373 curl_main ();
270} 374}
271 375
272 376
273static void
274disco_ns (void* cls)
275{
276 GNUNET_NAMESTORE_disconnect (namestore);
277}
278
279
280/** 377/**
281 * Callback invoked from the namestore service once record is 378 * Callback invoked from the namestore service once record is
282 * created. 379 * created.
@@ -290,24 +387,11 @@ disco_ns (void* cls)
290 * specified target peer; NULL on error 387 * specified target peer; NULL on error
291 */ 388 */
292static void 389static void
293commence_testing (void *cls, 390commence_testing (void *cls)
294 int32_t success,
295 const char *emsg)
296{ 391{
297 GNUNET_SCHEDULER_add_now (&disco_ns, NULL);
298
299 if ( (emsg != NULL) && (GNUNET_YES != success) )
300 {
301 fprintf (stderr,
302 "NS failed to create record %s\n",
303 emsg);
304 GNUNET_SCHEDULER_shutdown ();
305 return;
306 }
307
308 curl_task_id = 392 curl_task_id =
309 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 393 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
310 &start_curl, NULL); 394 &start_curl, NULL);
311} 395}
312 396
313 397
@@ -345,139 +429,135 @@ mhd_main ()
345 FD_ZERO (&es); 429 FD_ZERO (&es);
346 max_fd = -1; 430 max_fd = -1;
347 GNUNET_assert (MHD_YES == 431 GNUNET_assert (MHD_YES ==
348 MHD_get_fdset (mhd, &rs, &ws, &es, &max_fd)); 432 MHD_get_fdset (mhd, &rs, &ws, &es, &max_fd));
349 if (MHD_YES == MHD_get_timeout (mhd, &timeout)) 433 if (MHD_YES == MHD_get_timeout (mhd, &timeout))
350 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 434 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
351 (unsigned int) timeout); 435 (unsigned int) timeout);
352 else 436 else
353 delay = GNUNET_TIME_UNIT_FOREVER_REL; 437 delay = GNUNET_TIME_UNIT_FOREVER_REL;
354 GNUNET_NETWORK_fdset_copy_native (&nrs, 438 GNUNET_NETWORK_fdset_copy_native (&nrs,
355 &rs, 439 &rs,
356 max_fd + 1); 440 max_fd + 1);
357 GNUNET_NETWORK_fdset_copy_native (&nws, 441 GNUNET_NETWORK_fdset_copy_native (&nws,
358 &ws, 442 &ws,
359 max_fd + 1); 443 max_fd + 1);
360 mhd_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 444 mhd_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
361 delay, 445 delay,
362 &nrs, 446 &nrs,
363 &nws, 447 &nws,
364 &mhd_task, 448 &mhd_task,
365 NULL); 449 NULL);
366} 450}
367 451
452
453/**
454 * Main function that will be run
455 *
456 * @param cls closure
457 * @param args remaining command-line arguments
458 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
459 * @param c configuration
460 */
368static void 461static void
369run (void *cls, 462run (void *cls,
370 const struct GNUNET_CONFIGURATION_Handle *cfg, 463 char *const *args,
371 struct GNUNET_TESTING_Peer *peer) 464 const char *cfgfile,
465 const struct GNUNET_CONFIGURATION_Handle *c)
372{ 466{
373 enum MHD_FLAG flags; 467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
374 struct GNUNET_CRYPTO_EcdsaPrivateKey *host_key; 468 "Using `%s' as CA\n",
375 struct GNUNET_GNSRECORD_Data rd; 469 cafile_srv);
376 char *zone_keyfile; 470 char cert[MAX_PEM_SIZE];
377 471 char key[MAX_PEM_SIZE];
378 namestore = GNUNET_NAMESTORE_connect (cfg); 472 size_t key_buf_size;
379 GNUNET_assert (NULL != namestore); 473 size_t cert_buf_size;
380 flags = MHD_USE_DEBUG; 474
381 mhd = MHD_start_daemon (flags, 475 gnutls_global_init ();
382 PORT, 476 gnutls_x509_crt_init (&proxy_cert);
383 NULL, NULL, 477 gnutls_x509_privkey_init (&proxy_key);
384 &mhd_ahc, NULL, 478
385 MHD_OPTION_END); 479 if ( (GNUNET_OK !=
386 GNUNET_assert (NULL != mhd); 480 load_cert_from_file (proxy_cert,
387 mhd_main (); 481 cafile_srv)) ||
388 482 (GNUNET_OK !=
389 tmp_cfgfile = GNUNET_DISK_mktemp ("test_gns_proxy_tmp.conf"); 483 load_key_from_file (proxy_key,
390 if (NULL == tmp_cfgfile) 484 cafile_srv)) )
391 {
392 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
393 "Failed to create tmp cfg!\n");
394 do_shutdown ();
395 return;
396 }
397
398 if (GNUNET_OK != GNUNET_CONFIGURATION_write ((struct GNUNET_CONFIGURATION_Handle *)cfg,
399 tmp_cfgfile))
400 { 485 {
401 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 486 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
402 "Failed to write tmp cfg\n"); 487 _("Failed to load X.509 key and certificate from `%s'\n"),
403 do_shutdown (); 488 cafile_srv);
404 return; 489 gnutls_x509_crt_deinit (proxy_cert);
405 } 490 gnutls_x509_privkey_deinit (proxy_key);
406 491 gnutls_global_deinit ();
407 proxy_proc = GNUNET_OS_start_process (GNUNET_NO,
408 GNUNET_OS_INHERIT_STD_ALL,
409 NULL,
410 NULL,
411 NULL,
412 "gnunet-gns-proxy",
413 "gnunet-gns-proxy",
414 "-c", tmp_cfgfile, NULL);
415
416 if (NULL == proxy_proc)
417 {
418 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
419 "Unable to start proxy\n");
420 do_shutdown ();
421 return;
422 }
423
424 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
425 "ZONEKEY",
426 &zone_keyfile))
427 {
428 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
429 return; 492 return;
430 } 493 }
494 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
495 NULL);
496 key_buf_size = sizeof (key);
497 cert_buf_size = sizeof (cert);
498 gnutls_x509_crt_export (proxy_cert,
499 GNUTLS_X509_FMT_PEM,
500 cert,
501 &cert_buf_size);
502 gnutls_x509_privkey_export (proxy_key,
503 GNUTLS_X509_FMT_PEM,
504 key,
505 &key_buf_size);
506 mhd = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL | MHD_ALLOW_SUSPEND_RESUME, port,
507 NULL, NULL,
508 &mhd_ahc, NULL,
509 MHD_OPTION_HTTPS_MEM_KEY, key,
510 MHD_OPTION_HTTPS_MEM_CERT, cert,
511 MHD_OPTION_END);
512 GNUNET_assert (NULL != mhd);
513 mhd_main ();
431 514
432 host_key = GNUNET_CRYPTO_ecdsa_key_create_from_file (zone_keyfile); 515 GNUNET_SCHEDULER_add_now (&commence_testing,
433 rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; 516 NULL);
434 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_string_to_value (GNUNET_DNSPARSER_TYPE_A,
435 "127.0.0.1",
436 (void**)&rd.data,
437 &rd.data_size));
438 rd.record_type = GNUNET_DNSPARSER_TYPE_A;
439
440 GNUNET_NAMESTORE_record_create (namestore,
441 host_key,
442 "www",
443 &rd,
444 &commence_testing,
445 NULL);
446
447 GNUNET_free ((void**)rd.data);
448 GNUNET_free (zone_keyfile);
449 GNUNET_free (host_key);
450} 517}
451 518
452int 519int
453main (int argc, char *const *argv) 520main (int argc, char *const *argv)
454{ 521{
455 char *binary; 522 struct GNUNET_GETOPT_CommandLineOption options[] = {
456 523 GNUNET_GETOPT_option_uint16 ('p',
457 if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary ("gnunet-gns-proxy", GNUNET_NO, NULL)) 524 "port",
458 { 525 NULL,
459 fprintf (stderr, "Proxy binary not in PATH... skipping!\n"); 526 gettext_noop ("listen on specified port (default: 7777)"),
460 return 0; 527 &port),
461 } 528 GNUNET_GETOPT_option_string ('A',
462 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-dns"); 529 "curlcert",
463 if (GNUNET_YES != GNUNET_OS_check_helper_binary (binary, GNUNET_YES, NULL)) // TODO: once we have a windows-testcase, add test parameters here 530 NULL,
464 { 531 gettext_noop ("pem file to use as CA"),
465 fprintf (stderr, "DNS helper binary has wrong permissions... skipping!\n"); 532 &cafile_opt),
466 GNUNET_free (binary); 533 GNUNET_GETOPT_option_string ('S',
467 return 0; 534 "servercert",
468 } 535 NULL,
469 GNUNET_free (binary); 536 gettext_noop ("pem file to use for the server"),
537 &cafile_srv),
538
539 GNUNET_GETOPT_OPTION_END
540 };
470 541
471 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 542 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
472 { 543 {
473 fprintf (stderr, "failed to initialize curl\n"); 544 fprintf (stderr, "failed to initialize curl\n");
474 return 2; 545 return 2;
475 } 546 }
476 if (0 != GNUNET_TESTING_peer_run ("test-gnunet-gns-proxy", 547 if (GNUNET_OK !=
477 "test_gns_proxy.conf", 548 GNUNET_STRINGS_get_utf8_args (argc, argv,
478 &run, NULL)) 549 &argc, &argv))
550 return 2;
551 GNUNET_log_setup ("gnunet-gns-proxy-test",
552 "WARNING",
553 NULL);
554 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv,
555 "gnunet-gns-proxy-test",
556 _("GNUnet GNS proxy test"),
557 options,
558 &run, NULL))
479 return 1; 559 return 1;
480 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-gns-proxy"); 560 GNUNET_free_non_null ((char *) argv);
481 return global_ret; 561 return global_ret;
482} 562}
483 563
diff --git a/src/gns/test_gns_proxy.conf b/src/gns/test_gns_proxy.conf
index 51edd5a0c..3b21f1d90 100644
--- a/src/gns/test_gns_proxy.conf
+++ b/src/gns/test_gns_proxy.conf
@@ -1,30 +1,22 @@
1[PATHS] 1@INLINE@ test_gns_defaults.conf
2GNUNET_TEST_HOME = $GNUNET_TMP/gnunet-test-gns-proxy/
3 2
4[transport] 3[transport]
5PLUGINS = tcp 4PLUGINS = tcp
6 5
7[arm]
8PORT = 0
9ALLOW_SHUTDOWN = YES
10
11[testing]
12WEAKRANDOM = YES
13HOSTKEYSFILE = ${DATADIR}/testing_hostkeys.dat
14
15[gns] 6[gns]
7# PREFIX = valgrind --leak-check=full --track-origins=yes
16START_ON_DEMAND = YES 8START_ON_DEMAND = YES
17ZONEKEY = $GNUNET_TEST_HOME/.zonekey 9AUTO_IMPORT_PKEY = YES
18HIJACK_DNS = YES 10MAX_PARALLEL_BACKGROUND_QUERIES = 10
11DEFAULT_LOOKUP_TIMEOUT = 15 s
12RECORD_PUT_INTERVAL = 1 h
13ZONE_PUBLISH_TIME_WINDOW = 1 h
14DNS_ROOT=PD67SGHF3E0447TU9HADIVU9OM7V4QHTOG0EBU69TFRI2LG63DR0
15
19 16
20[gns-proxy] 17[gns-proxy]
21PROXY_CACERT = proxy/test_cert.pem 18PROXY_CACERT = /tmp/proxy_cacert.pem
22PROXY_UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-gns-proxy.sock 19PROXY_UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-gns-proxy.sock
23 20
24[namestore] 21[namestore]
25START_ON_DEMAND = YES 22START_ON_DEMAND = YES
26
27[dns]
28PROVIDE_EXIT = NO
29#DNS_EXIT = 8.8.8.8
30#PREFIX = valgrind --leak-check=full
diff --git a/src/gns/test_proxy.sh b/src/gns/test_proxy.sh
new file mode 100755
index 000000000..c960d4df9
--- /dev/null
+++ b/src/gns/test_proxy.sh
@@ -0,0 +1,53 @@
1#!/bin/bash
2
3TEST_DOMAIN="www.test"
4
5gnunet-arm -s -c test_gns_proxy.conf
6gnunet-gns-proxy-setup-ca -c test_gns_proxy.conf
7
8openssl genrsa -des3 -passout pass:xxxx -out server.pass.key 2048
9openssl rsa -passin pass:xxxx -in server.pass.key -out local.key
10rm server.pass.key
11openssl req -new -key local.key -out server.csr \
12 -subj "/C=DE/O=GNUnet/OU=GNS/CN=test.local"
13openssl x509 -req -days 1 -in server.csr -signkey local.key -out local.crt
14openssl x509 -in local.crt -out local.der -outform DER
15HEXCERT=`xxd -p local.der | tr -d '\n'`
16#echo "This is the certificate the server does not use: $HEXCERT"
17OLDBOXVALUE="6 8443 52 3 0 0 $HEXCERT"
18
19
20openssl req -new -key local.key -out server.csr \
21 -subj "/C=DE/O=GNUnet/OU=GNS/CN=test.local"
22openssl x509 -req -days 1 -in server.csr -signkey local.key -out local.crt
23openssl x509 -in local.crt -out local.der -outform DER
24HEXCERT=`xxd -p local.der | tr -d '\n'`
25#echo "This is the certificate the server does use: $HEXCERT"
26BOXVALUE="6 8443 52 3 0 0 $HEXCERT"
27
28cat local.crt > /tmp/server_cacert.pem
29cat local.key >> /tmp/server_cacert.pem
30
31gnunet-identity -C test -c test_gns_proxy.conf
32gnunet-namestore -p -z test -a -n www -t A -V 127.0.0.1 -e never -c test_gns_proxy.conf
33gnunet-namestore -p -z test -a -n www -t LEHO -V "test.local" -e never -c test_gns_proxy.conf
34gnunet-namestore -p -z test -a -n www -t BOX -V "$OLDBOXVALUE" -e never -c test_gns_proxy.conf
35gnunet-namestore -p -z test -a -n www -t BOX -V "$BOXVALUE" -e never -c test_gns_proxy.conf
36
37gnunet-arm -i gns-proxy -c test_gns_proxy.conf
38
39#gnurl --socks5-hostname 127.0.0.1:7777 https://www.test -v --cacert /tmp/proxy_cacert.pem
40./test_gns_proxy -A /tmp/proxy_cacert.pem -S /tmp/server_cacert.pem -p 8443 -c test_gns_proxy.conf
41
42RES=$?
43
44rm /tmp/proxy_cacert.pem
45rm /tmp/server_cacert.pem
46
47gnunet-arm -e test_gns_proxy.conf
48
49if test $RES != 0
50then
51 echo "Failed"
52 exit 1
53fi