diff options
Diffstat (limited to 'src/restclient')
-rw-r--r-- | src/restclient/anastasis_api_config.c | 113 | ||||
-rw-r--r-- | src/restclient/anastasis_api_curl_defaults.c | 13 | ||||
-rw-r--r-- | src/restclient/anastasis_api_policy_lookup.c | 23 | ||||
-rw-r--r-- | src/restclient/anastasis_api_policy_meta_lookup.c | 22 | ||||
-rw-r--r-- | src/restclient/anastasis_api_policy_store.c | 2 | ||||
-rw-r--r-- | src/restclient/anastasis_api_truth_challenge.c | 8 | ||||
-rw-r--r-- | src/restclient/anastasis_api_truth_store.c | 10 |
7 files changed, 90 insertions, 101 deletions
diff --git a/src/restclient/anastasis_api_config.c b/src/restclient/anastasis_api_config.c index 5dcc7ec..aee0357 100644 --- a/src/restclient/anastasis_api_config.c +++ b/src/restclient/anastasis_api_config.c @@ -86,6 +86,10 @@ handle_config_finished (void *cls, { struct ANASTASIS_ConfigOperation *co = cls; const json_t *json = response; + struct ANASTASIS_Config acfg = { + .http_status = response_code, + .response = json + }; co->job = NULL; switch (response_code) @@ -99,27 +103,29 @@ handle_config_finished (void *cls, case MHD_HTTP_OK: { const char *name; - struct ANASTASIS_Config acfg; - json_t *methods; + const json_t *methods; + struct TALER_JSON_ProtocolVersion pv; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("name", &name), GNUNET_JSON_spec_string ("business_name", - &acfg.business_name), + &acfg.details.ok.business_name), GNUNET_JSON_spec_string ("version", - &acfg.version), - GNUNET_JSON_spec_json ("methods", - &methods), + &acfg.details.ok.version), + TALER_JSON_spec_version ("version", + &pv), + GNUNET_JSON_spec_array_const ("methods", + &methods), GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes", - &acfg.storage_limit_in_megabytes), + &acfg.details.ok.storage_limit_in_megabytes), TALER_JSON_spec_amount_any ("annual_fee", - &acfg.annual_fee), + &acfg.details.ok.annual_fee), TALER_JSON_spec_amount_any ("truth_upload_fee", - &acfg.truth_upload_fee), + &acfg.details.ok.truth_upload_fee), TALER_JSON_spec_amount_any ("liability_limit", - &acfg.liability_limit), + &acfg.details.ok.liability_limit), GNUNET_JSON_spec_fixed_auto ("provider_salt", - &acfg.provider_salt), + &acfg.details.ok.provider_salt), GNUNET_JSON_spec_end () }; @@ -132,67 +138,51 @@ handle_config_finished (void *cls, json_dumpf (json, stderr, JSON_INDENT (2)); - response_code = 0; + acfg.http_status = 0; + acfg.ec = TALER_EC_GENERIC_REPLY_MALFORMED; break; } if (0 != strcmp (name, "anastasis")) { GNUNET_JSON_parse_free (spec); - response_code = 0; + acfg.http_status = 0; + acfg.ec = TALER_EC_GENERIC_REPLY_MALFORMED; break; } + if ( (ANASTASIS_PROTOCOL_CURRENT < pv.current) && + (ANASTASIS_PROTOCOL_CURRENT < pv.current - pv.age) ) { - unsigned int age; - unsigned int revision; - unsigned int current; - char dummy; - - if (3 != sscanf (acfg.version, - "%u:%u:%u%c", - ¤t, - &revision, - &age, - &dummy)) - { - GNUNET_break_op (0); - response_code = 0; - GNUNET_JSON_parse_free (spec); - break; - } - if ( (ANASTASIS_PROTOCOL_CURRENT < current) && - (ANASTASIS_PROTOCOL_CURRENT < current - age) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Provider protocol version too new\n"); - response_code = 0; - GNUNET_JSON_parse_free (spec); - break; - } - if ( (ANASTASIS_PROTOCOL_CURRENT > current) && - (ANASTASIS_PROTOCOL_CURRENT - ANASTASIS_PROTOCOL_AGE > current) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Provider protocol version too old\n"); - GNUNET_break_op (0); - response_code = 0; - GNUNET_JSON_parse_free (spec); - break; - } + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Provider protocol version too new\n"); + acfg.http_status = 0; + acfg.ec = TALER_EC_GENERIC_VERSION_MALFORMED; + break; } - if (! json_is_array (methods)) + if ( (ANASTASIS_PROTOCOL_CURRENT > pv.current) && + (ANASTASIS_PROTOCOL_CURRENT - ANASTASIS_PROTOCOL_AGE > pv.current) ) { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Provider protocol version too old\n"); GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); - response_code = 0; + acfg.http_status = 0; + acfg.ec = TALER_EC_GENERIC_VERSION_MALFORMED; break; } - acfg.methods_length = json_array_size (methods); + acfg.details.ok.methods_length = (unsigned int) json_array_size (methods); + if (((size_t) acfg.details.ok.methods_length) != + json_array_size (methods)) { - struct ANASTASIS_AuthorizationMethodConfig mcfg[GNUNET_NZL ( - acfg.methods_length)]; + GNUNET_break_op (0); + acfg.http_status = 0; + acfg.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + break; + } + { + struct ANASTASIS_AuthorizationMethodConfig mcfg[ + GNUNET_NZL (acfg.details.ok.methods_length)]; - for (unsigned int i = 0; i<acfg.methods_length; i++) + for (unsigned int i = 0; i<acfg.details.ok.methods_length; i++) { struct ANASTASIS_AuthorizationMethodConfig *m = &mcfg[i]; struct GNUNET_JSON_Specification spec[] = { @@ -210,19 +200,17 @@ handle_config_finished (void *cls, NULL, NULL)) ) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); - response_code = 0; + acfg.http_status = 0; + acfg.ec = TALER_EC_GENERIC_REPLY_MALFORMED; goto end; } } - acfg.methods = mcfg; + acfg.details.ok.methods = mcfg; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Good backend found at `%s'\n", co->url); co->cb (co->cb_cls, - MHD_HTTP_OK, &acfg); - GNUNET_JSON_parse_free (spec); ANASTASIS_config_cancel (co); return; } @@ -248,8 +236,7 @@ handle_config_finished (void *cls, } end: co->cb (co->cb_cls, - response_code, - NULL); + &acfg); ANASTASIS_config_cancel (co); } diff --git a/src/restclient/anastasis_api_curl_defaults.c b/src/restclient/anastasis_api_curl_defaults.c index 33665e0..f64347b 100644 --- a/src/restclient/anastasis_api_curl_defaults.c +++ b/src/restclient/anastasis_api_curl_defaults.c @@ -20,6 +20,7 @@ * @author Florian Dold */ #include "platform.h" +#include <taler/taler_curl_lib.h> #include "anastasis_api_curl_defaults.h" CURL * @@ -34,20 +35,12 @@ ANASTASIS_curl_easy_get_ (const char *url) curl_easy_setopt (eh, CURLOPT_URL, url)); - GNUNET_assert (CURLE_OK == - curl_easy_setopt (eh, - CURLOPT_FOLLOWLOCATION, - 1L)); + TALER_curl_set_secure_redirect_policy (eh, + url); GNUNET_assert (CURLE_OK == curl_easy_setopt (eh, CURLOPT_TCP_FASTOPEN, 1L)); - /* limit MAXREDIRS to 5 as a simple security measure against - a potential infinite loop caused by a malicious target */ - GNUNET_assert (CURLE_OK == - curl_easy_setopt (eh, - CURLOPT_MAXREDIRS, - 5L)); /* Enable compression (using whatever curl likes), see https://curl.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html */ GNUNET_break (CURLE_OK == diff --git a/src/restclient/anastasis_api_policy_lookup.c b/src/restclient/anastasis_api_policy_lookup.c index 42db90d..b3132ef 100644 --- a/src/restclient/anastasis_api_policy_lookup.c +++ b/src/restclient/anastasis_api_policy_lookup.c @@ -106,6 +106,9 @@ handle_policy_lookup_finished (void *cls, size_t data_size) { struct ANASTASIS_PolicyLookupOperation *plo = cls; + struct ANASTASIS_DownloadDetails dd = { + .http_status = response_code + }; plo->job = NULL; switch (response_code) @@ -117,7 +120,6 @@ handle_policy_lookup_finished (void *cls, break; case MHD_HTTP_OK: { - struct ANASTASIS_DownloadDetails dd; struct ANASTASIS_UploadSignaturePS usp = { .purpose.purpose = htonl (TALER_SIGNATURE_ANASTASIS_POLICY_UPLOAD), .purpose.size = htonl (sizeof (usp)), @@ -133,18 +135,17 @@ handle_policy_lookup_finished (void *cls, &plo->account_pub.pub)) { GNUNET_break_op (0); - response_code = 0; + dd.http_status = 0; + dd.ec = -1; // FIXME: needs new code in Gana! break; } /* Success, call callback with all details! */ - memset (&dd, 0, sizeof (dd)); - dd.sig = plo->account_sig; - dd.curr_policy_hash = usp.new_recovery_data_hash; - dd.policy = data; - dd.policy_size = data_size; - dd.version = plo->version; + dd.details.ok.sig = plo->account_sig; + dd.details.ok.curr_policy_hash = usp.new_recovery_data_hash; + dd.details.ok.policy = data; + dd.details.ok.policy_size = data_size; + dd.details.ok.version = plo->version; plo->cb (plo->cb_cls, - response_code, &dd); plo->cb = NULL; ANASTASIS_policy_lookup_cancel (plo); @@ -167,12 +168,10 @@ handle_policy_lookup_finished (void *cls, "Unexpected response code %u\n", (unsigned int) response_code); GNUNET_break (0); - response_code = 0; break; } plo->cb (plo->cb_cls, - response_code, - NULL); + &dd); plo->cb = NULL; ANASTASIS_policy_lookup_cancel (plo); } diff --git a/src/restclient/anastasis_api_policy_meta_lookup.c b/src/restclient/anastasis_api_policy_meta_lookup.c index 3d1482f..cf381fd 100644 --- a/src/restclient/anastasis_api_policy_meta_lookup.c +++ b/src/restclient/anastasis_api_policy_meta_lookup.c @@ -90,6 +90,10 @@ handle_policy_meta_lookup_finished (void *cls, { struct ANASTASIS_PolicyMetaLookupOperation *plo = cls; const json_t *json = response; + struct ANASTASIS_MetaDownloadDetails mdd = { + .http_status = response_code, + .response = json + }; plo->job = NULL; switch (response_code) @@ -116,10 +120,6 @@ handle_policy_meta_lookup_finished (void *cls, { struct ANASTASIS_MetaDataEntry metas[GNUNET_NZL (mlen)]; void *md[GNUNET_NZL (mlen)]; - struct ANASTASIS_MetaDownloadDetails mdd = { - .metas = metas, - .metas_length = mlen - }; size_t off = 0; const char *label; const json_t *val; @@ -127,6 +127,8 @@ handle_policy_meta_lookup_finished (void *cls, memset (md, 0, sizeof (md)); + mdd.details.ok.metas = metas; + mdd.details.ok.metas_length = mlen; json_object_foreach ((json_t *) json, label, val) @@ -148,6 +150,8 @@ handle_policy_meta_lookup_finished (void *cls, &dummy)) { GNUNET_break (0); + mdd.http_status = 0; + mdd.ec = TALER_EC_GENERIC_REPLY_MALFORMED; break; } if (GNUNET_OK != @@ -156,6 +160,8 @@ handle_policy_meta_lookup_finished (void *cls, NULL, NULL)) { GNUNET_break_op (0); + mdd.http_status = 0; + mdd.ec = TALER_EC_GENERIC_REPLY_MALFORMED; break; } metas[off].version = (uint32_t) ver; @@ -165,13 +171,13 @@ handle_policy_meta_lookup_finished (void *cls, if (off < mlen) { GNUNET_break (0); - response_code = 0; + mdd.http_status = 0; + mdd.ec = TALER_EC_GENERIC_REPLY_MALFORMED; for (size_t i = 0; i<off; i++) GNUNET_free (md[i]); break; } plo->cb (plo->cb_cls, - response_code, &mdd); for (size_t i = 0; i<off; i++) GNUNET_free (md[i]); @@ -197,15 +203,13 @@ handle_policy_meta_lookup_finished (void *cls, "Unexpected response code %u\n", (unsigned int) response_code); GNUNET_break (0); - response_code = 0; break; } GNUNET_log (GNUNET_ERROR_TYPE_INFO, "HTTP status for policy meta lookup is %u\n", (unsigned int) response_code); plo->cb (plo->cb_cls, - response_code, - NULL); + &mdd); plo->cb = NULL; ANASTASIS_policy_meta_lookup_cancel (plo); } diff --git a/src/restclient/anastasis_api_policy_store.c b/src/restclient/anastasis_api_policy_store.c index 5cfcfcb..3afee7d 100644 --- a/src/restclient/anastasis_api_policy_store.c +++ b/src/restclient/anastasis_api_policy_store.c @@ -417,7 +417,7 @@ ANASTASIS_policy_store ( val = GNUNET_STRINGS_data_to_string_alloc (&usp.new_recovery_data_hash, sizeof (struct GNUNET_HashCode)); GNUNET_asprintf (&hdr, - "%s: %s", + "%s: \"%s\"", MHD_HTTP_HEADER_IF_NONE_MATCH, val); GNUNET_free (val); diff --git a/src/restclient/anastasis_api_truth_challenge.c b/src/restclient/anastasis_api_truth_challenge.c index aa9119c..7a39db5 100644 --- a/src/restclient/anastasis_api_truth_challenge.c +++ b/src/restclient/anastasis_api_truth_challenge.c @@ -124,7 +124,7 @@ handle_truth_challenge_finished (void *cls, const char *ct; const char *tan_hint = NULL; const char *filename = NULL; - json_t *wire_details = NULL; + const json_t *wire_details = NULL; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ( "challenge_type", @@ -138,8 +138,8 @@ handle_truth_challenge_finished (void *cls, &filename), NULL), GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_json ("wire_details", - &wire_details), + GNUNET_JSON_spec_object_const ("wire_details", + &wire_details), NULL), GNUNET_JSON_spec_end () }; @@ -204,7 +204,6 @@ handle_truth_challenge_finished (void *cls, NULL, NULL)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); tcd.http_status = 0; tcd.ec = TALER_EC_GENERIC_REPLY_MALFORMED; break; @@ -212,7 +211,6 @@ handle_truth_challenge_finished (void *cls, tcd.details.success.cs = ANASTASIS_CS_WIRE_FUNDS; tco->cb (tco->cb_cls, &tcd); - GNUNET_JSON_parse_free (spec); ANASTASIS_truth_challenge_cancel (tco); return; } diff --git a/src/restclient/anastasis_api_truth_store.c b/src/restclient/anastasis_api_truth_store.c index c1cf634..855ad5a 100644 --- a/src/restclient/anastasis_api_truth_store.c +++ b/src/restclient/anastasis_api_truth_store.c @@ -169,10 +169,18 @@ handle_truth_store_finished (void *cls, ud.ec = TALER_JSON_get_error_code2 (data, data_size); break; + case MHD_HTTP_BAD_GATEWAY: + ud.ec = TALER_JSON_get_error_code2 (data, + data_size); + break; default: - GNUNET_break (0); ud.ec = TALER_JSON_get_error_code2 (data, data_size); + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unexpected HTTP status code %u/%d\n", + (unsigned int) response_code, + ud.ec); break; } tso->cb (tso->cb_cls, |