gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: fix truth upload resumption if


From: gnunet
Subject: [taler-anastasis] branch master updated: fix truth upload resumption if payment is required
Date: Tue, 16 Mar 2021 22:01:14 +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 748cd1a  fix truth upload resumption if payment is required
748cd1a is described below

commit 748cd1ac2ca2fef5ff7c652a74f5cc4ce7c01e48
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Tue Mar 16 22:01:11 2021 +0100

    fix truth upload resumption if payment is required
---
 src/backend/anastasis-httpd_policy_upload.c |  23 ++++--
 src/include/anastasis.h                     |  47 ++++++++++-
 src/lib/anastasis_backup.c                  | 117 ++++++++++++++++++----------
 src/reducer/anastasis_api_backup_redux.c    | 107 +++++++++++++++++++------
 src/testing/testing_cmd_truth_upload.c      |   1 -
 5 files changed, 221 insertions(+), 74 deletions(-)

diff --git a/src/backend/anastasis-httpd_policy_upload.c 
b/src/backend/anastasis-httpd_policy_upload.c
index f85d77f..cc07d3b 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -511,7 +511,7 @@ await_payment (struct PolicyUploadContext *puc)
 
     order_id = GNUNET_STRINGS_data_to_string_alloc (
       &puc->payment_identifier,
-      sizeof (puc->payment_identifier));
+      sizeof(struct ANASTASIS_PaymentSecretP));
     puc->cpo = TALER_MERCHANT_merchant_order_get (AH_ctx,
                                                   AH_backend_url,
                                                   order_id,
@@ -619,6 +619,7 @@ prepare_payment (struct PolicyUploadContext *puc)
       GNUNET_CRYPTO_QUALITY_NONCE,
       &puc->payment_identifier,
       sizeof (struct ANASTASIS_PaymentSecretP));
+    puc->payment_identifier_provided = true;
     return begin_payment (puc);
   }
   await_payment (puc);
@@ -1034,14 +1035,22 @@ AH_handler_policy_post (
     switch (ss)
     {
     case ANASTASIS_DB_STORE_STATUS_STORE_LIMIT_EXCEEDED:
-      GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
-                                  &puc->payment_identifier,
-                                  sizeof (struct ANASTASIS_PaymentSecretP));
+      if (! puc->payment_identifier_provided)
+      {
+        GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
+                                    &puc->payment_identifier,
+                                    sizeof (struct ANASTASIS_PaymentSecretP));
+        puc->payment_identifier_provided = true;
+      }
       return begin_payment (puc);
     case ANASTASIS_DB_STORE_STATUS_PAYMENT_REQUIRED:
-      GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
-                                  &puc->payment_identifier,
-                                  sizeof (struct ANASTASIS_PaymentSecretP));
+      if (! puc->payment_identifier_provided)
+      {
+        GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
+                                    &puc->payment_identifier,
+                                    sizeof (struct ANASTASIS_PaymentSecretP));
+        puc->payment_identifier_provided = true;
+      }
       return begin_payment (puc);
     case ANASTASIS_DB_STORE_STATUS_HARD_ERROR:
     case ANASTASIS_DB_STORE_STATUS_SOFT_ERROR:
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index 81e2547..d6cac02 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -560,13 +560,11 @@ struct ANASTASIS_TruthUpload;
  * Callee MUST free @a 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 to create policies, NULL on failure
  * @param ud upload details, useful to continue in case of errors, NULL on 
success
  */
 typedef void
 (*ANASTASIS_TruthCallback)(void *cls,
-                           enum TALER_ErrorCode ec,
                            struct ANASTASIS_Truth *t,
                            const struct ANASTASIS_UploadDetails *ud);
 
@@ -606,6 +604,51 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
                         ANASTASIS_TruthCallback tc,
                         void *tc_cls);
 
