gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: towards secret sharing upload l


From: gnunet
Subject: [taler-anastasis] branch master updated: towards secret sharing upload logic
Date: Fri, 19 Feb 2021 22:36:25 +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 c69fb89  towards secret sharing upload logic
c69fb89 is described below

commit c69fb89e380fd4c68b7ab3a9e7b1f2294f19165c
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Fri Feb 19 22:36:23 2021 +0100

    towards secret sharing upload logic
---
 src/reducer/anastasis_api_backup_redux.c | 1289 +++---------------------------
 1 file changed, 123 insertions(+), 1166 deletions(-)

diff --git a/src/reducer/anastasis_api_backup_redux.c 
b/src/reducer/anastasis_api_backup_redux.c
index be527d2..aa8431f 100644
--- a/src/reducer/anastasis_api_backup_redux.c
+++ b/src/reducer/anastasis_api_backup_redux.c
@@ -60,166 +60,6 @@ ANASTASIS_backup_state_to_string_ (enum 
ANASTASIS_BackupState bs)
 }
 
 
-/**
- * State for a "truth upload" CMD.
- */
-struct TruthUploadState
-{
-  /**
-   * URL of the anastasis backend.
-   */
-  const char *anastasis_url;
-
-  /**
-   * Salt of anastasis backend.
-   */
-  struct ANASTASIS_CRYPTO_PowSalt backend_salt;
-
-  /**
-   * The ID data to generate user identifier
-   */
-  const json_t *id_data;
-
-  /**
-   * The escrow method
-   */
-  const char *method;
-
-  /**
-   * Instructions to be returned to client/user
-   * (e.g. "Look at your smartphone. SMS was sent to you")
-   */
-  const char *instructions;
-
-  /**
-   * Mime type of truth_data (eg. jpeg, string etc.)
-   */
-  const char *mime_type;
-
-  /**
-   * The truth_data (e.g. hash of answer to a secure question)
-   */
-  const void *truth_data;
-
-  /**
-   * Size of truth_data
-   */
-  size_t truth_data_size;
-
-  /**
-   * Expected status code.
-   */
-  unsigned int http_status;
-
-  /**
-   * The /truth POST operation handle.
-   */
-  struct ANASTASIS_TruthUpload *tuo;
-
-  /**
-   * Action callback.
-   */
-  ANASTASIS_ActionCallback cb;
-
-  /**
-   * Closure for action callback.
-   */
-  void *cb_cls;
-
-  /**
-   * Truth object.
-   */
-  struct ANASTASIS_Truth *truth;
-
-  /**
-   * Truth index.
-   */
-  unsigned int index;
-
-  /**
-   * Redux json state.
-   */
-  json_t *state;
-
-  /**
-   * User id.
-   */
-  struct ANASTASIS_CRYPTO_UserIdentifierP user_id;
-};
-
-
-/**
- * State for a "secret share" oparation.
- */
-struct SecretShareState
-{
-  /**
-   * Claim token we got back, if any. Otherwise all zeros.
-   */
-  struct TALER_ClaimTokenP token;
-
-  /**
-   * Data to derive user identifier from.
-   */
-  const json_t *id_data;
-
-  /**
-   * The core secret to backup/recover.
-   */
-  const void *core_secret;
-
-  /**
-   * Size of core_secret.
-   */
-  size_t core_secret_size;
-
-  /**
-   * URL of the anastasis backend.
-   */
-  const char *anastasis_url;
-
-  /**
-   * Expected status code.
-   */
-  unsigned int http_status;
-
-  /**
-   * The /truth GET operation handle.
-   */
-  struct ANASTASIS_SecretShare *sso;
-
-  /**
-   * closure for the payment callback
-   */
-  void *spc_cls;
-
-  /**
-   * closure for the result callback
-   */
-  void *src_cls;
-
-  /**
-   * Payment order ID we got back, if any. Otherwise NULL.
-   */
-  char *payment_order_id;
-
-  /**
-   * Action callback.
-   */
-  ANASTASIS_ActionCallback cb;
-
-  /**
-   * Closure for action callback #cb.
-   */
-  void *cb_cls;
-
-  /**
-   * Json state.
-   */
-  json_t *state;
-};
-
-
 /**
  * Update the 'backup_state' field of @a state to @a new_backup_state.
  *
@@ -1354,1009 +1194,6 @@ done_policy_review (json_t *state,
 }
 
 
-///////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////
-
-
-#if GRAVEYARD
-
-// FIXME: all of these globals must die!
-/**
- * Generic container for an action with asynchronous activities.
- */
-static struct ANASTASIS_ReduxAction *ra;
-
-/**
- * Array of truth upload states.
- */
-static struct TruthUploadState **tus_arr;
-
-/**
- * The length of the #tus_arr array.
- */
-static unsigned int tus_arr_length;
-
-/**
- * Array of policies.
- */
-const static struct ANASTASIS_Policy **policy_arr;
-
-/**
- * The length of the #tus_arr array.
- */
-static unsigned int policy_arr_length = 0;
-
-
-/**
- * Initialize data for #ANASTASIS_truth_upload.
- *
- * @param state actual state to extract truth information from.
- * @return json containing truth information
- */
-static json_t *
-initialize_truths (json_t *state)
-{
-  size_t policy_index;
-  json_t *policy;
-  json_t *truths = json_array ();
-
-  GNUNET_assert (json_is_array (truths));
-  json_t *authentication_methods =
-    json_object_get (state,
-                     "authentication_methods");
-
-  GNUNET_assert (json_is_array (authentication_methods));
-  json_t *provider_methods = json_object_get (state,
-                                              "authentication_providers");
-
-  GNUNET_assert (NULL != provider_methods);
-  json_t *policy_json_array = json_object_get (state,
-                                               "policies");
-
-  GNUNET_assert (json_is_array (policy_json_array));
-  json_array_foreach (policy_json_array, policy_index, policy)
-  {
-    size_t index;
-    json_t *policy_method;
-    json_t *policy_methods = json_object_get (policy,
-                                              "methods");
-
-    GNUNET_assert (json_is_array (policy_methods));
-    json_array_foreach (policy_methods, index, policy_method)
-    {
-      const char *instructions;
-      const char *mime_type;
-      const char *backend_url;
-      const char *backend_salt;
-      size_t provider_index;
-      size_t check_index;
-      json_t *check_truth;
-      json_t *supported_provider;
-      size_t auth_method_index = json_integer_value (
-        json_object_get (policy_method,
-                         "authentication_method"));
-      json_t *auth_method = json_array_get (authentication_methods,
-                                            auth_method_index);
-      GNUNET_assert (NULL != auth_method);
-      const char *method = json_string_value (json_object_get (auth_method,
-                                                               "method"));
-      json_t *truth_data = json_object_get (auth_method,
-                                            "data");
-      const char *backend_id = json_string_value (json_object_get (
-                                                    policy_method,
-                                                    "provider"));
-      json_t *supported_providers = json_object_get (provider_methods,
-                                                     method);
-
-      GNUNET_assert (json_is_array (supported_providers));
-      json_array_foreach (supported_providers, provider_index,
-                          supported_provider)
-      {
-        json_t *provider_data =
-          json_object_get (supported_provider,
-                           backend_id);
-
-        if (NULL != provider_data)
-        {
-          backend_url = json_string_value (
-            json_object_get (provider_data,
-                             "provider_url"));
-          backend_salt = json_string_value (
-            json_object_get (provider_data,
-                             "provider_salt"));
-          break;
-        }
-      }
-      GNUNET_assert (NULL != backend_url);
-      GNUNET_assert (NULL != backend_salt);
-
-      if (0 == strcmp (method, "question"))
-      {
-        instructions = json_string_value (json_object_get (truth_data,
-                                                           "question"));
-        mime_type = "text";
-      }
-      else if (0 == strcmp (method, "sms"))
-      {
-        instructions = "Please look at your phone.";
-        mime_type = "text";
-      }
-      else if (0 == strcmp (method, "email"))
-      {
-        instructions = "Please look at your emails.";
-        mime_type = "text";
-      }
-      else if (0 == strcmp (method, "post"))
-      {
-        instructions = "Please look into your post box.";
-        mime_type = "text";
-      }
-      else if (0 == strcmp (method, "video"))
-      {
-        instructions = "Please look into the camera.";
-        mime_type = "image";
-      }
-      else
-      {
-        GNUNET_break (0);
-        return NULL;
-      }
-      json_t *truth = json_pack ("{s:I, s:s, s:s, s:s, s:o, s:s, s:s, s:s}",
-                                 "auth_method_index",
-                                 (json_int_t) auth_method_index,
-                                 "backend_url",
-                                 backend_url,
-                                 "backend_id",
-                                 backend_id,
-                                 "method",
-                                 method,
-                                 "truth_data",
-                                 truth_data,
-                                 "instructions",
-                                 instructions,
-                                 "mime_type",
-                                 mime_type,
-                                 "backend_salt",
-                                 backend_salt);
-
-      // check if truths allready contains this truth
-      bool existing = false;
-      json_array_foreach (truths, check_index, check_truth)
-      {
-        if (1 == json_equal (truth, check_truth))
-        {
-          existing = true;
-          break;
-        }
-      }
-      if (! existing)
-        GNUNET_assert (0 == json_array_append_new (truths, truth));
-    }
-  }
-  return truths;
-}
-
-
-/**
- * Check if all uploads have response code 204 or 402.
- *
- * @param uploads json object representing uploads (truth, recovery document)
- * @param pass if true, all response codes must be 204 to return true
- * @return true if all response codes are 204 or 402, else false
- */
-static bool
-check_uploads (json_t *uploads,
-               bool pass)
-{
-  GNUNET_assert (json_is_object (uploads));
-  const char *key;
-  json_t *value;
-
-  json_object_foreach (uploads, key, value)
-  {
-    int status = json_integer_value (json_object_get (value,
-                                                      "status"));
-    if (pass && (status != MHD_HTTP_NO_CONTENT))
-      return false;
-    if ((status != MHD_HTTP_NO_CONTENT) &&
-        (status != MHD_HTTP_PAYMENT_REQUIRED) )
-      return false;
-  }
-  return true;
-}
-
-
-/**
- * Initialize payment details array.
- *
- * @param state state to operate on
- * @param pds[OUT] payment details array
- */
-static unsigned int
-initialize_payment_details (json_t *state,
-                            struct ANASTASIS_PaymentDetails **pds)
-{
-  const char *upload_key;
-  json_t *upload_value;
-  json_t *rec_doc_uploads = json_object_get (state,
-                                             "recovery_document_uploads");
-  unsigned int pds_len = 0;
-
-  if (json_is_object (rec_doc_uploads))
-  {
-    json_object_foreach (rec_doc_uploads, upload_key, upload_value)
-    {
-      struct ANASTASIS_PaymentDetails p_details;
-
-      const char *pay_uri = json_string_value (
-        json_object_get (upload_value,
-                         "pay_url"));
-      const char *provider_url = json_string_value (
-        json_object_get (upload_value,
-                         "provider_url"));
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "At %s:%d Pay URI is: %s\n",
-                  __FILE__,
-                  __LINE__,
-                  pay_uri);
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "At %s:%d Provider URL is: %s\n",
-                  __FILE__,
-                  __LINE__,
-                  provider_url);
-      if ((NULL != pay_uri) &&
-          (NULL != provider_url))
-      {
-        struct TALER_MERCHANT_PayUriData pd;
-
-        if (GNUNET_OK !=
-            TALER_MERCHANT_parse_pay_uri (pay_uri,
-                                          &pd))
-        {
-          GNUNET_break (0);
-          return 0;
-        }
-        if (GNUNET_OK !=
-            GNUNET_STRINGS_string_to_data (pd.order_id,
-                                           strlen (pd.order_id),
-                                           &p_details.payment_secret,
-                                           sizeof (struct
-                                                   ANASTASIS_PaymentSecretP)))
-        {
-          GNUNET_break (0);
-          TALER_MERCHANT_parse_pay_uri_free (&pd);
-          return 0;
-        }
-        p_details.provider_url = GNUNET_strdup (provider_url);
-        TALER_MERCHANT_parse_pay_uri_free (&pd);
-        GNUNET_array_append (*pds,
-                             pds_len,
-                             p_details);
-      }
-    }
-  }
-  return pds_len;
-}
-
-
-// FIXME: this function should die
-static const char *
-get_provider_url_from_id (const char *id,
-                          json_t *state)
-{
-  const char *key;
-  json_t *method;
-  json_t *methods = json_object_get (state,
-                                     "authentication_providers");
-
-  json_object_foreach (methods, key, method)
-  {
-    GNUNET_assert (json_is_array (method));
-    json_t *method_data;
-    size_t index;
-
-    json_array_foreach (method, index, method_data)
-    {
-      json_t *provider_id = json_object_get (method_data, id);
-      if (NULL == provider_id)
-        continue;
-
-      const char *url = json_string_value (json_object_get (provider_id,
-                                                            "provider_url"));
-      return url;
-    }
-  }
-  return NULL;
-}
-
-
-/**
- * Initialize policies for recovery document.
- *
- * @param state json state to operate on
- * @param provider_ids if not NULL only policies for the providers set here 
are initialized
- */
-static void
-initialize_policies (json_t *state,
-                     json_t *provider_ids)
-{
-  size_t p_index;
-  json_t *rec_doc_uploads;
-  json_t *truth_uploads;
-  json_t *json_policy;
-  json_t *json_policies;
-
-  json_policies = json_object_get (state,
-                                   "policies");
-  GNUNET_assert (json_is_array (json_policies));
-  truth_uploads = json_object_get (state,
-                                   "truth_uploads");
-  GNUNET_assert (json_is_object (truth_uploads));
-  rec_doc_uploads = json_object_get (state,
-                                     "recovery_document_uploads");
-  if (NULL == rec_doc_uploads)
-    rec_doc_uploads = json_object ();
-  GNUNET_assert (json_is_object (rec_doc_uploads));
-
-  json_array_foreach (json_policies, p_index, json_policy)
-  {
-    size_t index;
-    unsigned int truth_index = 0;
-    json_t *auth_method;
-    json_t *auth_method_arr = json_object_get (json_policy,
-                                               "methods");
-    const struct ANASTASIS_Truth *truths[json_array_size (auth_method_arr)];
-
-    json_array_foreach (auth_method_arr,
-                        index,
-                        auth_method)
-    {
-      json_t *provider_id = json_object_get (auth_method,
-                                             "provider");
-      // initialize policies to upload recovery document just to
-      // specified providers
-      if (NULL != provider_ids)
-      {
-        size_t ids_index;
-        json_t *id;
-        bool provider_match = false;
-
-        GNUNET_assert (json_is_array (provider_ids));
-        json_array_foreach (provider_ids, ids_index, id)
-        {
-          if (1 == json_equal (provider_id, id))
-          {
-            provider_match = true;
-            break;
-          }
-        }
-        if (! provider_match)
-          continue;
-      }
-
-#if FIXME_LOGIC
-      const char *tu_key;
-      json_t *tu_value;
-      unsigned int auth_method_index = json_integer_value (json_object_get (
-                                                             auth_method,
-                                                             
"authentication_method"));
-      json_object_foreach (truth_uploads, tu_key, tu_value)
-      {
-        json_t *json_truth
-          = json_array_get (json_object_get (state, "truths"),
-                            atoi (tu_key));
-        if (json_integer_value (
-              json_object_get (json_truth, "auth_method_index"))
-            == auth_method_index)
-        {
-          truths[truth_index] = ANASTASIS_truth_from_json (
-            json_object_get (tu_value,
-                             "truth"));
-          truth_index++;
-          break;
-        }
-      }
-#endif
-      {
-        // initialize recovery document uploads array
-        bool existing = false;
-        const char *upload_key;
-        json_t *upload_value;
-
-        if (0 < json_object_size (rec_doc_uploads))
-        {
-          json_object_foreach (rec_doc_uploads, upload_key, upload_value)
-          {
-            if (1 == json_equal (provider_id, json_string (upload_key)))
-            {
-              existing = true;
-              break;
-            }
-          }
-        }
-
-        if (! existing)
-        {
-          const char *id = json_string_value (provider_id);
-          const char *provider_url = get_provider_url_from_id (id,
-                                                               state);
-          GNUNET_assert (0 ==
-                         json_object_set (rec_doc_uploads,
-                                          id,
-                                          json_pack ("{s:I, s:s}",
-                                                     "status",
-                                                     (json_int_t) 0,
-                                                     "provider_url",
-                                                     provider_url)));
-        }
-      }
-    }
-
-    if (NULL == json_object_get (state,
-                                 "recovery_document_uploads"))
-      GNUNET_assert (
-        0 == json_object_set (state,
-                              "recovery_document_uploads",
-                              rec_doc_uploads));
-
-    GNUNET_array_append (policy_arr,
-                         policy_arr_length,
-                         ANASTASIS_policy_create (truths,
-                                                  truth_index));
-  }
-}
-
-
-#if 0
-/**
- * Function called for payment routine for secret sharing.
- *
- * @param cls closure
- * @param taler_pay_url url for the payment (taler://pay/Foo)
- * @param server_url url of the server to pay for
- * @param ec status of the request
- */
-static void
-secret_share_payment_cb (void *cls,
-                         const char *taler_pay_url,
-                         const char *server_url,
-                         enum TALER_ErrorCode ec)
-{
-  struct SecretShareState *sss = cls;
-  const char *upload_key;
-  json_t *upload_value;
-  json_t *rec_doc_uploads = json_object_get (sss->state,
-                                             "recovery_document_uploads");
-
-  GNUNET_assert (json_is_object (rec_doc_uploads));
-  sss->sso = NULL;
-
-  json_object_foreach (rec_doc_uploads, upload_key, upload_value)
-  {
-    const char *url = json_string_value (
-      json_object_get (upload_value,
-                       "provider_url"));
-    if (0 == strcmp (url, server_url))
-    {
-      GNUNET_assert (0 ==
-                     json_object_set (upload_value,
-                                      "status",
-                                      json_integer (
-                                        (json_int_t) 
MHD_HTTP_PAYMENT_REQUIRED)));
-      GNUNET_assert (0 ==
-                     json_object_set (upload_value,
-                                      "pay_url",
-                                      json_string (taler_pay_url)));
-      break;
-    }
-  }
-
-  struct TALER_MERCHANT_PayUriData pd;
-
-  if (GNUNET_OK !=
-      TALER_MERCHANT_parse_pay_uri (taler_pay_url,
-                                    &pd))
-  {
-    GNUNET_break (0);
-    return;
-  }
-  sss->payment_order_id = GNUNET_strdup (pd.order_id);
-  TALER_MERCHANT_parse_pay_uri_free (&pd);
-  set_state (sss->state,
-             ANASTASIS_BACKUP_STATE_POLICIES_PAYING);
-  if (check_uploads (rec_doc_uploads, false))
-  {
-    sss->cb (sss->cb_cls,
-             TALER_EC_NONE,
-             sss->state);
-    sss->cb = NULL;
-  }
-  // FIXME: payment
-}
-
-
-#endif
-
-
-/**
- * Function called with the results of an #ANASTASIS_secret_share().
- *
- * @param cls closure
- * @param sr result of the operation
- */
-static void
-secret_share_result_cb (void *cls,
-                        const struct ANASTASIS_ShareResult *sr)
-{
-  struct SecretShareState *sss = cls;
-  json_t *rec_doc_uploads = json_object_get (sss->state,
-                                             "recovery_document_uploads");
-
-  sss->sso = NULL;
-  GNUNET_assert (json_is_object (rec_doc_uploads));
-#if 0
-  const char *upload_key;
-  json_t *upload_value;
-  json_object_foreach (rec_doc_uploads,
-                       upload_key,
-                       upload_value)
-  {
-    const char *url = json_string_value (
-      json_object_get (upload_value,
-                       "provider_url"));
-    if (0 == strcmp (url, server_url))
-    {
-      GNUNET_assert (0 ==
-                     json_object_set (upload_value,
-                                      "status",
-                                      json_integer ((json_int_t) 
http_status)));
-      break;
-    }
-  }
-
-  if (NULL != sss)
-  {
-    if (http_status == sss->http_status)
-    {
-      if (check_uploads (rec_doc_uploads, true))
-      {
-        set_state (sss->state,
-                   ANASTASIS_BACKUP_STATE_BACKUP_FINISHED);
-        sss->cb (sss->cb_cls,
-                 TALER_EC_NONE,
-                 sss->state);
-        sss->cb = NULL;
-        return;
-      }
-      if (check_uploads (rec_doc_uploads, false))
-      {
-        sss->cb (sss->cb_cls,
-                 TALER_EC_NONE,
-                 sss->state);
-        return;
-      }
-    }
-
-    json_t *error = json_pack ("{s:I, s:s}",
-                               "code",
-                               (json_int_t) ec,
-                               "hint",
-                               "Unexpected response code!");
-    sss->cb (sss->cb_cls,
-             TALER_EC_ANASTASIS_REDUCER_BACKEND_FAILURE,
-             error);
-    sss->cb = NULL;
-    return;
-  }
-#endif
-  GNUNET_break (0);
-}
-
-
-/**
- * Function to free a #SecretShareState.
- *
- * @param cls closure for a #SecretShareState.
- */
-static void
-free_enter_secret (void *cls)
-{
-  struct SecretShareState *sss = cls;
-  for (unsigned int i = 0; i < tus_arr_length; i++)
-  {
-    if (NULL != tus_arr[i]->tuo)
-    {
-      ANASTASIS_truth_upload_cancel (tus_arr[i]->tuo);
-      tus_arr[i]->tuo = NULL;
-    }
-    GNUNET_free (tus_arr[i]);
-  }
-  ANASTASIS_secret_share_cancel (sss->sso);
-  sss->sso = NULL;
-  GNUNET_free (sss);
-}
-
-
-/**
- * Upload recovery documents.
- *
- * @param state json state to operate on
- * @param provider_ids ids of providers to upload recovery document explicitly 
to
- * @param cb callback to call during/after operation
- * @param cb_cls callback closure
- */
-static void
-upload_rec_documents (json_t *state,
-                      json_t *provider_ids,
-                      ANASTASIS_ActionCallback cb,
-                      void *cb_cls)
-{
-  if (0 == policy_arr_length)
-  {
-    initialize_policies (state,
-                         provider_ids);
-  }
-  struct SecretShareState *sss = GNUNET_new (struct SecretShareState);
-  unsigned int pds_len;
-  struct ANASTASIS_PaymentDetails *pds = NULL;
-
-  sss->cb = cb;
-  sss->cb_cls = cb_cls;
-  sss->http_status = MHD_HTTP_NO_CONTENT;
-
-  GNUNET_assert (NULL !=
-                 (sss->id_data = json_object_get (state,
-                                                  "identity_attributes")));
-  GNUNET_assert (NULL !=
-                 (sss->core_secret = json_object_get (state,
-                                                      "core_secret")));
-  json_t *core_secret = json_object_get (state,
-                                         "core_secret");
-  const char *secret_type = json_string_value (
-    json_object_get (core_secret,
-                     "type"));
-  if (0 == strcmp (secret_type, "password"))
-  {
-    sss->core_secret = json_string_value (
-      json_object_get (core_secret,
-                       "secret"));
-    sss->core_secret_size = strlen (sss->core_secret);
-  }
-  else
-  {
-    const char *string_secret = json_string_value (
-      json_object_get (core_secret,
-                       "secret"));
-    sss->core_secret_size = (size_t) json_integer_value (
-      json_object_get (core_secret,
-                       "size"));
-    GNUNET_STRINGS_string_to_data (string_secret,
-                                   strlen (string_secret),
-                                   (void *) sss->core_secret,
-                                   sss->core_secret_size);
-  }
-
-  pds_len = initialize_payment_details (state,
-                                        &pds);
-
-  sss->state = json_incref (state);
-  // FIXME: implement PaymentDetails
-  sss->sso = ANASTASIS_secret_share (ANASTASIS_REDUX_ctx_,
-                                     sss->id_data,
-                                     policy_arr,
-                                     policy_arr_length,
-                                     pds,
-                                     pds_len,
-                                     false, /* do not insist on payment */
-                                     &secret_share_result_cb,
-                                     sss,
-                                     sss->core_secret,
-                                     sss->core_secret_size);
-  if (NULL == sss->sso)
-  {
-    GNUNET_break (0);
-    return;
-  }
-  {
-    ra = GNUNET_new (struct ANASTASIS_ReduxAction);
-    ra->cleanup_cls = sss;
-    ra->cleanup = free_enter_secret;
-  }
-}
-
-
-/**
- * Upload information
- * caller MUST free 't' using ANASTASIS_truth_free()
- *
- * @param cls closure for callback
- * @param ec status code of the request (success, failure, payment required)
- * @param t Truth object (contains provider url and truth public key)
- * @param ud upload details, useful to continue in case of errors, NULL on 
success
- */
-static void
-truth_upload_cb (void *cls,
-                 enum TALER_ErrorCode ec,
-                 struct ANASTASIS_Truth *t,
-                 const struct ANASTASIS_UploadDetails *ud)
-{
-  struct TruthUploadState *tus = cls;
-  json_t *truth_uploads;
-
-  tus->tuo = NULL;
-  if (NULL == t)
-  {
-    char buf[13];
-    json_t *truth_uploads;
-    json_t *p;
-
-    truth_uploads = json_object_get (tus->state,
-                                     "truth_uploads");
-    p = json_pack ("{s:I,s:s}",
-                   "status",
-                   (json_int_t) MHD_HTTP_PAYMENT_REQUIRED,
-                   "pay_url",
-                   ud->details.payment.payment_request);
-    GNUNET_assert (NULL != p);
-    {
-      GNUNET_snprintf (buf,
-                       sizeof (buf),
-                       "%u",
-                       tus->index);
-      GNUNET_assert (0 ==
-                     json_object_set (truth_uploads,
-                                      buf,
-                                      p));
-
-    }
-    set_state (tus->state,
-               ANASTASIS_BACKUP_STATE_POLICIES_PAYING);
-    tus->cb (tus->cb_cls,
-             TALER_EC_NONE,
-             tus->state);
-    tus->cb = NULL;
-    return;
-  }
-  tus->truth = t;
-  truth_uploads = json_object_get (tus->state,
-                                   "truth_uploads");
-#if FIXME_LOGIC
-  json_t *j;
-  j = ANASTASIS_truth_to_json (tus->truth);
-  GNUNET_assert (NULL != j);
-  p = json_pack ("{s:I,s:o}",
-                 "status",
-                 (json_int_t) MHD_HTTP_NO_CONTENT,
-                 "truth",
-                 j);
-  GNUNET_assert (NULL != p);
-#endif
-  {
-    char buf[13];
-
-    GNUNET_snprintf (buf,
-                     sizeof (buf),
-                     "%u",
-                     tus->index);
-    GNUNET_assert (0 ==
-                   json_object_set (truth_uploads,
-                                    buf,
-                                    /* WAS: p */ NULL));
-  }
-
-  if (check_uploads (truth_uploads, true) &&
-      (json_array_size (
-         json_object_get (tus->state, "truths"))
-       == (size_t) tus_arr_length))
-  {
-    // try uploading recovery document
-    upload_rec_documents (tus->state,
-                          NULL,
-                          tus->cb,
-                          tus->cb_cls);
-  }
-}
-
-
-/**
- * Function to upload truths and recovery document policies.
- *
- * @param state state to operate on
- * @param truth_indices indices of truths to upload explicitly
- * @param cb callback (#ANASTASIS_ActionCallback) to call after upload
- * @param cb_cls callback closure
- */
-static struct ANASTASIS_ReduxAction *
-upload (json_t *state,
-        ANASTASIS_ActionCallback cb,
-        void *cb_cls)
-{
-  size_t truth_index;
-  size_t truth_indices_size;
-  json_t *truth;
-  json_t *truths = json_object_get (state,
-                                    "truths");
-
-  GNUNET_assert (json_is_array (truths));
-  json_t *truth_uploads = json_object_get (state,
-                                           "truth_uploads");
-  GNUNET_assert (json_is_object (truth_uploads));
-  size_t truth_uploads_size = json_object_size (truth_uploads);
-  size_t truths_size = json_array_size (truths);
-
-  if (NULL != truth_indices)
-    truth_indices_size = json_array_size (truth_indices);
-
-  if (truth_uploads_size == truths_size)
-  {
-    if (! check_uploads (truth_uploads, true))
-    {
-      json_array_foreach (truths, truth_index, truth)
-      {
-        for (unsigned int i = 0; i < tus_arr_length; i++)
-        {
-          if (truth_index == tus_arr[i]->index)
-          {
-            tus_arr[i]->tuo = ANASTASIS_truth_upload (
-              ANASTASIS_REDUX_ctx_,
-              &tus_arr[i]->user_id,
-              tus_arr[i]->anastasis_url,
-              tus_arr[i]->method,
-              tus_arr[i]->instructions,
-              tus_arr[i]->mime_type,
-              &tus_arr[i]->backend_salt,
-              tus_arr[i]->truth_data,
-              tus_arr[i]->truth_data_size,
-              false,
-              NULL,
-              &truth_upload_cb,
-              tus_arr[i]);
-            if (NULL == tus_arr[i]->tuo)
-            {
-              GNUNET_break (0);
-              return;
-            }
-            break;
-          }
-        }
-      }
-    }
-    return;
-  }
-  else if ((NULL != truth_indices) &&
-           (truth_indices_size != truths_size))
-  {
-    GNUNET_assert (json_is_array (truth_indices));
-
-    json_array_foreach (truth_indices, truth_index, truth)
-    {
-      for (unsigned int i = 0; i < truths_size; i++)
-      {
-        if ((int) json_integer_value (truth) == tus_arr[i]->index)
-        {
-          tus_arr[i]->tuo = ANASTASIS_truth_upload (ANASTASIS_REDUX_ctx_,
-                                                    &tus_arr[i]->user_id,
-                                                    tus_arr[i]->anastasis_url,
-                                                    tus_arr[i]->method,
-                                                    tus_arr[i]->instructions,
-                                                    tus_arr[i]->mime_type,
-                                                    &tus_arr[i]->backend_salt,
-                                                    tus_arr[i]->truth_data,
-                                                    
tus_arr[i]->truth_data_size,
-                                                    false,
-                                                    NULL,
-                                                    &truth_upload_cb,
-                                                    tus_arr[i]);
-          if (NULL == tus_arr[i]->tuo)
-          {
-            GNUNET_break (0);
-            return;
-          }
-          break;
-        }
-      }
-    }
-  }
-  else
-  {
-    // first run or full retry
-    if (0 != tus_arr_length)
-    {
-      for (unsigned int i = 0; i < tus_arr_length; i++)
-      {
-        if (NULL != tus_arr[i]->tuo)
-        {
-          ANASTASIS_truth_upload_cancel (tus_arr[i]->tuo);
-          tus_arr[i]->tuo = NULL;
-        }
-        GNUNET_free (tus_arr[i]);
-      }
-      tus_arr_length = 0;
-    }
-    if (0 != truth_uploads_size)
-    {
-      GNUNET_assert (0 ==
-                     json_object_del (state,
-                                      "truth_uploads"));
-    }
-    json_array_foreach (truths, truth_index, truth)
-    {
-      struct TruthUploadState *tus = GNUNET_new (struct TruthUploadState);
-      tus->anastasis_url = json_string_value (json_object_get (truth,
-                                                               "backend_url"));
-      tus->state = json_incref (state);
-      tus->method = json_string_value (json_object_get (truth,
-                                                        "method"));
-      tus->instructions = json_string_value (json_object_get (truth,
-                                                              "instructions"));
-      tus->mime_type = json_string_value (json_object_get (truth,
-                                                           "mime_type"));
-      const char *salt_str = json_string_value (json_object_get (truth,
-                                                                 
"backend_salt"));
-      GNUNET_STRINGS_string_to_data (salt_str,
-                                     strlen (salt_str),
-                                     &tus->backend_salt,
-                                     sizeof (struct ANASTASIS_CRYPTO_PowSalt));
-      tus->id_data = json_object_get (state,
-                                      "identity_attributes");
-      tus->index = truth_index;
-      tus->cb = cb;
-      tus->cb_cls = cb_cls;
-
-      if (0 == strcmp ("question", tus->method))
-      {
-        json_t *truth_data = json_object_get (truth,
-                                              "truth_data");
-        // FIXME: hash secure question or salt into truth_data?
-        tus->truth_data = json_string_value (json_object_get (truth_data,
-                                                              "answer"));
-        tus->truth_data_size = strlen (tus->truth_data);
-      }
-      // FIXME: other method types
-      ANASTASIS_CRYPTO_user_identifier_derive (tus->id_data,
-                                               &tus->backend_salt,
-                                               &tus->user_id);
-      GNUNET_array_append (tus_arr,
-                           tus_arr_length,
-                           tus);
-      tus->tuo = ANASTASIS_truth_upload (ANASTASIS_REDUX_ctx_,
-                                         &tus->user_id,
-                                         tus->anastasis_url,
-                                         tus->method,
-                                         tus->instructions,
-                                         tus->mime_type,
-                                         &tus->backend_salt,
-                                         tus->truth_data,
-                                         tus->truth_data_size,
-                                         false,
-                                         NULL,
-                                         &truth_upload_cb,
-                                         tus);
-      if (NULL == tus->tuo)
-      {
-        GNUNET_break (0);
-        return;
-      }
-    }
-  }
-}
-
-
-#endif
-// GRAVEYARD
-
-///////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////
-
-
 /**
  * Information we keep for an upload() operation.
  */
