[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 13/15: worked on recovery reducer
From: |
gnunet |
Subject: |
[taler-anastasis] 13/15: worked on recovery reducer |
Date: |
Sun, 31 Jan 2021 17:06:19 +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 81ef6547dd8729d6ed905f8894d6149eb7138104
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Wed Jan 27 16:03:04 2021 +0100
worked on recovery reducer
---
src/lib/anastasis_api_recovery_redux.c | 85 ++++++++++++++++++++++++++++++----
src/lib/anastasis_api_redux.c | 79 ++++++-------------------------
src/lib/anastasis_api_redux.h | 63 +++++++++++++++++++++++++
3 files changed, 153 insertions(+), 74 deletions(-)
diff --git a/src/lib/anastasis_api_recovery_redux.c
b/src/lib/anastasis_api_recovery_redux.c
index d1ab313..79aa851 100644
--- a/src/lib/anastasis_api_recovery_redux.c
+++ b/src/lib/anastasis_api_recovery_redux.c
@@ -168,6 +168,7 @@ challenge_payment_cb (void *cls,
unsigned int http_status)
{
const char *m;
+ json_t *recovery_information;
json_t *challenges;
json_t *challenge;
struct ChallengeState *cs = cls;
@@ -237,7 +238,10 @@ challenge_payment_cb (void *cls,
ANASTASIS_recovery_state_to_string (
ANASTASIS_RECOVERY_STATE_CHALLENGE_PAYING));
- challenges = json_object_get (cs->state,
+ recovery_information = json_object_get (cs->state,
+ "recovery_information");
+ GNUNET_assert (json_is_object (recovery_information));
+ challenges = json_object_get (recovery_information,
"challenges");
GNUNET_assert (json_is_array (challenges));
challenge =
@@ -262,6 +266,7 @@ challenge_start_cb (void *cls,
const char *response_string,
unsigned int http_status_code)
{
+ json_t *recovery_information;
json_t *challenges;
json_t *challenge;
struct ANASTASIS_ChallengeInformation *ci;
@@ -282,11 +287,12 @@ challenge_start_cb (void *cls,
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,
+ recovery_information = json_object_get (cs->state,
+ "recovery_information");
+ GNUNET_assert (json_is_object (recovery_information));
+ challenges = json_object_get (recovery_information,
"challenges");
GNUNET_assert (json_is_array (challenges));
challenge =
@@ -369,7 +375,7 @@ select_challenge (json_t *state,
"select_challenge");
return NULL;
}
-
+ json_t *recovery_information;
json_t *challenge;
json_t *challenges;
const char *method;
@@ -383,7 +389,10 @@ select_challenge (json_t *state,
(unsigned int) json_integer_value (
json_object_get (arguments,
"challenge_index"));
- challenges = json_object_get (state,
+ recovery_information = json_object_get (state,
+ "recovery_information");
+ GNUNET_assert (json_is_object (recovery_information));
+ challenges = json_object_get (recovery_information,
"challenges");
GNUNET_assert (json_is_array (challenges));
challenge =
@@ -443,6 +452,53 @@ pay_challenge (json_t *state,
}
+static bool
+check_policy_fulfilled (json_t *state)
+{
+ size_t p_index;
+ json_t *recovery_information;
+ json_t *challenges;
+ json_t *policy;
+ json_t *policies;
+
+ recovery_information = json_object_get (state,
+ "recovery_information");
+ GNUNET_assert (json_is_object (recovery_information));
+ policies = json_object_get (recovery_information,
+ "policies");
+ GNUNET_assert (json_is_array (policies));
+ challenges = json_object_get (recovery_information,
+ "challenges");
+ GNUNET_assert (json_is_array (challenges));
+
+ json_array_foreach (policies, p_index, policy)
+ {
+ size_t c_index;
+ json_t *challenge_index;
+ bool fulfilled = true;
+
+ GNUNET_assert (json_is_array (policy));
+ json_array_foreach (policy, c_index, challenge_index)
+ {
+ json_t *challenge = json_array_get (challenges,
+ json_integer_value (
+ challenge_index));
+ unsigned int solved =
+ json_integer_value (json_object_get (challenge,
+ "solved"));
+ if (solved == 0)
+ {
+ fulfilled = false;
+ break;
+ }
+ }
+ if (fulfilled)
+ return true;
+ }
+ return false;
+}
+
+
static void
challenge_answer_cb (void *af_cls,
unsigned int http_status_code,
@@ -457,7 +513,15 @@ challenge_answer_cb (void *af_cls,
"Unexpected response code!");
return;
}
-
+ if (check_policy_fulfilled (cs->state))
+ {
+ struct RecoverSecretState *rss
+ = GNUNET_new (struct RecoverSecretState);
+ // FIXME: implement -> call recovery begin again
+ set_state (cs->state,
+ ANASTASIS_recovery_state_to_string (
+ ANASTASIS_RECOVERY_STATE_RECOVERY_FINISHED));
+ }
}
@@ -476,7 +540,7 @@ solve_challenge (json_t *state,
"solve_challenge");
return NULL;
}
-
+ json_t *recovery_information;
json_t *challenge;
json_t *challenges;
const char *method;
@@ -490,7 +554,10 @@ solve_challenge (json_t *state,
(unsigned int) json_integer_value (
json_object_get (arguments,
"challenge_index"));
- challenges = json_object_get (state,
+ recovery_information = json_object_get (state,
+ "recovery_information");
+ GNUNET_assert (json_is_object (recovery_information));
+ challenges = json_object_get (recovery_information,
"challenges");
GNUNET_assert (json_is_array (challenges));
challenge =
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index 4bbd3ad..c0d1d85 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -181,68 +181,6 @@ struct SelectCountryHandle
};
-/**
- * State for a "recover secret" CMD.
- */
-struct RecoverSecretState
-{
- /**
- * URL of the anastasis backend.
- */
- const char *anastasis_url;
-
- /**
- * Expected status code.
- */
- unsigned int http_status;
-
- /**
- * The /policy GET operation handle.
- */
- struct ANASTASIS_Recovery *recovery;
-
- /**
- * Identification data from the user
- */
- json_t *id_data;
-
- /**
- * version of the recovery document
- */
- unsigned int version;
-
- /**
- * Salt to be used to derive the id
- */
- struct ANASTASIS_CRYPTO_PowSalt *salt;
-
- /**
- * Recovery information from the lookup
- */
- struct ANASTASIS_RecoveryInformation *ri;
-
- /**
- * Information about the challenges.
- */
- struct ANASTASIS_ChallengeInformation *challenges;
-
- /**
- * Amount of challenges.
- */
- unsigned int challenges_length;
-
- /**
- * Reference to a state.
- */
- json_t *state;
-
- /**
- * callback (#DispatchHandler) to call during/after operation
- */
- ANASTASIS_ActionCallback cb;
-};
-
-
/**
* JSON containing country specific identity attributes to ask the user for.
*/
@@ -1035,6 +973,14 @@ policy_lookup_cb (void *cls,
if ((0 < json_array_size (challenges))
&& (0 < json_array_size (policies)))
{
+ GNUNET_assert (
+ 0 == json_object_set (recovery_information,
+ "provider_url",
+ json_string (rss->anastasis_url)));
+ GNUNET_assert (
+ 0 == json_object_set (recovery_information,
+ "version",
+ json_integer (rss->version)));
GNUNET_assert (
0 == json_object_set_new (recovery_information,
"policies",
@@ -1144,6 +1090,9 @@ enter_user_attributes (json_t *state,
attributes = json_object_get (arguments,
"identity_attributes");
GNUNET_assert (NULL != attributes);
+ json_object_set (state,
+ "identity_attributes",
+ attributes);
required_attributes = json_object_get (state,
"required_attributes");
@@ -1176,6 +1125,7 @@ enter_user_attributes (json_t *state,
cb (cb_cls,
ANASTASIS_EC_INVALID,
error);
+ json_decref (attributes);
json_decref (error);
return NULL;
}
@@ -1196,6 +1146,7 @@ enter_user_attributes (json_t *state,
cb (cb_cls,
ANASTASIS_EC_INVALID,
error);
+ json_decref (attributes);
json_decref (error);
return NULL;
}
@@ -1208,9 +1159,6 @@ enter_user_attributes (json_t *state,
if (0 == strcmp (s_mode, "backup_state"))
{
- json_object_set_new (state,
- "identity_attributes",
- attributes);
json_object_set_new (state,
s_mode,
json_string (
@@ -1223,6 +1171,7 @@ enter_user_attributes (json_t *state,
cb (cb_cls,
ANASTASIS_EC_NONE,
state);
+ json_decref (attributes);
return NULL;
}
else
diff --git a/src/lib/anastasis_api_redux.h b/src/lib/anastasis_api_redux.h
index c3cd309..edef6ec 100644
--- a/src/lib/anastasis_api_redux.h
+++ b/src/lib/anastasis_api_redux.h
@@ -1,6 +1,69 @@
#ifndef ANASTASIS_API_REDUX_H
#define ANASTASIS_API_REDUX_H
+
+/**
+ * State for a "recover secret" CMD.
+ */
+struct RecoverSecretState
+{
+ /**
+ * URL of the anastasis backend.
+ */
+ const char *anastasis_url;
+
+ /**
+ * Expected status code.
+ */
+ unsigned int http_status;
+
+ /**
+ * The /policy GET operation handle.
+ */
+ struct ANASTASIS_Recovery *recovery;
+
+ /**
+ * Identification data from the user
+ */
+ json_t *id_data;
+
+ /**
+ * version of the recovery document
+ */
+ unsigned int version;
+
+ /**
+ * Salt to be used to derive the id
+ */
+ struct ANASTASIS_CRYPTO_PowSalt *salt;
+
+ /**
+ * Recovery information from the lookup
+ */
+ struct ANASTASIS_RecoveryInformation *ri;
+
+ /**
+ * Information about the challenges.
+ */
+ struct ANASTASIS_ChallengeInformation *challenges;
+
+ /**
+ * Amount of challenges.
+ */
+ unsigned int challenges_length;
+
+ /**
+ * Reference to a state.
+ */
+ json_t *state;
+
+ /**
+ * callback (#DispatchHandler) to call during/after operation
+ */
+ ANASTASIS_ActionCallback cb;
+};
+
+
struct ANASTASIS_ReduxAction *
ANASTASIS_back_generic_decrement_ (json_t *state,
const json_t *arguments,
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-anastasis] branch master updated (529012a -> fea0fc4), gnunet, 2021/01/31
- [taler-anastasis] 03/15: visualization, gnunet, 2021/01/31
- [taler-anastasis] 05/15: fix curl fini error, gnunet, 2021/01/31
- [taler-anastasis] 07/15: handle fail of fetching recovery information, gnunet, 2021/01/31
- [taler-anastasis] 04/15: worked on reducer, gnunet, 2021/01/31
- [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 <=
- [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, 2021/01/31