gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: fix issue discovered as part of


From: gnunet
Subject: [taler-anastasis] branch master updated: fix issue discovered as part of #6753 tests
Date: Fri, 09 Apr 2021 20:03:19 +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 940dd86  fix issue discovered as part of #6753 tests
940dd86 is described below

commit 940dd862c6605162c0f4855209a2e0011e525227
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Fri Apr 9 20:03:16 2021 +0200

    fix issue discovered as part of #6753 tests
---
 src/backend/anastasis-httpd_truth.c        | 214 +++++++++++++++++------------
 src/include/anastasis_database_plugin.h    |   7 +
 src/stasis/plugin_anastasis_postgres.c     |  71 +++++++---
 src/stasis/stasis-0001.sql                 |   3 +
 src/stasis/test_anastasis_db.c             |   2 +
 src/testing/testing_cmd_challenge_answer.c |  98 +++++++++----
 6 files changed, 259 insertions(+), 136 deletions(-)

diff --git a/src/backend/anastasis-httpd_truth.c 
b/src/backend/anastasis-httpd_truth.c
index 9d1eee5..42aa452 100644
--- a/src/backend/anastasis-httpd_truth.c
+++ b/src/backend/anastasis-httpd_truth.c
@@ -215,6 +215,8 @@ request_done (struct TM_HandlerContext *hc)
 {
   struct GetContext *gc = hc->ctx;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Request completed\n");
   if (NULL == gc)
     return;
   hc->cc = NULL;
@@ -299,6 +301,9 @@ make_payment_request (struct GetContext *gc)
                      hn,
                      order_id);
     GNUNET_free (order_id);
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Sending payment request `%s'\n",
+                hdr);
     GNUNET_break (MHD_YES ==
                   MHD_add_response_header (resp,
                                            ANASTASIS_HTTP_HEADER_TALER,
@@ -369,6 +374,8 @@ proposal_cb (void *cls,
     gc->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
     return;
   }
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Setup fresh order, creating payment request\n");
   make_payment_request (gc);
 }
 
@@ -450,7 +457,11 @@ check_payment_cb (void *cls,
                                          &gc->truth_uuid,
                                          &gc->payment_identifier);
       if (0 <= qs)
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                    "Order has been paid, continuing with request 
processing\n");
         return; /* continue as planned */
+      }
       GNUNET_break (0);
       gc->resp = TALER_MHD_make_error (TALER_EC_GENERIC_DB_STORE_FAILED,
                                        "update challenge payment");
@@ -460,6 +471,8 @@ check_payment_cb (void *cls,
   case TALER_MERCHANT_OSC_CLAIMED:
   case TALER_MERCHANT_OSC_UNPAID:
     /* repeat payment request */
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Order remains unpaid, sending payment request again\n");
     make_payment_request (gc);
     return;
   }
@@ -501,14 +514,17 @@ begin_payment (struct GetContext *gc)
   GNUNET_assert (! gc->suspended);
   gc->suspended = true;
   MHD_suspend_connection (gc->connection);
-  order_id = GNUNET_STRINGS_data_to_string_alloc (
-    &gc->payment_identifier,
-    sizeof (gc->payment_identifier));
   if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
   {
     /* We already created the order, check if it was paid */
     struct GNUNET_TIME_Relative timeout;
 
+    order_id = GNUNET_STRINGS_data_to_string_alloc (
+      &gc->payment_identifier,
+      sizeof (gc->payment_identifier));
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Order exists, checking payment status for order `%s'\n",
+                order_id);
     timeout = GNUNET_TIME_absolute_get_remaining (gc->timeout);
     gc->cpo = TALER_MERCHANT_merchant_order_get (AH_ctx,
                                                  AH_backend_url,
@@ -523,11 +539,26 @@ begin_payment (struct GetContext *gc)
   {
     /* Create a fresh order */
     json_t *order;
+    struct GNUNET_TIME_Absolute pay_deadline;
 
-    order = json_pack ("{s:o, s:s, s:s}",
+    GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+                                &gc->payment_identifier,
+                                sizeof (struct ANASTASIS_PaymentSecretP));
+    order_id = GNUNET_STRINGS_data_to_string_alloc (
+      &gc->payment_identifier,
+      sizeof (gc->payment_identifier));
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Creating fresh order `%s'\n",
+                order_id);
+    pay_deadline = GNUNET_TIME_relative_to_absolute (
+      ANASTASIS_CHALLENGE_OFFER_LIFETIME);
+    GNUNET_TIME_round_abs (&pay_deadline);
+    order = json_pack ("{s:o, s:s, s:s, s:o}",
                        "amount", TALER_JSON_from_amount (&gc->challenge_cost),
                        "summary", "challenge fee for anastasis service",
-                       "order_id", order_id);
+                       "order_id", order_id,
+                       "pay_deadline", GNUNET_JSON_from_time_abs (
+                         pay_deadline));
     gc->po = TALER_MERCHANT_orders_post2 (AH_ctx,
                                           AH_backend_url,
                                           order,
@@ -587,6 +618,8 @@ return_key_share (
     }
   }
 
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Returning key share\n");
   {
     struct MHD_Response *resp;
     MHD_RESULT ret;
@@ -604,6 +637,65 @@ return_key_share (
 }
 
 
+/**
+ * Run the authorization method-specific 'process' function and continue
+ * based on its result with generating an HTTP response.
+ *
+ * @param connection the connection we are handling
+ * @param gc our overall handler context
+ */
+static MHD_RESULT
+run_authorization_process (struct MHD_Connection *connection,
+                           struct GetContext *gc)
+{
+  enum ANASTASIS_AUTHORIZATION_Result ret;
+  enum GNUNET_DB_QueryStatus qs;
+
+  ret = gc->authorization->process (gc->as,
+                                    connection);
+  switch (ret)
+  {
+  case ANASTASIS_AUTHORIZATION_RES_SUCCESS:
+    /* Challenge sent successfully */
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Authorization request sent successfully\n");
+    qs = db->mark_challenge_sent (db->cls,
+                                  &gc->payment_identifier,
+                                  &gc->truth_uuid,
+                                  gc->code);
+    GNUNET_break (0 < qs);
+    gc->authorization->cleanup (gc->as);
+    gc->as = NULL;
+    return MHD_YES;
+  case ANASTASIS_AUTHORIZATION_RES_FAILED:
+    /* Challenge transmission failed, our fault! */
+    // FIXME #6750: give at least a refund!?
+    gc->authorization->cleanup (gc->as);
+    gc->as = NULL;
+    return MHD_YES;
+  case ANASTASIS_AUTHORIZATION_RES_SUSPENDED:
+    /* connection was suspended again, odd that this happens */
+    return MHD_YES;
+  case ANASTASIS_AUTHORIZATION_RES_SUCCESS_REPLY_FAILED:
+    /* Challenge sent successfully */
+    qs = db->mark_challenge_sent (db->cls,
+                                  &gc->payment_identifier,
+                                  &gc->truth_uuid,
+                                  gc->code);
+    GNUNET_break (0 < qs);
+    gc->authorization->cleanup (gc->as);
+    gc->as = NULL;
+    return MHD_NO;
+  case ANASTASIS_AUTHORIZATION_RES_FAILED_REPLY_FAILED:
+    gc->authorization->cleanup (gc->as);
+    gc->as = NULL;
+    return MHD_NO;
+  }
+  GNUNET_break (0);
+  return MHD_NO;
+}
+
+
 /**
  * @param connection the MHD connection to handle
  * @param url handles a URL of the format "/truth/$UUID[&response=$RESPONSE]"
@@ -656,6 +748,9 @@ AH_handler_truth_get (
                                              
ANASTASIS_HTTP_HEADER_PAYMENT_IDENTIFIER);
         }
         gc->payment_identifier_provided = true;
+        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                    "Client provided payment identifier `%s'\n",
+                    pay_id);
       }
     }
 
