gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-anastasis] branch master updated: misc bugfixes


From: gnunet
Subject: [taler-anastasis] branch master updated: misc bugfixes
Date: Tue, 02 Mar 2021 20:12:48 +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 07c269a  misc bugfixes
07c269a is described below

commit 07c269a0f7c82d61791f60d74ece93e90f74a09b
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Tue Mar 2 20:12:46 2021 +0100

    misc bugfixes
---
 src/cli/resources/06-backup.json                   |   2 +-
 src/cli/test_anastasis_reducer_enter_secret.sh     |   6 +-
 ...tasis_reducer_recovery_enter_user_attributes.sh | 177 ++++++++++++++++--
 src/include/anastasis.h                            |   8 +-
 src/lib/anastasis_recovery.c                       |  39 ++--
 src/reducer/anastasis_api_backup_redux.c           |   8 +-
 src/reducer/anastasis_api_recovery_redux.c         | 203 +++++++++++++++++++--
 src/reducer/anastasis_api_redux.c                  |   2 +-
 8 files changed, 398 insertions(+), 47 deletions(-)

diff --git a/src/cli/resources/06-backup.json b/src/cli/resources/06-backup.json
index f305632..81a2e9f 100644
--- a/src/cli/resources/06-backup.json
+++ b/src/cli/resources/06-backup.json
@@ -212,4 +212,4 @@
       ]
     }
   ]
-}
\ No newline at end of file
+}
diff --git a/src/cli/test_anastasis_reducer_enter_secret.sh 
b/src/cli/test_anastasis_reducer_enter_secret.sh
index 5b4d5ac..7ec594c 100755
--- a/src/cli/test_anastasis_reducer_enter_secret.sh
+++ b/src/cli/test_anastasis_reducer_enter_secret.sh
@@ -26,8 +26,7 @@ function cleanup()
     do
         kill $n 2> /dev/null || true
     done
-    rm -f $CONF $WALLET_DB $TFILE $UFILE
-    rm -r $TMP_DIR
+    rm -rf $CONF $WALLET_DB $TFILE $UFILE $TMP_DIR
     wait
 }
 
@@ -273,8 +272,7 @@ echo " DONE"
 echo -en $COLOR$BOLD"Test enter secret in a backup state ..."$NORM$NOCOLOR
 
 $PREFIX anastasis-reducer -a \
-  '{"secret": "veryhardtoguesssecret",
-    "type": "password"}' \
+  '{"secret": "veryhardtoguesssecret" }' \
   enter_secret resources/06-backup.json $TFILE
 
 STATE=`jq -r -e .backup_state < $TFILE`
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 6d50e89..7a6465f 100755
--- a/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh
+++ b/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh
@@ -21,7 +21,7 @@ function cleanup()
     do
         kill $n 2> /dev/null || true
     done
-    rm -rf $CONF $WALLET_DB $TFILE $UFILE $TMP_DIR
+    rm -rf $CONF $WALLET_DB $R1FILE $R2FILE $B1FILE $B2FILE $TMP_DIR
     wait
 }
 
@@ -39,8 +39,10 @@ cp test_reducer.conf $CONF
 
 TMP_DIR=`mktemp -d keys-tmp-XXXXXX`
 WALLET_DB=`mktemp test_reducer_walletXXXXXX.json`
-TFILE=`mktemp test_reducer_statePPXXXXXX`
-UFILE=`mktemp test_reducer_stateBFXXXXXX`
+B1FILE=`mktemp test_reducer_stateB1XXXXXX`
+B2FILE=`mktemp test_reducer_stateB2XXXXXX`
+R1FILE=`mktemp test_reducer_stateR1XXXXXX`
+R2FILE=`mktemp test_reducer_stateR2XXXXXX`
 
 # Install cleanup handler (except for kill -9)
 trap cleanup EXIT
@@ -266,9 +268,18 @@ curl -H "Content-Type: application/json" -X POST -d 
'{"payto_uris":["payto://x-t
 
 echo " DONE"
 
-bash
-
-echo "Test user attributes collection in a recovery state"
+echo -n "Running backup logic ...,"
+anastasis-reducer -b > $B1FILE
+echo -n "."
+anastasis-reducer -a \
+  '{"continent": "Testcontinent"}' \
+  select_continent < $B1FILE > $B2FILE
+echo -n "."
+anastasis-reducer -a \
+  '{"country_code": "xx",
+    "currency":"TESTKUDOS"}' \
+  select_country < $B2FILE > $B1FILE
+echo -n "."
 anastasis-reducer -a \
   '{"identity_attributes": {
     "full_name": "Max Musterman",