+
+/**
+ * Retries upload of truth data to an escrow provider. The resulting
+ * truth object is returned via the @a tc function. If payment is
+ * required, it is requested via the @a tcp callback.
+ *
+ * @param ctx the CURL context used to connect to the backend
+ * @param user_id user identifier derived from user data and backend salt
+ * @param type defines the type of the challenge (secure question, sms, email)
+ * @param instructions depending on @a type! usually only for security 
question/answer!
+ * @param mime_type format of the challenge
+ * @param provider_salt the providers salt
+ * @param truth_data contains the truth for this challenge i.e. phone number, 
email address
+ * @param truth_data_size size of the data
+ * @param payment_requested true if the client wants to pay more for the 
account now
+ * @param paid_order_id payment identifier of last payment
+ * @param pay_timeout how long to wait for payment
+ * @param uuid truth UUID to use
+ * @param salt salt to use to hash security questions
+ * @param truth_key symmetric encryption key to use to encrypt @a truth_data
+ * @param key_share share of the overall key to store in this truth object
+ * @param tc opens the truth callback which contains the status of the upload
+ * @param tc_cls closure for the callback
+ */
+struct ANASTASIS_TruthUpload *
+ANASTASIS_truth_upload2 (struct GNUNET_CURL_Context *ctx,
+                         const struct ANASTASIS_CRYPTO_UserIdentifierP 
*user_id,
+                         const char *provider_url,
+                         const char *type,
+                         const char *instructions,
+                         const char *mime_type,
+                         const struct ANASTASIS_CRYPTO_PowSalt *provider_salt,
+                         const void *truth_data,
+                         size_t truth_data_size,
+                         bool payment_requested,
+                         const struct ANASTASIS_PaymentSecretP *paid_order_id,
+                         struct GNUNET_TIME_Relative pay_timeout,
+                         const struct ANASTASIS_CRYPTO_TruthUUIDP *uuid,
+                         const struct ANASTASIS_CRYPTO_PowSalt *salt,
+                         const struct ANASTASIS_CRYPTO_TruthKeyP *truth_key,
+                         const struct ANASTASIS_CRYPTO_KeyShareP *key_share,
+                         ANASTASIS_TruthCallback tc,
+                         void *tc_cls);
+
+
 /**
  * Cancels a truth upload process.
  *
diff --git a/src/lib/anastasis_backup.c b/src/lib/anastasis_backup.c
index e6eb272..429a36e 100644
--- a/src/lib/anastasis_backup.c
+++ b/src/lib/anastasis_backup.c
@@ -217,40 +217,33 @@ truth_store_callback (void *cls,
   struct ANASTASIS_TruthUpload *tu = cls;
 
   tu->tso = NULL;
-  if (ANASTASIS_US_SUCCESS == ud->us)
-  {
-    tu->tc (tu->tc_cls,
-            ANASTASIS_US_SUCCESS,
-            tu->t,
-            NULL);
-    tu->t = NULL;
-  }
-  else
-  {
-    tu->tc (tu->tc_cls,
-            ud->us,
-            NULL,
-            ud);
-  }
+  tu->tc (tu->tc_cls,
+          tu->t,
+          ud);
+  tu->t = NULL;
   ANASTASIS_truth_upload_cancel (tu);
 }
 
 
 struct ANASTASIS_TruthUpload *
-ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
-                        const struct ANASTASIS_CRYPTO_UserIdentifierP *user_id,
-                        const char *provider_url,
-                        const char *type,
-                        const char *instructions,
-                        const char *mime_type,
-                        const struct ANASTASIS_CRYPTO_PowSalt *provider_salt,
-                        const void *truth_data,
-                        size_t truth_data_size,
-                        bool payment_requested,
-                        const struct ANASTASIS_PaymentSecretP *paid_order_id,
-                        struct GNUNET_TIME_Relative pay_timeout,
-                        ANASTASIS_TruthCallback tc,
-                        void *tc_cls)
+ANASTASIS_truth_upload2 (struct GNUNET_CURL_Context *ctx,
+                         const struct ANASTASIS_CRYPTO_UserIdentifierP 
*user_id,
+                         const char *provider_url,
+                         const char *type,
+                         const char *instructions,
+                         const char *mime_type,
+                         const struct ANASTASIS_CRYPTO_PowSalt *provider_salt,
+                         const void *truth_data,
+                         size_t truth_data_size,
+                         bool payment_requested,
+                         const struct ANASTASIS_PaymentSecretP *paid_order_id,
+                         struct GNUNET_TIME_Relative pay_timeout,
+                         const struct ANASTASIS_CRYPTO_TruthUUIDP *uuid,
+                         const struct ANASTASIS_CRYPTO_PowSalt *salt,
+                         const struct ANASTASIS_CRYPTO_TruthKeyP *truth_key,
+                         const struct ANASTASIS_CRYPTO_KeyShareP *key_share,
+                         ANASTASIS_TruthCallback tc,
+                         void *tc_cls)
 {
   struct ANASTASIS_TruthUpload *tu;
   struct ANASTASIS_Truth *t;
@@ -276,20 +269,14 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
     ? GNUNET_strdup (mime_type)
     : NULL;
   t->provider_salt = *provider_salt;
-  GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
-                              &t->salt,
-                              sizeof (t->salt));
   tu->t = t;
-  GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
-                              &t->uuid,
-                              sizeof (t->uuid));
-  ANASTASIS_CRYPTO_keyshare_create (&t->key_share);
+  t->salt = *salt;
+  t->uuid = *uuid;
+  t->truth_key = *truth_key;
+  t->key_share = *key_share;
   ANASTASIS_CRYPTO_keyshare_encrypt (&t->key_share,
                                      &tu->id,
                                      &encrypted_key_share);
-  GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
-                              &t->truth_key,
-                              sizeof (t->truth_key));
   if (0 == strcmp ("question",
                    type))
   {
@@ -345,6 +332,58 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
 }
 
 
+struct ANASTASIS_TruthUpload *
+ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
+                        const struct ANASTASIS_CRYPTO_UserIdentifierP *user_id,
+                        const char *provider_url,
+                        const char *type,
+                        const char *instructions,
+                        const char *mime_type,
+                        const struct ANASTASIS_CRYPTO_PowSalt *provider_salt,
+                        const void *truth_data,
+                        size_t truth_data_size,
+                        bool payment_requested,
+                        const struct ANASTASIS_PaymentSecretP *paid_order_id,
+                        struct GNUNET_TIME_Relative pay_timeout,
+                        ANASTASIS_TruthCallback tc,
+                        void *tc_cls)
+{
+  struct ANASTASIS_CRYPTO_PowSalt salt;
+  struct ANASTASIS_CRYPTO_TruthUUIDP uuid;
+  struct ANASTASIS_CRYPTO_TruthKeyP truth_key;
+  struct ANASTASIS_CRYPTO_KeyShareP key_share;
+
+  GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
+                              &salt,
+                              sizeof (salt));
+  GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
+                              &uuid,
+                              sizeof (uuid));
+  GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
+                              &truth_key,
+                              sizeof (truth_key));
+  ANASTASIS_CRYPTO_keyshare_create (&key_share);
+  return ANASTASIS_truth_upload2 (ctx,
+                                  user_id,
+                                  provider_url,
+                                  type,
+                                  instructions,
+                                  mime_type,
+                                  provider_salt,
+                                  truth_data,
+                                  truth_data_size,
+                                  payment_requested,
+                                  paid_order_id,
+                                  pay_timeout,
+                                  &uuid,
+                                  &salt,
+                                  &truth_key,
+                                  &key_share,
+                                  tc,
+                                  tc_cls);
+}
+
+
 void
 ANASTASIS_truth_upload_cancel (struct ANASTASIS_TruthUpload *tu)
 {
diff --git a/src/reducer/anastasis_api_backup_redux.c 
b/src/reducer/anastasis_api_backup_redux.c
index debbbae..ea43203 100644
--- a/src/reducer/anastasis_api_backup_redux.c
+++ b/src/reducer/anastasis_api_backup_redux.c
@@ -1876,13 +1876,11 @@ lookup_salt (const json_t *state,
  * Callee MUST free @a t using ANASTASIS_truth_free().
  *
  * @param cls closure with a `struct TruthUpload`
- * @param ec status code of the request (success, failure, payment required)
  * @param t truth object to create policies, NULL on failure
- * @param ud upload details, useful to continue in case of errors, NULL on 
success
+ * @param ud upload details
  */
 static void
 truth_upload_cb (void *cls,
-                 enum TALER_ErrorCode ec,
                  struct ANASTASIS_Truth *t,
                  const struct ANASTASIS_UploadDetails *ud)
 {
@@ -1890,15 +1888,12 @@ truth_upload_cb (void *cls,
 
   tue->tu = NULL;
   tue->t = t;
-  if (NULL != ud)
+  tue->ec = ud->ec;
+  if (ANASTASIS_US_PAYMENT_REQUIRED == ud->us)
   {
-    tue->ec = ud->ec;
-    if (ANASTASIS_US_PAYMENT_REQUIRED == ud->us)
-    {
-      tue->payment_request = GNUNET_strdup (
-        ud->details.payment.payment_request);
-      tue->ps = ud->details.payment.ps;
-    }
+    tue->payment_request = GNUNET_strdup (
+      ud->details.payment.payment_request);
+    tue->ps = ud->details.payment.ps;
   }
   check_upload_finished (tue->uc);
 }
@@ -2007,6 +2002,7 @@ check_truth_upload (struct UploadContext *uc,
 {
   json_t *user_id;
   struct GNUNET_TIME_Relative timeout = GNUNET_TIME_UNIT_ZERO;
+  json_t *jtruth;
 
   user_id = json_object_get (uc->state,
                              "identity_attributes");
@@ -2057,6 +2053,20 @@ check_truth_upload (struct UploadContext *uc,
     }
   }
 
+  {
+    json_t *policies = json_object_get (uc->state,
+                                        "policies");
+    json_t *policy = json_array_get (policies,
+                                     pmr->policy_index);
+    json_t *methods = json_object_get (policy,
+                                       "methods");
+    json_t *method = json_array_get (methods,
+                                     pmr->method_index);
+
+    jtruth = json_object_get (method,
+                              "truth");
+  }
+
   /* need new upload */
   {
     struct TruthUpload *tue = GNUNET_new (struct TruthUpload);
@@ -2127,22 +2137,69 @@ check_truth_upload (struct UploadContext *uc,
     ANASTASIS_CRYPTO_user_identifier_derive (user_id,
                                              &salt,
                                              &id);
-    tue->tu = ANASTASIS_truth_upload (ANASTASIS_REDUX_ctx_,
-                                      &id,
-                                      provider_url,
-                                      type,
-                                      instructions,
-                                      mime_type,
-                                      &salt,
-                                      truth_data,
-                                      truth_data_size,
-                                      force_payment,
-                                      (NULL != payment_request)
+    {
+      struct ANASTASIS_CRYPTO_TruthUUIDP uuid;
+      struct ANASTASIS_CRYPTO_PowSalt salt;
+      struct ANASTASIS_CRYPTO_TruthKeyP truth_key;
+      struct ANASTASIS_CRYPTO_KeyShareP key_share;
+      struct GNUNET_JSON_Specification jspec[] = {
+        GNUNET_JSON_spec_fixed_auto ("salt",
+                                     &salt),
+        GNUNET_JSON_spec_fixed_auto ("truth_key",
+                                     &truth_key),
+        GNUNET_JSON_spec_fixed_auto ("uuid",
+                                     &uuid),
+        GNUNET_JSON_spec_fixed_auto ("key_share",
+                                     &key_share),
+        GNUNET_JSON_spec_end ()
+      };
+
+      if (GNUNET_OK !=
+          GNUNET_JSON_parse (jtruth,
+                             jspec,
+                             NULL, NULL))
+      {
+        tue->tu = ANASTASIS_truth_upload (ANASTASIS_REDUX_ctx_,
+                                          &id,
+                                          provider_url,
+                                          type,
+                                          instructions,
+                                          mime_type,
+                                          &salt,
+                                          truth_data,
+                                          truth_data_size,
+                                          force_payment,
+                                          (NULL != payment_request)
+                                          ? &tue->ps
+                                          : NULL,
+                                          timeout,
+                                          &truth_upload_cb,
+                                          tue);
+      }
+      else
+      {
+        tue->tu = ANASTASIS_truth_upload2 (ANASTASIS_REDUX_ctx_,
+                                           &id,
+                                           provider_url,
+                                           type,
+                                           instructions,
+                                           mime_type,
+                                           &salt,
+                                           truth_data,
+                                           truth_data_size,
+                                           force_payment,
+                                           (NULL != payment_request)
                                           ? &tue->ps
                                           : NULL,
-                                      timeout,
-                                      &truth_upload_cb,
-                                      tue);
+                                           timeout,
+                                           &uuid,
+                                           &salt,
+                                           &truth_key,
+                                           &key_share,
+                                           &truth_upload_cb,
+                                           tue);
+      }
+    }
     if (NULL == tue->tu)
     {
       GNUNET_break (0);
diff --git a/src/testing/testing_cmd_truth_upload.c 
b/src/testing/testing_cmd_truth_upload.c
index ce34a51..a647c7f 100644
--- a/src/testing/testing_cmd_truth_upload.c
+++ b/src/testing/testing_cmd_truth_upload.c
@@ -131,7 +131,6 @@ struct TruthUploadState
  */
 static void
 truth_upload_cb (void *cls,
-                 enum TALER_ErrorCode ec,
                  struct ANASTASIS_Truth *t,
                  const struct ANASTASIS_UploadDetails *ud)
 {

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