@@ -761,47 +856,12 @@ AH_handler_truth_get (
     if (NULL != gc->as)
     {
       /* Authorization process is "running", check what is going on */
-      enum ANASTASIS_AUTHORIZATION_Result ret;
-      enum GNUNET_DB_QueryStatus qs;
-
       GNUNET_assert (NULL != gc->authorization);
-      ret = gc->authorization->process (gc->as,
-                                        connection);
-      switch (ret)
-      {
-      case ANASTASIS_AUTHORIZATION_RES_SUCCESS:
-        /* Challenge sent successfully */
-        qs = db->mark_challenge_sent (db->cls,
-                                      &gc->truth_uuid,
-                                      gc->code);
-        GNUNET_break (0 < qs);
-        gc->authorization->cleanup (gc->as);
-        gc->as = NULL;
-        return MHD_YES;
-      case ANASTASIS_AUTHORIZATION_RES_FAILED:
-        /* Challenge transmission failed, our fault! */
-        // FIXME #6750: give at least a refund!?
-        gc->authorization->cleanup (gc->as);
-        gc->as = NULL;
-        return MHD_YES;
-      case ANASTASIS_AUTHORIZATION_RES_SUSPENDED:
-        /* connection was suspended again, odd that this happens */
-        GNUNET_break (0); /* mark oddity: why did plugin resume and then 
suspend again? */
-        return MHD_YES;
-      case ANASTASIS_AUTHORIZATION_RES_SUCCESS_REPLY_FAILED:
-        /* Challenge sent successfully */
-        qs = db->mark_challenge_sent (db->cls,
-                                      &gc->truth_uuid,
-                                      gc->code);
-        GNUNET_break (0 < qs);
-        gc->authorization->cleanup (gc->as);
-        gc->as = NULL;
-        return MHD_NO;
-      case ANASTASIS_AUTHORIZATION_RES_FAILED_REPLY_FAILED:
-        gc->authorization->cleanup (gc->as);
-        gc->as = NULL;
-        return MHD_NO;
-      }
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "Continuing with running the authorization process\n");
+      return run_authorization_process (connection,
+                                        gc);
+
     }
     /* We get here if the async check for payment said this request
        was indeed paid! */