@@ -276,18 +287,162 @@ anastasis-reducer -a \
     "birth_year": 2000,
     "birth_month": 1,
     "birth_day": 1}}' \
-  enter_user_attributes $SFILE $TFILE
+  enter_user_attributes < $B1FILE > $B2FILE
+echo -n ","
+# "91GPWWR" encodes "Hans"
+anastasis-reducer -a \
+  '{"authentication_method": {
+    "type": "question",
+    "instructions": "What is your name?",
+    "challenge": "91GPWWR"
+    } }' \
+  add_authentication < $B2FILE > $B1FILE
+echo -n "."
+# "64S36" encodes "123"
+anastasis-reducer -a \
+  '{"authentication_method": {
+    "type": "question",
+    "instructions": "How old are you?",
+    "challenge": "64S36"
+    } }' \
+  add_authentication < $B1FILE > $B2FILE
+echo -n "."
+# "9NGQ4WR" encodes "Mars"
+anastasis-reducer -a \
+  '{"authentication_method": {
+    "type": "question",
+    "instructions": "Where do you live?",
+    "challenge": "9NGQ4WR"
+    } }' \
+  add_authentication < $B2FILE > $B1FILE
+echo -n "."
+# Finished adding authentication methods
+anastasis-reducer \
+  next < $B1FILE > $B2FILE
+echo -n ","
+# Finished policy review
+anastasis-reducer \
+  next < $B2FILE > $B1FILE
+echo -n "."
+anastasis-reducer -a \
+  '{"secret": "veryhardtoguesssecret"}' \
+  enter_secret < $B1FILE > $B2FILE
+echo " OK"
+echo -n "Preparing wallet"
+rm $WALLET_DB
+taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB api 
'withdrawTestBalance' \
+  "$(jq -n '
+    {
+        amount: "TESTKUDOS:20",
+        bankBaseUrl: $BANK_URL,
+        exchangeBaseUrl: $EXCHANGE_URL
+    }' \
+    --arg BANK_URL "$BANK_URL" \
+    --arg EXCHANGE_URL "$EXCHANGE_URL"
+  )" 2> /dev/null >/dev/null
+taler-wallet-cli --wallet-db=$WALLET_DB run-until-done 2>/dev/null >/dev/null
+echo " OK"
 
-STATE=`jq -r -e .recovery_state < $TFILE`
+echo -en "Making payments for policy uploads ... "
+OBJECT_SIZE=`jq -r -e '.policy_payment_requests | length' < $B2FILE`
+for ((INDEX=0; INDEX < $OBJECT_SIZE; INDEX++))
+do
+    PAY_URI=`jq --argjson INDEX $INDEX -r -e 
'.policy_payment_requests[$INDEX].payto' < $B2FILE`
+    # run wallet CLI
+    echo -n "$INDEX"
+    taler-wallet-cli --wallet-db=$WALLET_DB handle-uri $PAY_URI -y 2>/dev/null 
>/dev/null
+    echo -n ","
+done
+echo " OK"
+echo -en "Running wallet run-pending..."
+taler-wallet-cli --wallet-db=$WALLET_DB run-pending 2>/dev/null >/dev/null
+echo -e " payments DONE"
+
+echo -en "Try to upload again ..."
+anastasis-reducer \
+  pay < $B2FILE > $B1FILE
+echo " OK: Backup finished"
+echo -n "Final backup checks ..."
+STATE=`jq -r -e .backup_state < $B1FILE`
+if test "$STATE" != "BACKUP_FINISHED"
+then
+    exit_fail "Expected new state to be 'BACKUP_FINISHED', got '$STATE'"
+fi
+
+jq -r -e .core_secret < $B1FILE > /dev/null && exit_fail "'core_secret' was 
not cleared upon success"
+
+echo " OK"
+
+echo -n "Running recovery basic logic ..."
+anastasis-reducer -r > $R1FILE
+anastasis-reducer -a \
+  '{"continent": "Testcontinent"}' \
+  select_continent < $R1FILE > $R2FILE
+anastasis-reducer -a \
+  '{"country_code": "xx",
+    "currency":"TESTKUDOS"}' \
+  select_country < $R2FILE > $R1FILE
+anastasis-reducer -a '{"identity_attributes": { "full_name": "Max Musterman", 
"ahv_number": "756.9217.0769.85", "birth_year": 2000, "birth_month": 1, 
"birth_day": 1}}' enter_user_attributes < $R1FILE > $R2FILE
+
+
+STATE=`jq -r -e .recovery_state < $R2FILE`
 if test "$STATE" != "CHALLENGE_SELECTING"
 then
     exit_fail "Expected new state to be 'CHALLENGE_SELECTING', got '$STATE'"
 fi
