diff options
Diffstat (limited to 'src/restclient/anastasis_api_keyshare_lookup.c')
-rw-r--r-- | src/restclient/anastasis_api_keyshare_lookup.c | 67 |
1 files changed, 52 insertions, 15 deletions
diff --git a/src/restclient/anastasis_api_keyshare_lookup.c b/src/restclient/anastasis_api_keyshare_lookup.c index 50e0d67..4840a7e 100644 --- a/src/restclient/anastasis_api_keyshare_lookup.c +++ b/src/restclient/anastasis_api_keyshare_lookup.c @@ -3,14 +3,14 @@ Copyright (C) 2020, 2021 Anastasis SARL Anastasis is free software; you can redistribute it and/or modify it under the - terms of the GNU Lesser General Public License as published by the Free Software + terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU Affero General Public License along with + You should have received a copy of the GNU General Public License along with Anastasis; see the file COPYING.GPL. If not, see <http://www.gnu.org/licenses/> */ /** @@ -228,7 +228,6 @@ handle_keyshare_lookup_finished (void *cls, kdd.status = ANASTASIS_KSD_REDIRECT_FOR_AUTHENTICATION; kdd.details.redirect_url = kslo->location; break; - case MHD_HTTP_ALREADY_REPORTED: case MHD_HTTP_FORBIDDEN: /* Nothing really to verify, authentication required/failed */ kdd.status = ANASTASIS_KSD_INVALID_ANSWER; @@ -245,19 +244,57 @@ handle_keyshare_lookup_finished (void *cls, /* Nothing really to verify */ kdd.status = ANASTASIS_KSD_AUTHENTICATION_TIMEOUT; break; - case MHD_HTTP_GONE: - /* Nothing really to verify */ - kdd.status = ANASTASIS_KSD_TRUTH_UNKNOWN; - break; - case MHD_HTTP_EXPECTATION_FAILED: + case MHD_HTTP_CONFLICT: /* Nothing really to verify */ kdd.status = ANASTASIS_KSD_CLIENT_FAILURE; - kdd.details.server_failure.http_status = MHD_HTTP_EXPECTATION_FAILED; + kdd.details.server_failure.http_status = MHD_HTTP_CONFLICT; kdd.details.server_failure.ec = TALER_JSON_get_error_code2 (data, data_size); break; + case MHD_HTTP_GONE: + /* Nothing really to verify */ + kdd.status = ANASTASIS_KSD_TRUTH_UNKNOWN; + break; case MHD_HTTP_TOO_MANY_REQUESTS: kdd.status = ANASTASIS_KSD_RATE_LIMIT_EXCEEDED; + { + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_uint32 ( + "request_limit", + &kdd.details.rate_limit_exceeded.request_limit), + GNUNET_JSON_spec_relative_time ( + "request_frequency", + &kdd.details.rate_limit_exceeded.request_frequency), + GNUNET_JSON_spec_end () + }; + json_t *reply; + + reply = json_loadb (data, + data_size, + JSON_REJECT_DUPLICATES, + NULL); + if (NULL == reply) + { + GNUNET_break_op (0); + kdd.status = ANASTASIS_KSD_SERVER_ERROR; + kdd.details.server_failure.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + kdd.details.server_failure.http_status = response_code; + break; + } + if (GNUNET_OK != + GNUNET_JSON_parse (reply, + spec, + NULL, NULL)) + { + GNUNET_break_op (0); + kdd.status = ANASTASIS_KSD_SERVER_ERROR; + kdd.details.server_failure.ec = TALER_JSON_get_error_code (reply); + kdd.details.server_failure.http_status = response_code; + json_decref (reply); + break; + } + json_decref (reply); + } break; case MHD_HTTP_INTERNAL_SERVER_ERROR: /* Server had an internal issue; we should retry, but this API @@ -411,7 +448,7 @@ ANASTASIS_keyshare_lookup ( char *val; char *hdr; - /* Set Truth-Decryption-Key header */ + /* Set Anastasis-Truth-Decryption-Key header */ val = GNUNET_STRINGS_data_to_string_alloc (truth_key, sizeof (*truth_key)); GNUNET_asprintf (&hdr, @@ -487,8 +524,8 @@ ANASTASIS_keyshare_lookup ( answer_s, "timeout_ms", (0 != timeout.rel_value_us) - ? timeout_ms - : NULL, + ? timeout_ms + : NULL, NULL); GNUNET_free (answer_s); } @@ -500,8 +537,8 @@ ANASTASIS_keyshare_lookup ( path, "timeout_ms", (0 != timeout.rel_value_us) - ? timeout_ms - : NULL, + ? timeout_ms + : NULL, NULL); } } |