aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http_server.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-06-27 15:02:11 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-06-27 15:02:11 +0000
commite7e99d8571ea6f90626a41fdea321e19d6426578 (patch)
treede68652672d48408991509be4cb15613e8b0e1b9 /src/transport/plugin_transport_http_server.c
parent67ba272f86ae7aed754aeb94ba2aa19477a4e9e4 (diff)
downloadgnunet-e7e99d8571ea6f90626a41fdea321e19d6426578.tar.gz
gnunet-e7e99d8571ea6f90626a41fdea321e19d6426578.zip
Implementing bug 0002910
- extended plugin to contain option field in addresses Implementing bug 0002677 - adding ssl verification for external hostname having - the server send the HTTP_OPTIONS_VERIFY_CERTIFICATE option - client use this option to enable ssl verification
Diffstat (limited to 'src/transport/plugin_transport_http_server.c')
-rw-r--r--src/transport/plugin_transport_http_server.c88
1 files changed, 52 insertions, 36 deletions
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c
index 3ccdf4c94..5ae16ca98 100644
--- a/src/transport/plugin_transport_http_server.c
+++ b/src/transport/plugin_transport_http_server.c
@@ -55,7 +55,6 @@
55 */ 55 */
56struct Plugin; 56struct Plugin;
57 57
58
59/** 58/**
60 * Session handle for connections. 59 * Session handle for connections.
61 */ 60 */
@@ -209,6 +208,11 @@ struct HTTP_Server_Plugin
209 char *protocol; 208 char *protocol;
210 209
211 /** 210 /**
211 * My options to be included in the address
212 */
213 uint32_t options;
214
215 /**
212 * External address 216 * External address
213 */ 217 */
214 char *external_hostname; 218 char *external_hostname;
@@ -245,7 +249,7 @@ struct HTTP_Server_Plugin
245 * External hostname the plugin can be connected to, can be different to 249 * External hostname the plugin can be connected to, can be different to
246 * the host's FQDN, used e.g. for reverse proxying 250 * the host's FQDN, used e.g. for reverse proxying
247 */ 251 */
248 char *ext_addr; 252 struct HttpAddress *ext_addr;
249 253
250 /** 254 /**
251 * Notify transport only about external address 255 * Notify transport only about external address
@@ -377,7 +381,7 @@ struct HttpAddressWrapper
377 */ 381 */
378 struct HttpAddressWrapper *prev; 382 struct HttpAddressWrapper *prev;
379 383
380 void *addr; 384 struct HttpAddress *address;
381 385
382 size_t addrlen; 386 size_t addrlen;
383}; 387};
@@ -662,7 +666,7 @@ http_server_plugin_address_suggested (void *cls, const void *addr,
662 next = pos->next; 666 next = pos->next;
663 if (GNUNET_YES == (http_common_cmp_addresses(addr, 667 if (GNUNET_YES == (http_common_cmp_addresses(addr,
664 addrlen, 668 addrlen,
665 pos->addr, 669 pos->address,
666 pos->addrlen))) 670 pos->addrlen)))
667 return GNUNET_OK; 671 return GNUNET_OK;
668 672
@@ -1021,7 +1025,7 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin,
1021 const union MHD_ConnectionInfo *conn_info; 1025 const union MHD_ConnectionInfo *conn_info;
1022 struct GNUNET_ATS_Information ats; 1026 struct GNUNET_ATS_Information ats;
1023 1027
1024 char *addr; 1028 struct HttpAddress *addr;
1025 size_t addr_len; 1029 size_t addr_len;
1026 1030
1027 struct GNUNET_PeerIdentity target; 1031 struct GNUNET_PeerIdentity target;
@@ -1111,7 +1115,7 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin,
1111 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1115 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1112 "Creating new session for peer `%s' connecting from `%s'\n", 1116 "Creating new session for peer `%s' connecting from `%s'\n",
1113 GNUNET_i2s (&target), 1117 GNUNET_i2s (&target),
1114 http_common_plugin_address_to_string (NULL, addr, addr_len)); 1118 http_common_plugin_address_to_string (NULL, p->protocol, addr, addr_len));
1115 1119
1116 s = GNUNET_malloc (sizeof (struct Session)); 1120 s = GNUNET_malloc (sizeof (struct Session));
1117 memcpy (&s->target, &target, sizeof (struct GNUNET_PeerIdentity)); 1121 memcpy (&s->target, &target, sizeof (struct GNUNET_PeerIdentity));
@@ -1313,7 +1317,7 @@ server_receive_mst_cb (void *cls, void *client,
1313 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1317 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1314 "Peer `%s' address `%s' next read delayed for %llu ms\n", 1318 "Peer `%s' address `%s' next read delayed for %llu ms\n",
1315 GNUNET_i2s (&s->target), 1319 GNUNET_i2s (&s->target),
1316 http_common_plugin_address_to_string (NULL, s->addr, s->addrlen), 1320 http_common_plugin_address_to_string (NULL, p->protocol, s->addr, s->addrlen),
1317 delay); 1321 delay);
1318 } 1322 }
1319 server_reschedule_session_timeout (s); 1323 server_reschedule_session_timeout (s);
@@ -1420,6 +1424,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1420 s, sc, 1424 s, sc,
1421 GNUNET_i2s (&s->target), 1425 GNUNET_i2s (&s->target),
1422 http_common_plugin_address_to_string (NULL, 1426 http_common_plugin_address_to_string (NULL,
1427 p->protocol,
1423 s->addr, 1428 s->addr,
1424 s->addrlen)); 1429 s->addrlen));
1425 sc->connected = GNUNET_YES; 1430 sc->connected = GNUNET_YES;
@@ -1433,6 +1438,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1433 s, sc, 1438 s, sc,
1434 GNUNET_i2s (&s->target), 1439 GNUNET_i2s (&s->target),
1435 http_common_plugin_address_to_string (NULL, 1440 http_common_plugin_address_to_string (NULL,
1441 p->protocol,
1436 s->addr, 1442 s->addr,
1437 s->addrlen)); 1443 s->addrlen));
1438 sc->connected = GNUNET_NO; 1444 sc->connected = GNUNET_NO;
@@ -1452,6 +1458,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1452 s, sc, 1458 s, sc,
1453 GNUNET_i2s (&s->target), 1459 GNUNET_i2s (&s->target),
1454 http_common_plugin_address_to_string (NULL, 1460 http_common_plugin_address_to_string (NULL,
1461 p->protocol,
1455 s->addr, 1462 s->addr,
1456 s->addrlen), 1463 s->addrlen),
1457 *upload_data_size); 1464 *upload_data_size);
@@ -1532,7 +1539,7 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection,
1532 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1539 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1533 "Peer `%s' connection %p, GET on address `%s' disconnected\n", 1540 "Peer `%s' connection %p, GET on address `%s' disconnected\n",
1534 GNUNET_i2s (&s->target), s->server_send, 1541 GNUNET_i2s (&s->target), s->server_send,
1535 http_common_plugin_address_to_string (NULL, s->addr, s->addrlen)); 1542 http_common_plugin_address_to_string (NULL, p->protocol, s->addr, s->addrlen));
1536 s->server_send = NULL; 1543 s->server_send = NULL;
1537 if (NULL != (s->server_recv)) 1544 if (NULL != (s->server_recv))
1538 { 1545 {
@@ -1550,7 +1557,7 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection,
1550 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1557 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1551 "Peer `%s' connection %p PUT on address `%s' disconnected\n", 1558 "Peer `%s' connection %p PUT on address `%s' disconnected\n",
1552 GNUNET_i2s (&s->target), s->server_recv, 1559 GNUNET_i2s (&s->target), s->server_recv,
1553 http_common_plugin_address_to_string (NULL, s->addr, s->addrlen)); 1560 http_common_plugin_address_to_string (NULL, p->protocol, s->addr, s->addrlen));
1554 s->server_recv = NULL; 1561 s->server_recv = NULL;
1555 /* Do not terminate session when PUT disconnects 1562 /* Do not terminate session when PUT disconnects
1556 if (NULL != (s->server_send)) 1563 if (NULL != (s->server_send))
@@ -1578,7 +1585,7 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection,
1578 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1585 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1579 "Peer `%s' on address `%s' disconnected\n", 1586 "Peer `%s' on address `%s' disconnected\n",
1580 GNUNET_i2s (&s->target), 1587 GNUNET_i2s (&s->target),
1581 http_common_plugin_address_to_string (NULL, s->addr, s->addrlen)); 1588 http_common_plugin_address_to_string (NULL, p->protocol, s->addr, s->addrlen));
1582 1589
1583 if ((GNUNET_YES == s->session_passed) && (GNUNET_NO == s->session_ended)) 1590 if ((GNUNET_YES == s->session_passed) && (GNUNET_NO == s->session_ended))
1584 { 1591 {
@@ -2152,22 +2159,22 @@ server_add_address (void *cls, int add_remove, const struct sockaddr *addr,
2152 struct HttpAddressWrapper *w = NULL; 2159 struct HttpAddressWrapper *w = NULL;
2153 2160
2154 w = GNUNET_malloc (sizeof (struct HttpAddressWrapper)); 2161 w = GNUNET_malloc (sizeof (struct HttpAddressWrapper));
2155 w->addr = http_common_address_from_socket (plugin->protocol, addr, addrlen); 2162 w->address = http_common_address_from_socket (plugin->protocol, addr, addrlen);
2156 if (NULL == w->addr) 2163 if (NULL == w->address)
2157 { 2164 {
2158 GNUNET_free (w); 2165 GNUNET_free (w);
2159 return; 2166 return;
2160 } 2167 }
2161 w->addrlen = http_common_address_get_size (w->addr); 2168 w->addrlen = http_common_address_get_size (w->address);
2162 2169
2163 GNUNET_CONTAINER_DLL_insert(plugin->addr_head, plugin->addr_tail, w); 2170 GNUNET_CONTAINER_DLL_insert(plugin->addr_head, plugin->addr_tail, w);
2164 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 2171 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2165 "Notifying transport to add address `%s'\n", 2172 "Notifying transport to add address `%s'\n",
2166 http_common_plugin_address_to_string(NULL, w->addr, w->addrlen)); 2173 http_common_plugin_address_to_string (NULL, p->protocol, w->address, w->addrlen));
2167#if BUILD_HTTPS 2174#if BUILD_HTTPS
2168 plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, w->addrlen, "https_client"); 2175 plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client");
2169#else 2176#else
2170 plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, w->addrlen, "http_client"); 2177 plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "http_client");
2171#endif 2178#endif
2172} 2179}
2173 2180
@@ -2194,7 +2201,7 @@ server_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
2194 2201
2195 while (NULL != w) 2202 while (NULL != w)
2196 { 2203 {
2197 if (GNUNET_YES == http_common_cmp_addresses(w->addr, w->addrlen, saddr, saddr_len)) 2204 if (GNUNET_YES == http_common_cmp_addresses(w->address, w->addrlen, saddr, saddr_len))
2198 break; 2205 break;
2199 w = w->next; 2206 w = w->next;
2200 } 2207 }
@@ -2205,14 +2212,14 @@ server_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
2205 2212
2206 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 2213 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2207 "Notifying transport to remove address `%s'\n", 2214 "Notifying transport to remove address `%s'\n",
2208 http_common_plugin_address_to_string (NULL, w->addr, w->addrlen)); 2215 http_common_plugin_address_to_string (NULL, p->protocol, w->address, w->addrlen));
2209 GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w); 2216 GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w);
2210#if BUILD_HTTPS 2217#if BUILD_HTTPS
2211 plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, w->addrlen, "https_client"); 2218 plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client");
2212#else 2219#else
2213 plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, w->addrlen, "http_client"); 2220 plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "http_client");
2214#endif 2221#endif
2215 GNUNET_free (w->addr); 2222 GNUNET_free (w->address);
2216 GNUNET_free (w); 2223 GNUNET_free (w);
2217} 2224}
2218 2225
@@ -2533,7 +2540,7 @@ server_stop_report_addresses (struct HTTP_Server_Plugin *plugin)
2533 { 2540 {
2534 w = plugin->addr_head; 2541 w = plugin->addr_head;
2535 GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w); 2542 GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w);
2536 GNUNET_free (w->addr); 2543 GNUNET_free (w->address);
2537 GNUNET_free (w); 2544 GNUNET_free (w);
2538 } 2545 }
2539} 2546}
@@ -2588,30 +2595,29 @@ static void
2588server_notify_external_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 2595server_notify_external_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2589{ 2596{
2590 struct HTTP_Server_Plugin *plugin = cls; 2597 struct HTTP_Server_Plugin *plugin = cls;
2598 unsigned int urlen;
2599 char *url;
2591 2600
2592 plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK; 2601 plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK;
2593
2594 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 2602 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2595 return; 2603 return;
2596 2604
2605 GNUNET_asprintf(&url, "%s://%s", plugin->protocol, plugin->external_hostname);
2597 2606
2598#if BUILD_HTTPS 2607 urlen = strlen (url) + 1;
2599 GNUNET_asprintf(&plugin->ext_addr, "%s%s://%s", plugin->protocol, 2608 plugin->ext_addr = GNUNET_malloc (sizeof (struct HttpAddress) + urlen);
2600 (GNUNET_YES == plugin->verify_external_hostname) ? "+" : "", 2609 plugin->ext_addr->options = htonl(plugin->options);
2601 plugin->external_hostname); 2610 plugin->ext_addr->urlen = htonl (urlen);
2602#else 2611 plugin->ext_addr_len = sizeof (struct HttpAddress) + urlen;
2603 GNUNET_asprintf(&plugin->ext_addr, "%s://%s", plugin->protocol, 2612 memcpy (&plugin->ext_addr[1], url, urlen);
2604 plugin->external_hostname); 2613 GNUNET_free (url);
2605#endif
2606
2607 plugin->ext_addr_len = strlen (plugin->ext_addr) + 1;
2608 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 2614 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2609 "Notifying transport about external hostname address `%s'\n", plugin->ext_addr); 2615 "Notifying transport about external hostname address `%s'\n", plugin->ext_addr);
2610 2616
2611#if BUILD_HTTPS 2617#if BUILD_HTTPS
2612 if (GNUNET_YES == plugin->verify_external_hostname) 2618 if (GNUNET_YES == plugin->verify_external_hostname)
2613 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, plugin->name, 2619 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, plugin->name,
2614 "Enabling SSL verification for external hostname address `%s'\n", plugin->ext_addr); 2620 "Enabling SSL verification for external hostname address `%s'\n", plugin->external_hostname);
2615 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, 2621 plugin->env->notify_address (plugin->env->cls, GNUNET_YES,
2616 plugin->ext_addr, plugin->ext_addr_len, 2622 plugin->ext_addr, plugin->ext_addr_len,
2617 "https_client"); 2623 "https_client");
@@ -2756,6 +2762,8 @@ server_configure_plugin (struct HTTP_Server_Plugin *plugin)
2756 "VERIFY_EXTERNAL_HOSTNAME"); 2762 "VERIFY_EXTERNAL_HOSTNAME");
2757 if (GNUNET_SYSERR == plugin->verify_external_hostname) 2763 if (GNUNET_SYSERR == plugin->verify_external_hostname)
2758 plugin->verify_external_hostname = GNUNET_NO; 2764 plugin->verify_external_hostname = GNUNET_NO;
2765 if (GNUNET_YES == plugin->verify_external_hostname)
2766 plugin->options |= HTTP_OPTIONS_VERIFY_CERTIFICATE;
2759#endif 2767#endif
2760 2768
2761 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name, 2769 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
@@ -2908,6 +2916,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
2908 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 2916 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2909 "Notifying transport to remove address `%s'\n", 2917 "Notifying transport to remove address `%s'\n",
2910 http_common_plugin_address_to_string (NULL, 2918 http_common_plugin_address_to_string (NULL,
2919 p->protocol,
2911 plugin->ext_addr, 2920 plugin->ext_addr,
2912 plugin->ext_addr_len)); 2921 plugin->ext_addr_len));
2913#if BUILD_HTTPS 2922#if BUILD_HTTPS
@@ -2961,6 +2970,13 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
2961 return NULL; 2970 return NULL;
2962} 2971}
2963 2972
2973const char *http_plugin_address_to_string (void *cls,
2974 const void *addr,
2975 size_t addrlen)
2976{
2977 return http_common_plugin_address_to_string (cls, p->protocol, addr, addrlen);
2978}
2979
2964 2980
2965/** 2981/**
2966 * Entry point for the plugin. 2982 * Entry point for the plugin.
@@ -2985,7 +3001,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
2985 initialze the plugin or the API */ 3001 initialze the plugin or the API */
2986 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); 3002 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
2987 api->cls = NULL; 3003 api->cls = NULL;
2988 api->address_to_string = &http_common_plugin_address_to_string; 3004 api->address_to_string = &http_plugin_address_to_string;
2989 api->string_to_address = &http_common_plugin_string_to_address; 3005 api->string_to_address = &http_common_plugin_string_to_address;
2990 api->address_pretty_printer = &http_common_plugin_address_pretty_printer; 3006 api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
2991 return api; 3007 return api;
@@ -2998,7 +3014,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
2998 api->check_address = &http_server_plugin_address_suggested; 3014 api->check_address = &http_server_plugin_address_suggested;
2999 api->get_session = &http_server_plugin_get_session; 3015 api->get_session = &http_server_plugin_get_session;
3000 3016
3001 api->address_to_string = &http_common_plugin_address_to_string; 3017 api->address_to_string = &http_plugin_address_to_string;
3002 api->string_to_address = &http_common_plugin_string_to_address; 3018 api->string_to_address = &http_common_plugin_string_to_address;
3003 api->address_pretty_printer = &http_common_plugin_address_pretty_printer; 3019 api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
3004 3020