+echo " OK"
 
-SELECTED_COUNTRY=`jq -r -e .selected_country < $TFILE`
-if test "$SELECTED_COUNTRY" != "ch"
+echo -n "Running challenge logic ..."
+
+UUID0=`jq -r -e .recovery_information.challenges[0].uuid < $R2FILE`
+UUID1=`jq -r -e .recovery_information.challenges[1].uuid < $R2FILE`
+
+anastasis-reducer -a \
+  "$(jq -n '
+    {
+        uuid: $UUID
+    }' \
+    --arg UUID "$UUID0"
+  )" \
+  select_challenge < $R2FILE > $R1FILE
+
+export R1FILE
+export R2FILE
+export UUID0
+export UUID1
+bash
+
+anastasis-reducer -a \
+  "$(jq -n '
+    {
+        uuid: $UUID,
+        answer: "Hans"
+    }' \
+    --arg UUID "$UUID0"
+  )" \
+  solve_challenge < $R1FILE > $R2FILE
+
+anastasis-reducer -a \
+  "$(jq -n '
+    {
+        uuid: $UUID,
+        answer: "123"
+    }' \
+    --arg UUID "$UUID1"
+  )" \
+  solve_challenge < $R1FILE > $R2FILE
+
+echo " OK"
+
+# finally: check here that we recovered the secret...
+
+bash
+
+STATE=`jq -r -e .recovery_state < $TFILE`
+if test "$STATE" != "CHALLENGE_SELECTING"
 then
-    exit_fail "Expected selected country to be 'ch', got '$SELECTED_COUNTRY'"
+    exit_fail "Expected new state to be 'CHALLENGE_SELECTING', got '$STATE'"
 fi
 
+
 exit 0
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index bad431c..aa61823 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -55,14 +55,14 @@ struct ANASTASIS_ChallengeDetails
   struct ANASTASIS_CRYPTO_TruthUUIDP uuid;
 
   /**
-   * Cost to solve this challenge
+   * Which type is this challenge (E-Mail, Security Question, SMS...)
    */
-  struct TALER_Amount cost;
+  const char *type;
 
   /**
-   * Which type is this challenge (E-Mail, Security Question, SMS...)
+   * Defines the base URL of the Anastasis provider used for the challenge.
    */
