summaryrefslogtreecommitdiff
path: root/src/reducer/anastasis_api_recovery_redux.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-08-23 18:22:06 +0200
committerChristian Grothoff <christian@grothoff.org>2021-08-23 18:22:06 +0200
commitd153d8036ea14503f812717b8994a4a845ab643e (patch)
tree04de8dfb53255762f6649dc680be12b0f2954929 /src/reducer/anastasis_api_recovery_redux.c
parent4aedf96ba44ffc804749b595a1ad5d4a17d82d77 (diff)
downloadanastasis-d153d8036ea14503f812717b8994a4a845ab643e.tar.gz
anastasis-d153d8036ea14503f812717b8994a4a845ab643e.tar.bz2
anastasis-d153d8036ea14503f812717b8994a4a845ab643e.zip
-more work on iban logic
Diffstat (limited to 'src/reducer/anastasis_api_recovery_redux.c')
-rw-r--r--src/reducer/anastasis_api_recovery_redux.c104
1 files changed, 89 insertions, 15 deletions
diff --git a/src/reducer/anastasis_api_recovery_redux.c b/src/reducer/anastasis_api_recovery_redux.c
index c29a08a..6b85a75 100644
--- a/src/reducer/anastasis_api_recovery_redux.c
+++ b/src/reducer/anastasis_api_recovery_redux.c
@@ -399,6 +399,51 @@ find_challenge_in_ri (json_t *state,
/**
+ * Find challenge of @a uuid in @a state under "cs".
+ *
+ * @param state the state to search
+ * @param uuid the UUID to search for
+ * @return NULL on error, otherwise challenge entry; RC is NOT incremented
+ */
+static json_t *
+find_challenge_in_cs (json_t *state,
+ const struct ANASTASIS_CRYPTO_TruthUUIDP *uuid)
+{
+ json_t *rd = json_object_get (state,
+ "recovery_document");
+ json_t *cs = json_object_get (rd,
+ "cs");
+ json_t *c;
+ size_t off;
+
+ json_array_foreach (cs, off, c)
+ {
+ struct ANASTASIS_CRYPTO_TruthUUIDP u;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("uuid",
+ &u),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (c,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break (0);
+ continue;
+ }
+ if (0 !=
+ GNUNET_memcmp (uuid,
+ &u))
+ continue;
+ return c;
+ }
+ return NULL;
+}
+
+
+/**
* Defines a callback for the response status for a challenge start
* operation.
*
@@ -713,9 +758,17 @@ answer_feedback_cb (
const json_t *body = csr->details.external_challenge;
const char *method;
json_t *details;
+ bool is_async = false;
+ uint64_t code = 0;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_string ("method",
&method),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_bool ("async",
+ &is_async)),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_uint64 ("answer_code",
+ &code)),
GNUNET_JSON_spec_json ("details",
&details),
GNUNET_JSON_spec_end ()
@@ -741,7 +794,31 @@ answer_feedback_cb (
err));
return;
}
+ if (is_async)
+ {
+ json_t *c = find_challenge_in_cs (sctx->state,
+ &cd->uuid);
+ if (NULL == c)
+ {
+ GNUNET_break (0);
+ set_state (sctx->state,
+ ANASTASIS_RECOVERY_STATE_ERROR);
+ sctx->cb (sctx->cb_cls,
+ TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+ sctx->state);
+ sctx_free (sctx);
+ return;
+ }
+ GNUNET_assert (0 ==
+ json_object_set_new (c,
+ "async",
+ json_true ()));
+ GNUNET_assert (0 ==
+ json_object_set_new (c,
+ "answer-pin",
+ json_integer (code)));
+ }
reply = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("state",
"external-instructions"),
@@ -815,10 +892,11 @@ solve_challenge_cb (void *cls,
return;
}
- if (GNUNET_OK !=
- GNUNET_JSON_parse (sctx->args,
- tspec,
- NULL, NULL))
+ if ( (NULL != sctx->args) &&
+ (GNUNET_OK !=
+ GNUNET_JSON_parse (sctx->args,
+ tspec,
+ NULL, NULL)) )
{
GNUNET_break_op (0);
ANASTASIS_redux_fail_ (sctx->cb,
@@ -845,7 +923,7 @@ solve_challenge_cb (void *cls,
(! cd->async) )
continue;
- challenge = find_challenge_in_ri (sctx->state,
+ challenge = find_challenge_in_cs (sctx->state,
&cd->uuid);
if (NULL == challenge)
{
@@ -963,6 +1041,7 @@ solve_challenge_cb (void *cls,
struct ANASTASIS_Challenge *ci = ri->cs[i];
const struct ANASTASIS_ChallengeDetails *cd;
int ret;
+ json_t *c;
cd = ANASTASIS_challenge_get_details (ci);
if (cd->async)
@@ -980,6 +1059,9 @@ solve_challenge_cb (void *cls,
sctx_free (sctx);
return;
}
+ c = find_challenge_in_cs (sctx->state,
+ &cd->uuid);
+ GNUNET_assert (NULL != c);
if (0 == strcmp ("question",
cd->type))
{
@@ -999,7 +1081,7 @@ solve_challenge_cb (void *cls,
}
/* persist answer, in case payment is required */
GNUNET_assert (0 ==
- json_object_set (challenge,
+ json_object_set (c,
"answer",
janswer));
ret = ANASTASIS_challenge_answer (ci,
@@ -1023,7 +1105,7 @@ solve_challenge_cb (void *cls,
/* persist answer, in case async processing
happens via poll */
GNUNET_assert (0 ==
- json_object_set (challenge,
+ json_object_set (c,
"answer-pin",
pin));
ret = ANASTASIS_challenge_answer2 (ci,
@@ -1316,14 +1398,6 @@ poll_challenges (json_t *state,
= GNUNET_new (struct SelectChallengeContext);
json_t *rd;
- if (NULL == arguments)
- {
- ANASTASIS_redux_fail_ (cb,
- cb_cls,
- TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID,
- "arguments missing");
- return NULL;
- }
rd = json_object_get (state,
"recovery_document");
if (NULL == rd)