[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: start with deserialization logi
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: start with deserialization logic |
Date: |
Wed, 10 Feb 2021 21:51:44 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new c523a63 start with deserialization logic
c523a63 is described below
commit c523a638549414f51b36cfe2169432266b84079a
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Feb 10 21:51:42 2021 +0100
start with deserialization logic
---
src/include/anastasis.h | 7 +-
src/lib/anastasis_recovery.c | 302 ++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 302 insertions(+), 7 deletions(-)
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index 74e2833..d6ca715 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -435,6 +435,7 @@ struct ANASTASIS_Recovery;
* Starts the recovery process by opening callbacks for the coresecret and a
policy callback. A list of
* providers is checked for policies and passed back to the client.
*
+ * @param ctx context for making HTTP requests
* @param id_data contains the users identity, (user account on providers)
* @param version defines the version which will be downloaded NULL for latest
version
* @param anastasis_provider_url NULL terminated list of possible provider urls
@@ -470,8 +471,9 @@ ANASTASIS_recovery_serialize (const struct
ANASTASIS_Recovery *r);
/**
- * Suspend recovery operation, serializing its state and returning it.
+ * Deserialize recovery operation.
*
+ * @param ctx context for making HTTP requests
* @param input result from #ANASTASIS_recovery_serialize()
* @param pc opens the policy call back which holds the downloaded version and
the policies
* @param pc_cls closure for callback
@@ -480,7 +482,8 @@ ANASTASIS_recovery_serialize (const struct
ANASTASIS_Recovery *r);
* @return recovery operation handle
*/
struct ANASTASIS_Recovery *
-ANASTASIS_recovery_deserialize (const json_t *input,
+ANASTASIS_recovery_deserialize (struct GNUNET_CURL_Context *ctx,
+ const json_t *input,
ANASTASIS_PolicyCallback pc,
void *pc_cls,
ANASTASIS_CoreSecretCallback csc,
diff --git a/src/lib/anastasis_recovery.c b/src/lib/anastasis_recovery.c
index 3a5a909..039ed91 100644
--- a/src/lib/anastasis_recovery.c
+++ b/src/lib/anastasis_recovery.c
@@ -203,6 +203,11 @@ struct ANASTASIS_Recovery
*/
struct ANASTASIS_Challenge **solved_challenges;
+ /**
+ * Our provider URL.
+ */
+ char *provider_url;
+
/**
* Retrieved encrypted core secret from policy
*/
@@ -827,11 +832,13 @@ ANASTASIS_recovery_begin (struct GNUNET_CURL_Context *ctx,
r->pc_cls = pc_cls;
r->ctx = ctx;
r->id_data = json_incref ((json_t *) id_data);
+ r->provider_url = GNUNET_strdup (anastasis_provider_url);
ANASTASIS_CRYPTO_user_identifier_derive (id_data,
salt,
&r->id);
ANASTASIS_CRYPTO_account_public_key_derive (&r->id,
&pub_key);
+ r->ri.version = version;
if (0 != version)
{
r->plo = ANASTASIS_policy_lookup_version (r->ctx,
@@ -862,20 +869,304 @@ ANASTASIS_recovery_begin (struct GNUNET_CURL_Context
*ctx,
json_t *
ANASTASIS_recovery_serialize (const struct ANASTASIS_Recovery *r)
{
- GNUNET_break (0);
- return NULL;
+ json_t *dps_arr;
+ json_t *cs_arr;
+
+ dps_arr = json_array ();
+ GNUNET_assert (NULL != dps_arr);
+ for (unsigned int i = 0; i<r->ri.dps_len; i++)
+ {
+ const struct DecryptionPolicy *dp = &r->dps[i];
+ json_t *c_arr;
+ json_t *dps;
+
+ c_arr = json_array ();
+ GNUNET_assert (NULL != c_arr);
+ for (unsigned int j = 0; j < dp->pub_details.challenges_length; j++)
+ {
+ const struct ANASTASIS_Challenge *c = dp->pub_details.challenges[i];
+ json_t *cs;
+
+ cs = json_pack ("{s:o}",
+ "uuid",
+ GNUNET_JSON_from_data_auto (&c->uuid));
+ GNUNET_assert (NULL != cs);
+ GNUNET_assert (0 ==
+ json_array_append (dps_arr,
+ cs));
+ }
+ dps = json_pack ("{s:o, s:o, s:o}",
+ "emk",
+ GNUNET_JSON_from_data_auto (&dp->emk),
+ "salt",
+ GNUNET_JSON_from_data_auto (&dp->salt),
+ "challenges",
+ c_arr);
+ GNUNET_assert (NULL != dps);
+ GNUNET_assert (0 ==
+ json_array_append (dps_arr,
+ dps));
+ }
+ cs_arr = json_array ();
+ GNUNET_assert (NULL != cs_arr);
+ for (unsigned int i = 0; i<r->ri.cs_len; i++)
+ {
+ const struct ANASTASIS_Challenge *c = &r->cs[i];
+ json_t *cs;
+
+ cs = json_pack ("{s:o,s:o,s:o,s:o?,"
+ " s:s,s:s,s:s,s:o}",
+ "uuid",
+ GNUNET_JSON_from_data_auto (&c->uuid),
+ "truth_key",
+ GNUNET_JSON_from_data_auto (&c->truth_key),
+ "truth_salt",
+ GNUNET_JSON_from_data_auto (&c->truth_salt),
+ "key_share",
+ c->ci.solved
+ ? GNUNET_JSON_from_data_auto (&c->key_share)
+ : NULL,
+ "url",
+ c->url,
+ "method",
+ c->method,
+ "instructions",
+ c->instructions,
+ "cost",
+ TALER_JSON_from_amount (&c->ci.cost));
+ GNUNET_assert (NULL != cs);
+ GNUNET_assert (0 ==
+ json_array_append (cs_arr,
+ cs));
+ }
+
+ return json_pack ("{s:o, s:o, s:o, s:I, s:O, s:s, s:o}",
+ "id",
+ GNUNET_JSON_from_data_auto (&r->id),
+ "dps",
+ dps_arr,
+ "cs",
+ cs_arr,
+ "version",
+ (json_int_t) r->ri.version,
+ "id_data",
+ r->id_data,
+ "provider_url",
+ r->provider_url,
+ "core_secret",
+ GNUNET_JSON_from_data (r->enc_core_secret,
+ r->enc_core_secret_size));
+}
+
+
+/**
+ * Parse the @a cs_array and update @a r accordingly
+ *
+ * @param[in,out] r recovery information to update
+ * @param cs_arr serialized data to parse
+ * @return #GNUNET_OK on success
+ */
+static int
+parse_cs_array (struct ANASTASIS_Recovery *r,
+ json_t *cs_arr)
+{
+ json_t *cs;
+ unsigned int n_index;
+
+ if (! json_is_array (cs_arr))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ r->ri.cs_len = json_array_size (cs_arr);
+ r->solved_challenges = GNUNET_new_array (r->ri.cs_len,
+ struct ANASTASIS_Challenge *);
+ r->ri.cs = GNUNET_new_array (r->ri.cs_len,
+ struct ANASTASIS_Challenge *);
+ r->cs = GNUNET_new_array (r->ri.cs_len,
+ struct ANASTASIS_Challenge);
+ json_array_foreach (cs_arr, n_index, cs)
+ {
+ struct ANASTASIS_Challenge *c = &r->cs[n_index];
+ const char *instructions;
+ const char *url;
+ const char *escrow_method;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("uuid",
+ &c->uuid),
+ GNUNET_JSON_spec_string ("url",
+ &url),
+ GNUNET_JSON_spec_string ("instructions",
+ &instructions),
+ GNUNET_JSON_spec_fixed_auto ("truth_key",
+ &c->truth_key),
+ GNUNET_JSON_spec_fixed_auto ("truth_salt",
+ &c->truth_salt),
+ GNUNET_JSON_spec_string ("method",
+ &escrow_method),
+ TALER_JSON_spec_amount ("cost",
+ &c->ci.cost),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_fixed_auto ("key_share",
+ &c->key_share)),
+ GNUNET_JSON_spec_end ()
+ };
+
+ r->ri.cs[n_index] = c;
+ c->recovery = r;
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (cs,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ c->url = GNUNET_strdup (url);
+ c->method = GNUNET_strdup (escrow_method);
+ c->ci.method = c->method;
+ c->instructions = GNUNET_strdup (instructions);
+ c->ci.instructions = c->instructions;
+ if (NULL != json_object_get (cs,
+ "key_share"))
+ c->ci.solved = true;
+ }
+
+ return GNUNET_OK;
+}
+
+
+/**
+ * Parse the @a dps_array and update @a r accordingly
+ *
+ * @param[in,out] r recovery information to update
+ * @param dps_arr serialized data to parse
+ * @return #GNUNET_OK on success
+ */
+static int
+parse_dps_array (struct ANASTASIS_Recovery *r,
+ json_t *dps_arr)
+{
+ if (! json_is_array (dps_arr))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_SYSERR;
}
struct ANASTASIS_Recovery *
-ANASTASIS_recovery_deserialize (const json_t *input,
+ANASTASIS_recovery_deserialize (struct GNUNET_CURL_Context *ctx,
+ const json_t *input,
ANASTASIS_PolicyCallback pc,
void *pc_cls,
ANASTASIS_CoreSecretCallback csc,
void *csc_cls)
{
- GNUNET_break (0);
- return NULL;
+ struct ANASTASIS_Recovery *r;
+
+ r = GNUNET_new (struct ANASTASIS_Recovery);
+ r->csc = csc;
+ r->csc_cls = csc_cls;
+ r->pc = pc;
+ r->pc_cls = pc_cls;
+ r->ctx = ctx;
+ {
+ const char *err_json_name;
+ unsigned int err_line;
+ uint32_t version;
+ json_t *dps_arr;
+ json_t *cs_arr;
+ json_t *id_data;
+ const char *provider_url;
+ void *ecs;
+ size_t ecs_size;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("id",
+ &r->id),
+ GNUNET_JSON_spec_string ("provider_url",
+ &provider_url),
+ GNUNET_JSON_spec_uint32 ("version",
+ &version),
+ GNUNET_JSON_spec_json ("dps",
+ &dps_arr),
+ GNUNET_JSON_spec_json ("cs",
+ &cs_arr),
+ GNUNET_JSON_spec_json ("id_data",
+ &id_data),
+ GNUNET_JSON_spec_varsize ("enc_core_secret",
+ &ecs,
+ &ecs_size),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (input,
+ spec,
+ &err_json_name,
+ &err_line))
+ {
+ GNUNET_break_op (0);
+ return NULL;
+ }
+ if ( (GNUNET_OK !=
+ parse_cs_array (r,
+ cs_arr)) ||
+ (GNUNET_OK !=
+ parse_dps_array (r,
+ dps_arr)) )
+ {
+ ANASTASIS_recovery_abort (r);
+ GNUNET_JSON_parse_free (spec);
+ return NULL;
+ }
+ r->id_data = json_incref (id_data);
+ r->provider_url = GNUNET_strdup (provider_url);
+ if (0 != ecs_size)
+ {
+ r->enc_core_secret = GNUNET_memdup (ecs,
+ ecs_size);
+ r->enc_core_secret_size = ecs_size;
+ }
+ }
+ if (0 == r->ri.dps_len)
+ {
+ struct ANASTASIS_CRYPTO_AccountPublicKeyP pub_key;
+
+ ANASTASIS_CRYPTO_account_public_key_derive (&r->id,
+ &pub_key);
+ if (0 != r->ri.version)
+ {
+ r->plo = ANASTASIS_policy_lookup_version (r->ctx,
+ r->provider_url,
+ &pub_key,
+ &policy_lookup_cb,
+ r,
+ r->ri.version);
+ }
+ else
+ {
+ r->plo = ANASTASIS_policy_lookup (r->ctx,
+ r->provider_url,
+ &pub_key,
+ &policy_lookup_cb,
+ r);
+ }
+ if (NULL == r->plo)
+ {
+ GNUNET_break (0);
+ ANASTASIS_recovery_abort (r);
+ return NULL;
+ }
+ }
+ else
+ {
+ /* FIXME: maybe better do this asynchronously in a new task? */
+ r->pc (r->pc_cls,
+ &r->ri);
+ }
+ return r;
}
@@ -900,5 +1191,6 @@ ANASTASIS_recovery_abort (struct ANASTASIS_Recovery *r)
}
GNUNET_free (r->ri.cs);
json_decref (r->id_data);
+ GNUNET_free (r->provider_url);
GNUNET_free (r);
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: start with deserialization logic,
gnunet <=