diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-06-27 15:02:11 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-06-27 15:02:11 +0000 |
commit | e7e99d8571ea6f90626a41fdea321e19d6426578 (patch) | |
tree | de68652672d48408991509be4cb15613e8b0e1b9 /src/transport/plugin_transport_http_client.c | |
parent | 67ba272f86ae7aed754aeb94ba2aa19477a4e9e4 (diff) | |
download | gnunet-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_client.c')
-rw-r--r-- | src/transport/plugin_transport_http_client.c | 66 |
1 files changed, 48 insertions, 18 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index 00b704a27..e2aaaa9e1 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c | |||
@@ -152,7 +152,7 @@ struct Session | |||
152 | /** | 152 | /** |
153 | * Address | 153 | * Address |
154 | */ | 154 | */ |
155 | void *addr; | 155 | struct HttpAddress *addr; |
156 | 156 | ||
157 | /** | 157 | /** |
158 | * Address length | 158 | * Address length |
@@ -277,6 +277,11 @@ struct HTTP_Client_Plugin | |||
277 | char *protocol; | 277 | char *protocol; |
278 | 278 | ||
279 | /** | 279 | /** |
280 | * My options to be included in the address | ||
281 | */ | ||
282 | uint32_t options; | ||
283 | |||
284 | /** | ||
280 | * Maximum number of sockets the plugin can use | 285 | * Maximum number of sockets the plugin can use |
281 | * Each http inbound /outbound connections are two connections | 286 | * Each http inbound /outbound connections are two connections |
282 | */ | 287 | */ |
@@ -917,7 +922,7 @@ client_receive_mst_cb (void *cls, void *client, | |||
917 | GNUNET_break (s->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED)); | 922 | GNUNET_break (s->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED)); |
918 | 923 | ||
919 | delay = s->plugin->env->receive (plugin->env->cls, &s->target, message, | 924 | delay = s->plugin->env->receive (plugin->env->cls, &s->target, message, |
920 | s, s->addr, s->addrlen); | 925 | s, (const char *) s->addr, s->addrlen); |
921 | 926 | ||
922 | plugin->env->update_address_metrics (plugin->env->cls, | 927 | plugin->env->update_address_metrics (plugin->env->cls, |
923 | &s->target, | 928 | &s->target, |
@@ -939,7 +944,8 @@ client_receive_mst_cb (void *cls, void *client, | |||
939 | 944 | ||
940 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 945 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
941 | "Client: peer `%s' address `%s' next read delayed for %llu ms\n", | 946 | "Client: peer `%s' address `%s' next read delayed for %llu ms\n", |
942 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), | 947 | GNUNET_i2s (&s->target), |
948 | http_common_plugin_address_to_string (NULL, s->plugin->protocol, s->addr, s->addrlen), | ||
943 | delay); | 949 | delay); |
944 | } | 950 | } |
945 | client_reschedule_session_timeout (s); | 951 | client_reschedule_session_timeout (s); |
@@ -1227,6 +1233,7 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1227 | static int | 1233 | static int |
1228 | client_connect_get (struct Session *s) | 1234 | client_connect_get (struct Session *s) |
1229 | { | 1235 | { |
1236 | |||
1230 | CURLMcode mret; | 1237 | CURLMcode mret; |
1231 | /* create get connection */ | 1238 | /* create get connection */ |
1232 | s->client_get = curl_easy_init (); | 1239 | s->client_get = curl_easy_init (); |
@@ -1239,8 +1246,17 @@ client_connect_get (struct Session *s) | |||
1239 | #endif | 1246 | #endif |
1240 | #if BUILD_HTTPS | 1247 | #if BUILD_HTTPS |
1241 | curl_easy_setopt (s->client_get, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); | 1248 | curl_easy_setopt (s->client_get, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); |
1242 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 0); | 1249 | if (HTTP_OPTIONS_VERIFY_CERTIFICATE == |
1243 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 0); | 1250 | (ntohl (s->addr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) |
1251 | { | ||
1252 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 1); | ||
1253 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 1); | ||
1254 | } | ||
1255 | else | ||
1256 | { | ||
1257 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 0); | ||
1258 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 0); | ||
1259 | } | ||
1244 | curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); | 1260 | curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); |
1245 | curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS); | 1261 | curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS); |
1246 | #else | 1262 | #else |
@@ -1249,8 +1265,6 @@ client_connect_get (struct Session *s) | |||
1249 | #endif | 1265 | #endif |
1250 | 1266 | ||
1251 | curl_easy_setopt (s->client_get, CURLOPT_URL, s->url); | 1267 | curl_easy_setopt (s->client_get, CURLOPT_URL, s->url); |
1252 | curl_easy_setopt (s->client_get, CURLOPT_URL, s->url); | ||
1253 | curl_easy_setopt (s->client_get, CURLOPT_URL, s->url); | ||
1254 | //curl_easy_setopt (s->client_get, CURLOPT_HEADERFUNCTION, &curl_get_header_cb); | 1268 | //curl_easy_setopt (s->client_get, CURLOPT_HEADERFUNCTION, &curl_get_header_cb); |
1255 | //curl_easy_setopt (s->client_get, CURLOPT_WRITEHEADER, ps); | 1269 | //curl_easy_setopt (s->client_get, CURLOPT_WRITEHEADER, ps); |
1256 | curl_easy_setopt (s->client_get, CURLOPT_READFUNCTION, client_send_cb); | 1270 | curl_easy_setopt (s->client_get, CURLOPT_READFUNCTION, client_send_cb); |
@@ -1309,8 +1323,17 @@ client_connect_put (struct Session *s) | |||
1309 | #endif | 1323 | #endif |
1310 | #if BUILD_HTTPS | 1324 | #if BUILD_HTTPS |
1311 | curl_easy_setopt (s->client_put, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); | 1325 | curl_easy_setopt (s->client_put, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); |
1312 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 0); | 1326 | if (HTTP_OPTIONS_VERIFY_CERTIFICATE == |
1313 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 0); | 1327 | (ntohl (s->addr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) |
1328 | { | ||
1329 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 1); | ||
1330 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 1); | ||
1331 | } | ||
1332 | else | ||
1333 | { | ||
1334 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 0); | ||
1335 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 0); | ||
1336 | } | ||
1314 | curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); | 1337 | curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); |
1315 | curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS); | 1338 | curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS); |
1316 | #else | 1339 | #else |
@@ -1366,9 +1389,8 @@ client_connect (struct Session *s) | |||
1366 | struct HTTP_Client_Plugin *plugin = s->plugin; | 1389 | struct HTTP_Client_Plugin *plugin = s->plugin; |
1367 | int res = GNUNET_OK; | 1390 | int res = GNUNET_OK; |
1368 | 1391 | ||
1369 | |||
1370 | /* create url */ | 1392 | /* create url */ |
1371 | if (NULL == http_common_plugin_address_to_string (NULL, s->addr, s->addrlen)) | 1393 | if (NULL == http_common_plugin_address_to_string (NULL, plugin->protocol, s->addr, s->addrlen)) |
1372 | { | 1394 | { |
1373 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1395 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1374 | "Invalid address peer `%s'\n", | 1396 | "Invalid address peer `%s'\n", |
@@ -1377,9 +1399,9 @@ client_connect (struct Session *s) | |||
1377 | } | 1399 | } |
1378 | 1400 | ||
1379 | GNUNET_asprintf (&s->url, "%s/%s;%u", | 1401 | GNUNET_asprintf (&s->url, "%s/%s;%u", |
1380 | http_common_plugin_address_to_string (plugin, s->addr, s->addrlen), | 1402 | http_common_plugin_address_to_url (NULL, s->addr, s->addrlen), |
1381 | GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey), | 1403 | GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey), |
1382 | plugin->last_tag); | 1404 | plugin->last_tag); |
1383 | 1405 | ||
1384 | plugin->last_tag++; | 1406 | plugin->last_tag++; |
1385 | 1407 | ||
@@ -1454,10 +1476,10 @@ http_client_plugin_get_session (void *cls, | |||
1454 | return NULL; | 1476 | return NULL; |
1455 | } | 1477 | } |
1456 | 1478 | ||
1479 | /* Determine network location */ | ||
1457 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); | 1480 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
1458 | ats.value = htonl (GNUNET_ATS_NET_UNSPECIFIED); | 1481 | ats.value = htonl (GNUNET_ATS_NET_UNSPECIFIED); |
1459 | sa = http_common_socket_from_address (address->address, address->address_length, &res); | 1482 | sa = http_common_socket_from_address (address->address, address->address_length, &res); |
1460 | |||
1461 | if (GNUNET_SYSERR == res) | 1483 | if (GNUNET_SYSERR == res) |
1462 | { | 1484 | { |
1463 | return NULL; | 1485 | return NULL; |
@@ -1508,7 +1530,7 @@ http_client_plugin_get_session (void *cls, | |||
1508 | { | 1530 | { |
1509 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | 1531 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, |
1510 | "Cannot connect to peer `%s' address `%s''\n", | 1532 | "Cannot connect to peer `%s' address `%s''\n", |
1511 | http_common_plugin_address_to_string (NULL, s->addr, s->addrlen), | 1533 | http_common_plugin_address_to_string (NULL, plugin->name, s->addr, s->addrlen), |
1512 | GNUNET_i2s (&s->target)); | 1534 | GNUNET_i2s (&s->target)); |
1513 | client_delete_session (s); | 1535 | client_delete_session (s); |
1514 | return NULL; | 1536 | return NULL; |
@@ -1721,6 +1743,13 @@ client_configure_plugin (struct HTTP_Client_Plugin *plugin) | |||
1721 | return GNUNET_OK; | 1743 | return GNUNET_OK; |
1722 | } | 1744 | } |
1723 | 1745 | ||
1746 | const char *http_plugin_address_to_string (void *cls, | ||
1747 | const void *addr, | ||
1748 | size_t addrlen) | ||
1749 | { | ||
1750 | return http_common_plugin_address_to_string (cls, p->name, addr, addrlen); | ||
1751 | } | ||
1752 | |||
1724 | /** | 1753 | /** |
1725 | * Entry point for the plugin. | 1754 | * Entry point for the plugin. |
1726 | */ | 1755 | */ |
@@ -1737,7 +1766,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
1737 | initialze the plugin or the API */ | 1766 | initialze the plugin or the API */ |
1738 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 1767 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); |
1739 | api->cls = NULL; | 1768 | api->cls = NULL; |
1740 | api->address_to_string = &http_common_plugin_address_to_string; | 1769 | api->address_to_string = &http_plugin_address_to_string; |
1741 | api->string_to_address = &http_common_plugin_string_to_address; | 1770 | api->string_to_address = &http_common_plugin_string_to_address; |
1742 | api->address_pretty_printer = &http_common_plugin_address_pretty_printer; | 1771 | api->address_pretty_printer = &http_common_plugin_address_pretty_printer; |
1743 | return api; | 1772 | return api; |
@@ -1752,7 +1781,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
1752 | api->disconnect = &http_client_plugin_disconnect; | 1781 | api->disconnect = &http_client_plugin_disconnect; |
1753 | api->check_address = &http_client_plugin_address_suggested; | 1782 | api->check_address = &http_client_plugin_address_suggested; |
1754 | api->get_session = &http_client_plugin_get_session; | 1783 | api->get_session = &http_client_plugin_get_session; |
1755 | api->address_to_string = &http_common_plugin_address_to_string; | 1784 | api->address_to_string = &http_plugin_address_to_string; |
1756 | api->string_to_address = &http_common_plugin_string_to_address; | 1785 | api->string_to_address = &http_common_plugin_string_to_address; |
1757 | api->address_pretty_printer = &http_common_plugin_address_pretty_printer; | 1786 | api->address_pretty_printer = &http_common_plugin_address_pretty_printer; |
1758 | 1787 | ||
@@ -1765,6 +1794,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
1765 | plugin->protocol = "http"; | 1794 | plugin->protocol = "http"; |
1766 | #endif | 1795 | #endif |
1767 | plugin->last_tag = 1; | 1796 | plugin->last_tag = 1; |
1797 | plugin->options = 0; /* Setup options */ | ||
1768 | 1798 | ||
1769 | if (GNUNET_SYSERR == client_configure_plugin (plugin)) | 1799 | if (GNUNET_SYSERR == client_configure_plugin (plugin)) |
1770 | { | 1800 | { |