summaryrefslogtreecommitdiff
path: root/src/authorization/anastasis_authorization_plugin_email.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/authorization/anastasis_authorization_plugin_email.c')
-rw-r--r--src/authorization/anastasis_authorization_plugin_email.c76
1 files changed, 33 insertions, 43 deletions
diff --git a/src/authorization/anastasis_authorization_plugin_email.c b/src/authorization/anastasis_authorization_plugin_email.c
index 0eefcc5..7fc97e7 100644
--- a/src/authorization/anastasis_authorization_plugin_email.c
+++ b/src/authorization/anastasis_authorization_plugin_email.c
@@ -3,7 +3,7 @@
Copyright (C) 2019-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
@@ -220,7 +220,7 @@ email_validate (void *cls,
{
if (MHD_NO ==
TALER_MHD_reply_with_error (connection,
- MHD_HTTP_EXPECTATION_FAILED,
+ MHD_HTTP_CONFLICT,
TALER_EC_ANASTASIS_EMAIL_INVALID,
NULL))
return GNUNET_SYSERR;
@@ -296,8 +296,12 @@ email_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);
@@ -310,20 +314,17 @@ email_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
-email_process (struct ANASTASIS_AUTHORIZATION_State *as,
- struct GNUNET_TIME_Absolute timeout,
- struct MHD_Connection *connection)
+static enum ANASTASIS_AUTHORIZATION_ChallengeResult
+email_challenge (struct ANASTASIS_AUTHORIZATION_State *as,
+ struct MHD_Connection *connection)
{
MHD_RESULT mres;
const char *mime;
const char *lang;
- (void) timeout;
mime = MHD_lookup_connection_value (connection,
MHD_HEADER_KIND,
MHD_HTTP_HEADER_ACCEPT);
@@ -348,8 +349,8 @@ email_process (struct ANASTASIS_AUTHORIZATION_State *as,
TALER_EC_ANASTASIS_EMAIL_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,
@@ -367,27 +368,19 @@ email_process (struct ANASTASIS_AUTHORIZATION_State *as,
TALER_EC_ANASTASIS_EMAIL_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;
@@ -409,8 +402,8 @@ email_process (struct ANASTASIS_AUTHORIZATION_State *as,
TALER_EC_ANASTASIS_EMAIL_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;
@@ -423,14 +416,14 @@ email_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) )
@@ -447,8 +440,8 @@ email_process (struct ANASTASIS_AUTHORIZATION_State *as,
TALER_EC_ANASTASIS_EMAIL_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 */
@@ -471,12 +464,9 @@ email_process (struct ANASTASIS_AUTHORIZATION_State *as,
user = GNUNET_strndup (as->email,
len);
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",
user));
GNUNET_free (user);
}
@@ -502,12 +492,12 @@ email_process (struct ANASTASIS_AUTHORIZATION_State *as,
"text/plain"));
}
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;
}
}
@@ -606,7 +596,7 @@ libanastasis_plugin_authorization_email_init (void *cls)
plugin->cls = ctx;
plugin->validate = &email_validate;
plugin->start = &email_start;
- plugin->process = &email_process;
+ plugin->challenge = &email_challenge;
plugin->cleanup = &email_cleanup;
if (GNUNET_OK !=