challenger

OAuth 2.0-based authentication service that validates user can receive messages at a certain address
Log | Files | Refs | Submodules | README | LICENSE

commit b180a54821572de577aa9cbbbb846b2cc3d2fdac
parent 11064577a029c9dbfabe5cbdb7f5bab4650a5a7d
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat,  6 May 2023 19:13:06 +0200

-fix FTBFS

Diffstat:
Msrc/challenger/challenger-httpd.c | 12++++++------
Msrc/challenger/challenger-httpd.h | 2+-
Msrc/challenger/challenger-httpd_auth.c | 53++++++++++++++++++++++++++++++++++-------------------
Msrc/challenger/challenger-httpd_challenge.c | 47++++++++++++++++++++++-------------------------
Msrc/challenger/challenger-httpd_common.h | 2+-
Msrc/challenger/challenger-httpd_info.c | 15+++++++++------
Msrc/challenger/challenger-httpd_login.c | 16++++++++--------
Msrc/challenger/challenger-httpd_setup.c | 18+++++++++---------
Msrc/challenger/challenger-httpd_solve.c | 4+++-
9 files changed, 93 insertions(+), 76 deletions(-)

diff --git a/src/challenger/challenger-httpd.c b/src/challenger/challenger-httpd.c @@ -73,7 +73,7 @@ static struct MHD_Daemon *mhd; /** * Connection handle to the our database */ -struct CHALLENGER_DatabasePlugin *db; +struct CHALLENGER_DatabasePlugin *CH_db; /** * How long is an individual validation request valid? @@ -331,10 +331,10 @@ do_shutdown (void *cls) MHD_stop_daemon (mhd); mhd = NULL; } - if (NULL != db) + if (NULL != CH_db) { - CHALLENGER_DB_plugin_unload (db); - db = NULL; + CHALLENGER_DB_plugin_unload (CH_db); + CH_db = NULL; } } @@ -576,14 +576,14 @@ run (void *cls, &rc); rc = GNUNET_CURL_gnunet_rc_create (CH_ctx); if (NULL == - (db = CHALLENGER_DB_plugin_load (config))) + (CH_db = CHALLENGER_DB_plugin_load (config))) { result = EXIT_NOTINSTALLED; GNUNET_SCHEDULER_shutdown (); return; } if (GNUNET_OK != - db->preflight (db->cls)) + CH_db->preflight (CH_db->cls)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Database not setup. Did you run challenger-dbinit?\n"); diff --git a/src/challenger/challenger-httpd.h b/src/challenger/challenger-httpd.h @@ -122,7 +122,7 @@ struct CH_RequestHandler /** * Handle to the database backend. */ -extern struct CHALLENGER_DatabasePlugin *db; +extern struct CHALLENGER_DatabasePlugin *CH_db; /** * Our context for making HTTP requests. diff --git a/src/challenger/challenger-httpd_auth.c b/src/challenger/challenger-httpd_auth.c @@ -22,6 +22,7 @@ #include "challenger-httpd.h" #include <gnunet/gnunet_util_lib.h> #include "challenger-httpd_auth.h" +#include "challenger-httpd_common.h" #include <taler/taler_json_lib.h> #include <taler/taler_merchant_service.h> #include <taler/taler_signatures.h> @@ -172,7 +173,7 @@ post_iter (void *cls, else *ptr = GNUNET_realloc (*ptr, slen + size + 1); - memcpy ((*ptr)[slen], + memcpy (&(*ptr)[slen], data, size); return MHD_YES; @@ -185,7 +186,6 @@ CH_handler_auth (struct CH_HandlerContext *hc, size_t *upload_data_size) { struct AuthContext *bc = hc->ctx; - char *access_token; if (NULL == bc) { @@ -220,7 +220,7 @@ CH_handler_auth (struct CH_HandlerContext *hc, GNUNET_break_op (0); return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_INVALID, + TALER_EC_GENERIC_PARAMETER_MALFORMED, "authorization_code"); } @@ -261,9 +261,23 @@ CH_handler_auth (struct CH_HandlerContext *hc, { enum GNUNET_DB_QueryStatus qs; char *client_url = NULL; + unsigned long long client_id; + char dummy; + + if (1 != sscanf (bc->client_id, + "%llu%c", + &client_id, + &dummy)) + { + GNUNET_break_op (0); + return TALER_MHD_reply_with_error (hc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "client_id"); + } qs = CH_db->client_check (CH_db->cls, - bc->client_id, + client_id, bc->client_secret, 0, /* do not increment */ &client_url); @@ -273,7 +287,7 @@ CH_handler_auth (struct CH_HandlerContext *hc, GNUNET_break (0); return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_XX, + TALER_EC_GENERIC_DB_FETCH_FAILED, "client_check"); case GNUNET_DB_STATUS_SOFT_ERROR: GNUNET_break (0); @@ -282,7 +296,7 @@ CH_handler_auth (struct CH_HandlerContext *hc, GNUNET_break_op (0); return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_NOT_FOUND, - TALER_EC_CHALLENGER_XXX, + TALER_EC_CHALLENGER_GENERIC_CLIENT_UNKNOWN, NULL); case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: break; @@ -294,7 +308,7 @@ CH_handler_auth (struct CH_HandlerContext *hc, GNUNET_break_op (0); return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_FORBIDDEN, - TALER_EC_CHALLENGER_XXX, + TALER_EC_CHALLENGER_GENERIC_CLIENT_FORBIDDEN_BAD_REDIRECT_URI, NULL); } GNUNET_free (client_url); @@ -307,7 +321,7 @@ CH_handler_auth (struct CH_HandlerContext *hc, GNUNET_break_op (0); return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_FORBIDDEN, - TALER_EC_CHALLENGER_XXX, + TALER_EC_CHALLENGER_CLIENT_FORBIDDEN_BAD_CODE, NULL); } @@ -334,7 +348,7 @@ CH_handler_auth (struct CH_HandlerContext *hc, GNUNET_break (0); return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_XX, + TALER_EC_GENERIC_DB_FETCH_FAILED, "validation_get"); case GNUNET_DB_STATUS_SOFT_ERROR: GNUNET_break (0); @@ -343,7 +357,7 @@ CH_handler_auth (struct CH_HandlerContext *hc, GNUNET_break_op (0); return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_NOT_FOUND, - TALER_EC_CHALLENGER_XXX, + TALER_EC_CHALLENGER_GENERIC_VALIDATION_UNKNOWN, "validation_get"); case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: break; @@ -365,7 +379,7 @@ CH_handler_auth (struct CH_HandlerContext *hc, GNUNET_free (code); return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_FORBIDDEN, - TALER_EC_CHALLENGER_XXX, + TALER_EC_CHALLENGER_CLIENT_FORBIDDEN_BAD_CODE, "code"); } GNUNET_free (code); @@ -375,7 +389,7 @@ CH_handler_auth (struct CH_HandlerContext *hc, struct CHALLENGER_AccessTokenP grant; enum GNUNET_DB_QueryStatus qs; /* FIXME: do not hard-code 1h? */ - struct GNUNET_TIME_Relative expiration + struct GNUNET_TIME_Relative grant_expiration = GNUNET_TIME_UNIT_HOURS; GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, @@ -384,15 +398,16 @@ CH_handler_auth (struct CH_HandlerContext *hc, qs = CH_db->auth_add_grant (CH_db->cls, &bc->nonce, &grant, - expiration); + grant_expiration, + CH_validation_expiration); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: GNUNET_break (0); return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_XX, - "add_grant"); + TALER_EC_GENERIC_DB_STORE_FAILED, + "auth_add_grant"); case GNUNET_DB_STATUS_SOFT_ERROR: GNUNET_break (0); return GNUNET_NO; @@ -400,8 +415,8 @@ CH_handler_auth (struct CH_HandlerContext *hc, GNUNET_break (0); return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_NOT_FOUND, - TALER_EC_CHALLENGER_XXX, - "add_grant"); + TALER_EC_CHALLENGER_GRANT_UNKNOWN, + "auth_add_grant"); case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: break; } @@ -415,7 +430,7 @@ CH_handler_auth (struct CH_HandlerContext *hc, GNUNET_JSON_pack_string ("token_type", "Bearer"), GNUNET_JSON_pack_uint64 ("expires_in", - expiration.rel_time_us - / GNUNET_TIME_UNIT_SECONDS.rel_time_us)); + grant_expiration.rel_value_us + / GNUNET_TIME_UNIT_SECONDS.rel_value_us)); } } diff --git a/src/challenger/challenger-httpd_challenge.c b/src/challenger/challenger-httpd_challenge.c @@ -152,7 +152,7 @@ CH_wakeup_challenge_on_shutdown () GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc); - MHD_resume_connection (bs->connection); + MHD_resume_connection (bc->hc->connection); bc->suspended = GNUNET_SYSERR; } } @@ -209,7 +209,7 @@ child_done_cb (void *cls, bc->cwh = NULL; bc->pst = type; bc->exit_code = exit_code; - MHD_resume_connection (bs->connection); + MHD_resume_connection (bc->hc->connection); GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc); @@ -221,11 +221,9 @@ child_done_cb (void *cls, * Transmit the TAN to the given address. * * @param[in,out] bc context to submit TAN for - * @param tan TAN value to submit */ static void -send_tan (struct ChallengeContext *bc, - uint32_t tan) +send_tan (struct ChallengeContext *bc) { struct GNUNET_DISK_PipeHandle *p; struct GNUNET_DISK_FileHandle *pipe_stdin; @@ -234,10 +232,10 @@ send_tan (struct ChallengeContext *bc, p = GNUNET_DISK_pipe (GNUNET_DISK_PF_BLOCKING_RW); if (NULL == p) { - MHD_STATUS mres; + MHD_RESULT mres; // FIXME: generate HTML error instead... - mres = TALER_MHD_reply_with_error (connection, + mres = TALER_MHD_reply_with_error (bc->hc->connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_CHALLENGER_HELPER_EXEC_FAILED, "pipe"); @@ -254,7 +252,7 @@ send_tan (struct ChallengeContext *bc, CH_auth_command, bc->address, NULL); - if (NULL == child) + if (NULL == bc->child) { MHD_RESULT mres; @@ -276,7 +274,7 @@ send_tan (struct ChallengeContext *bc, GNUNET_asprintf (&msg, "PIN: %u", - (unsigned int) pin); + (unsigned int) bc->tan); { const char *off = msg; size_t left = strlen (off); @@ -295,7 +293,7 @@ send_tan (struct ChallengeContext *bc, MHD_RESULT mres; // FIXME: generate HTML error instead... - mres = TALER_MHD_reply_with_error (connection, + mres = TALER_MHD_reply_with_error (bc->hc->connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_CHALLENGER_HELPER_EXEC_FAILED, "write"); @@ -304,7 +302,6 @@ send_tan (struct ChallengeContext *bc, : GNUNET_SYSERR; return; } - msg_off += ret; off += ret; left -= ret; } @@ -313,7 +310,7 @@ send_tan (struct ChallengeContext *bc, bc->cwh = GNUNET_wait_child (bc->child, &child_done_cb, bc); - MHD_suspend_connection (connection); + MHD_suspend_connection (bc->hc->connection); GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc); @@ -426,7 +423,7 @@ CH_handler_challenge (struct CH_HandlerContext *hc, (unsigned int) bc->exit_code, bc->pst); // FIXME: generate HTML error instead... - return TALER_MHD_reply_with_error (connection, + return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_CHALLENGER_HELPER_EXEC_FAILED, es); @@ -451,14 +448,14 @@ CH_handler_challenge (struct CH_HandlerContext *hc, { enum GNUNET_DB_QueryStatus qs; - qs = db->challenge_set_address_and_pin (db->cls, - &nonce, - bc->address, - CH_validation_duration, - &bc->tan, - &bc->last_tx_time, - &bc->pin_attempts_left, - &bc->retransmit); + qs = CH_db->challenge_set_address_and_pin (CH_db->cls, + &bc->nonce, + bc->address, + CH_validation_duration, + &bc->tan, + &bc->last_tx_time, + &bc->pin_attempts_left, + &bc->retransmit); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -536,8 +533,7 @@ CH_handler_challenge (struct CH_HandlerContext *hc, if (bc->retransmit) { /* (Re)transmit PIN/TAN */ - send_tan (bc, - tan); + send_tan (bc); if (GNUNET_YES == bc->suspended) return MHD_YES; /* Did we already try to generate a response? */ @@ -563,8 +559,9 @@ CH_handler_challenge (struct CH_HandlerContext *hc, bc->retransmit), GNUNET_JSON_pack_string ("next_tx_time", GNUNET_TIME_absolute2s ( - GNUNET_TIME_absolute_to_timestamp ( - bc->next_tx_time))) + GNUNET_TIME_absolute_add ( + bc->last_tx_time, + CH_validation_duration))) ); ret = TALER_TEMPLATING_reply (hc->connection, MHD_HTTP_OK, diff --git a/src/challenger/challenger-httpd_common.h b/src/challenger/challenger-httpd_common.h @@ -21,7 +21,7 @@ #ifndef CHALLENGER_HTTPD_COMMON_H #define CHALLENGER_HTTPD_COMMON_H -#include <microhttpd.h> +#include "challenger-httpd.h" /** * Extract the client secret from the diff --git a/src/challenger/challenger-httpd_info.c b/src/challenger/challenger-httpd_info.c @@ -21,6 +21,7 @@ #include "platform.h" #include "challenger-httpd.h" #include <gnunet/gnunet_util_lib.h> +#include "challenger-httpd_common.h" #include "challenger-httpd_info.h" /** @@ -62,8 +63,10 @@ CH_handler_info (struct CH_HandlerContext *hc, token = auth + strlen (BEARER_PREFIX); if (GNUNET_OK != - CH_token_to_grant (token, - &grant)) + GNUNET_STRINGS_string_to_data (token, + strlen (token), + &grant, + sizeof (grant))) { GNUNET_break_op (0); return TALER_MHD_reply_with_error (hc->connection, @@ -80,7 +83,7 @@ CH_handler_info (struct CH_HandlerContext *hc, MHD_RESULT mret; qs = CH_db->info_get_grant (CH_db->cls, - &bc->grant, + &grant, &address, &address_expiration); switch (qs) @@ -89,7 +92,7 @@ CH_handler_info (struct CH_HandlerContext *hc, GNUNET_break (0); return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_XX, + TALER_EC_GENERIC_DB_FETCH_FAILED, "info_get_grant"); case GNUNET_DB_STATUS_SOFT_ERROR: GNUNET_break (0); @@ -97,8 +100,8 @@ CH_handler_info (struct CH_HandlerContext *hc, case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: GNUNET_break (0); return TALER_MHD_reply_with_error (hc->connection, - MHD_HTTP_FORBIDDEN, - TALER_EC_CHALLENGER_XXX, + MHD_HTTP_NOT_FOUND, + TALER_EC_CHALLENGER_GRANT_UNKNOWN, "info_get_grant"); case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: break; diff --git a/src/challenger/challenger-httpd_login.c b/src/challenger/challenger-httpd_login.c @@ -132,14 +132,14 @@ CH_handler_login (struct CH_HandlerContext *hc, uint32_t address_attempts_left; enum GNUNET_DB_QueryStatus qs; - qs = db->login_start (db->cls, - &nonce, - client_id, - scope, - state, - redirect_uri, - &last_address, - &address_attempts_left); + qs = CH_db->login_start (CH_db->cls, + &nonce, + client_id, + scope, + state, + redirect_uri, + &last_address, + &address_attempts_left); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/challenger/challenger-httpd_setup.c b/src/challenger/challenger-httpd_setup.c @@ -62,11 +62,11 @@ CH_handler_setup (struct CH_HandlerContext *hc, enum GNUNET_DB_QueryStatus qs; char *client_url = NULL; - qs = db->client_check (db->cls, - (uint64_t) client_id, - client_secret, - 1, - &client_url); + qs = CH_db->client_check (CH_db->cls, + (uint64_t) client_id, + client_secret, + 1, + &client_url); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -96,10 +96,10 @@ CH_handler_setup (struct CH_HandlerContext *hc, GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, &nonce, sizeof (nonce)); - qs = db->setup_nonce (db->cls, - client_id, - &nonce, - expiration_time); + qs = CH_db->setup_nonce (CH_db->cls, + client_id, + &nonce, + expiration_time); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/challenger/challenger-httpd_solve.c b/src/challenger/challenger-httpd_solve.c @@ -21,8 +21,10 @@ #include "platform.h" #include "challenger-httpd.h" #include <gnunet/gnunet_util_lib.h> +#include "challenger-httpd_common.h" #include "challenger-httpd_solve.h" #include <taler/taler_json_lib.h> +#include <taler/taler_templating_lib.h> #include <taler/taler_merchant_service.h> #include <taler/taler_signatures.h> @@ -409,7 +411,7 @@ CH_handler_solve (struct CH_HandlerContext *hc, { MHD_RESULT ret; - ret = MHD_queue_response (connection, + ret = MHD_queue_response (hc->connection, MHD_HTTP_FOUND, response); MHD_destroy_response (response);