@@ -879,15 +939,15 @@ AH_handler_truth_get (
 
       if (! gc->payment_identifier_provided)
       {
-        GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
-                                    &gc->payment_identifier,
-                                    sizeof (struct ANASTASIS_PaymentSecretP));
         GNUNET_free (truth_mime);
         GNUNET_free (encrypted_truth);
+        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                    "Beginning payment, client did not provide payment 
identifier\n");
         return begin_payment (gc);
       }
       qs = db->check_challenge_payment (db->cls,
                                         &gc->payment_identifier,
+                                        &gc->truth_uuid,
                                         &paid);
       switch (qs)
       {
@@ -901,20 +961,31 @@ AH_handler_truth_get (
                                            TALER_EC_GENERIC_DB_FETCH_FAILED,
                                            "check challenge payment");
       case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
-        /* Re-use existing payment identifier */
+        /* Create fresh payment identifier (cannot trust client) */
+        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                    "Client-provided payment identifier is unknown.\n");
         GNUNET_free (truth_mime);
         GNUNET_free (encrypted_truth);
         return begin_payment (gc);
       case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
         if (! paid)
         {
+          GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                      "Payment identifier known. Checking payment with 
client's payment identifier\n");
           GNUNET_free (truth_mime);
           GNUNET_free (encrypted_truth);
           return begin_payment (gc);
         }
+        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                    "Payment confirmed\n");
         break;
       }
     }
+    else
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "Request is free of charge\n");
+    }
   }
 
   /* We've been paid, now validate response */
@@ -1134,6 +1205,8 @@ AH_handler_truth_get (
                                          NULL);
     case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
       /* challenge code was stored successfully*/
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "Created fresh challenge\n");
       break;
     }
 
