gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: fix misc issues, including refu


From: gnunet
Subject: [taler-anastasis] branch master updated: fix misc issues, including refunds and provider selection
Date: Sun, 11 Apr 2021 15:21:36 +0200

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 897a89f  fix misc issues, including refunds and provider selection
897a89f is described below

commit 897a89faabfdcc910f1db7c491358d8a6c33ff47
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Apr 11 15:21:33 2021 +0200

    fix misc issues, including refunds and provider selection
---
 src/cli/resources/06-backup.json                   |   8 +
 ...tasis_reducer_recovery_enter_user_attributes.sh |   8 +-
 src/include/anastasis.h                            |  16 +-
 src/include/anastasis_testing_lib.h                |  16 +-
 src/lib/anastasis_backup.c                         | 175 ++++-----------
 src/reducer/anastasis_api_backup_redux.c           | 236 +++++++++++++++------
 src/testing/test_anastasis.c                       |   2 +
 src/testing/testing_cmd_secret_share.c             |  78 ++++---
 8 files changed, 287 insertions(+), 252 deletions(-)

diff --git a/src/cli/resources/06-backup.json b/src/cli/resources/06-backup.json
index 4553a8b..e15b5b9 100644
--- a/src/cli/resources/06-backup.json
+++ b/src/cli/resources/06-backup.json
@@ -170,6 +170,14 @@
       "instructions": "Where do you live?",
       "challenge": "Mars"
     }