-  const char *type;
+  const char *provider_url;
 
   /**
    * Instructions for solving the challenge (generic, set client-side
diff --git a/src/lib/anastasis_recovery.c b/src/lib/anastasis_recovery.c
index 111ffca..c6f5853 100644
--- a/src/lib/anastasis_recovery.c
+++ b/src/lib/anastasis_recovery.c
@@ -713,6 +713,7 @@ policy_lookup_cb (void *cls,
     cs->url = GNUNET_strdup (url);
     cs->type = GNUNET_strdup (escrow_type);
     cs->ci.type = cs->type;
+    cs->ci.provider_url = cs->url;
     cs->instructions = GNUNET_strdup (instructions);
     cs->ci.instructions = cs->instructions;
   }
@@ -885,7 +886,7 @@ ANASTASIS_recovery_serialize (const struct 
ANASTASIS_Recovery *r)
     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];
+      const struct ANASTASIS_Challenge *c = dp->pub_details.challenges[j];
       json_t *cs;
 
       cs = json_pack ("{s:o}",
@@ -893,7 +894,7 @@ ANASTASIS_recovery_serialize (const struct 
ANASTASIS_Recovery *r)
                       GNUNET_JSON_from_data_auto (&c->ci.uuid));
       GNUNET_assert (NULL != cs);
       GNUNET_assert (0 ==
-                     json_array_append_new (dps_arr,
+                     json_array_append_new (c_arr,
                                             cs));
     }
     dps = json_pack ("{s:o, s:o, s:o}",
@@ -916,7 +917,7 @@ ANASTASIS_recovery_serialize (const struct 
ANASTASIS_Recovery *r)
     json_t *cs;
 
     cs = json_pack ("{s:o,s:o,s:o,s:o?,"
-                    " s:s,s:s,s:s,s:o}",
+                    " s:s,s:s,s:s}",
                     "uuid",
                     GNUNET_JSON_from_data_auto (&c->ci.uuid),
                     "truth_key",
@@ -932,9 +933,7 @@ ANASTASIS_recovery_serialize (const struct 
ANASTASIS_Recovery *r)
                     "type",
                     c->type,
                     "instructions",
-                    c->instructions,
-                    "cost",
-                    TALER_JSON_from_amount (&c->ci.cost));
+                    c->instructions);
     GNUNET_assert (NULL != cs);
     GNUNET_assert (0 ==
                    json_array_append_new (cs_arr,
@@ -1005,8 +1004,6 @@ parse_cs_array (struct ANASTASIS_Recovery *r,
                                    &c->truth_salt),
       GNUNET_JSON_spec_string ("type",
                                &escrow_type),
-      TALER_JSON_spec_amount ("cost",
-                              &c->ci.cost),
       GNUNET_JSON_spec_mark_optional (
         GNUNET_JSON_spec_fixed_auto ("key_share",
                                      &c->key_share)),
@@ -1057,6 +1054,11 @@ parse_dps_array (struct ANASTASIS_Recovery *r,
     return GNUNET_SYSERR;
   }
   r->ri.dps_len = json_array_size (dps_arr);
+  r->dps = GNUNET_new_array (r->ri.dps_len,
+                             struct DecryptionPolicy);
+  r->ri.dps = GNUNET_new_array (r->ri.dps_len,
+                                struct ANASTASIS_DecryptionPolicy *);
+
   json_array_foreach (dps_arr, n_index, dps)
   {
     struct DecryptionPolicy *dp = &r->dps[n_index];
@@ -1070,14 +1072,22 @@ parse_dps_array (struct ANASTASIS_Recovery *r,
                              &challenges),
       GNUNET_JSON_spec_end ()
     };
+    const char *err_json_name;
+    unsigned int err_line;
 
     r->ri.dps[n_index] = &dp->pub_details;
     if (GNUNET_OK !=
         GNUNET_JSON_parse (dps,
                            spec,
-                           NULL, NULL))
+                           &err_json_name,
+                           &err_line))
     {
-      GNUNET_break_op (0);
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Failed to parse decryption policy JSON entry `%s'\n",
+                  err_json_name);
+      json_dumpf (dps,
+                  stderr,
+                  JSON_INDENT (2));
       return GNUNET_SYSERR;
     }
     if (! json_is_array (challenges))
@@ -1175,7 +1185,7 @@ ANASTASIS_recovery_deserialize (struct 
GNUNET_CURL_Context *ctx,
                              &cs_arr),
       GNUNET_JSON_spec_json ("id_data",
                              &id_data),
-      GNUNET_JSON_spec_varsize ("enc_core_secret",
+      GNUNET_JSON_spec_varsize ("core_secret",
                                 &ecs,
                                 &ecs_size),
       GNUNET_JSON_spec_end ()
@@ -1187,7 +1197,12 @@ ANASTASIS_recovery_deserialize (struct 
GNUNET_CURL_Context *ctx,
                            &err_json_name,
                            &err_line))
     {
-      GNUNET_break_op (0);
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Failed to parse recovery document JSON entry `%s'\n",
+                  err_json_name);
+      json_dumpf (input,
+                  stderr,
+                  JSON_INDENT (2));
       return NULL;
     }
     if ( (GNUNET_OK !=
diff --git a/src/reducer/anastasis_api_backup_redux.c 
b/src/reducer/anastasis_api_backup_redux.c
index bb5d4f7..eadb0c1 100644
--- a/src/reducer/anastasis_api_backup_redux.c
+++ b/src/reducer/anastasis_api_backup_redux.c
@@ -1999,6 +1999,7 @@ check_truth_upload (struct UploadContext *uc,
                            spec,
                            NULL, NULL))
     {
+      json_dumpf (auth_method, stderr, JSON_INDENT (2));
       GNUNET_break (0);
       GNUNET_free (tue);
       return GNUNET_SYSERR;
@@ -2468,9 +2469,10 @@ ANASTASIS_backup_action_ (json_t *state,
   bs = ANASTASIS_backup_state_from_string_ (s);
   if (ANASTASIS_BACKUP_STATE_ERROR == bs)
   {
-    cb (cb_cls,
-        TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
-        NULL);
+    ANASTASIS_redux_fail_ (cb,
+                           cb_cls,
+                           TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
+                           "unknown 'backup_state'");
     return NULL;
   }
   for (unsigned int i = 0; NULL != dispatchers[i].fun; i++)
diff --git a/src/reducer/anastasis_api_recovery_redux.c 
b/src/reducer/anastasis_api_recovery_redux.c
index 9b48f61..8a24c29 100644
--- a/src/reducer/anastasis_api_recovery_redux.c
+++ b/src/reducer/anastasis_api_recovery_redux.c
@@ -218,6 +218,63 @@ report_solved (void *cls)
 }
 
 
+/**
+ * Find challenge of @a uuid in @a state under "recovery_information".
+ *
+ * @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_ri (json_t *state,
+                      const struct ANASTASIS_CRYPTO_TruthUUIDP *uuid)
+{
+  struct ANASTASIS_CRYPTO_TruthUUIDP u;
+  struct GNUNET_JSON_Specification spec[] = {
+    GNUNET_JSON_spec_fixed_auto ("uuid",
+                                 &u),
+    GNUNET_JSON_spec_end ()
+  };
+  json_t *ri;
+  json_t *challenges;
+  json_t *challenge;
+  size_t index;
+
+  ri = json_object_get (state,
+                        "recovery_information");
+  if (NULL == ri)
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
+  challenges = json_object_get (ri,
+                                "challenges");
+  if (NULL == challenges)
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
+  json_array_foreach (challenges, index, challenge)
+  {
+    if (GNUNET_OK !=
+        GNUNET_JSON_parse (challenge,
+                           spec,
+                           NULL, NULL))
+    {
+      GNUNET_break (0);
+      return NULL;
+    }
+    if (0 ==
+        GNUNET_memcmp (&u,
+                       uuid))
+    {
+      return challenge;
+    }
+  }
+  return NULL;
+}
+
+
 /**
  * Defines a callback for the response status for a challenge start
  * operation.
@@ -359,6 +416,19 @@ answer_feedback_cb (
                                           uuid,
                                           pay));
     }
+    /* Remember payment secret for later (once application claims it paid) */
+    {
+      json_t *challenge = find_challenge_in_ri (sctx->state,
+                                                &cd->uuid);
+
+      GNUNET_assert (NULL != challenge);
+      GNUNET_assert (0 ==
+                     json_object_set_new (challenge,
+                                          "payment_secret",
+                                          GNUNET_JSON_from_data_auto (
+                                            &csr->details.payment_required.
+                                            payment_secret)));
+    }
     set_state (sctx->state,
                ANASTASIS_RECOVERY_STATE_CHALLENGE_PAYING);
     sctx->cb (sctx->cb_cls,
@@ -456,24 +526,40 @@ run_challenge_cb (void *cls,
   }
 
   /* Check if we got a payment_secret */
-  if (NULL != json_object_get (sctx->args,
-                               "payment_secret"))
   {
-    if (GNUNET_OK !=
-        GNUNET_JSON_parse (sctx->args,
-                           spec,
-                           NULL, NULL))
+    json_t *challenge = find_challenge_in_ri (sctx->state,
+                                              &sctx->uuid);
+
+    if (NULL == challenge)
     {
       ANASTASIS_redux_fail_ (sctx->cb,
                              sctx->cb_cls,
-                             TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID,
-                             "'payment_secret' malformed");
+                             TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
+                             "challenge not found");
       sctx_free (sctx);
       return;
     }
-    psp = &ps;
+    if (NULL !=
+        json_object_get (challenge,
+                         "payment_secret"))
+    {
+      if (GNUNET_OK !=
+          GNUNET_JSON_parse (sctx->args,
+                             spec,
+                             NULL, NULL))
+      {
+        ANASTASIS_redux_fail_ (sctx->cb,
+                               sctx->cb_cls,
+                               TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
+                               "'payment_secret' malformed");
+        sctx_free (sctx);
+        return;
+      }
+      psp = &ps;
+    }
   }
 