@@ -1149,6 +1222,8 @@ AH_handler_truth_get (
     }
   }
 
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Beginning authorization process\n");
   gc->as = gc->authorization->start (gc->authorization->cls,
                                      &AH_trigger_daemon,
                                      NULL,
@@ -1170,43 +1245,6 @@ AH_handler_truth_get (
   GNUNET_CONTAINER_DLL_insert (gc_head,
                                gc_tail,
                                gc);
-  {
-    enum ANASTASIS_AUTHORIZATION_Result aret;
-    enum GNUNET_DB_QueryStatus qs;
-
-    aret = gc->authorization->process (gc->as,
-                                       connection);
-    switch (aret)
-    {
-    case ANASTASIS_AUTHORIZATION_RES_SUCCESS:
-      /* all good, challenge sent! */
-      qs = db->mark_challenge_sent (db->cls,
-                                    &gc->truth_uuid,
-                                    gc->code);
-      GNUNET_break (0 < qs);
-      break;
-    case ANASTASIS_AUTHORIZATION_RES_FAILED:
-      /* sending challenge failed */
-      // FIXME #6750: give at least a refund!?
-      break;
-    case ANASTASIS_AUTHORIZATION_RES_SUSPENDED:
-      /* we have been suspended, see you later */
-      return MHD_YES;
-    case ANASTASIS_AUTHORIZATION_RES_SUCCESS_REPLY_FAILED:
-      /* Challenge sent successfully, but HTTP reply failed */
-      qs = db->mark_challenge_sent (db->cls,
-                                    &gc->truth_uuid,
-                                    gc->code);
-      GNUNET_break (0 < qs);
-      gc->authorization->cleanup (gc->as);
-      return MHD_NO;
-    case ANASTASIS_AUTHORIZATION_RES_FAILED_REPLY_FAILED:
-      /* failure to send challenge AND to queue reply, kill connection */
-      gc->authorization->cleanup (gc->as);
-      return MHD_NO;
-    }
-    gc->authorization->cleanup (gc->as);
-    gc->as = NULL;
-    return MHD_YES;
-  }
+  return run_authorization_process (connection,
+                                    gc);
 }
diff --git a/src/include/anastasis_database_plugin.h 
b/src/include/anastasis_database_plugin.h
index 1d1420f..d51ac6b 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -24,6 +24,10 @@
 #include "anastasis_service.h"
 #include <gnunet/gnunet_db_lib.h>
 
+/**
+ * How long is an offer for a challenge payment valid for payment?
+ */
+#define ANASTASIS_CHALLENGE_OFFER_LIFETIME GNUNET_TIME_UNIT_HOURS
 
 /**
  * Return values for checking code validity.
@@ -429,6 +433,7 @@ struct ANASTASIS_DatabasePlugin
    *
    * @param cls closure
    * @param payment_secret payment secret which the user must provide with 
every upload
+   * @param truth_uuid unique identifier of the truth the user must satisfy 
the challenge
    * @param[out] paid bool value to show if payment is paid
    * @param[out] valid_counter bool value to show if post_counter is > 0
    * @return transaction status
@@ -437,6 +442,7 @@ struct ANASTASIS_DatabasePlugin
   (*check_challenge_payment)(
     void *cls,
     const struct ANASTASIS_PaymentSecretP *payment_secret,
+    const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid,
     bool *paid);
 
 
@@ -563,6 +569,7 @@ struct ANASTASIS_DatabasePlugin
   enum GNUNET_DB_QueryStatus
   (*mark_challenge_sent)(
     void *cls,
+    const struct ANASTASIS_PaymentSecretP *payment_secret,
     const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid,
     uint64_t code);
 
diff --git a/src/stasis/plugin_anastasis_postgres.c 
b/src/stasis/plugin_anastasis_postgres.c
index 772572b..977d2f1 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -959,11 +959,13 @@ static enum GNUNET_DB_QueryStatus
 postgres_check_challenge_payment (
   void *cls,
   const struct ANASTASIS_PaymentSecretP *payment_secret,
+  const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid,
   bool *paid)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_auto_from_type (payment_secret),
+    GNUNET_PQ_query_param_auto_from_type (truth_uuid),
     GNUNET_PQ_query_param_end
   };
   struct GNUNET_PQ_ResultSpec rs[] = {
@@ -1499,20 +1501,18 @@ postgres_lookup_challenge_payment (
   struct ANASTASIS_PaymentSecretP *payment_secret)
 {
   struct PostgresClosure *pg = cls;
-  struct GNUNET_TIME_Absolute timestamp;
-  struct TALER_Amount amount;
+  struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
+  struct GNUNET_TIME_Absolute recent
+    = GNUNET_TIME_absolute_subtract (now,
+                                     ANASTASIS_CHALLENGE_OFFER_LIFETIME);
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_auto_from_type (truth_uuid),
+    GNUNET_PQ_query_param_absolute_time (&recent),
     GNUNET_PQ_query_param_end
   };
   struct GNUNET_PQ_ResultSpec rs[] = {
-    GNUNET_PQ_result_spec_absolute_time ("creation_date",
-                                         &timestamp),
     GNUNET_PQ_result_spec_auto_from_type ("payment_identifier",
                                           payment_secret),
-    TALER_PQ_result_spec_amount ("amount",
-                                 pg->currency,
-                                 &amount),
     GNUNET_PQ_result_spec_end
   };
 
@@ -1692,30 +1692,52 @@ retry:
  * Remember in the database that we successfully sent a challenge.
  *
  * @param cls closure
+ * @param payment_secret payment secret which the user must provide with every 
upload
  * @param truth_uuid the identifier for the challenge
  * @param code the challenge that was sent
  */
 static enum GNUNET_DB_QueryStatus
 postgres_mark_challenge_sent (
   void *cls,
+  const struct ANASTASIS_PaymentSecretP *payment_secret,
   const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid,
   uint64_t code)
 {
   struct PostgresClosure *pg = cls;
-  struct GNUNET_TIME_Absolute now;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_auto_from_type (truth_uuid),
-    GNUNET_PQ_query_param_uint64 (&code),
-    TALER_PQ_query_param_absolute_time (&now),
-    GNUNET_PQ_query_param_end
-  };
+  enum GNUNET_DB_QueryStatus qs;
 
   check_connection (pg);
-  now = GNUNET_TIME_absolute_get ();
-  GNUNET_TIME_round_abs (&now);
-  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+  {
+    struct GNUNET_TIME_Absolute now;
+    struct GNUNET_PQ_QueryParam params[] = {
+      GNUNET_PQ_query_param_auto_from_type (truth_uuid),
+      GNUNET_PQ_query_param_uint64 (&code),
+      TALER_PQ_query_param_absolute_time (&now),
+      GNUNET_PQ_query_param_end
+    };
+
+    now = GNUNET_TIME_absolute_get ();
+    GNUNET_TIME_round_abs (&now);
+    qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "challengecode_mark_sent",
                                              params);
+    if (qs <= 0)
+      return qs;
+  }
+  {
+    struct GNUNET_PQ_QueryParam params[] = {
+      GNUNET_PQ_query_param_auto_from_type (truth_uuid),
+      GNUNET_PQ_query_param_auto_from_type (payment_secret),
+      GNUNET_PQ_query_param_end
+    };
+
+    qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+                                             "challengepayment_dec_counter",
+                                             params);
+    if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+      return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; /* probably was free */
+    return qs;
+  }
 }
 
 
