diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2022-03-10 04:18:17 +0100 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2022-03-10 04:18:17 +0100 |
commit | 69e887bb68064ddf40db83d46ae3333659112db4 (patch) | |
tree | 0624b5ca5963eb7f42b98f6e3a948534585f0ec2 /src/backend | |
parent | 2ba4773bc79ee6dff50a6322dbbf3569e47708eb (diff) | |
download | anastasis-69e887bb68064ddf40db83d46ae3333659112db4.tar.gz anastasis-69e887bb68064ddf40db83d46ae3333659112db4.tar.bz2 anastasis-69e887bb68064ddf40db83d46ae3333659112db4.zip |
-clean up challenge logic for new truth api
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/anastasis-httpd_truth-challenge.c | 87 | ||||
-rw-r--r-- | src/backend/anastasis-httpd_truth-solve.c | 62 |
2 files changed, 57 insertions, 92 deletions
diff --git a/src/backend/anastasis-httpd_truth-challenge.c b/src/backend/anastasis-httpd_truth-challenge.c index 65dc244..3a3688e 100644 --- a/src/backend/anastasis-httpd_truth-challenge.c +++ b/src/backend/anastasis-httpd_truth-challenge.c @@ -44,6 +44,12 @@ #define AUTO_REFUND_TIMEOUT GNUNET_TIME_relative_multiply ( \ GNUNET_TIME_UNIT_MINUTES, 2) +/** + * How long should the wallet check for payment before giving up? + */ +#define PAYMENT_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 15) + /** * How many retries do we allow per code? @@ -135,8 +141,7 @@ struct ChallengeContext struct GNUNET_CONTAINER_HeapNode *hn; /** - * How long do we wait at most for payment or - * authorization? + * When should this request time out? */ struct GNUNET_TIME_Absolute timeout; @@ -887,16 +892,23 @@ static MHD_RESULT run_authorization_process (struct MHD_Connection *connection, struct ChallengeContext *gc) { - enum ANASTASIS_AUTHORIZATION_Result ret; + enum ANASTASIS_AUTHORIZATION_ChallengeResult ret; enum GNUNET_DB_QueryStatus qs; GNUNET_assert (! gc->suspended); - ret = gc->authorization->process (gc->as, - gc->timeout, - connection); + if (NULL == gc->authorization->challenge) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (gc->connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_ANASTASIS_TRUTH_AUTHORIZATION_START_FAILED, + "challenge method not implemented for authorization method"); + } + ret = gc->authorization->challenge (gc->as, + connection); switch (ret) { - case ANASTASIS_AUTHORIZATION_RES_SUCCESS: + case ANASTASIS_AUTHORIZATION_CRES_SUCCESS: /* Challenge sent successfully */ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Authorization request sent successfully\n"); @@ -908,7 +920,7 @@ run_authorization_process (struct MHD_Connection *connection, gc->authorization->cleanup (gc->as); gc->as = NULL; return MHD_YES; - case ANASTASIS_AUTHORIZATION_RES_FAILED: + case ANASTASIS_AUTHORIZATION_CRES_FAILED: if (gc->payment_identifier_provided) { begin_refund (gc); @@ -916,11 +928,11 @@ run_authorization_process (struct MHD_Connection *connection, gc->authorization->cleanup (gc->as); gc->as = NULL; return MHD_YES; - case ANASTASIS_AUTHORIZATION_RES_SUSPENDED: + case ANASTASIS_AUTHORIZATION_CRES_SUSPENDED: /* connection was suspended */ gc_suspended (gc); return MHD_YES; - case ANASTASIS_AUTHORIZATION_RES_SUCCESS_REPLY_FAILED: + case ANASTASIS_AUTHORIZATION_CRES_SUCCESS_REPLY_FAILED: /* Challenge sent successfully */ qs = db->mark_challenge_sent (db->cls, &gc->payment_identifier, @@ -930,27 +942,10 @@ run_authorization_process (struct MHD_Connection *connection, gc->authorization->cleanup (gc->as); gc->as = NULL; return MHD_NO; - case ANASTASIS_AUTHORIZATION_RES_FAILED_REPLY_FAILED: + case ANASTASIS_AUTHORIZATION_CRES_FAILED_REPLY_FAILED: gc->authorization->cleanup (gc->as); gc->as = NULL; return MHD_NO; - case ANASTASIS_AUTHORIZATION_RES_FINISHED: - /* Neither case should EVER happen here! */ - GNUNET_break (0); - GNUNET_assert (! gc->suspended); - gc->authorization->cleanup (gc->as); - gc->as = NULL; - if (gc->in_list) - { - GNUNET_CONTAINER_DLL_remove (gc_head, - gc_tail, - gc); - gc->in_list = false; - } - return TALER_MHD_reply_with_error (gc->connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, - "authorization successful when we were only supposed to be challenging"); } GNUNET_break (0); return MHD_NO; @@ -981,40 +976,8 @@ AH_handler_truth_challenge ( gc->connection = connection; gc->truth_uuid = *truth_uuid; gc->hc->cc = &request_done; - - { - const char *long_poll_timeout_ms; - - long_poll_timeout_ms = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "timeout_ms"); - if (NULL != long_poll_timeout_ms) - { - unsigned int timeout; - char dummy; - - if (1 != sscanf (long_poll_timeout_ms, - "%u%c", - &timeout, - &dummy)) - { - GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "timeout_ms (must be non-negative number)"); - } - gc->timeout - = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply ( - GNUNET_TIME_UNIT_MILLISECONDS, - timeout)); - } - else - { - gc->timeout = GNUNET_TIME_relative_to_absolute ( - GNUNET_TIME_UNIT_SECONDS); - } - } + gc->timeout = GNUNET_TIME_relative_to_absolute ( + PAYMENT_TIMEOUT); } /* end of first-time initialization (if NULL == gc) */ else { diff --git a/src/backend/anastasis-httpd_truth-solve.c b/src/backend/anastasis-httpd_truth-solve.c index 2e4fea0..9142ad2 100644 --- a/src/backend/anastasis-httpd_truth-solve.c +++ b/src/backend/anastasis-httpd_truth-solve.c @@ -789,37 +789,36 @@ static MHD_RESULT run_authorization_process (struct MHD_Connection *connection, struct SolveContext *gc) { - enum ANASTASIS_AUTHORIZATION_Result ret; + enum ANASTASIS_AUTHORIZATION_SolveResult ret; GNUNET_assert (! gc->suspended); - ret = gc->authorization->process (gc->as, - gc->timeout, - connection); - switch (ret) + if (NULL == gc->authorization->solve) { - case ANASTASIS_AUTHORIZATION_RES_SUCCESS: - case ANASTASIS_AUTHORIZATION_RES_SUCCESS_REPLY_FAILED: - /* Neither case should EVER happen here! */ GNUNET_break (0); - gc->authorization->cleanup (gc->as); - gc->as = NULL; return TALER_MHD_reply_with_error (gc->connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, - "challenge sent when we were only supposed to be checking"); - case ANASTASIS_AUTHORIZATION_RES_SUSPENDED: + TALER_EC_ANASTASIS_TRUTH_AUTHORIZATION_START_FAILED, + "solve method not implemented for authorization method"); + } + ret = gc->authorization->solve (gc->as, + gc->timeout, + &gc->challenge_response, + connection); + switch (ret) + { + case ANASTASIS_AUTHORIZATION_SRES_SUSPENDED: /* connection was suspended */ gc_suspended (gc); return MHD_YES; - case ANASTASIS_AUTHORIZATION_RES_FAILED: + case ANASTASIS_AUTHORIZATION_SRES_FAILED: gc->authorization->cleanup (gc->as); gc->as = NULL; return MHD_YES; - case ANASTASIS_AUTHORIZATION_RES_FAILED_REPLY_FAILED: + case ANASTASIS_AUTHORIZATION_SRES_FAILED_REPLY_FAILED: gc->authorization->cleanup (gc->as); gc->as = NULL; return MHD_NO; - case ANASTASIS_AUTHORIZATION_RES_FINISHED: + case ANASTASIS_AUTHORIZATION_SRES_FINISHED: GNUNET_assert (! gc->suspended); gc->authorization->cleanup (gc->as); gc->as = NULL; @@ -983,7 +982,7 @@ direct_validation (struct SolveContext *gc, size_t decrypted_truth_size) { /* Non-random code, call plugin directly! */ - enum ANASTASIS_AUTHORIZATION_Result aar; + enum ANASTASIS_AUTHORIZATION_SolveResult aar; enum GNUNET_GenericReturnValue res; res = rate_limit (gc); @@ -1004,25 +1003,28 @@ direct_validation (struct SolveContext *gc, TALER_EC_ANASTASIS_TRUTH_AUTHORIZATION_START_FAILED, NULL); } - aar = gc->authorization->process (gc->as, - GNUNET_TIME_UNIT_ZERO_ABS, - gc->connection); - switch (aar) + if (NULL == gc->authorization->solve) { - case ANASTASIS_AUTHORIZATION_RES_SUCCESS: GNUNET_break (0); + return TALER_MHD_reply_with_error (gc->connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_ANASTASIS_TRUTH_AUTHORIZATION_START_FAILED, + "solve method not implemented for authorization method"); + } + aar = gc->authorization->solve (gc->as, + GNUNET_TIME_UNIT_ZERO_ABS, + &gc->challenge_response, + gc->connection); + switch (aar) + { + case ANASTASIS_AUTHORIZATION_SRES_FAILED: return MHD_YES; - case ANASTASIS_AUTHORIZATION_RES_FAILED: - return MHD_YES; - case ANASTASIS_AUTHORIZATION_RES_SUSPENDED: + case ANASTASIS_AUTHORIZATION_SRES_SUSPENDED: gc_suspended (gc); return MHD_YES; - case ANASTASIS_AUTHORIZATION_RES_SUCCESS_REPLY_FAILED: - GNUNET_break (0); - return MHD_NO; - case ANASTASIS_AUTHORIZATION_RES_FAILED_REPLY_FAILED: + case ANASTASIS_AUTHORIZATION_SRES_FAILED_REPLY_FAILED: return MHD_NO; - case ANASTASIS_AUTHORIZATION_RES_FINISHED: + case ANASTASIS_AUTHORIZATION_SRES_FINISHED: return return_key_share (&gc->truth_uuid, gc->connection); } |