[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 11/15: worked on challenge select
From: |
gnunet |
Subject: |
[taler-anastasis] 11/15: worked on challenge select |
Date: |
Sun, 31 Jan 2021 17:06:17 +0100 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a commit to branch master
in repository anastasis.
commit 8fe74901dc4c34c9ece376be4b8270103bb43217
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Thu Jan 21 11:44:41 2021 +0100
worked on challenge select
---
contrib/Makefile.am | 5 +-
...tasis_reducer_recovery_enter_user_attributes.sh | 6 +-
src/include/anastasis.h | 20 +++
src/lib/anastasis.c | 55 +++++--
src/lib/anastasis_api_recovery_redux.c | 171 ++++++++++++++++++++-
src/lib/anastasis_api_redux.c | 9 +-
src/lib/testing_cmd_challenge_answer.c | 3 +-
7 files changed, 241 insertions(+), 28 deletions(-)
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index cf4e7de..76cc661 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -18,7 +18,6 @@ pkgdata_DATA = \
test_resources/test_reducer_stateBFSTATE \
test_resources/test_reducer_statePPSTATE \
test_resources/test_reducer_backup_stateUACSTATE \
- test_resources/test_reducer_recovery_stateUACSTATE \
test_resources/test_reducer_stateSESTATE \
test_resources/test_reducer_statePRSTATE \
test_resources/test_reducer_stateAESTATE \
@@ -27,4 +26,6 @@ pkgdata_DATA = \
test_resources/test_reducer_stateCSSTATE_FINAL \
test_resources/test_reducer_stateCPSTATE \
test_resources/test_reducer_stateCSOSTATE \
- test_resources/test_reducer_stateRFSTATE
+ test_resources/test_reducer_stateRFSTATE \
+ test_resources/test_reducer_recovery_stateUACSTATE \
+ test_resources/test_reducer_recovery_stateCSSTATE
diff --git a/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh
b/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh
index 604a6c2..59f8d61 100755
--- a/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh
+++ b/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh
@@ -22,7 +22,7 @@ function cleanup()
kill $n 2> /dev/null || true
done
rm -f $CONF $CONF_1 $CONF_2 $CONF_3 $CONF_4
- #rm -f $TFILE
+ rm -f $TFILE
wait
}
@@ -127,9 +127,9 @@ echo "Test user attributes collection in a recovery state"
enter_user_attributes $SFILE $TFILE
STATE=`jq -r -e .recovery_state < $TFILE`
-if test "$STATE" != "AUTHENTICATIONS_EDITING"
+if test "$STATE" != "CHALLENGE_SELECTING"
then
- exit_fail "Expected new state to be AUTHENTICATIONS_EDITING, got $STATE"
+ exit_fail "Expected new state to be CHALLENGE_SELECTING, got $STATE"
fi
SELECTED_COUNTRY=`jq -r -e .selected_country < $TFILE`
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index b2d9e73..9c38345 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -113,10 +113,12 @@ struct ANASTASIS_Challenge;
* The answer feedback defines the callback for an escrow challenge e.g.
(wrong SMS Pin)
*
* @param af_cls handle for the callback
+ * @param http_status_code status code
* @param ec enum with the different possible states like wrong pin, success
*/
typedef void
(*ANASTASIS_AnswerFeedback)(void *af_cls,
+ unsigned int http_status_code,
enum TALER_ErrorCode ec);
@@ -203,6 +205,17 @@ typedef void
struct ANASTASIS_ChallengeInformation *
ANASTASIS_get_challenge (struct ANASTASIS_Challenge *challenge);
+
+/**
+ * Converts a json challenge to struct.
+ *
+ * @param challenge reference to json challenge to be converted
+ * @return ANASTASIS_Challenge object
+ */
+struct ANASTASIS_Challenge *
+ANASTASIS_json_to_challenge (json_t *challenge);
+
+
/**
* Returns JSON-encoded challenge information.
*
@@ -309,6 +322,13 @@ void
ANASTASIS_recovery_abort (struct ANASTASIS_Recovery *r);
+/**
+* Frees the recovery struct
+* @param r handle to the recovery struct
+*/
+void
+ANASTASIS_recovery_free (struct ANASTASIS_Recovery *r);
+
/* Upload api
----------------------------------------------------------------- */
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index db97095..bf67949 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -302,7 +302,8 @@ keyshare_lookup_cb (void *cls,
if (http_status != c->http_status)
{
c->af (c->af_cls,
- http_status);
+ http_status,
+ ANASTASIS_EC_INVALID); // FIXME: Error Code
return;
}
struct ANASTASIS_CRYPTO_UserIdentifierP id;
@@ -320,7 +321,8 @@ keyshare_lookup_cb (void *cls,
c->recovery->solved_challenges[c->recovery->solved_challenge_pos] = *c;
c->recovery->solved_challenge_pos++;
c->af (c->af_cls,
- http_status);
+ http_status,
+ ANASTASIS_EC_NONE);
/**
* 0 equals the challenge was not solved 1 it was solved
@@ -531,6 +533,28 @@ ANASTASIS_get_challenge (struct ANASTASIS_Challenge
*challenge)
return ci;
}
+
+struct ANASTASIS_Challenge *
+ANASTASIS_json_to_challenge (json_t *challenge)
+{
+ GNUNET_assert (json_is_object (challenge));
+ const char *challenge_str;
+ struct ANASTASIS_Challenge *c;
+
+ challenge_str =
+ json_string_value (
+ json_object_get (challenge,
+ "challenge"));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_STRINGS_string_to_data (
+ challenge_str,
+ strlen (challenge_str),
+ c,
+ sizeof (struct ANASTASIS_Challenge)));
+ return c;
+}
+
+
json_t *
ANASTASIS_challenge_information_to_json (const struct
ANASTASIS_ChallengeInformation *ci)
@@ -971,6 +995,21 @@ ANASTASIS_recovery_begin (struct GNUNET_CURL_Context *ctx,
}
+void
+ANASTASIS_recovery_free (struct ANASTASIS_Recovery *r)
+{
+ if (NULL != r->solved_challenges)
+ GNUNET_free (r->solved_challenges);
+ if (NULL != r->encrypted_recovery_document)
+ GNUNET_free (r->encrypted_recovery_document);
+ if (NULL != r->ri->dps)
+ GNUNET_free (r->ri->dps);
+ if (NULL != r->ri)
+ GNUNET_free (r->ri);
+ GNUNET_free (r);
+}
+
+
/**
* Cancels the recovery process
* @param r handle to the recovery struct
@@ -985,17 +1024,7 @@ ANASTASIS_recovery_abort (struct ANASTASIS_Recovery *r)
ANASTASIS_policy_lookup_cancel (r->plo);
r->plo = NULL;
}
- if (NULL != r->solved_challenges)
- {
- GNUNET_free (r->solved_challenges);
- }
- if (NULL != r->encrypted_recovery_document)
- {
- GNUNET_free (r->encrypted_recovery_document);
- }
- if (NULL != r->ri)
- GNUNET_free (r->ri);
- GNUNET_free (r);
+ ANASTASIS_recovery_free (r);
}
diff --git a/src/lib/anastasis_api_recovery_redux.c
b/src/lib/anastasis_api_recovery_redux.c
index 5424e37..1a81d83 100644
--- a/src/lib/anastasis_api_recovery_redux.c
+++ b/src/lib/anastasis_api_recovery_redux.c
@@ -78,14 +78,124 @@ typedef struct ANASTASIS_ReduxAction *
void *cb_cls);
+/**
+ * State for a "challenge answer" CMD.
+ */
+struct ChallengeState
+{
+ /**
+ * Reference to the challenge we are solving
+ */
+ struct ANASTASIS_Challenge *c;
+
+ /**
+ * Expected status code.
+ */
+ unsigned int http_status;
+
+ /**
+ * Answer to the challenge we are solving
+ */
+ const char *answer;
+
+ /**
+ * Index of the challenge we are solving
+ */
+ unsigned int challenge_index;
+
+ /**
+ * 0 for no plugin needed 1 for plugin needed to authenticate
+ */
+ unsigned int mode;
+
+ /**
+ * Handle for an challenge answer operation
+ */
+ struct ANASTASIS_ChallengeAnswerOperation *cao;
+
+ /**
+ * Function to call after challenge answer.
+ */
+ ANASTASIS_ActionCallback cb;
+
+ /**
+ * Closure for action callback #cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Current state
+ */
+ json_t *state;
+};
+
+
static void
set_state (json_t *state,
- const char *new_recovery_state)
+ const char *new_backup_state)
{
GNUNET_assert (0 ==
json_object_set_new (state,
"recovery_state",
- json_string (new_recovery_state)));
+ json_string (new_backup_state)));
+}
+
+
+static void
+challenge_answer_cb (void *af_cls,
+ unsigned int http_status_code,
+ enum TALER_ErrorCode ec)
+{
+ json_t *challenges;
+ json_t *challenge;
+ struct ANASTASIS_ChallengeInformation *ci;
+ struct ChallengeState *cs = af_cls;
+
+ if (http_status_code == MHD_HTTP_PAYMENT_REQUIRED)
+ {
+ // FIXME: Payment for challenge (get code etc.) implemented?
+ set_state (cs->state,
+ ANASTASIS_recovery_state_to_string (
+ ANASTASIS_RECOVERY_STATE_CHALLENGE_PAYING));
+ }
+ else if (http_status_code != MHD_HTTP_OK)
+ {
+ json_t *error
+ = json_pack ("{s:I, s:s}",
+ "code",
+ (json_int_t) ec,
+ "hint",
+ "Failed challenge answer!");
+ cs->cb (cs->cb_cls,
+ ANASTASIS_EC_NONE,
+ error);
+ cs->cb = NULL;
+ return;
+ }
+ else
+ {
+ set_state (cs->state,
+ ANASTASIS_recovery_state_to_string (
+ ANASTASIS_RECOVERY_STATE_CHALLENGE_SOLVING));
+ }
+
+
+ ci = ANASTASIS_get_challenge (cs->c);
+ GNUNET_assert (NULL != ci);
+ challenges = json_object_get (cs->state,
+ "challenges");
+ GNUNET_assert (json_is_array (challenges));
+ challenge =
+ json_array_get (challenges,
+ cs->challenge_index);
+ challenge = ANASTASIS_challenge_information_to_json (ci);
+ GNUNET_assert (0 == json_array_set_new (challenges,
+ cs->challenge_index,
+ challenge));
+ cs->cb (cs->cb_cls,
+ ANASTASIS_EC_NONE,
+ cs->state);
+ cs->cb = NULL;
}
@@ -146,10 +256,59 @@ select_challenge (json_t *state,
ANASTASIS_ActionCallback cb,
void *cb_cls)
{
- // FIXME: implement
- cb (cb_cls,
- ANASTASIS_EC_NONE,
- state);
+ if (NULL == arguments)
+ {
+ ANASTASIS_redux_fail (cb,
+ cb_cls,
+ TALER_EC_ANASTASIS_REDUCER_ACTION_INVALID,
+ "select_challenge");
+ return NULL;
+ }
+
+ json_t *challenge;
+ json_t *challenges;
+ const char *method;
+ const struct ANASTASIS_Challenge *c;
+ struct ChallengeState *cs = GNUNET_new (struct ChallengeState);
+
+ cs->cb = cb;
+ cs->cb_cls = cb_cls;
+ cs->state = state;
+ cs->challenge_index =
+ (unsigned int) json_integer_value (
+ json_object_get (arguments,
+ "challenge_index"));
+ challenges = json_object_get (state,
+ "challenges");
+ GNUNET_assert (json_is_array (challenges));
+ challenge =
+ json_array_get (challenges,
+ cs->challenge_index);
+ c = ANASTASIS_json_to_challenge (challenge);
+
+ method = json_string_value (
+ json_object_get (challenge,
+ "method"));
+ if (0 == strcmp (method, "question"))
+ {
+ cs->mode = 0;
+ cs->answer = json_string_value (
+ json_object_get (arguments,
+ "answer"));
+ }
+ else
+ {
+ cs->mode = 1;
+ cs->answer = json_string_value (
+ json_object_get (arguments,
+ "code"));
+ }
+
+ cs->cao = ANASTASIS_challenge_answer (ctx,
+ (struct ANASTASIS_Challenge *) c,
+ cs->answer,
+ &challenge_answer_cb,
+ cs);
return NULL;
}
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index f034db3..4bbd3ad 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -1026,6 +1026,7 @@ policy_lookup_cb (void *cls,
json_integer ((json_int_t) k)));
}
}
+ GNUNET_free (ri->dps[i].nonces);
if (0 < json_array_size (policy))
GNUNET_assert (
0 == json_array_append_new (policies,
@@ -1053,6 +1054,8 @@ policy_lookup_cb (void *cls,
}
else
{
+ json_decref (challenges);
+ json_decref (policies);
json_decref (recovery_information);
json_t *error
= json_pack ("{s:I, s:s}",
@@ -1064,6 +1067,7 @@ policy_lookup_cb (void *cls,
rss->cb (NULL,
ANASTASIS_EC_INVALID,
error);
+ rss->cb = NULL;
}
rss->recovery = NULL;
}
@@ -1096,11 +1100,10 @@ free_enter_user_attributes (void *cls)
rss->recovery);
rss->recovery = NULL;
}
+ if (NULL != rss->challenges)
+ GNUNET_free (rss->challenges);
json_decref (rss->state);
json_decref (rss->id_data);
- GNUNET_free (rss->ri->cs);
- GNUNET_free (rss->ri->dps);
- GNUNET_free (rss->ri);
GNUNET_free (rss);
}
diff --git a/src/lib/testing_cmd_challenge_answer.c
b/src/lib/testing_cmd_challenge_answer.c
index 3f7baa2..798cf6a 100644
--- a/src/lib/testing_cmd_challenge_answer.c
+++ b/src/lib/testing_cmd_challenge_answer.c
@@ -76,10 +76,11 @@ struct ChallengeState
static void
challenge_answer_cb (void *af_cls,
+ unsigned int http_status_code,
enum TALER_ErrorCode ec)
{
struct ChallengeState *cs = af_cls;
- if (ec != MHD_HTTP_OK)
+ if (http_status_code != MHD_HTTP_OK)
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (cs->is);
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-anastasis] 14/15: import .sql files for testing reducer recovery, (continued)
- [taler-anastasis] 14/15: import .sql files for testing reducer recovery, gnunet, 2021/01/31
- [taler-anastasis] 09/15: fix key share decryption, gnunet, 2021/01/31
- [taler-anastasis] 13/15: worked on recovery reducer, gnunet, 2021/01/31
- [taler-anastasis] 12/15: worked on recovery reducer, gnunet, 2021/01/31
- [taler-anastasis] 08/15: nonces use json array, gnunet, 2021/01/31
- [taler-anastasis] 06/15: fetch recovery information, gnunet, 2021/01/31
- [taler-anastasis] 15/15: Merge branch 'master' of ssh://git.taler.net/anastasis, gnunet, 2021/01/31
- [taler-anastasis] 01/15: set state to CHALLENGE_SELECTING, gnunet, 2021/01/31
- [taler-anastasis] 02/15: worked on recovery redux, gnunet, 2021/01/31
- [taler-anastasis] 10/15: fix memory leak, gnunet, 2021/01/31
- [taler-anastasis] 11/15: worked on challenge select,
gnunet <=