+
   for (unsigned int i = 0; i<ri->cs_len; i++)
   {
     struct ANASTASIS_Challenge *ci = ri->cs[i];
@@ -1020,6 +1106,79 @@ core_early_secret_cb (void *cls,
 }
 
 
+/**
+ * Determine recovery @a cost of solving a challenge of type @a type
+ * at @a provider_url by inspecting @a state.
+ *
+ * @param state the state to inspect
+ * @param provider_url the provider to lookup config info from
+ * @param type the method to lookup the cost of
+ * @param[out] cost the recovery cost to return
+ * @return #GNUNET_OK on success, #GNUNET_NO if not found, #GNUNET_SYSERR on 
state error
+ */
+static int
+lookup_cost (const json_t *state,
+             const char *provider_url,
+             const char *type,
+             struct TALER_Amount *cost)
+{
+  const json_t *providers;
+  const json_t *provider;
+  const json_t *methods;
+
+  providers = json_object_get (state,
+                               "authentication_providers");
+  if (NULL == providers)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  provider = json_object_get (providers,
+                              provider_url);
+  if (NULL == provider)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  methods = json_object_get (provider,
+                             "methods");
+  if ( (NULL == methods) ||
+       (! json_is_array (methods)) )
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  {
+    size_t index;
+    json_t *method;
+
+    json_array_foreach (methods, index, method) {
+      const char *t;
+      struct GNUNET_JSON_Specification spec[] = {
+        GNUNET_JSON_spec_string ("type",
+                                 &t),
+        TALER_JSON_spec_amount ("usage_fee",
+                                cost),
+        GNUNET_JSON_spec_end ()
+      };
+
+      if (GNUNET_OK !=
+          GNUNET_JSON_parse (method,
+                             spec,
+                             NULL, NULL))
+      {
+        GNUNET_break (0);
+        continue;
+      }
+      if (0 == strcmp (t,
+                       type))
+        return GNUNET_OK;
+    }
+  }
+  return GNUNET_NO; /* not found */
+}
+
+
 /**
  * Callback which passes back the recovery document and its possible
  * policies. Also passes back the version of the document for the user
@@ -1098,13 +1257,35 @@ policy_lookup_cb (void *cls,
     struct ANASTASIS_Challenge *c = ri->cs[i];
     const struct ANASTASIS_ChallengeDetails *cd;
     json_t *cj;
+    struct TALER_Amount cost;
+    int ret;
 
     cd = ANASTASIS_challenge_get_details (c);
-    cj = json_pack ("{s:o,s:o,s:s,s:s,s:b}",
+    ret = lookup_cost (rss->state,
+                       cd->provider_url,
+                       cd->type,
+                       &cost);
+    if (GNUNET_SYSERR == ret)
+    {
+      json_decref (challenges);
+      json_decref (policies);
+      set_state (rss->state,
+                 ANASTASIS_GENERIC_STATE_ERROR);
+      ANASTASIS_redux_fail_ (rss->cb,
+                             rss->cb_cls,
+                             TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
+                             "failed to 'lookup_cost'");
+      free_rss (rss);
+      return;
+    }
+
+    cj = json_pack ("{s:o,s:o?,s:s,s:s,s:b}",
                     "uuid",
                     GNUNET_JSON_from_data_auto (&cd->uuid),
                     "cost",
-                    TALER_JSON_from_amount (&cd->cost),
+                    (GNUNET_NO == ret)
+                      ? NULL
+                      : TALER_JSON_from_amount (&cost),
                     "type",
                     cd->type,
                     "instructions",
diff --git a/src/reducer/anastasis_api_redux.c 
b/src/reducer/anastasis_api_redux.c
index a52dbc2..77d3cf3 100644
--- a/src/reducer/anastasis_api_redux.c
+++ b/src/reducer/anastasis_api_redux.c
@@ -1305,7 +1305,7 @@ enter_user_attributes (json_t *state,
       GNUNET_assert (0 ==
                      json_object_set_new (
                        state,
-                       "backup_state",
+                       "recovery_state",
                        json_string (
                          ANASTASIS_recovery_state_to_string_ (
                            ANASTASIS_RECOVERY_STATE_CHALLENGE_SELECTING))));

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]