gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 01/02: Played with payment: Not able to give own payme


From: gnunet
Subject: [taler-anastasis] 01/02: Played with payment: Not able to give own payment identifier...
Date: Thu, 19 Dec 2019 08:59:14 +0100

This is an automated email from the git hooks/post-receive script.

dennis-neufeld pushed a commit to branch master
in repository anastasis.

commit 63d0369a9c23111d0a88810f022415f78d5ec5b1
Author: Dennis Neufeld <address@hidden>
AuthorDate: Wed Dec 18 21:55:32 2019 +0000

    Played with payment: Not able to give own payment identifier...
---
 src/backend/anastasis-httpd.c               |  3 +-
 src/backend/anastasis-httpd_policy.c        |  8 ++--
 src/backend/anastasis-httpd_policy.h        |  6 +--
 src/backend/anastasis-httpd_policy_upload.c | 71 +++++++++++++++++++++--------
 src/include/anastasis_database_plugin.h     |  4 +-
 src/include/anastasis_testing_lib.h         |  2 -
 src/lib/anastasis_api_policy_store.c        | 30 ++++++------
 src/lib/test_anastasis_api.c                |  2 -
 src/lib/testing_api_cmd_policy_store.c      | 35 +++++++++++---
 src/stasis/plugin_anastasis_postgres.c      |  8 ++--
 10 files changed, 109 insertions(+), 60 deletions(-)