+  ],
+    "policy_providers" : [
+    {
+      "provider_url": "http://localhost:8089/";
+    },
+    {
+      "provider_url": "http://localhost:8089/";
+    }
   ],
   "policies": [
     {
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 796acd9..716bc02 100755
--- a/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh
+++ b/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh
@@ -333,7 +333,7 @@ rm $WALLET_DB
 taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB api 
'withdrawTestBalance' \
   "$(jq -n '
     {
-        amount: "TESTKUDOS:20",
+        amount: "TESTKUDOS:100",
         bankBaseUrl: $BANK_URL,
         exchangeBaseUrl: $EXCHANGE_URL
     }' \
@@ -351,9 +351,9 @@ do
     # 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 ","
+    echo -n ", "
 done
-echo " OK"
+echo "OK"
 echo -e "Running wallet run-pending..."
 taler-wallet-cli --wallet-db=$WALLET_DB run-pending 2>/dev/null >/dev/null
 echo -e "Payments done"
@@ -371,7 +371,7 @@ do
     # 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 ","
+    echo -n ", "
 done
 echo " OK"
 echo -en "Running wallet run-pending..."
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index 5184a9d..c654987 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -889,7 +889,7 @@ struct ANASTASIS_SecretShare;
 /**
  * Details of a past payment
  */
-struct ANASTASIS_PaymentDetails
+struct ANASTASIS_ProviderDetails
 {
   /**
    * URL of the provider backend.
@@ -900,6 +900,12 @@ struct ANASTASIS_PaymentDetails
    * Payment order ID / secret of a past payment.
    */
   struct ANASTASIS_PaymentSecretP payment_secret;
+
+  /**
+   * Server salt. Points into a truth object from which we got the
+   * salt.
+   */
+  struct ANASTASIS_CRYPTO_ProviderSaltP provider_salt;
 };
 
 
@@ -909,10 +915,10 @@ struct ANASTASIS_PaymentDetails
  *
  * @param ctx the CURL context used to connect to the backend
  * @param id_data used to create a account identifier on the escrow provider
+ * @param providers array of providers with URLs to upload the policies to
+ * @param pss_length length of the @a providers array
  * @param policies list of policies which are included in this recovery 
document
  * @param policies_length amount of policies in the document
- * @param pds contains details of past payments
- * @param pds_len length of @a pds array
  * @param payment_requested the client insists on paying for the policy store, 
even if not
  *                 yet needed
  * @param pay_timeout how long to wait for payment
@@ -926,10 +932,10 @@ struct ANASTASIS_PaymentDetails
 struct ANASTASIS_SecretShare *
 ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
                         const json_t *id_data,
+                        const struct ANASTASIS_ProviderDetails providers[],
+                        unsigned int pss_length,
                         const struct ANASTASIS_Policy *policies[],
                         unsigned int policies_len,
-                        const struct ANASTASIS_PaymentDetails *pds,
-                        unsigned int pds_len,
                         bool payment_requested,
                         struct GNUNET_TIME_Relative pay_timeout,
                         ANASTASIS_ShareResultCallback src,
diff --git a/src/include/anastasis_testing_lib.h 
b/src/include/anastasis_testing_lib.h
index 844823f..a54e3ae 100644
--- a/src/include/anastasis_testing_lib.h
+++ b/src/include/anastasis_testing_lib.h
@@ -505,10 +505,10 @@ ANASTASIS_TESTING_cmd_keyshare_lookup (
  * @return #GNUNET_OK on success.
  */
 int
-ANASTASIS_TESTING_get_trait_salt (const struct TALER_TESTING_Command *cmd,
-                                  unsigned int index,
-                                  const struct
-                                  ANASTASIS_CRYPTO_ProviderSaltP **s);
+ANASTASIS_TESTING_get_trait_salt (
+  const struct TALER_TESTING_Command *cmd,
+  unsigned int index,
+  const struct ANASTASIS_CRYPTO_ProviderSaltP **s);
 
 
 /**
@@ -519,9 +519,9 @@ ANASTASIS_TESTING_get_trait_salt (const struct 
TALER_TESTING_Command *cmd,
  * @return #GNUNET_OK on success.
  */
 struct TALER_TESTING_Trait
-ANASTASIS_TESTING_make_trait_salt (unsigned int index,
-                                   const struct
-                                   ANASTASIS_CRYPTO_ProviderSaltP *s);
+ANASTASIS_TESTING_make_trait_salt (
+  unsigned int index,
+  const struct ANASTASIS_CRYPTO_ProviderSaltP *s);
 
 
 /**
@@ -727,6 +727,7 @@ enum ANASTASIS_TESTING_SecretShareOption
  *
  * @param label command label
  * @param anastasis_url base URL of the anastasis serving our requests.
+ * @param config_ref reference to /config operation for @a anastasis_url
  * @param prev_secret_share reference to a previous secret share command
  * @param id_data ID data to generate user identifier
  * @param core_secret core secret to backup/recover
@@ -740,6 +741,7 @@ struct TALER_TESTING_Command
 ANASTASIS_TESTING_cmd_secret_share (
   const char *label,
   const char *anastasis_url,
+  const char *config_ref,
   const char *prev_secret_share,
   const json_t *id_data,
   const void *core_secret,
diff --git a/src/lib/anastasis_backup.c b/src/lib/anastasis_backup.c
index 17363c6..396a243 100644
--- a/src/lib/anastasis_backup.c
+++ b/src/lib/anastasis_backup.c
@@ -572,10 +572,10 @@ struct PolicyStoreState
   struct ANASTASIS_PaymentSecretP payment_secret;
 
   /**
-   * Server salt. Points into a truth object from which we
-   * got the salt.
+   * Server salt. Points into a truth object from which we got the
+   * salt.
    */
-  const struct ANASTASIS_CRYPTO_ProviderSaltP *server_salt;
+  struct ANASTASIS_CRYPTO_ProviderSaltP server_salt;
 
   /**
    * The /policy POST operation handle.
@@ -698,111 +698,57 @@ policy_store_cb (void *cls,
       return;
 
   {
-    unsigned int pr_cnt = 0;
+    struct ANASTASIS_SharePaymentRequest spr[GNUNET_NZL (ss->pss_length)];
+    const char *provider_urls[GNUNET_NZL (ss->pss_length)];
+    unsigned long long versions[GNUNET_NZL (ss->pss_length)];
+    unsigned int off = 0;
+    unsigned int voff = 0;
+    struct ANASTASIS_ShareResult sr;
+
     for (unsigned int i = 0; i<ss->pss_length; i++)
-      if (NULL != ss->pss[i].payment_request)
-        pr_cnt++;
     {
-      struct ANASTASIS_SharePaymentRequest spr[GNUNET_NZL (pr_cnt)];
-      const char *provider_urls[GNUNET_NZL (pr_cnt)];
-      unsigned long long versions[GNUNET_NZL (pr_cnt)];
-      unsigned int off = 0;
-      unsigned int voff = 0;
-      struct ANASTASIS_ShareResult sr;
-
-      for (unsigned int i = 0; i<ss->pss_length; i++)
-      {
-        struct PolicyStoreState *pssi = &ss->pss[i];
-
-        if (NULL == pssi->payment_request)
-        {
-          versions[voff] = pssi->policy_version;
-          provider_urls[voff] = pssi->anastasis_url;
-          voff++;
-        }
-        else
-        {
-          spr[off].payment_request_url = pssi->payment_request;
-          spr[off].provider_url = pssi->anastasis_url;
-          off++;
-        }
-      }
-      if (off > 0)
+      struct PolicyStoreState *pssi = &ss->pss[i];
+
+      if (NULL == pssi->payment_request)
       {
-        sr.ss = ANASTASIS_SHARE_STATUS_PAYMENT_REQUIRED;
-        sr.details.payment_required.payment_requests = spr;
-        sr.details.payment_required.payment_requests_length = pr_cnt;
+        versions[voff] = pssi->policy_version;
+        provider_urls[voff] = pssi->anastasis_url;
+        voff++;
       }
       else
       {
-        sr.ss = ANASTASIS_SHARE_STATUS_SUCCESS;
-        sr.details.success.policy_versions = versions;
-        sr.details.success.provider_urls = provider_urls;
-        sr.details.success.num_providers = voff;
+        spr[off].payment_request_url = pssi->payment_request;
+        spr[off].provider_url = pssi->anastasis_url;
+        off++;
       }
-      ss->src (ss->src_cls,
-               &sr);
     }
-  }
-  ANASTASIS_secret_share_cancel (ss);
-}
-
-
-/**
- * Counts the number of different providers
- *
- * @param policies Array of policies
- * @param policies_len Length of @a policies array
- * @return number of different providers
- */
-static unsigned int
-get_num_urls (const struct ANASTASIS_Policy *policies[],
-              unsigned int policies_len)
-{
-  unsigned int unique_urls_len = 0;
-
-  if (0 == policies_len)
-    return 0;
-  for (unsigned int i = 0; i < policies_len; i++)
-  {
-    for (unsigned int j = 0; j < policies[i]->truths_length; j++)
+    if (off > 0)
     {
-      bool found = false;
-
-      for (unsigned int l = 0; l <= i; l++)
-      {
-        unsigned int limit;
-
-        if (l == i)
-          limit = j;
-        else
-          limit = policies[l]->truths_length;
-        for (unsigned int k = 0; k < limit; k++)
-        {
-          if (0 ==
-              strcmp (policies[i]->truths[j]->url,
-                      policies[l]->truths[k]->url))
-          {
-            found = true;
-            break;
-          }
-        }
-      }
-      if (! found)
-        unique_urls_len++;
+      sr.ss = ANASTASIS_SHARE_STATUS_PAYMENT_REQUIRED;
+      sr.details.payment_required.payment_requests = spr;
+      sr.details.payment_required.payment_requests_length = off;
+    }
+    else
+    {
+      sr.ss = ANASTASIS_SHARE_STATUS_SUCCESS;
+      sr.details.success.policy_versions = versions;
+      sr.details.success.provider_urls = provider_urls;
+      sr.details.success.num_providers = voff;
     }
+    ss->src (ss->src_cls,
+             &sr);
   }
-  return unique_urls_len;
+  ANASTASIS_secret_share_cancel (ss);
 }
 
 
 struct ANASTASIS_SecretShare *
 ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
                         const json_t *id_data,
+                        const struct ANASTASIS_ProviderDetails providers[],
+                        unsigned int pss_length,
                         const struct ANASTASIS_Policy *policies[],
                         unsigned int policies_len,
-                        const struct ANASTASIS_PaymentDetails *pds,
-                        unsigned int pds_len,
                         bool payment_requested,
                         struct GNUNET_TIME_Relative pay_timeout,
                         ANASTASIS_ShareResultCallback src,
@@ -811,14 +757,11 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
                         size_t core_secret_size)
 {
   struct ANASTASIS_SecretShare *ss;
-  unsigned int pss_length = get_num_urls (policies,
-                                          policies_len);
   struct ANASTASIS_CRYPTO_EncryptedMasterKeyP
     encrypted_master_keys[GNUNET_NZL (policies_len)];
   void *encrypted_core_secret;
   json_t *dec_policies;
   json_t *esc_methods;
-  unsigned int index_pss = 0;
   size_t recovery_document_size;
   char *recovery_document_str;
 
@@ -834,6 +777,7 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
                               struct PolicyStoreState);
   ss->pss_length = pss_length;
   ss->ctx = ctx;
+
   {
     struct ANASTASIS_CRYPTO_PolicyKeyP policy_keys[GNUNET_NZL (policies_len)];
 
@@ -939,50 +883,8 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
         ANASTASIS_secret_share_cancel (ss);
         return NULL;
       }
-
-      /* Check if this truth also specifies a new unique provider */
-      {
-        bool contains_url = false;
-        for (unsigned int j = 0; j < ss->pss_length; j++)
-        {
-          if (NULL != ss->pss[j].anastasis_url)
-          {
-            if (0 == strcmp (ss->pss[j].anastasis_url,
-                             pt->url))
-            {
-              contains_url = true;
-              break;
-            }
-          }
-        }
-        if (contains_url)
-          continue;
-      }
-
-      /* new provider, setup per-provider data structure */
-      {
-        struct PolicyStoreState *pssi;
-
-        GNUNET_assert (index_pss < pss_length);
-        pssi = &ss->pss[index_pss++];
-        pssi->anastasis_url = GNUNET_strdup (pt->url);
-        pssi->server_salt = &pt->provider_salt;
-        for (unsigned int m = 0; 0 < pds_len; m++)
-        {
-          if (NULL == pds[m].provider_url)
-            continue;
-          if (0 == strcmp (pds[m].provider_url,
-                           pt->url))
-          {
-            pssi->payment_secret = pds[m].payment_secret;
-            break;
-          }
-        }
-      }
     }
   }
