summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2023-09-24 12:51:03 +0200
committerChristian Grothoff <christian@grothoff.org>2023-09-24 12:51:03 +0200
commitcc15874189dcfb4336921559ce94f4234daa3ca2 (patch)
treea8b8e41bdf7a5f8d8dfb05a8086aa2a766d31dee /src
parent9e009f65b0541b1554137f198a7194a637dfd8e1 (diff)
downloadmerchant-cc15874189dcfb4336921559ce94f4234daa3ca2.tar.gz
merchant-cc15874189dcfb4336921559ce94f4234daa3ca2.tar.bz2
merchant-cc15874189dcfb4336921559ce94f4234daa3ca2.zip
improve error handling when token auth fails
Diffstat (limited to 'src')
-rw-r--r--src/backend/taler-merchant-httpd.c58
-rw-r--r--src/backend/taler-merchant-httpd_get-rewards-ID.c5
2 files changed, 36 insertions, 27 deletions
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));
}