diff --git a/src/backend/anastasis-httpd.c b/src/backend/anastasis-httpd.c
index 0db9ed9..c1200af 100644
--- a/src/backend/anastasis-httpd.c
+++ b/src/backend/anastasis-httpd.c
@@ -278,8 +278,7 @@ url_handler (void *cls,
     if (0 == strcmp (method, MHD_HTTP_METHOD_GET))
     {
       return AH_handler_policy_get (connection,
-                                    url,
-                                    con_cls);
+                                    url);
     }
     if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
     {
diff --git a/src/backend/anastasis-httpd_policy.c 
b/src/backend/anastasis-httpd_policy.c
index 49da521..8cc2292 100644
--- a/src/backend/anastasis-httpd_policy.c
+++ b/src/backend/anastasis-httpd_policy.c
@@ -130,11 +130,12 @@ AH_return_policy (struct MHD_Connection *connection,
                                                 sizeof (recovery_data_hash));
     GNUNET_break (MHD_YES ==
                   MHD_add_response_header (resp,
-                                           "Sync-Signature",
+                                           "Anastasis-Policy-Signature",
                                            sig_s));
+    // FIXME: reasonable?
     GNUNET_break (MHD_YES ==
                   MHD_add_response_header (resp,
-                                           "Sync-Previous",
+                                           "Anastasis-Previous",
                                            prev_s));
     GNUNET_break (MHD_YES ==
                   MHD_add_response_header (resp,
@@ -160,8 +161,7 @@ AH_return_policy (struct MHD_Connection *connection,
  */
 int
 AH_handler_policy_get (struct MHD_Connection *connection,
-                       const char *url,
-                       void **con_cls)
+                       const char *url)
 {
   struct ANASTASIS_AccountPubP accountPubP;
   void *res_recovery_data;
diff --git a/src/backend/anastasis-httpd_policy.h 
b/src/backend/anastasis-httpd_policy.h
index 06401fc..0b02269 100644
--- a/src/backend/anastasis-httpd_policy.h
+++ b/src/backend/anastasis-httpd_policy.h
@@ -27,13 +27,11 @@
 /**
  * @param connection the MHD connection to handle
  * @param url handles a URL of the format 
"/policy/$ACCOUNT_PUB[&version=$NUMBER]"
- * @param con_cls
  * @return MHD result code
  */
 int
 AH_handler_policy_get (struct MHD_Connection *connection,
-                       const char *url,
-                       void **con_cls);
+                       const char *url);
 
 /**
  * @param connection the MHD connection to handle
@@ -61,7 +59,7 @@ AH_handler_policy_post (struct MHD_Connection *connection,
  * @return MHD result code
  */
 int
-AH_return_backup (struct MHD_Connection *connection,
+AH_return_policy (struct MHD_Connection *connection,
                   const struct ANASTASIS_AccountPubP *account,
                   unsigned int default_http_status);
 
diff --git a/src/backend/anastasis-httpd_policy_upload.c 
b/src/backend/anastasis-httpd_policy_upload.c
index ce121f5..da589b1 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -259,13 +259,6 @@ proposal_cb (void *cls,
   struct PolicyUploadContext *puc = cls;
   enum ANASTASIS_DB_QueryStatus qs;
   unsigned int post_counter;
-  struct ANASTASIS_PaymentSecretP payment_identifier;
-
-  // generate new payment identifier
-  GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
-                              &payment_identifier,
-                              sizeof (payment_identifier));
-  puc->payment_identifier = payment_identifier;
 
   puc->po = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -436,34 +429,47 @@ begin_payment (struct PolicyUploadContext *puc,
 {
   json_t *order;
   enum ANASTASIS_DB_QueryStatus qs;
+  char *order_id;
 
-  qs = db->lookup_pending_payment_by_account (db->cls,
+  qs = db->lookup_expired_payment_by_account (db->cls,
                                               &puc->account,
                                               puc);
   if (qs < 0)
   {
-    /*FIXME: In our case we don't safe the order_id to db,
-     so there is no exsisting order in db*/
     struct MHD_Response *resp;
     int ret;
 
     resp = TALER_MHD_make_error (TALER_EC_SYNC_PAYMENT_CHECK_ORDER_DB_ERROR,
-                                 "Failed to check for existing order in 
anastasis database");
+                                 "Failed to check for expired payment in 
anastasis database");
     ret = MHD_queue_response (puc->con,
                               MHD_HTTP_INTERNAL_SERVER_ERROR,
                               resp);
     MHD_destroy_response (resp);
     return ret;
   }
+  
+  // generate new payment identifier
+  GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+                              &puc->payment_identifier,
+                              sizeof (
+                                struct ANASTASIS_PaymentSecretP));
 
   if (qs == ANASTASIS_DB_STATUS_NO_RESULTS)
   {
+    //create new user
     qs = db->increment_lifetime (db->cls,
                                  &puc->account,
                                  &puc->payment_identifier,
                                  GNUNET_TIME_UNIT_ZERO);
   }
 
+  order_id = GNUNET_STRINGS_data_to_string_alloc (&puc->payment_identifier,
+                                        sizeof(
+                                          struct ANASTASIS_PaymentSecretP));
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              "\n\n\n ORDER ID:    %s\n\n\n",
+              order_id);
+
   GNUNET_CONTAINER_DLL_insert (puc_head,
                                puc_tail,
                                puc);
@@ -474,7 +480,8 @@ begin_payment (struct PolicyUploadContext *puc,
   order = json_pack ("{s:o, s:s, s:s}",
                      "amount", TALER_JSON_from_amount (&AH_annual_fee),
                      "summary", "annual fee for anastasis service",
-                     "fulfillment_url", AH_fulfillment_url);
+                     "fulfillment_url", AH_fulfillment_url,
+                     "order_id", order_id);
   puc->po = TALER_MERCHANT_order_put (AH_ctx,
                                       AH_backend_url,
                                       order,
@@ -509,16 +516,16 @@ handle_database_error (struct PolicyUploadContext *puc,
                                        TALER_EC_SYNC_PREVIOUS_BACKUP_UNKNOWN,
                                        "Cannot update, unknown previous 
recovery document");
   case ANASTASIS_DB_STATUS_PAYMENT_REQUIRED:
-    /* FIXME: payment handling */
-
     {
-      const char *order_id;
+      char *order_id;
+      
+      order_id = GNUNET_STRINGS_data_to_string_alloc (&puc->payment_identifier,
+                                                sizeof (
+                                                  struct 
ANASTASIS_PaymentSecretP));
 
-      order_id = MHD_lookup_connection_value (puc->con,
-                                              MHD_GET_ARGUMENT_KIND,
-                                              "paying");
+      puc->order_id = order_id;
 
-      if (NULL == order_id)
+      if (NULL == order_id || GNUNET_is_zero (order_id))
       {
         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                     "Payment required, starting payment process\n");
@@ -664,6 +671,29 @@ AH_handler_policy_post (struct MHD_Connection *connection,
                                            "If-Match does not include a 
base32-encoded SHA-512 hash");
       }
     }
+    {
+      // Check if header contains Payment-Identifier
+      const char *pay_id;
+
+      pay_id = MHD_lookup_connection_value (connection,
+                                            MHD_HEADER_KIND,
+                                            "Payment-Identifier");
+      
+      if ( (NULL != pay_id) &&
+           (GNUNET_OK !=
+            GNUNET_STRINGS_string_to_data (pay_id,
+                                           strlen (pay_id),
+                                           &puc->payment_identifier,
+                                           sizeof (&puc->payment_identifier))) 
)
+      {
+        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 SHA-512 hash");
+      }
+    }
     {
       // Check if header contains Anastasis-Policy-Signature
       const char *sig_s;
@@ -745,8 +775,9 @@ AH_handler_policy_post (struct MHD_Connection *connection,
         memset (&hc, 0, sizeof (hc));
         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                     "User not known. Payment required to create new 
account\n");
+        qs = ANASTASIS_DB_STATUS_PAYMENT_REQUIRED;
         return handle_database_error (puc,
-                                      ANASTASIS_DB_STATUS_PAYMENT_REQUIRED);
+                                      qs);           
       }
       if (0 == GNUNET_memcmp (&hc,
                               &puc->new_policy_upload_hash))
diff --git a/src/include/anastasis_database_plugin.h 
b/src/include/anastasis_database_plugin.h
index 3dcb4cc..b9afe38 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -40,7 +40,7 @@
 typedef void
 (*ANASTASIS_DB_PaymentPendingIterator)(void *cls,
                                        struct GNUNET_TIME_Absolute timestamp,
-                                       const char *order_id,
+                                       void *payment_identifier,
                                        const struct TALER_Amount *amount);
 
 /**
@@ -282,7 +282,7 @@ struct ANASTASIS_DatabasePlugin
    * @param account_pub account to look for pending payment under
    */
   enum ANASTASIS_DB_QueryStatus
-  (*lookup_pending_payment_by_account)(void *cls,
+  (*lookup_expired_payment_by_account)(void *cls,
                                        const struct
                                        ANASTASIS_AccountPubP *account_pub,
                                        void *it_cls);
diff --git a/src/include/anastasis_testing_lib.h 
b/src/include/anastasis_testing_lib.h
index d113a2c..963afaf 100644
--- a/src/include/anastasis_testing_lib.h
+++ b/src/include/anastasis_testing_lib.h
@@ -240,8 +240,6 @@ ANASTASIS_TESTING_cmd_policy_store (const char *label,
                                     unsigned int http_status,
                                     enum
                                     ANASTASIS_TESTING_PolicyStoreOption pso,
-                                    const struct
-                                    ANASTASIS_PaymentSecretP *payment_id,
                                     const void *policy_data,
                                     size_t policy_data_size);
 /**
diff --git a/src/lib/anastasis_api_policy_store.c 
b/src/lib/anastasis_api_policy_store.c
index e9371a0..fc40e36 100644
--- a/src/lib/anastasis_api_policy_store.c
+++ b/src/lib/anastasis_api_policy_store.c
@@ -358,22 +358,24 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
     }
 
     /* Setup Payment-Identifier header */
-    val = GNUNET_STRINGS_data_to_string_alloc (&paymentSecretP,
+    if (NULL != paymentSecretP) {
+      val = GNUNET_STRINGS_data_to_string_alloc (&paymentSecretP,
                                                sizeof (paymentSecretP));
-    GNUNET_asprintf (&hdr,
-                     "Payment-Identifier: %s",
-                     val);
-    GNUNET_free (val);
-    ext = curl_slist_append (job_headers,
-                             hdr);
-    GNUNET_free (hdr);
-    if (NULL == ext)
-    {
-      GNUNET_break (0);
-      curl_slist_free_all (job_headers);
-      return NULL;
+      GNUNET_asprintf (&hdr,
+                      "Payment-Identifier: %s",
+                      val);
+      GNUNET_free (val);
+      ext = curl_slist_append (job_headers,
+                              hdr);
+      GNUNET_free (hdr);
+      if (NULL == ext)
+      {
+        GNUNET_break (0);
+        curl_slist_free_all (job_headers);
+        return NULL;
+      }
+      job_headers = ext;
     }
-    job_headers = ext;
   }
   /* Finished setting up headers */
 
diff --git a/src/lib/test_anastasis_api.c b/src/lib/test_anastasis_api.c
index 590d6a9..25be00f 100644
--- a/src/lib/test_anastasis_api.c
+++ b/src/lib/test_anastasis_api.c
@@ -281,7 +281,6 @@ run (void *cls,
                                         NULL,
                                         MHD_HTTP_OK,
                                         ANASTASIS_TESTING_PSO_NONE,
-                                        &paymentSecret,
                                         "Test-1",
                                         strlen ("Test-1")),
 
@@ -306,7 +305,6 @@ run (void *cls,
                                         "backup-upload-1",
                                         MHD_HTTP_OK,
                                         ANASTASIS_TESTING_PSO_NONE,
-                                        &paymentSecret,
                                         "Test-2",
                                         strlen ("Test-2")),
 
diff --git a/src/lib/testing_api_cmd_policy_store.c 
b/src/lib/testing_api_cmd_policy_store.c
index e2d752b..28046e0 100644
--- a/src/lib/testing_api_cmd_policy_store.c
+++ b/src/lib/testing_api_cmd_policy_store.c
@@ -364,14 +364,40 @@ policy_store_run (void *cls,
                         pss->recovery_data_size,
                         &pss->curr_hash);
   }
+  if (NULL != pss->payment_order_req)
+  {
+    if (!GNUNET_is_zero (pss->payment_order_req))
+    {
+      const char *pay_req;
+      struct ANASTASIS_PaymentSecretP pay_sec;
+
+      pay_req = pss->payment_order_req;
+
+      GNUNET_STRINGS_string_to_data (pay_req,
+                                    strlen (pay_req),
+                                    &pay_sec,
+                                    sizeof (
+                                      struct ANASTASIS_PaymentSecretP));
+      pss->payment_id = &pay_sec;
+      GNUNET_free (&pay_req);
+      GNUNET_free (&pay_sec);
+    }
+  }
   pss->pso = ANASTASIS_policy_store (is->ctx,
                                      pss->anastasis_url,
                                      &pss->anastasis_priv,
-                                     NULL /* pre_recovery_data_hash */,
+                                     ( ( (NULL != pss->prev_upload) &&
+                                         (0 != GNUNET_is_zero 
(&pss->prev_hash)) ) ||
+                                      (0 != 
(ANASTASIS_TESTING_PSO_PREV_HASH_WRONG
+                                              & pss->psopt)) )
+                                     ? &pss->prev_hash
+                                     : NULL,
                                      pss->recovery_data,
                                      pss->recovery_data_size,
-                                     GNUNET_NO /* payment req */,
-                                     pss->payment_id,
+                                     (0 != 
(ANASTASIS_TESTING_PSO_REQUEST_PAYMENT & pss->psopt)),
+                                     ( NULL != pss->payment_id)
+                                     ? pss->payment_id
+                                     : NULL,
                                      &policy_store_cb,
                                      pss);
   if (NULL == pss->pso)
@@ -466,8 +492,6 @@ ANASTASIS_TESTING_cmd_policy_store (const char *label,
                                     unsigned int http_status,
                                     enum
                                     ANASTASIS_TESTING_PolicyStoreOption pso,
-                                    const struct
-                                    ANASTASIS_PaymentSecretP *payment_id,
                                     const void *recovery_data,
                                     size_t recovery_data_size)
 {
@@ -476,7 +500,6 @@ ANASTASIS_TESTING_cmd_policy_store (const char *label,
   pss = GNUNET_new (struct PolicyStoreState);
   pss->recovery_data = recovery_data;
   pss->recovery_data_size = recovery_data_size;
-  pss->payment_id = payment_id;
   pss->http_status = http_status;
   pss->psopt = pso;
   pss->anastasis_url = anastasis_url;
diff --git a/src/stasis/plugin_anastasis_postgres.c 
b/src/stasis/plugin_anastasis_postgres.c
index 12b96d7..8c34761 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -224,7 +224,7 @@ commit_transaction (void *cls)
  * @param it_cls closure for @a it
  */
 static enum ANASTASIS_DB_QueryStatus
-postgres_lookup_pending_payment_by_account (void *cls,
+postgres_lookup_expired_payment_by_account (void *cls,
                                             const struct
                                             ANASTASIS_AccountPubP 
*anastasis_pub,
                                             void *it_cls)
@@ -255,7 +255,7 @@ postgres_lookup_pending_payment_by_account (void *cls,
   if (qs == ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT)
   {
     time_remaining = GNUNET_TIME_absolute_get_remaining (paid_until);
-    if ( GNUNET_TIME_round_rel (&time_remaining) == 0)
+    if( GNUNET_TIME_round_rel (&time_remaining) == 0)
       return ANASTASIS_DB_STATUS_PAYMENT_REQUIRED;
   }
   GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
@@ -1219,8 +1219,8 @@ libanastasis_plugin_db_postgres_init (void *cls)
   plugin->get_latest_recovery_document = 
&postgres_get_latest_recovery_document;
   plugin->get_recovery_document = &postgres_get_recovery_document;
   plugin->lookup_account = &postgres_lookup_account;
-  plugin->lookup_pending_payment_by_account =
-    &postgres_lookup_pending_payment_by_account;
+  plugin->lookup_expired_payment_by_account =
+    &postgres_lookup_expired_payment_by_account;
   plugin->increment_lifetime = &postgres_increment_lifetime;
   plugin->start = &begin_transaction;
   plugin->check_connection = &check_connection;

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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