gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: clean up payment secret/order I


From: gnunet
Subject: [taler-anastasis] branch master updated: clean up payment secret/order ID duplication in transmission
Date: Tue, 20 Oct 2020 15:29:40 +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 979f131  clean up payment secret/order ID  duplication in transmission
979f131 is described below

commit 979f131841c33a9acb10af7258a7b5cfd97cf1a5
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Tue Oct 20 15:29:37 2020 +0200

    clean up payment secret/order ID  duplication in transmission
---
 src/backend/anastasis-httpd_policy_upload.c | 107 +++++++++++++++-------------
 src/cli/anastasis-cli-splitter.c            |  22 ++++--
 src/include/anastasis.h                     |   4 +-
 src/include/anastasis_service.h             |   4 +-
 src/lib/anastasis.c                         |  66 +++++++++++------
 src/lib/anastasis_api_policy_store.c        |  19 +++--
 src/lib/testing_api_cmd_policy_store.c      |  44 ++++++++----
 src/lib/testing_cmd_secret_share.c          |  26 +++++--
 8 files changed, 179 insertions(+), 113 deletions(-)

diff --git a/src/backend/anastasis-httpd_policy_upload.c 
b/src/backend/anastasis-httpd_policy_upload.c
index 7830720..39bfd9a 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -151,6 +151,11 @@ struct PolicyUploadContext
    */
   bool make_claim_token;
 
+  /**
+   * true if client provided a payment secret / order ID?
+   */
+  bool payment_identifier_provided;
+
   /**
    * The claim token
    */
@@ -536,10 +541,9 @@ begin_payment (struct PolicyUploadContext *puc,
     return MHD_YES;
   }
 
-  order_id = GNUNET_STRINGS_data_to_string_alloc (&puc->payment_identifier,
-                                                  sizeof(
-                                                    struct
-                                                    ANASTASIS_PaymentSecretP));
+  order_id = GNUNET_STRINGS_data_to_string_alloc (
+    &puc->payment_identifier,
+    sizeof(struct ANASTASIS_PaymentSecretP));
 
   GNUNET_CONTAINER_DLL_insert (puc_head,
                                puc_tail,
@@ -597,38 +601,33 @@ handle_database_error (struct PolicyUploadContext *puc,
                                        "Cannot update, unknown previous 
recovery document");
   case ANASTASIS_DB_STATUS_PAYMENT_REQUIRED:
     {
-      const char *order_id;
-
-      order_id = MHD_lookup_connection_value (puc->con,
-                                              MHD_GET_ARGUMENT_KIND,
-                                              "paying");
-
-      if (NULL == order_id)
+      if (! puc->payment_identifier_provided)
       {
+        GNUNET_CRYPTO_random_block (
+          GNUNET_CRYPTO_QUALITY_NONCE,
+          &puc->payment_identifier,
+          sizeof (struct ANASTASIS_PaymentSecretP));
         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                    "Payment-Identifier generated (before): %s\n",
-                    TALER_B2S (&puc->payment_identifier));
-        // generate new payment identifier
-        GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
-                                    &puc->payment_identifier,
-                                    sizeof (
-                                      struct ANASTASIS_PaymentSecretP));
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                    "Payment-Identifier generated: %s\n",
+                    "Payment-Identifier generated: %s, starting payment 
process\n",
                     TALER_B2S (&puc->payment_identifier));
-
-        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                    "Payment required, starting payment process\n");
         return begin_payment (puc,
                               GNUNET_NO);
       }
 
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                  "Payment required, awaiting completion of `%s'\n",
-                  order_id);
-      await_payment (puc,
-                     CHECK_PAYMENT_TIMEOUT,
-                     order_id);
+      {
+        char *order_id;
+
+        order_id = GNUNET_STRINGS_data_to_string_alloc (
+          &puc->payment_identifier,
+          sizeof (puc->payment_identifier));
+        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                    "Payment required, awaiting completion of `%s'\n",
+                    order_id);
+        await_payment (puc,
+                       CHECK_PAYMENT_TIMEOUT,
+                       order_id);
+        GNUNET_free (order_id);
+      }
     }
     return MHD_YES;
   case ANASTASIS_DB_STATUS_HARD_ERROR:
