challenger

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

commit 9eb507be71bc2e8d53650868bfc7861522a70215
parent 0f545aa02cfe572c8f0e381e38f317e5dcf4a843
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 28 Apr 2023 23:02:57 +0200

-fix

Diffstat:
Msrc/challenger/Makefile.am | 1+
Msrc/challenger/challenger-httpd.c | 5+++++
Msrc/challenger/challenger-httpd.h | 5+++++
Msrc/challenger/challenger-httpd_challenge.c | 48++++++++++++++++++++++++++----------------------
Msrc/challenger/challenger-httpd_login.c | 47++++++++++++++++++++++++++---------------------
Msrc/challenger/challenger-httpd_setup.c | 8++++----
Msrc/challenger/challenger-httpd_solve.c | 4++--
7 files changed, 69 insertions(+), 49 deletions(-)

diff --git a/src/challenger/Makefile.am b/src/challenger/Makefile.am @@ -38,6 +38,7 @@ challenger_httpd_SOURCES = \ challenger_httpd_LDADD = \ $(top_builddir)/src/util/libchallengerutil.la \ $(top_builddir)/src/challengerdb/libchallengerdb.la \ + -ltalertemplating \ -lmicrohttpd \ -ljansson \ -ltalermhd \ diff --git a/src/challenger/challenger-httpd.c b/src/challenger/challenger-httpd.c @@ -81,6 +81,11 @@ struct CHALLENGER_DatabasePlugin *db; struct GNUNET_TIME_Relative CH_validation_duration; /** + * How often do we retransmit the challenge. + */ +struct GNUNET_TIME_Relative CH_pin_retransmission_frequency; + +/** * A client has requested the given url using the given method * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT, * #MHD_HTTP_METHOD_DELETE, #MHD_HTTP_METHOD_POST, etc). The callback diff --git a/src/challenger/challenger-httpd.h b/src/challenger/challenger-httpd.h @@ -135,6 +135,11 @@ extern struct GNUNET_CURL_Context *CH_ctx; extern struct GNUNET_TIME_Relative CH_validation_duration; /** + * How often do we retransmit the challenge. + */ +extern struct GNUNET_TIME_Relative CH_pin_retransmission_frequency; + +/** * Kick MHD to run now, to be called after MHD_resume_connection(). * Basically, we need to explicitly resume MHD's event loop whenever * we made progress serving a request. This function re-schedules diff --git a/src/challenger/challenger-httpd_challenge.c b/src/challenger/challenger-httpd_challenge.c @@ -23,6 +23,7 @@ #include <gnunet/gnunet_util_lib.h> #include "challenger-httpd_challenge.h" #include <taler/taler_json_lib.h> +#include <taler/taler_templating_lib.h> #include <taler/taler_merchant_service.h> #include <taler/taler_signatures.h> @@ -65,7 +66,7 @@ cleanup_ctx (void *cls) GNUNET_break_op (MHD_YES == MHD_destroy_post_processor (bc->pp)); } - GNUENT_free (bc->address); + GNUNET_free (bc->address); GNUNET_free (bc); } @@ -136,7 +137,7 @@ CH_handler_challenge (struct CH_HandlerContext *hc, sizeof (nonce))) { GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, + return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_NOT_FOUND, TALER_EC_GENERIC_PARAMETER_MISSING, hc->path); @@ -173,25 +174,25 @@ CH_handler_challenge (struct CH_HandlerContext *hc, struct GNUNET_TIME_Absolute last_tx_time = GNUNET_TIME_absolute_get (); uint32_t last_pin - = GNUNET_CRYPTO_random_uint32 (GNUNET_CRYPTO_RANDOM_NONCE) % 100000000; - uint32_t pin_transmissions_left; + = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, + 100000000); uint32_t pin_attempts_left = 3; /* if addr is new */ enum GNUNET_DB_QueryStatus qs; struct GNUNET_TIME_Absolute next_tx_time; + bool retransmit; next_tx_time = GNUNET_TIME_absolute_subtract (last_tx_time, - get_duration); + CH_validation_duration); qs = db->challenge_set_address_and_pin (db->cls, &nonce, - address, + bc->address, next_tx_time, - &last_tx, + &last_tx_time, &last_pin, - &pin_transmissions_left, - &pin_attempts_left); + &retransmit); switch (qs) { - case GNUNET_DB_SUCCESS_HARD_ERROR: + case GNUNET_DB_STATUS_HARD_ERROR: { enum GNUNET_GenericReturnValue ret; json_t *root = json_object (); @@ -201,7 +202,9 @@ CH_handler_challenge (struct CH_HandlerContext *hc, ret = TALER_TEMPLATING_reply (hc->connection, MHD_HTTP_INTERNAL_SERVER_ERROR, "internal-server-error.must", - NULL); + NULL, + NULL, + root); json_decref (root); if (GNUNET_SYSERR == ret) { @@ -211,10 +214,10 @@ CH_handler_challenge (struct CH_HandlerContext *hc, GNUNET_break (GNUNET_OK == ret); return MHD_YES; } - case GNUNET_DB_SUCCESS_SOFT_ERROR: + case GNUNET_DB_STATUS_SOFT_ERROR: GNUNET_break (0); return GNUNET_NO; - case GNUNET_DB_SUCCESS_NO_RESULTS: + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: { enum GNUNET_GenericReturnValue ret; json_t *root = json_object (); @@ -223,7 +226,9 @@ CH_handler_challenge (struct CH_HandlerContext *hc, ret = TALER_TEMPLATING_reply (hc->connection, MHD_HTTP_NOT_FOUND, "validation-unknown.must", - NULL); + NULL, + NULL, + root); json_decref (root); if (GNUNET_SYSERR == ret) { @@ -233,7 +238,7 @@ CH_handler_challenge (struct CH_HandlerContext *hc, GNUNET_break (GNUNET_OK == ret); return MHD_YES; } - case GNUNET_DB_SUCCESS_ONE_RESULT: + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: break; } if (0 == pin_attempts_left) @@ -243,7 +248,7 @@ CH_handler_challenge (struct CH_HandlerContext *hc, GNUNET_assert (NULL != root); ret = TALER_TEMPLATING_reply (hc->connection, - MHD_HTTP_XXX, + MHD_HTTP_TOO_MANY_REQUESTS, "attempts-exhausted.must", NULL, NULL, @@ -257,10 +262,8 @@ CH_handler_challenge (struct CH_HandlerContext *hc, GNUNET_break (GNUNET_OK == ret); return MHD_YES; } - if ( (GNUNET_TIME_relative_cmp (duration, - (>), - CH_pin_retransmission_frequency)) && - (pin_transmissions_left > 0) ) + + if (retransmit) { /* Retransmit PIN */ } @@ -271,8 +274,9 @@ CH_handler_challenge (struct CH_HandlerContext *hc, args = GNUNET_JSON_PACK ( GNUNET_JSON_pack_uint64 ("attempts_left", pin_attempts_left), - GNUNET_JSON_pack_absolute_time ("next_tx_time", - next_tx_time), + GNUNET_JSON_pack_timestamp ("next_tx_time", + GNUNET_TIME_absolute_to_timestamp ( + next_tx_time)) ); ret = TALER_TEMPLATING_reply (hc->connection, MHD_HTTP_OK, diff --git a/src/challenger/challenger-httpd_login.c b/src/challenger/challenger-httpd_login.c @@ -21,6 +21,7 @@ #include "platform.h" #include "challenger-httpd.h" #include <gnunet/gnunet_util_lib.h> +#include <taler/taler_templating_lib.h> #include "challenger-httpd_login.h" @@ -43,19 +44,19 @@ CH_handler_login (struct CH_HandlerContext *hc, sizeof (nonce))) { GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, + return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_NOT_FOUND, TALER_EC_GENERIC_PARAMETER_MISSING, hc->path); } response_type - = MHD_lookup_connection_value (connection, + = MHD_lookup_connection_value (hc->connection, MHD_GET_ARGUMENT_KIND, "response_type"); if (NULL == response_type) { GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, + return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MISSING, "response_type"); @@ -64,7 +65,7 @@ CH_handler_login (struct CH_HandlerContext *hc, "code")) { GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, + return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MALFORMED, "response_type (mus be 'code')"); @@ -75,13 +76,13 @@ CH_handler_login (struct CH_HandlerContext *hc, char dummy; client_id_str - = MHD_lookup_connection_value (connection, + = MHD_lookup_connection_value (hc->connection, MHD_GET_ARGUMENT_KIND, "client_id"); if (NULL == client_id_str) { GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, + return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MISSING, "client_id"); @@ -92,14 +93,14 @@ CH_handler_login (struct CH_HandlerContext *hc, &dummy)) { GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, + return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MALFORMED, "client_id"); } } redirect_uri - = MHD_lookup_connection_value (connection, + = MHD_lookup_connection_value (hc->connection, MHD_GET_ARGUMENT_KIND, "redirect_uri"); if ( (NULL != redirect_uri) && @@ -111,19 +112,19 @@ CH_handler_login (struct CH_HandlerContext *hc, strlen ("https://"))) ) { GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, + return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MALFORMED, "redirect_uri (has to start with 'http://' or 'https://')"); } state - = MHD_lookup_connection_value (connection, + = MHD_lookup_connection_value (hc->connection, MHD_GET_ARGUMENT_KIND, "state"); if (NULL == state) state = ""; scope - = MHD_lookup_connection_value (connection, + = MHD_lookup_connection_value (hc->connection, MHD_GET_ARGUMENT_KIND, "scope"); (void) scope; /* ignored */ @@ -135,14 +136,14 @@ CH_handler_login (struct CH_HandlerContext *hc, qs = db->login_start (db->cls, &nonce, client_id, - client_scope, - client_state, - client_redirect_url, + scope, + state, + redirect_uri, &last_address, &address_attempts_left); switch (qs) { - case GNUNET_DB_SUCCESS_HARD_ERROR: + case GNUNET_DB_STATUS_HARD_ERROR: { enum GNUNET_GenericReturnValue ret; json_t *root = json_object (); @@ -152,7 +153,9 @@ CH_handler_login (struct CH_HandlerContext *hc, ret = TALER_TEMPLATING_reply (hc->connection, MHD_HTTP_INTERNAL_SERVER_ERROR, "internal-server-error.must", - NULL); + NULL, + NULL, + root); json_decref (root); if (GNUNET_SYSERR == ret) { @@ -162,10 +165,10 @@ CH_handler_login (struct CH_HandlerContext *hc, GNUNET_break (GNUNET_OK == ret); return MHD_YES; } - case GNUNET_DB_SUCCESS_SOFT_ERROR: + case GNUNET_DB_STATUS_SOFT_ERROR: GNUNET_break (0); return GNUNET_NO; - case GNUNET_DB_SUCCESS_NO_RESULTS: + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: { enum GNUNET_GenericReturnValue ret; json_t *root = json_object (); @@ -174,7 +177,9 @@ CH_handler_login (struct CH_HandlerContext *hc, ret = TALER_TEMPLATING_reply (hc->connection, MHD_HTTP_NOT_FOUND, "validation-unknown.must", - NULL); + NULL, + NULL, + root); json_decref (root); if (GNUNET_SYSERR == ret) { @@ -184,7 +189,7 @@ CH_handler_login (struct CH_HandlerContext *hc, GNUNET_break (GNUNET_OK == ret); return MHD_YES; } - case GNUNET_DB_SUCCESS_ONE_RESULT: + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: break; } { @@ -197,7 +202,7 @@ CH_handler_login (struct CH_HandlerContext *hc, GNUNET_JSON_pack_string ("last_address", last_address), GNUNET_JSON_pack_uint64 ("changes_left", - address_attempts_left), + address_attempts_left) ); ret = TALER_TEMPLATING_reply ( hc->connection, diff --git a/src/challenger/challenger-httpd_setup.c b/src/challenger/challenger-httpd_setup.c @@ -96,10 +96,10 @@ CH_handler_setup (struct CH_HandlerContext *hc, GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, &nonce, sizeof (nonce)); - qs = db->validation_setup (db->cls, - client_id, - &nonce, - expiration_time); + qs = db->setup_nonce (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 @@ -65,7 +65,7 @@ cleanup_ctx (void *cls) GNUNET_break_op (MHD_YES == MHD_destroy_post_processor (bc->pp)); } - GNUENT_free (bc->pin); + GNUNET_free (bc->pin); GNUNET_free (bc); } @@ -136,7 +136,7 @@ CH_handler_solve (struct CH_HandlerContext *hc, sizeof (nonce))) { GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, + return TALER_MHD_reply_with_error (hc->connection, MHD_HTTP_NOT_FOUND, TALER_EC_GENERIC_PARAMETER_MISSING, hc->path);