diff options
author | Christian Grothoff <christian@grothoff.org> | 2023-09-24 12:51:03 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2023-09-24 12:51:03 +0200 |
commit | cc15874189dcfb4336921559ce94f4234daa3ca2 (patch) | |
tree | a8b8e41bdf7a5f8d8dfb05a8086aa2a766d31dee | |
parent | 9e009f65b0541b1554137f198a7194a637dfd8e1 (diff) |
improve error handling when token auth fails
m--------- | contrib/wallet-core | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd.c | 58 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_get-rewards-ID.c | 5 |
3 files changed, 36 insertions, 27 deletions
diff --git a/contrib/wallet-core b/contrib/wallet-core -Subproject c5a3cd4c50676c49fa6c67cbdeb609101c38e76 +Subproject 9e2d95b39723a038eb714d723ac0910a5bf596e diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index 17e50dbc..00d49b70 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -155,9 +155,9 @@ static uint16_t port; * Should a "Connection: close" header be added to each HTTP response? */ static int merchant_connection_close; + /** * Context for all exchange operations (useful to the event loop). - * FIXME: rename, move to taler-merchant-httpd.c */ struct GNUNET_CURL_Context *TMH_curl_ctx; @@ -188,11 +188,13 @@ char *TMH_default_auth; * * @param token the login token given in the request * @param instance_id the instance the login is to be checked against - * @return scope of the token if it is valid + * @param[out] as set to scope of the token if it is valid + * @return TALER_EC_NONE on success */ -static enum TMH_AuthScope +static enum TALER_ErrorCode TMH_check_token (const char *token, - const char *instance_id) + const char *instance_id, + enum TMH_AuthScope *as) { enum TMH_AuthScope scope; struct GNUNET_TIME_Timestamp expiration; @@ -200,24 +202,26 @@ TMH_check_token (const char *token, struct TALER_MERCHANTDB_LoginTokenP btoken; if (NULL == token) - return TMH_AS_NONE; + { + *as = TMH_AS_NONE; + return TALER_EC_NONE; + } /* This was presumably checked before... */ GNUNET_assert (0 == strncasecmp (token, RFC_8959_PREFIX, strlen (RFC_8959_PREFIX))); token += strlen (RFC_8959_PREFIX); - if (GNUNET_OK != GNUNET_STRINGS_string_to_data (token, strlen (token), &btoken, sizeof (btoken))) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to convert %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Given authorization token `%s' is malformed\n", token); GNUNET_break_op (0); - return TMH_AS_NONE; + return TALER_EC_GENERIC_TOKEN_MALFORMED; } qs = TMH_db->select_login_token (TMH_db->cls, instance_id, @@ -226,26 +230,25 @@ TMH_check_token (const char *token, &scope); if (qs < 0) { - /* FIXME: may want to return 500 internal server error - in the future in this case... */ GNUNET_break (0); - return TMH_AS_NONE; + return TALER_EC_GENERIC_DB_FETCH_FAILED; } if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Token unknown\n"); - return TMH_AS_NONE; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Authorization token `%s' unknown\n", + token); + return TALER_EC_GENERIC_TOKEN_UNKNOWN; } if (GNUNET_TIME_absolute_is_past (expiration.abs_time)) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Token expired\n"); - /* FIXME: may want to return special EC to indicate - (recently) expired token in the future */ - return TMH_AS_NONE; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Authorization token `%s' expired\n", + token); + return TALER_EC_GENERIC_TOKEN_EXPIRED; } - return scope; + *as = scope; + return TALER_EC_NONE; } @@ -1821,8 +1824,17 @@ url_handler (void *cls, else { if (NULL != hc->instance) - hc->auth_scope = TMH_check_token (auth, - hc->instance->settings.id); + { + enum TALER_ErrorCode ec; + + ec = TMH_check_token (auth, + hc->instance->settings.id, + &hc->auth_scope); + if (TALER_EC_NONE != ec) + return TALER_MHD_reply_with_ec (connection, + ec, + NULL); + } else hc->auth_scope = TMH_AS_NONE; } diff --git a/src/backend/taler-merchant-httpd_get-rewards-ID.c b/src/backend/taler-merchant-httpd_get-rewards-ID.c index 31ee2afa..e1232735 100644 --- a/src/backend/taler-merchant-httpd_get-rewards-ID.c +++ b/src/backend/taler-merchant-httpd_get-rewards-ID.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2014-2021 Taler Systems SA + (C) 2014-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -219,9 +219,6 @@ TMH_get_rewards_ID (const struct TMH_RequestHandler *rh, next_url), TALER_JSON_pack_amount ("reward_amount", &remaining), - // FIXME: tip_amount is for legacy compatibility, to be removed "later" - TALER_JSON_pack_amount ("tip_amount", - &remaining), GNUNET_JSON_pack_timestamp ("expiration", expiration)); } |