-  /* We must have setup the entire pss array at this point */
-  GNUNET_assert (index_pss == pss_length);
 
   {
     json_t *recovery_document;
@@ -1039,8 +941,11 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
     struct ANASTASIS_CRYPTO_AccountPrivateKeyP anastasis_priv;
 
     pss->ss = ss;
+    pss->anastasis_url = GNUNET_strdup (providers[l].provider_url);
+    pss->server_salt = providers[l].provider_salt;
+    pss->payment_secret = providers[l].payment_secret;
     ANASTASIS_CRYPTO_user_identifier_derive (id_data,
-                                             pss->server_salt,
+                                             &pss->server_salt,
                                              &pss->id);
     ANASTASIS_CRYPTO_account_private_key_derive (&pss->id,
                                                  &anastasis_priv);
diff --git a/src/reducer/anastasis_api_backup_redux.c 
b/src/reducer/anastasis_api_backup_redux.c
index 4f42f2b..5f085f7 100644
--- a/src/reducer/anastasis_api_backup_redux.c
+++ b/src/reducer/anastasis_api_backup_redux.c
@@ -687,6 +687,53 @@ method_candidate (struct PolicyBuilder *pb,
 }
 
 
+/**
+ * Lookup @a salt of @a provider_url in @a state.
+ *
+ * @param state the state to inspect
+ * @param provider_url provider to look into
+ * @param[out] salt value to extract
+ * @return #GNUNET_OK on success
+ */
+static int
+lookup_salt (const json_t *state,
+             const char *provider_url,
+             struct ANASTASIS_CRYPTO_ProviderSaltP *salt)
+{
+  const json_t *aps;
+  const json_t *cfg;
+  struct GNUNET_JSON_Specification spec[] = {
+    GNUNET_JSON_spec_fixed_auto ("salt",
+                                 salt),
+    GNUNET_JSON_spec_end ()
+  };
+
+  aps = json_object_get (state,
+                         "authentication_providers");
+  if (NULL == aps)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  cfg = json_object_get (aps,
+                         provider_url);
+  if (NULL == cfg)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  if (GNUNET_OK !=
+      GNUNET_JSON_parse (cfg,
+                         spec,
+                         NULL, NULL))
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  return GNUNET_OK;
+}
+
+
 /**
  * DispatchHandler/Callback function which is called for a
  * "done_authentication" action.  Automaticially computes policies
@@ -708,6 +755,8 @@ done_authentication (json_t *state,
   struct PolicyBuilder pb = {
     .ec = TALER_EC_NONE
   };
+  json_t *providers;
+  json_t *policy_providers;
 
   pb.providers = json_object_get (state,
                                   "authentication_providers");
@@ -783,6 +832,84 @@ done_authentication (json_t *state,
                  json_object_set_new (state,
                                       "policies",
                                       pb.policies));
+
+  providers = json_object_get (arguments,
+                               "providers");
+  if (NULL == providers)
+  {
+    /* Setup a providers array from all working providers */
+    json_t *available = json_object_get (state,
+                                         "authentication_providers");
+    const char *url;
+    json_t *details;
+
+    policy_providers = json_array ();
+    json_object_foreach (available, url, details)
+    {
+      json_t *provider;
+      struct ANASTASIS_CRYPTO_ProviderSaltP salt;
+
+      if (GNUNET_OK !=
+          lookup_salt (state,
+                       url,
+                       &salt))
+        continue; /* skip providers that are down */
+      provider = json_pack ("{s:s}",
+                            "provider_url", url);
+      GNUNET_assert (NULL != provider);
+      GNUNET_assert (0 ==
+                     json_array_append_new (policy_providers,
+                                            provider));
+    }
+  }
+  else
+  {
+    /* Setup a providers array from all working providers */
+    size_t off;
+    json_t *url;
+
+    policy_providers = json_array ();
+    json_array_foreach (providers, off, url)
+    {
+      json_t *provider;
+      struct ANASTASIS_CRYPTO_ProviderSaltP salt;
+      const char *url_str;
+
+      url_str = json_string_value (url);
+      if ( (NULL == url_str) ||
+           (GNUNET_OK !=
+            lookup_salt (state,
+                         url_str,
+                         &salt)) )
+      {
+        GNUNET_break (0);
+        ANASTASIS_redux_fail_ (cb,
+                               cb_cls,
+                               TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID,
+                               "unworkable provider requested");
+        return NULL;
+      }
+      provider = json_pack ("{s:s}",
+                            "provider_url", url);
+      GNUNET_assert (NULL != provider);
+      GNUNET_assert (0 ==
+                     json_array_append_new (policy_providers,
+                                            provider));
+    }
+  }
+  if (0 == json_array_size (policy_providers))
+  {
+    json_decref (policy_providers);
+    ANASTASIS_redux_fail_ (cb,
+                           cb_cls,
+                           TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
+                           "no workable providers in state");
+    return NULL;
+  }
+  GNUNET_assert (0 ==
+                 json_object_set_new (state,
+                                      "policy_providers",
+                                      policy_providers));
   set_state (state,
              ANASTASIS_BACKUP_STATE_POLICIES_REVIEWING);
   cb (cb_cls,
@@ -1548,7 +1675,7 @@ share_secret (struct UploadContext *uc)
   size_t core_secret_size;
   void *core_secret;
   json_t *jpolicies;
-  json_t *payments = NULL;
+  json_t *providers = NULL;
   bool force_payment = false;
   unsigned int policies_len;
   unsigned int pds_len;
@@ -1561,9 +1688,8 @@ share_secret (struct UploadContext *uc)
                              &force_payment)),
     GNUNET_JSON_spec_json ("policies",
                            &jpolicies),