@@ -1855,7 +1877,9 @@ libanastasis_plugin_db_postgres_init (void *cls)
                             ",amount_frac"
                             ",paid"
                             " FROM anastasis_challenge_payment"
-                            " WHERE payment_identifier=$1;",
+                            " WHERE payment_identifier=$1"
+                            "   AND truth_uuid=$2"
+                            "   AND counter>0;",
                             1),
     GNUNET_PQ_make_prepare ("challenge_pending_payment_select",
                             "SELECT"
@@ -1867,7 +1891,9 @@ libanastasis_plugin_db_postgres_init (void *cls)
                             " WHERE"
                             "  paid=FALSE"
                             " AND"
-                            "  truth_uuid=$1;",
+                            "  truth_uuid=$1"
+                            " AND"
+                            "  creation_date > $2;",
                             1),
     GNUNET_PQ_make_prepare ("recdoc_payments_select",
                             "SELECT"
@@ -2026,6 +2052,13 @@ libanastasis_plugin_db_postgres_init (void *cls)
                             "   AND code=$2"
                             "   AND retry_counter > 0;",
                             1),
+    GNUNET_PQ_make_prepare ("challengepayment_dec_counter",
+                            "UPDATE anastasis_challenge_payment"
+                            " SET counter=counter - 1"
+                            " WHERE truth_uuid=$1"
+                            "   AND payment_identifier=$2"
+                            "   AND counter > 0;",
+                            2),
     GNUNET_PQ_make_prepare ("challengecode_mark_sent",
                             "UPDATE anastasis_challengecode"
                             " SET retransmission_date=$3"
diff --git a/src/stasis/stasis-0001.sql b/src/stasis/stasis-0001.sql
index 8d998ca..7025029 100644
--- a/src/stasis/stasis-0001.sql
+++ b/src/stasis/stasis-0001.sql
@@ -108,6 +108,7 @@ CREATE TABLE IF NOT EXISTS anastasis_challenge_payment
    amount_frac INT4 NOT NULL,
    payment_identifier BYTEA NOT NULL CHECK(LENGTH(payment_identifier)=32),
    creation_date INT8 NOT NULL,
+   counter INT4 NOT NULL DEFAULT 3,
    paid BOOLEAN NOT NULL DEFAULT FALSE
   );
 COMMENT ON TABLE anastasis_recdoc_payment