@@ -2537,13 +1374,18 @@ upload_cancel_cb (void *cls)
 
 
 /**
- * All truth uploads are done, begin with uploading the policy.
+ * Function called with the results of a #ANASTASIS_secret_share().
  *
- * @param[in,out] uc context for the operation
+ * @param cls closure with a `struct UploadContext *`
+ * @param sr share result
  */
 static void
-share_secret (struct UploadContext *uc)
+secret_share_result_cb (void *cls,
+                        const struct ANASTASIS_ShareResult *sr)
 {
+  struct UploadContext *uc = cls;
+
+  uc->ss = NULL;
   GNUNET_break (0); // FIXME: not implemented
   uc->cb (uc->cb_cls,
           TALER_EC_INVALID,
@@ -2552,6 +1394,121 @@ share_secret (struct UploadContext *uc)
 }
 
 
+/**
+ * All truth uploads are done, begin with uploading the policy.
+ *
+ * @param[in,out] uc context for the operation
+ */
+static void
+share_secret (struct UploadContext *uc)
+{
+  json_t *user_id;
+  size_t core_secret_size;
+  void *core_secret;
+  json_t *policies;
+  json_t *payments = NULL;
+  unsigned int policies_len;
+  unsigned int pds_len;
+  struct GNUNET_JSON_Specification spec[] = {
+    GNUNET_JSON_spec_json ("identity_attributes",
+                           &user_id),
+    GNUNET_JSON_spec_json ("policies",
+                           &policies),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_json ("policy_payments",
+                             &payments)),
+    GNUNET_JSON_spec_varsize ("core_secret",
+                              &core_secret,
+                              &core_secret_size),
+    GNUNET_JSON_spec_end ()
+  };
+
+  if (GNUNET_OK !=
+      GNUNET_JSON_parse (uc->state,
+                         spec,
+                         NULL, NULL))
+  {
+    GNUNET_break (0);
+    uc->cb (uc->cb_cls,
+            TALER_EC_INVALID,
+            NULL);
+    upload_cancel_cb (uc);
+    return;
+  }
+
+  if ( (! json_is_object (user_id)) ||
+       (! json_is_array (policies)) ||
+       (0 == json_array_size (policies)) ||
+       ( (NULL != payments) &&
+         (! json_is_array (payments)) ) )
+  {
+    GNUNET_break (0);
+    uc->cb (uc->cb_cls,
+            TALER_EC_INVALID,
+            NULL);
+    GNUNET_JSON_parse_free (spec);
+    upload_cancel_cb (uc);
+    return;
+  }
+  policies_len = json_array_size (policies);
+  pds_len = json_array_size (payments);
+
+  {
+    struct ANASTASIS_Policy *vpolicies[policies_len];
+    const struct ANASTASIS_Policy *policies[policies_len];
+    struct ANASTASIS_PaymentDetails pds[GNUNET_NZL (pds_len)];
+
+    for (unsigned int i = 0; i<policies_len; i++)
+    {
+      unsigned int truths_len;
+      json_t *jtruths;
+
+      jtruths = NULL;
+      truths_len = 42; // FIXME
+      // FIXME: initialize truths/truths_len
+      {
+        struct ANASTASIS_Policy *p;
+        const struct ANASTASIS_Truth *truths[truths_len];
+
+        for (unsigned int j = 0; j<truths_len; j++)
+        {
+          truths[j] = NULL; // FIXME!
+        }
+        p = ANASTASIS_policy_create (truths,
+                                     truths_len);
+        vpolicies[i] = p;
+        policies[i] = p;
+      }
+    }
+    // FIXME: initialize pds
+
+    uc->ss = ANASTASIS_secret_share (ANASTASIS_REDUX_ctx_,
+                                     user_id,
+                                     policies,
+                                     policies_len,
+                                     pds,
+                                     pds_len,
+                                     false, /* do not insist on payment */
+                                     &secret_share_result_cb,
+                                     uc,
+                                     core_secret,
+                                     core_secret_size);
+    for (unsigned int i = 0; i<policies_len; i++)
+      ANASTASIS_policy_destroy (vpolicies[i]);
+  }
+  GNUNET_JSON_parse_free (spec);
+  if (NULL == uc->ss)
+  {
+    GNUNET_break (0);
+    uc->cb (uc->cb_cls,
+            TALER_EC_INVALID,
+            NULL);
+    upload_cancel_cb (uc);
+    return;
+  }
+}
+
+
 /**
  * Some truth uploads require payment, serialize state and
  * request payment to be executed by the application.

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