@@ -683,6 +682,33 @@ AH_handler_policy_post (struct MHD_Connection *connection,
     puc->hc.cc = &cleanup_ctx;
     puc->con = connection;
 
+    {
+      const char *pay_id;
+
+      pay_id = MHD_lookup_connection_value (connection,
+                                            MHD_HEADER_KIND,
+                                            "Payment-Identifier");
+      if (NULL != pay_id)
+      {
+        if (GNUNET_OK !=
+            GNUNET_STRINGS_string_to_data (pay_id,
+                                           strlen (pay_id),
+                                           &puc->payment_identifier,
+                                           sizeof (struct
+                                                   ANASTASIS_PaymentSecretP)))
+        {
+          GNUNET_break_op (0);
+          return TALER_MHD_reply_with_error (connection,
+                                             MHD_HTTP_BAD_REQUEST,
+                                             // FIXME: find error code
+                                             TALER_EC_SYNC_BAD_IF_MATCH,
+                                             "Payment-Identifier does not 
include a base32-encoded Payment-Secret");
+        }
+        puc->payment_identifier_provided = true;
+      }
+    }
+
+
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "At %s:%d handler is policy_post\n", __FILE__, __LINE__);
 
@@ -847,27 +873,8 @@ AH_handler_policy_post (struct MHD_Connection *connection,
     {
       struct GNUNET_HashCode hc;
       enum ANASTASIS_DB_QueryStatus qs;
-      const char *pay_id;
 
-      pay_id = MHD_lookup_connection_value (connection,
-                                            MHD_HEADER_KIND,
-                                            "Payment-Identifier");
-      if (pay_id &&
-          (GNUNET_OK !=
-           GNUNET_STRINGS_string_to_data (pay_id,
-                                          strlen (pay_id),
-                                          &puc->payment_identifier,
-                                          sizeof (struct
-                                                  ANASTASIS_PaymentSecretP))) )
-      {
-        GNUNET_break_op (0);
-        return TALER_MHD_reply_with_error (connection,
-                                           MHD_HTTP_BAD_REQUEST,
-                                           // FIXME: find error code
-                                           TALER_EC_SYNC_BAD_IF_MATCH,
-                                           "Payment-Identifier does not 
include a base32-encoded Payment-Identifier");
-      }
-      if (pay_id)
+      if (puc->payment_identifier_provided)
       {
         // check if payment identifier is valid (existing and paid)
         bool paid;
@@ -904,7 +911,7 @@ AH_handler_policy_post (struct MHD_Connection *connection,
         }
       }
 
-      if (! pay_id)
+      if (! puc->payment_identifier_provided)
       {
         // generate new payment identifier
         GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
diff --git a/src/cli/anastasis-cli-splitter.c b/src/cli/anastasis-cli-splitter.c
index 32c615d..c790e90 100644
--- a/src/cli/anastasis-cli-splitter.c
+++ b/src/cli/anastasis-cli-splitter.c
@@ -1341,7 +1341,19 @@ read_keyboard_command (void *cls)
         if (characters > 1)
         {
           add_history (buffer);
-          pds[i].payment_order_id = GNUNET_strdup (buffer); // FIXME: leaks!
+
+          if (GNUNET_OK !=
+              GNUNET_STRINGS_string_to_data (buffer,
+                                             strlen (buffer),
+                                             &pds[i].payment_secret,
+                                             sizeof (struct
+                                                     
ANASTASIS_PaymentSecretP)))
+          {
+            fprintf (stderr,
+                     "Invalid payment secret entered, please try again\n");
+            i--;
+            continue;
+          }
           free (buffer);
           buffer = (char *) NULL;
         }
@@ -1349,14 +1361,10 @@ read_keyboard_command (void *cls)
          * Shall we even ask for payment secret, if given before? Or shall the 
user have the option
          * to use a different payment secret for second/further 'publish' 
command/s?
         */
-        else
-        {
-          GNUNET_free (pds[i].payment_order_id);
-        }
         printf ("\n");
+        GNUNET_free (pds[i].provider_url); // FIXME: better: shrink array!
       }
-      // FIXME: pds not as global
-      // FIXME: pds content???
+      // FIXME: pds not as global, setup ONLY here
       sss->sso = ANASTASIS_secret_share (ctx,
                                          sss->id_data,
                                          NULL,
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index 587222b..395c4ea 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -38,9 +38,9 @@ struct ANASTASIS_PaymentDetails
   const char *provider_url;
 
   /**
-   * Payment order ID of a past payment
+   * Payment order ID / secret of a past payment.
    */
-  const char *payment_order_id;
+  struct ANASTASIS_PaymentSecretP payment_secret;
 };
 
 
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index afe93a8..fd71456 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -420,7 +420,7 @@ typedef void
  * @param recovery_data policy data to be stored
  * @param recovery_data_size number of bytes in @a recovery_data
  * @param payment_requested #GNUNET_YES if the client wants to pay more for 
the account now
- * @param payment_order_id payment identifier of last payment
+ * @param payment_secret payment secret of last payment, or NULL (corresponds 
to the Taler order ID)
  * @param cb callback processing the response from /policy
  * @param cb_cls closure for cb
  * @return handle for the operation
@@ -434,7 +434,7 @@ ANASTASIS_policy_store (
   const void *recovery_data,
   size_t recovery_data_size,
   int payment_requested,
-  const char *payment_order_id,
+  const struct ANASTASIS_PaymentSecretP *payment_secret,
   ANASTASIS_PolicyStoreCallback cb,
   void *cb_cls);
 
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index d2844f9..5e3dd99 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -32,81 +32,100 @@ struct ANASTASIS_Recovery
 {
   /**
    * Callback to send back a recovery document with the policies and the 
version
-  */
+   */
   ANASTASIS_PolicyCallback pc;
+
   /**
    * closure for the Policy callback
-  */
+   */
   void *pc_cls;
+
   /**
-  * Callback to send back the core secret which was saved by anastasis, after 
all challenges are completed
+   * Callback to send back the core secret which was saved by
+   * anastasis, after all challenges are completed
   */
   ANASTASIS_CoreSecretCallback csc;
+
   /**
-  * Closure for the core secret callback
-  */
+   * Closure for the core secret callback
+   */
   void *csc_cls;
+
   /**
    * Identity key material used for the derivation of keys
-  */
+   */
   struct ANASTASIS_CRYPTO_UserIdentifierP id;
+
   /**
    * Public key for a request
-  */
+   */
   struct ANASTASIS_CRYPTO_AccountPublicKeyP pub_key;
+
   /**
    * Curl context
-  */
+   */
   struct GNUNET_CURL_Context *ctx;
+
   /**
    * Reference to the policy lookup operation which is executed
-  */
+   */
   struct ANASTASIS_PolicyLookupOperation *plo;
+
   /**
-   * encrypted recovery document, only used for the decription
+   * Encrypted recovery document, only used for the decription
    */
   void *encrypted_recovery_document;
+
   /**
-  * size of the ecrypted recovery document
-  */
+   * size of the ecrypted recovery document
+   */
   size_t enc_rec_doc_size;
+
   /**
-  * expected http status
-  */
+   * expected http status
+   */
   unsigned int http_status;
+
   /**
    * expected http status
    */
   unsigned int response_code;
+
   /**
    * retrieved encrypted core secret from policy
    */
   void *enc_core_secret;
+
   /**
    * size of the core secret
    */
   size_t enc_core_secret_size;
+
   /**
    * Length of available decryption policies //FIXME: Copy paste?
    */
   struct ANASTASIS_CRYPTO_PowSalt policy_salt;
+
   /**
    * Length of available decryption policies //FIXME: Copy paste?
    */
   struct ANASTASIS_Challenge *solved_challenges;
+
   /**
    * Length of available decryption policies //FIXME: Copy paste?
    */
   unsigned int solved_challenge_pos;
+
   /**
    * Recovery information which is sent to the user
    */
   struct ANASTASIS_RecoveryInformation *ri;
 };
 
+
 /**
- * Challenge struct contains the nonce and public key's needed for the 
recovery process and a reference to
- * ANASTASIS_Recovery.
+ * Challenge struct contains the nonce and public key's needed for the
+ * recovery process and a reference to ANASTASIS_Recovery.
  */
 struct ANASTASIS_Challenge
 {
@@ -414,6 +433,7 @@ ANASTASIS_get_challenge (struct ANASTASIS_Challenge 
*challenge,
                          ANASTASIS_ChallengeCallback cc)
 {
   struct ANASTASIS_ChallengeInformation *ci;
+
   ci = GNUNET_new (struct ANASTASIS_ChallengeInformation);
   challenge->cc = cc;
   ci->truth_public_key = &challenge->truth_public_key;
@@ -1327,7 +1347,7 @@ struct PolicyStoreState
   /**
    * Payment identifier.
    */
-  struct ANASTASIS_PaymentSecretP payment_id;
+  struct ANASTASIS_PaymentSecretP payment_secret;
 
   /**
    * Payment order ID we got back, if any. Otherwise NULL.
@@ -1388,6 +1408,7 @@ struct ANASTASIS_SecretShare
   unsigned int pss_length;
 };
 
+
 static void
 policy_store_cb (void *cls,
                  enum ANASTASIS_ErrorCode ec,
@@ -1594,7 +1615,6 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
                         const void *core_secret,
                         size_t core_secret_size)
 {
-
   struct ANASTASIS_SecretShare *ss;
   unsigned int pss_length = ANASTASIS_get_num_urls (policies,
                                                     policies_len);
@@ -1812,11 +1832,13 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
         {
           for (unsigned int m = 0; 0 < pds_len; m++)
           {
+            if (NULL == pds[m].provider_url)
+              continue;
             if (0 == strcmp (pds[m].provider_url,
                              policies[k]->truths[l]->url))
             {
-              ss->pss[index_pss]->payment_order_id
-                = GNUNET_strdup (pds[m].payment_order_id);
+              ss->pss[index_pss]->payment_secret
+                = pds[m].payment_secret;
               break;
             }
           }
@@ -1884,7 +1906,7 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
                                               ss->pss[l]->recovery_data,
                                               ss->pss[l]->recovery_data_size,
                                               ss->pss[l]->payment_requested,
-                                              ss->pss[l]->payment_order_id,
+                                              &ss->pss[l]->payment_secret,
                                               &policy_store_cb,
                                               ss->pss[l]);
     GNUNET_assert (NULL != ss->pss[l]->pso);
@@ -1903,5 +1925,5 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
 void
 ANASTASIS_secret_share_cancel (struct ANASTASIS_SecretShare *ss)
 {
-
+  // FIXME: implement!
 }
diff --git a/src/lib/anastasis_api_policy_store.c 
b/src/lib/anastasis_api_policy_store.c
index 5adcf86..1169b5c 100644
--- a/src/lib/anastasis_api_policy_store.c
+++ b/src/lib/anastasis_api_policy_store.c
@@ -279,7 +279,7 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
                         const void *recovery_data,
                         size_t recovery_data_size,
                         int payment_requested,
-                        const char *paid_order_id,
+                        const struct ANASTASIS_PaymentSecretP *payment_secret,
                         ANASTASIS_PolicyStoreCallback cb,
                         void *cb_cls)
 {
@@ -365,12 +365,17 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
       job_headers = ext;
     }
     /* Setup Payment-Identifier header */
-    if (NULL != paid_order_id)
+    if (NULL != payment_secret)
     {
+      char *paid_order_id;
+
+      paid_order_id = GNUNET_STRINGS_data_to_string_alloc (
+        payment_secret,
+        sizeof (*payment_secret));
       GNUNET_asprintf (&hdr,
                        "Payment-Identifier: %s",
                        paid_order_id);
-
+      GNUNET_free (paid_order_id);
       ext = curl_slist_append (job_headers,
                                hdr);
       GNUNET_free (hdr);
@@ -407,17 +412,9 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
                                  path,
                                  "pay",
                                  "y",
-                                 (NULL != paid_order_id)
-                                 ? "paying"
-                                 : NULL,
-                                 paid_order_id,
                                  NULL)
                : TALER_url_join (backend_url,
                                  path,
-                                 (NULL != paid_order_id)
-                                 ? "paying"
-                                 : NULL,
-                                 paid_order_id,
                                  NULL);
     GNUNET_free (path);
   }
diff --git a/src/lib/testing_api_cmd_policy_store.c 
b/src/lib/testing_api_cmd_policy_store.c
index 75a59b4..c200151 100644
--- a/src/lib/testing_api_cmd_policy_store.c
+++ b/src/lib/testing_api_cmd_policy_store.c
@@ -122,12 +122,17 @@ struct PolicyStoreState
   /**
    * Payment order ID we are to provide in the request, may be NULL.
    */
-  const char *payment_order_req;
+  struct ANASTASIS_PaymentSecretP payment_order_req;
 
   /**
    * Options for how we are supposed to do the upload.
    */
   enum ANASTASIS_TESTING_PolicyStoreOption psopt;
+
+  /**
+   * True if @e payment_order_req is initialized.
+   */
+  bool payment_order_set;
 };
 
 /**
@@ -328,6 +333,7 @@ policy_store_run (void *cls,
     }
     {
       const char *order_id;
+
       if (GNUNET_OK !=
           TALER_TESTING_get_trait_order_id (ref,
                                             0,
@@ -337,14 +343,19 @@ policy_store_run (void *cls,
         TALER_TESTING_interpreter_fail (pss->is);
         return;
       }
-      pss->payment_order_req = order_id;
 
-      if (NULL == pss->payment_order_req)
+      if (GNUNET_OK !=
+          GNUNET_STRINGS_string_to_data (order_id,
+                                         strlen (order_id),
+                                         &pss->payment_order_req,
+                                         sizeof (struct
+                                                 ANASTASIS_PaymentSecretP)))
       {
-        GNUNET_break (0);
+        GNUNET_break_op (0);
         TALER_TESTING_interpreter_fail (pss->is);
         return;
       }
+      pss->payment_order_set = true;
     }
   }
   else
@@ -378,7 +389,9 @@ policy_store_run (void *cls,
                                      (0 !=
                                       (ANASTASIS_TESTING_PSO_REQUEST_PAYMENT
                                        & pss->psopt)),
-                                     pss->payment_order_req,
+                                     pss->payment_order_set
+                                     ? &pss->payment_order_req
+                                     : NULL,
                                      &policy_store_cb,
                                      pss);
   if (NULL == pss->pso)
@@ -493,14 +506,15 @@ ANASTASIS_TESTING_cmd_policy_store (const char *label,
   pss->anastasis_url = anastasis_url;
   pss->prev_upload = prev_upload;
   pss->last_upload = last_upload;
-
-  struct TALER_TESTING_Command cmd = {
-    .cls = pss,
-    .label = label,
-    .run = &policy_store_run,
-    .cleanup = &policy_store_cleanup,
-    .traits = &policy_store_traits
-  };
-
-  return cmd;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = pss,
+      .label = label,
+      .run = &policy_store_run,
+      .cleanup = &policy_store_cleanup,
+      .traits = &policy_store_traits
+    };
+
+    return cmd;
+  }
 }
diff --git a/src/lib/testing_cmd_secret_share.c 
b/src/lib/testing_cmd_secret_share.c
index 4c777f7..cbf87bc 100644
--- a/src/lib/testing_cmd_secret_share.c
+++ b/src/lib/testing_cmd_secret_share.c
@@ -252,8 +252,8 @@ secret_share_run (void *cls,
 {
   struct SecretShareState *sss = cls;
   const struct ANASTASIS_Policy *policies[sss->cmd_label_array_length];
-  unsigned int pds_len = 1;
-  struct ANASTASIS_PaymentDetails pds[pds_len];
+  unsigned int pds_len;
+  struct ANASTASIS_PaymentDetails pds[1];
 
   GNUNET_assert (sss->cmd_label_array_length > 0);
   GNUNET_assert (NULL != sss->cmd_label_array);
@@ -333,8 +333,26 @@ secret_share_run (void *cls,
   memset (pds,
           0,
           sizeof (pds));
-  pds[0].payment_order_id = sss->payment_order_id;
-  pds[0].provider_url = sss->anastasis_url;
+  if (NULL != sss->payment_order_id)
+  {
+    if (GNUNET_OK !=
+        GNUNET_STRINGS_string_to_data (sss->payment_order_id,
+                                       strlen (sss->payment_order_id),
+                                       &pds[0].payment_secret,
+                                       sizeof (struct
+                                               ANASTASIS_PaymentSecretP)))
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (sss->is);
+      return;
+    }
+    pds[0].provider_url = sss->anastasis_url;
+    pds_len = 1;
+  }
+  else
+  {
+    pds_len = 0;
+  }
   sss->sso = ANASTASIS_secret_share (is->ctx,
                                      sss->id_data,
                                      NULL,

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