@@ -122,6 +123,8 @@ COMMENT ON COLUMN anastasis_challenge_payment.amount_frac
   IS 'Amount we were paid fraction';
 COMMENT ON COLUMN anastasis_challenge_payment.payment_identifier
   IS 'Payment identifier which the user has to provide';
+COMMENT ON COLUMN anastasis_challenge_payment.counter
+  IS 'How many more times will we issue the challenge for the given payment';
 COMMENT ON COLUMN anastasis_challenge_payment.creation_date
   IS 'Creation date of the payment';
 COMMENT ON COLUMN anastasis_challenge_payment.paid
diff --git a/src/stasis/test_anastasis_db.c b/src/stasis/test_anastasis_db.c
index 186c507..eb73746 100644
--- a/src/stasis/test_anastasis_db.c
+++ b/src/stasis/test_anastasis_db.c
@@ -163,6 +163,7 @@ run (void *cls)
   FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
           plugin->check_challenge_payment (plugin->cls,
                                            &paymentSecretP,
+                                           &truth_uuid,
                                            &paid));
   FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
           plugin->record_challenge_payment (plugin->cls,
@@ -176,6 +177,7 @@ run (void *cls)
   FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
           plugin->check_challenge_payment (plugin->cls,
                                            &paymentSecretP,
+                                           &truth_uuid,
                                            &paid));
   FAILIF (! paid);
   FAILIF (ANASTASIS_DB_STORE_STATUS_SUCCESS !=
diff --git a/src/testing/testing_cmd_challenge_answer.c 
b/src/testing/testing_cmd_challenge_answer.c
index 693e604..b243d61 100644
--- a/src/testing/testing_cmd_challenge_answer.c
+++ b/src/testing/testing_cmd_challenge_answer.c
@@ -69,7 +69,7 @@ struct ChallengeState
   char *order_id;
 
   /**
-   * Payment order ID we are to provide in the request, may be NULL.
+   * Payment order ID we are to provide in the request.
    */
   struct ANASTASIS_PaymentSecretP payment_order_req;
 
@@ -178,6 +178,10 @@ challenge_answer_cb (void *af_cls,
         GNUNET_free (fn);
         return;
       }
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "Read challenge answer `%s' from file `%s'\n",
+                  cs->code,
+                  fn);
       TALER_TESTING_interpreter_next (cs->is);
       GNUNET_break (0 == fclose (file));
       GNUNET_free (fn);
@@ -209,6 +213,16 @@ challenge_answer_cb (void *af_cls,
         return;
       }
       cs->order_id = GNUNET_strdup (pud.order_id);
+      if (GNUNET_OK !=
+          GNUNET_STRINGS_string_to_data (cs->order_id,
+                                         strlen (cs->order_id),
+                                         &cs->payment_order_req,
+                                         sizeof (cs->payment_order_req)))
+      {
+        GNUNET_break (0);
+        TALER_TESTING_interpreter_fail (cs->is);
+        return;
+      }
       TALER_MERCHANT_parse_pay_uri_free (&pud);
     }
     TALER_TESTING_interpreter_next (cs->is);