-    GNUNET_JSON_spec_mark_optional (
-      GNUNET_JSON_spec_json ("policy_payments",
-                             &payments)),
+    GNUNET_JSON_spec_json ("policy_providers",
+                           &providers),
     GNUNET_JSON_spec_varsize ("core_secret",
                               &core_secret,
                               &core_secret_size),
@@ -1613,12 +1739,11 @@ share_secret (struct UploadContext *uc)
     }
   }
 
-
   if ( (! json_is_object (user_id)) ||
        (! json_is_array (jpolicies)) ||
        (0 == json_array_size (jpolicies)) ||
-       ( (NULL != payments) &&
-         (! json_is_array (payments)) ) )
+       ( (NULL != providers) &&
+         (! json_is_array (providers)) ) )
   {
     ANASTASIS_redux_fail_ (uc->cb,
                            uc->cb_cls,
@@ -1628,15 +1753,31 @@ share_secret (struct UploadContext *uc)
     upload_cancel_cb (uc);
     return;
   }
+
   policies_len = json_array_size (jpolicies);
-  pds_len = json_array_size (payments);
+  pds_len = json_array_size (providers);
+
+  if (0 == pds_len)
+  {
+    ANASTASIS_redux_fail_ (uc->cb,
+                           uc->cb_cls,
+                           TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
+                           "no workable providers in state");
+    GNUNET_JSON_parse_free (spec);
+    upload_cancel_cb (uc);
+    return;
+  }
+
 
   {
     struct ANASTASIS_Policy *vpolicies[policies_len];
     const struct ANASTASIS_Policy *policies[policies_len];
-    struct ANASTASIS_PaymentDetails pds[GNUNET_NZL (pds_len)];
+    struct ANASTASIS_ProviderDetails pds[GNUNET_NZL (pds_len)];
 
     /* initialize policies/vpolicies arrays */
+    memset (pds,
+            0,
+            sizeof (pds));
     for (unsigned int i = 0; i<policies_len; i++)
     {
       const json_t *policy = json_array_get (jpolicies,
@@ -1771,24 +1912,34 @@ share_secret (struct UploadContext *uc)
     /* initialize 'pds' array */
     for (unsigned int i = 0; i<pds_len; i++)
     {
-      json_t *pdj = json_array_get (payments,
+      json_t *pdj = json_array_get (providers,
                                     i);
       struct GNUNET_JSON_Specification ispec[] = {
-        GNUNET_JSON_spec_fixed_auto ("payment_secret",
-                                     &pds[i]),
+        /* FIXME #6842: this 'payment_secret' is currently never initialized 
anywhere;
+           this is a bug, because the provider should check for it, and not
+           accept the request if it is missing! */
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_fixed_auto ("payment_secret",
+                                       &pds[i].payment_secret)),
+        GNUNET_JSON_spec_string ("provider_url",
+                                 &pds[i].provider_url),
         GNUNET_JSON_spec_end ()
       };
 
-      if (GNUNET_OK !=
-          GNUNET_JSON_parse (pdj,
-                             ispec,
-                             NULL, NULL))
+      if ( (GNUNET_OK !=
+            GNUNET_JSON_parse (pdj,
+                               ispec,
+                               NULL, NULL)) ||
+           (GNUNET_OK !=
+            lookup_salt (uc->state,
+                         pds[i].provider_url,
+                         &pds[i].provider_salt)) )
       {
         GNUNET_break (0);
         ANASTASIS_redux_fail_ (uc->cb,
                                uc->cb_cls,
                                TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
-                               "'payment_secret' malformed");
+                               "'providers' entry malformed");
         for (unsigned int i = 0; i<policies_len; i++)
           ANASTASIS_policy_destroy (vpolicies[i]);
         upload_cancel_cb (uc);
@@ -1799,10 +1950,10 @@ share_secret (struct UploadContext *uc)
 
     uc->ss = ANASTASIS_secret_share (ANASTASIS_REDUX_ctx_,
                                      user_id,
-                                     policies,
-                                     policies_len,
                                      pds,
                                      pds_len,
+                                     policies,
+                                     policies_len,
                                      force_payment,
                                      timeout,
                                      &secret_share_result_cb,
@@ -1906,53 +2057,6 @@ check_upload_finished (struct UploadContext *uc)
 }
 
 
-/**
- * Lookup @a salt of @a provider_url in @a state.
- *
- * @param state the state to inspect
- * @param provider_url provider to look into
- * @param[out] salt value to extract
- * @return #GNUNET_OK on success
- */
-static int
-lookup_salt (const json_t *state,
-             const char *provider_url,
-             struct ANASTASIS_CRYPTO_ProviderSaltP *salt)
-{
-  const json_t *aps;
-  const json_t *cfg;
-  struct GNUNET_JSON_Specification spec[] = {
-    GNUNET_JSON_spec_fixed_auto ("salt",
-                                 salt),
-    GNUNET_JSON_spec_end ()
-  };
-
-  aps = json_object_get (state,
-                         "authentication_providers");
-  if (NULL == aps)
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
-  cfg = json_object_get (aps,
-                         provider_url);
-  if (NULL == cfg)
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
-  if (GNUNET_OK !=
-      GNUNET_JSON_parse (cfg,
-                         spec,
-                         NULL, NULL))
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
-  return GNUNET_OK;
-}
-
-
 /**
  * Upload result information.  The resulting truth object can be used
  * to create policies.  If payment is required, the @a taler_pay_url
diff --git a/src/testing/test_anastasis.c b/src/testing/test_anastasis.c
index 73c0d13..2ff7cb0 100644
--- a/src/testing/test_anastasis.c
+++ b/src/testing/test_anastasis.c
@@ -226,6 +226,7 @@ run (void *cls,
                                          NULL),
     ANASTASIS_TESTING_cmd_secret_share ("secret-share-1",
                                         anastasis_url,
+                                        "salt-request-1",
                                         NULL,
                                         id_data,
                                         "core secret",
@@ -253,6 +254,7 @@ run (void *cls,
                                           NULL),
     ANASTASIS_TESTING_cmd_secret_share ("secret-share-2",
                                         anastasis_url,
+                                        "salt-request-1",
                                         "secret-share-1",
                                         id_data,
                                         "core secret",
diff --git a/src/testing/testing_cmd_secret_share.c 
b/src/testing/testing_cmd_secret_share.c
index 4a99072..85eb639 100644
--- a/src/testing/testing_cmd_secret_share.c
+++ b/src/testing/testing_cmd_secret_share.c
@@ -68,6 +68,11 @@ struct SecretShareState
    */
   const char *anastasis_url;
 
+  /**
+   * URL of a /config command for the @e anastasis_url.
+   */
+  const char *config_ref;
+
   /**
    * The /truth GET operation handle.
    */
@@ -184,8 +189,7 @@ secret_share_run (void *cls,
 {
   struct SecretShareState *sss = cls;
   const struct ANASTASIS_Policy *policies[sss->cmd_label_array_length];
-  unsigned int pds_len;
-  struct ANASTASIS_PaymentDetails pds;
+  struct ANASTASIS_ProviderDetails pds;
 
   GNUNET_assert (sss->cmd_label_array_length > 0);
   GNUNET_assert (NULL != sss->cmd_label_array);
@@ -197,9 +201,8 @@ secret_share_run (void *cls,
       const struct TALER_TESTING_Command *ref;
       const struct ANASTASIS_Policy *policy;
 
-      ref = TALER_TESTING_interpreter_lookup_command (
-        is,
-        sss->cmd_label_array[i]);
+      ref = TALER_TESTING_interpreter_lookup_command (is,
+                                                      sss->cmd_label_array[i]);
       if (NULL == ref)
       {
         GNUNET_break (0);
@@ -223,17 +226,16 @@ secret_share_run (void *cls,
   if (NULL != sss->prev_secret_share)
   {
     const struct TALER_TESTING_Command *ref;
+    const char *order_id;
 
-    ref = TALER_TESTING_interpreter_lookup_command
-            (is,
-            sss->prev_secret_share);
+    ref = TALER_TESTING_interpreter_lookup_command (is,
+                                                    sss->prev_secret_share);
     if (NULL == ref)
     {
       GNUNET_break (0);
       TALER_TESTING_interpreter_fail (sss->is);
       return;
     }
-    const char *order_id;
     if (GNUNET_OK !=
         TALER_TESTING_get_trait_order_id (ref,
                                           0,
@@ -259,11 +261,11 @@ secret_share_run (void *cls,
   if (NULL != sss->payment_order_id)
   {
     if (GNUNET_OK !=
-        GNUNET_STRINGS_string_to_data (sss->payment_order_id,
-                                       strlen (sss->payment_order_id),
-                                       &pds.payment_secret,
-                                       sizeof (struct
-                                               ANASTASIS_PaymentSecretP)))
+        GNUNET_STRINGS_string_to_data (
+          sss->payment_order_id,
+          strlen (sss->payment_order_id),
+          &pds.payment_secret,
+          sizeof (struct ANASTASIS_PaymentSecretP)))
     {
       GNUNET_break (0);
       TALER_TESTING_interpreter_fail (sss->is);
@@ -271,26 +273,44 @@ secret_share_run (void *cls,
       return;
     }
     GNUNET_free (sss->payment_order_id);
-    pds.provider_url = sss->anastasis_url;
-    pds_len = 1;
   }
-  else
+  pds.provider_url = sss->anastasis_url;
   {
-    pds_len = 0;
+    const struct TALER_TESTING_Command *ref;
+    const struct ANASTASIS_CRYPTO_ProviderSaltP *salt;
+
+    ref = TALER_TESTING_interpreter_lookup_command (is,
+                                                    sss->config_ref);
+    if (NULL == ref)
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (sss->is);
+      return;
+    }
+    if (GNUNET_OK !=
+        ANASTASIS_TESTING_get_trait_salt (ref,
+                                          0,
+                                          &salt))
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (sss->is);
+      return;
+    }
+    pds.provider_salt = *salt;
   }
+
   sss->sso = ANASTASIS_secret_share (is->ctx,
                                      sss->id_data,
+                                     &pds,
+                                     1,
                                      policies,
                                      sss->cmd_label_array_length,
-                                     (0 == pds_len) ? NULL : &pds,
-                                     pds_len,
                                      false,
                                      GNUNET_TIME_UNIT_ZERO,
                                      &secret_share_result_cb,
                                      sss,
                                      sss->core_secret,
                                      sss->core_secret_size);
-
   if (NULL == sss->sso)
   {
     GNUNET_break (0);
@@ -363,24 +383,11 @@ secret_share_traits (void *cls,
 }
 
 
-/**
- * Make the "secret share" command.
- *
- * @param label command label
- * @param anastasis_url base URL of the anastasis serving our requests.
- * @param prev_secret_share reference to a previous secret share command
- * @param id_data ID data to generate user identifier
- * @param core_secret core secret to backup/recover
- * @param core_secret_size size of core_secret
- * @param http_status expected HTTP status.
- * @param sso secret share options
- * @param ... NULL-terminated list of policy create commands
- * @return the command
- */
 struct TALER_TESTING_Command
 ANASTASIS_TESTING_cmd_secret_share (
   const char *label,
   const char *anastasis_url,
+  const char *config_ref,
   const char *prev_secret_share,
   const json_t *id_data,
   const void *core_secret,
@@ -395,6 +402,7 @@ ANASTASIS_TESTING_cmd_secret_share (
   sss->want_status = want_status;
   sss->ssopt = sso;
   sss->anastasis_url = anastasis_url;
+  sss->config_ref = config_ref;
   sss->label = label;
   sss->id_data = json_incref ((json_t *) id_data);
   sss->core_secret = core_secret;

-- 
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]