diff options
Diffstat (limited to 'src/authorization/anastasis_authorization_plugin_post.c')
-rw-r--r-- | src/authorization/anastasis_authorization_plugin_post.c | 83 |
1 files changed, 36 insertions, 47 deletions
diff --git a/src/authorization/anastasis_authorization_plugin_post.c b/src/authorization/anastasis_authorization_plugin_post.c index 4adeffd..9410b58 100644 --- a/src/authorization/anastasis_authorization_plugin_post.c +++ b/src/authorization/anastasis_authorization_plugin_post.c @@ -3,7 +3,7 @@ Copyright (C) 2021 Anastasis SARL Anastasis is free software; you can redistribute it and/or modify it under the - terms of the GNU Lesser General Public License as published by the Free Software + terms of the GNU Affero General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY @@ -232,7 +232,7 @@ post_validate (void *cls, { if (MHD_NO == TALER_MHD_reply_with_error (connection, - MHD_HTTP_EXPECTATION_FAILED, + MHD_HTTP_CONFLICT, TALER_EC_ANASTASIS_POST_INVALID, "JSON malformed")) return GNUNET_SYSERR; @@ -248,7 +248,7 @@ post_validate (void *cls, json_decref (j); if (MHD_NO == TALER_MHD_reply_with_error (connection, - MHD_HTTP_EXPECTATION_FAILED, + MHD_HTTP_CONFLICT, TALER_EC_ANASTASIS_POST_INVALID, "JSON lacked required address information")) return GNUNET_SYSERR; @@ -334,8 +334,12 @@ post_done_cb (void *cls, { struct ANASTASIS_AUTHORIZATION_State *as = cls; - as->child = NULL; as->cwh = NULL; + if (NULL != as->child) + { + GNUNET_OS_process_destroy (as->child); + as->child = NULL; + } as->pst = type; as->exit_code = exit_code; MHD_resume_connection (as->connection); @@ -348,14 +352,12 @@ post_done_cb (void *cls, * I.e. start to send SMS or e-mail or launch video identification. * * @param as authorization state - * @param timeout how long do we have to produce a reply * @param connection HTTP client request (for queuing response, such as redirection to video portal) * @return state of the request */ -static enum ANASTASIS_AUTHORIZATION_Result -post_process (struct ANASTASIS_AUTHORIZATION_State *as, - struct GNUNET_TIME_Absolute timeout, - struct MHD_Connection *connection) +static enum ANASTASIS_AUTHORIZATION_ChallengeResult +post_challenge (struct ANASTASIS_AUTHORIZATION_State *as, + struct MHD_Connection *connection) { const char *mime; const char *lang; @@ -379,7 +381,6 @@ post_process (struct ANASTASIS_AUTHORIZATION_State *as, GNUNET_JSON_spec_end () }; - (void) timeout; mime = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_ACCEPT); @@ -401,8 +402,8 @@ post_process (struct ANASTASIS_AUTHORIZATION_State *as, TALER_EC_ANASTASIS_POST_INVALID, "address information incomplete"); if (MHD_YES != mres) - return ANASTASIS_AUTHORIZATION_RES_FAILED_REPLY_FAILED; - return ANASTASIS_AUTHORIZATION_RES_FAILED; + return ANASTASIS_AUTHORIZATION_CRES_FAILED_REPLY_FAILED; + return ANASTASIS_AUTHORIZATION_CRES_FAILED; } if (NULL == as->msg) { @@ -418,8 +419,8 @@ post_process (struct ANASTASIS_AUTHORIZATION_State *as, TALER_EC_ANASTASIS_POST_HELPER_EXEC_FAILED, "pipe"); if (MHD_YES != mres) - return ANASTASIS_AUTHORIZATION_RES_FAILED_REPLY_FAILED; - return ANASTASIS_AUTHORIZATION_RES_FAILED; + return ANASTASIS_AUTHORIZATION_CRES_FAILED_REPLY_FAILED; + return ANASTASIS_AUTHORIZATION_CRES_FAILED; } as->child = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ERR, p, @@ -441,28 +442,19 @@ post_process (struct ANASTASIS_AUTHORIZATION_State *as, TALER_EC_ANASTASIS_POST_HELPER_EXEC_FAILED, "exec"); if (MHD_YES != mres) - return ANASTASIS_AUTHORIZATION_RES_FAILED_REPLY_FAILED; - return ANASTASIS_AUTHORIZATION_RES_FAILED; + return ANASTASIS_AUTHORIZATION_CRES_FAILED_REPLY_FAILED; + return ANASTASIS_AUTHORIZATION_CRES_FAILED; } pipe_stdin = GNUNET_DISK_pipe_detach_end (p, GNUNET_DISK_PIPE_END_WRITE); GNUNET_assert (NULL != pipe_stdin); GNUNET_DISK_pipe_close (p); - { - char *tpk; - - tpk = GNUNET_STRINGS_data_to_string_alloc ( - &as->truth_uuid, - sizeof (as->truth_uuid)); - GNUNET_asprintf (&as->msg, - get_message (as->ctx->messages, - connection, - "body"), - (unsigned long long) as->code, - tpk); - GNUNET_free (tpk); - } - + GNUNET_asprintf (&as->msg, + get_message (as->ctx->messages, + connection, + "body"), + ANASTASIS_pin2s (as->code), + ANASTASIS_CRYPTO_uuid2s (&as->truth_uuid)); { const char *off = as->msg; size_t left = strlen (off); @@ -483,8 +475,8 @@ post_process (struct ANASTASIS_AUTHORIZATION_State *as, TALER_EC_ANASTASIS_POST_HELPER_EXEC_FAILED, "write"); if (MHD_YES != mres) - return ANASTASIS_AUTHORIZATION_RES_FAILED_REPLY_FAILED; - return ANASTASIS_AUTHORIZATION_RES_FAILED; + return ANASTASIS_AUTHORIZATION_CRES_FAILED_REPLY_FAILED; + return ANASTASIS_AUTHORIZATION_CRES_FAILED; } as->msg_off += ret; off += ret; @@ -497,14 +489,14 @@ post_process (struct ANASTASIS_AUTHORIZATION_State *as, as); as->connection = connection; MHD_suspend_connection (connection); - return ANASTASIS_AUTHORIZATION_RES_SUSPENDED; + return ANASTASIS_AUTHORIZATION_CRES_SUSPENDED; } if (NULL != as->cwh) { /* Spurious call, why are we here? */ GNUNET_break (0); MHD_suspend_connection (connection); - return ANASTASIS_AUTHORIZATION_RES_SUSPENDED; + return ANASTASIS_AUTHORIZATION_CRES_SUSPENDED; } if ( (GNUNET_OS_PROCESS_EXITED != as->pst) || (0 != as->exit_code) ) @@ -521,8 +513,8 @@ post_process (struct ANASTASIS_AUTHORIZATION_State *as, TALER_EC_ANASTASIS_POST_HELPER_COMMAND_FAILED, es); if (MHD_YES != mres) - return ANASTASIS_AUTHORIZATION_RES_FAILED_REPLY_FAILED; - return ANASTASIS_AUTHORIZATION_RES_FAILED; + return ANASTASIS_AUTHORIZATION_CRES_FAILED_REPLY_FAILED; + return ANASTASIS_AUTHORIZATION_CRES_FAILED; } /* Build HTTP response */ @@ -533,12 +525,9 @@ post_process (struct ANASTASIS_AUTHORIZATION_State *as, "application/json")) { resp = TALER_MHD_MAKE_JSON_PACK ( - GNUNET_JSON_pack_uint64 ("code", - TALER_EC_ANASTASIS_TRUTH_CHALLENGE_RESPONSE_REQUIRED), - GNUNET_JSON_pack_string ("hint", - TALER_ErrorCode_get_hint ( - TALER_EC_ANASTASIS_TRUTH_CHALLENGE_RESPONSE_REQUIRED)), - GNUNET_JSON_pack_string ("detail", + GNUNET_JSON_pack_string ("challenge_type", + "TAN_SENT"), + GNUNET_JSON_pack_string ("tan_address_hint", zip)); } else @@ -558,12 +547,12 @@ post_process (struct ANASTASIS_AUTHORIZATION_State *as, TALER_MHD_add_global_headers (resp); } mres = MHD_queue_response (connection, - MHD_HTTP_FORBIDDEN, + MHD_HTTP_OK, resp); MHD_destroy_response (resp); if (MHD_YES != mres) - return ANASTASIS_AUTHORIZATION_RES_SUCCESS_REPLY_FAILED; - return ANASTASIS_AUTHORIZATION_RES_SUCCESS; + return ANASTASIS_AUTHORIZATION_CRES_SUCCESS_REPLY_FAILED; + return ANASTASIS_AUTHORIZATION_CRES_SUCCESS; } } @@ -648,7 +637,7 @@ libanastasis_plugin_authorization_post_init (void *cls) plugin->cls = ctx; plugin->validate = &post_validate; plugin->start = &post_start; - plugin->process = &post_process; + plugin->challenge = &post_challenge; plugin->cleanup = &post_cleanup; if (GNUNET_OK != |