@@ -243,7 +257,6 @@ challenge_answer_run (void *cls,
   struct ChallengeState *cs = cls;
   const struct ANASTASIS_Challenge *c;
   const struct ANASTASIS_PaymentSecretP *ps;
-  const char *answer;
 
   cs->is = is;
   if (NULL != cs->challenge_ref)
@@ -269,12 +282,13 @@ challenge_answer_run (void *cls,
       return;
     }
   }
-  if (1 == cs->mode)
+
+  if (NULL != cs->payment_ref)
   {
     const struct TALER_TESTING_Command *ref;
 
     ref = TALER_TESTING_interpreter_lookup_command (is,
-                                                    cs->answer);
+                                                    cs->payment_ref);
     if (NULL == ref)
     {
       GNUNET_break (0);
@@ -282,9 +296,9 @@ challenge_answer_run (void *cls,
       return;
     }
     if (GNUNET_OK !=
-        ANASTASIS_TESTING_get_trait_code (ref,
-                                          0,
-                                          &answer))
+        ANASTASIS_TESTING_get_trait_payment_secret (ref,
+                                                    0,
+                                                    &ps))
     {
       GNUNET_break (0);
       TALER_TESTING_interpreter_fail (cs->is);
@@ -293,15 +307,20 @@ challenge_answer_run (void *cls,
   }
   else
   {
-    answer = cs->answer;
+    ps = NULL;
   }
 
-  if (NULL != cs->payment_ref)
+  cs->c = (struct ANASTASIS_Challenge *) c;
+
+  if (1 == cs->mode)
   {
     const struct TALER_TESTING_Command *ref;
+    const char *answer;
+    unsigned long long code;
+    char dummy;
 
     ref = TALER_TESTING_interpreter_lookup_command (is,
-                                                    cs->payment_ref);
+                                                    cs->answer);
     if (NULL == ref)
     {
       GNUNET_break (0);
@@ -309,33 +328,54 @@ challenge_answer_run (void *cls,
       return;
     }
     if (GNUNET_OK !=
-        ANASTASIS_TESTING_get_trait_payment_secret (ref,
-                                                    0,
-                                                    &ps))
+        ANASTASIS_TESTING_get_trait_code (ref,
+                                          0,
+                                          &answer))
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (cs->is);
+      return;
+    }
+    if (1 !=
+        sscanf (answer,
+                "%llu%c",
+                &code,
+                &dummy))
     {
       GNUNET_break (0);
       TALER_TESTING_interpreter_fail (cs->is);
       return;
     }
+    if (GNUNET_OK !=
+        ANASTASIS_challenge_answer2 (cs->c,
+                                     ps,
+                                     GNUNET_TIME_UNIT_ZERO,
+                                     code,
+                                     &challenge_answer_cb,
+                                     cs))
+    {
+      GNUNET_break (0);
+      cs->c = NULL;
+      TALER_TESTING_interpreter_fail (cs->is);
+      return;
+    }
+
   }
   else
   {
-    ps = NULL;
-  }
-
-  cs->c = (struct ANASTASIS_Challenge *) c;
-  if (GNUNET_OK !=
-      ANASTASIS_challenge_answer (cs->c,
-                                  ps,
-                                  GNUNET_TIME_UNIT_ZERO,
-                                  answer,
-                                  &challenge_answer_cb,
-                                  cs))
-  {
-    GNUNET_break (0);
-    cs->c = NULL;
-    TALER_TESTING_interpreter_fail (cs->is);
-    return;
+    if (GNUNET_OK !=
+        ANASTASIS_challenge_answer (cs->c,
+                                    ps,
+                                    GNUNET_TIME_UNIT_ZERO,
+                                    cs->answer,
+                                    &challenge_answer_cb,
+                                    cs))
+    {
+      GNUNET_break (0);
+      cs->c = NULL;
+      TALER_TESTING_interpreter_fail (cs->is);
+      return;
+    }
   }
 }
 

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