gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-exchange] branch master updated (1a537490 -> a83aa1f


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] branch master updated (1a537490 -> a83aa1f7)
Date: Mon, 22 Jul 2019 13:28:50 +0200

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

grothoff pushed a change to branch master
in repository exchange.

    from 1a537490 fix test case clean up logic on skip
     new c0c80d4a replace GNUNET_asserts() with more proper error handling, fix 
indentation
     new a83aa1f7 include new payback-refresh possibilities in coin history 
generation

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/exchange/taler-exchange-httpd_db.c        |  26 +-
 src/exchange/taler-exchange-httpd_payback.c   |  20 -
 src/exchange/taler-exchange-httpd_refund.c    |   6 +
 src/exchange/taler-exchange-httpd_responses.c | 578 ++++++++++++++++----------
 src/exchangedb/plugin_exchangedb_common.c     |   4 +
 src/include/taler_signatures.h                |  45 +-
 6 files changed, 437 insertions(+), 242 deletions(-)

diff --git a/src/exchange/taler-exchange-httpd_db.c 
b/src/exchange/taler-exchange-httpd_db.c
index 1f47f8e1..3b9dc36b 100644
--- a/src/exchange/taler-exchange-httpd_db.c
+++ b/src/exchange/taler-exchange-httpd_db.c
@@ -168,8 +168,8 @@ TEH_DB_run_transaction (struct MHD_Connection *connection,
 // FIXME: maybe move to another module, i.e. exchangedb???
 int
 TEH_DB_calculate_transaction_list_totals (struct 
TALER_EXCHANGEDB_TransactionList *tl,
-                                         const struct TALER_Amount *off,
-                                         struct TALER_Amount *ret)
+                                          const struct TALER_Amount *off,
+                                          struct TALER_Amount *ret)
 {
   struct TALER_Amount spent = *off;
   struct TALER_Amount refunded;
@@ -222,6 +222,17 @@ TEH_DB_calculate_transaction_list_totals (struct 
TALER_EXCHANGEDB_TransactionLis
         return GNUNET_SYSERR;
       }
       break;
+    case TALER_EXCHANGEDB_TT_OLD_COIN_PAYBACK:
+      /* refunded += pos->value */
+      if (GNUNET_OK !=
+          TALER_amount_add (&refunded,
+                            &refunded,
+                            &pos->details.old_coin_payback->value))
+      {
+        GNUNET_break (0);
+        return GNUNET_SYSERR;
+      }
+      break;
     case TALER_EXCHANGEDB_TT_PAYBACK:
       /* spent += pos->value */
       if (GNUNET_OK !=
@@ -233,6 +244,17 @@ TEH_DB_calculate_transaction_list_totals (struct 
TALER_EXCHANGEDB_TransactionLis
         return GNUNET_SYSERR;
       }
       break;
+    case TALER_EXCHANGEDB_TT_PAYBACK_REFRESH:
+      /* spent += pos->value */
+      if (GNUNET_OK !=
+          TALER_amount_add (&spent,
+                            &spent,
+                            &pos->details.payback_refresh->value))
+      {
+        GNUNET_break (0);
+        return GNUNET_SYSERR;
+      }
+      break;
     }
   }
   /* spent = spent - refunded */
diff --git a/src/exchange/taler-exchange-httpd_payback.c 
b/src/exchange/taler-exchange-httpd_payback.c
index 232c639e..2f1a2dde 100644
--- a/src/exchange/taler-exchange-httpd_payback.c
+++ b/src/exchange/taler-exchange-httpd_payback.c
@@ -285,26 +285,6 @@ payback_transaction (void *cls,
     }
     return qs;
   }
-  /* increment reserve balance */
-  qs = TEH_plugin->increment_reserve_balance (TEH_plugin->cls,
-                                              session,
-                                              &pc->reserve_pub,
-                                              pc->coin,
-                                              pc->coin_sig,
-                                              pc->coin_bks,
-                                              &pc->amount,
-                                              &pc->h_blind,
-                                              pc->now);
-  if (0 > qs)
-  {
-    if (GNUNET_DB_STATUS_HARD_ERROR == qs)
-    {
-      TALER_LOG_WARNING ("Failed to store /payback information in database\n");
-      *mhd_ret = TEH_RESPONSE_reply_internal_db_error (connection,
-                                                       
TALER_EC_PAYBACK_DB_PUT_FAILED);
-    }
-    return qs;
-  }
   return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
 }
 
diff --git a/src/exchange/taler-exchange-httpd_refund.c 
b/src/exchange/taler-exchange-httpd_refund.c
index ee6aac1b..69b5cae9 100644
--- a/src/exchange/taler-exchange-httpd_refund.c
+++ b/src/exchange/taler-exchange-httpd_refund.c
@@ -236,9 +236,15 @@ refund_transaction (void *cls,
         }
       }
       break;
+    case TALER_EXCHANGEDB_TT_OLD_COIN_PAYBACK:
+      /* Paybacks cannot be refunded, ignore here */
+      break;
     case TALER_EXCHANGEDB_TT_PAYBACK:
       /* Paybacks cannot be refunded, ignore here */
       break;
+    case TALER_EXCHANGEDB_TT_PAYBACK_REFRESH:
+      /* Paybacks cannot be refunded, ignore here */
+      break;
     }
   }
   /* handle if deposit was NOT found */
diff --git a/src/exchange/taler-exchange-httpd_responses.c 
b/src/exchange/taler-exchange-httpd_responses.c
index 8b242096..3cf3e781 100644
--- a/src/exchange/taler-exchange-httpd_responses.c
+++ b/src/exchange/taler-exchange-httpd_responses.c
@@ -29,6 +29,14 @@
 #include "taler_json_lib.h"
 #include "taler-exchange-httpd_keystate.h"
 
+/**
+ * Enable checking signatures before we hand them out
+ * (even though we should have checked them before).
+ * So technically these checks are redundant, but good
+ * during testing.
+ */
+#define SANITY_CHECKS_ON 1
+
 
 /**
  * Add headers we want to return in every response.
@@ -97,7 +105,7 @@ TEH_RESPONSE_can_compress (struct MHD_Connection *connection)
  */
 int
 TEH_RESPONSE_body_compress (void **buf,
-                           size_t *buf_size)
+                            size_t *buf_size)
 {
   Bytef *cbuf;
   uLongf cbuf_size;
@@ -251,14 +259,14 @@ TEH_RESPONSE_reply_json_pack (struct MHD_Connection 
*connection,
  */
 int
 TEH_RESPONSE_reply_arg_invalid (struct MHD_Connection *connection,
-                               enum TALER_ErrorCode ec,
+                                enum TALER_ErrorCode ec,
                                 const char *param_name)
 {
   return TEH_RESPONSE_reply_json_pack (connection,
                                        MHD_HTTP_BAD_REQUEST,
                                        "{s:s, s:I, s:s}",
                                        "error", "invalid parameter",
-                                      "code", (json_int_t) ec,
+                                       "code", (json_int_t) ec,
                                        "parameter", param_name);
 }
 
@@ -275,14 +283,14 @@ TEH_RESPONSE_reply_arg_invalid (struct MHD_Connection 
*connection,
  */
 int
 TEH_RESPONSE_reply_arg_unknown (struct MHD_Connection *connection,
-                               enum TALER_ErrorCode ec,
+                                enum TALER_ErrorCode ec,
                                 const char *param_name)
 {
   return TEH_RESPONSE_reply_json_pack (connection,
                                        MHD_HTTP_NOT_FOUND,
                                        "{s:s, s:I, s:s}",
                                        "error", "unknown entity referenced",
-                                      "code", (json_int_t) ec,
+                                       "code", (json_int_t) ec,
                                        "parameter", param_name);
 }
 
@@ -297,14 +305,14 @@ TEH_RESPONSE_reply_arg_unknown (struct MHD_Connection 
*connection,
  */
 int
 TEH_RESPONSE_reply_signature_invalid (struct MHD_Connection *connection,
-                                     enum TALER_ErrorCode ec,
+                                      enum TALER_ErrorCode ec,
                                       const char *param_name)
 {
   return TEH_RESPONSE_reply_json_pack (connection,
                                        MHD_HTTP_UNAUTHORIZED,
                                        "{s:s, s:I, s:s}",
                                        "error", "invalid signature",
-                                      "code", (json_int_t) ec,
+                                       "code", (json_int_t) ec,
                                        "parameter", param_name);
 }
 
@@ -370,7 +378,7 @@ TEH_RESPONSE_reply_external_error (struct MHD_Connection 
*connection,
                                        MHD_HTTP_BAD_REQUEST,
                                        "{s:s, s:I, s:s}",
                                        "error", "client error",
-                                      "code", (json_int_t) ec,
+                                       "code", (json_int_t) ec,
                                        "hint", hint);
 }
 
@@ -391,7 +399,7 @@ TEH_RESPONSE_reply_commit_error (struct MHD_Connection 
*connection,
                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
                                        "{s:s, s:I}",
                                        "error", "commit failure",
-                                      "code", (json_int_t) ec);
+                                       "code", (json_int_t) ec);
 }
 
 
@@ -405,10 +413,10 @@ TEH_RESPONSE_reply_commit_error (struct MHD_Connection 
*connection,
  */
 int
 TEH_RESPONSE_reply_internal_db_error (struct MHD_Connection *connection,
-                                     enum TALER_ErrorCode ec)
+                                      enum TALER_ErrorCode ec)
 {
   return TEH_RESPONSE_reply_internal_error (connection,
-                                           ec,
+                                            ec,
                                             "Failure in database interaction");
 }
 
@@ -452,7 +460,7 @@ TEH_RESPONSE_reply_invalid_json (struct MHD_Connection 
*connection)
                                        MHD_HTTP_BAD_REQUEST,
                                        "{s:s, s:I}",
                                        "error", "invalid json",
-                                      "code", (json_int_t) 
TALER_EC_JSON_INVALID);
+                                       "code", (json_int_t) 
TALER_EC_JSON_INVALID);
 }
 
 
@@ -473,7 +481,9 @@ TEH_RESPONSE_compile_transaction_history (const struct 
TALER_EXCHANGEDB_Transact
     GNUNET_break (0); /* out of memory!? */
     return NULL;
   }
-  for (const struct TALER_EXCHANGEDB_TransactionList *pos = tl; NULL != pos; 
pos = pos->next)
+  for (const struct TALER_EXCHANGEDB_TransactionList *pos = tl;
+       NULL != pos;
+       pos = pos->next)
   {
     switch (pos->type)
     {
@@ -494,31 +504,37 @@ TEH_RESPONSE_compile_transaction_history (const struct 
TALER_EXCHANGEDB_Transact
                            &deposit->deposit_fee);
         dr.merchant = deposit->merchant_pub;
         dr.coin_pub = deposit->coin.coin_pub;
-       /* internal sanity check before we hand out a bogus sig... */
+#if SANITY_CHECKS_ON
+        /* internal sanity check before we hand out a bogus sig... */
         if (GNUNET_OK !=
             GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_DEPOSIT,
                                         &dr.purpose,
                                         &deposit->csig.eddsa_signature,
                                         &deposit->coin.coin_pub.eddsa_pub))
-       {
-         GNUNET_break (0);
-         json_decref (history);
-         return NULL;
-       }
-
-       GNUNET_assert (0 ==
-                      json_array_append_new (history,
-                                             json_pack ("{s:s, s:o, s:o, s:o, 
s:o, s:o, s:o, s:o, s:o}",
-                                                        "type", "DEPOSIT",
-                                                        "amount", 
TALER_JSON_from_amount (&deposit->amount_with_fee),
-                                                        "deposit_fee", 
TALER_JSON_from_amount (&deposit->deposit_fee),
-                                                        "timestamp", 
GNUNET_JSON_from_time_abs (deposit->timestamp),
-                                                        "refund_deadline", 
GNUNET_JSON_from_time_abs (deposit->refund_deadline),
-                                                        "merchant_pub", 
GNUNET_JSON_from_data_auto (&deposit->merchant_pub),
-                                                        "h_contract_terms", 
GNUNET_JSON_from_data_auto (&deposit->h_contract_terms),
-                                                        "h_wire", 
GNUNET_JSON_from_data_auto (&deposit->h_wire),
-                                                        "coin_sig", 
GNUNET_JSON_from_data_auto (&deposit->csig))));
-       break;
+        {
+          GNUNET_break (0);
+          json_decref (history);
+          return NULL;
+        }
+#endif
+        if (0 !=
+            json_array_append_new (history,
+                                   json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o, 
s:o, s:o, s:o}",
+                                              "type", "DEPOSIT",
+                                              "amount", TALER_JSON_from_amount 
(&deposit->amount_with_fee),
+                                              "deposit_fee", 
TALER_JSON_from_amount (&deposit->deposit_fee),
+                                              "timestamp", 
GNUNET_JSON_from_time_abs (deposit->timestamp),
+                                              "refund_deadline", 
GNUNET_JSON_from_time_abs (deposit->refund_deadline),
+                                              "merchant_pub", 
GNUNET_JSON_from_data_auto (&deposit->merchant_pub),
+                                              "h_contract_terms", 
GNUNET_JSON_from_data_auto (&deposit->h_contract_terms),
+                                              "h_wire", 
GNUNET_JSON_from_data_auto (&deposit->h_wire),
+                                              "coin_sig", 
GNUNET_JSON_from_data_auto (&deposit->csig))))
+        {
+          GNUNET_break (0);
+          json_decref (history);
+          return NULL;
+        }
+        break;
       }
     case TALER_EXCHANGEDB_TT_REFRESH_MELT:
       {
@@ -533,42 +549,48 @@ TEH_RESPONSE_compile_transaction_history (const struct 
TALER_EXCHANGEDB_Transact
         TALER_amount_hton (&ms.melt_fee,
                            &melt->melt_fee);
         ms.coin_pub = melt->session.coin.coin_pub;
-       /* internal sanity check before we hand out a bogus sig... */
+#if SANITY_CHECKS_ON
+        /* internal sanity check before we hand out a bogus sig... */
         if (GNUNET_OK !=
             GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_MELT,
                                         &ms.purpose,
                                         
&melt->session.coin_sig.eddsa_signature,
                                         
&melt->session.coin.coin_pub.eddsa_pub))
-       {
-         GNUNET_break (0);
-         json_decref (history);
-         return NULL;
-       }
-
-       GNUNET_assert (0 ==
-                      json_array_append_new (history,
-                                             json_pack ("{s:s, s:o, s:o, s:o, 
s:o}",
-                                                        "type", "MELT",
-                                                        "amount", 
TALER_JSON_from_amount (&melt->session.amount_with_fee),
-                                                        "melt_fee", 
TALER_JSON_from_amount (&melt->melt_fee),
-                                                        "rc", 
GNUNET_JSON_from_data_auto (&melt->session.rc),
-                                                        "coin_sig", 
GNUNET_JSON_from_data_auto (&melt->session.coin_sig))));
+        {
+          GNUNET_break (0);
+          json_decref (history);
+          return NULL;
+        }
+#endif
+        if (0 !=
+            json_array_append_new (history,
+                                   json_pack ("{s:s, s:o, s:o, s:o, s:o}",
+                                              "type", "MELT",
+                                              "amount", TALER_JSON_from_amount 
(&melt->session.amount_with_fee),
+                                              "melt_fee", 
TALER_JSON_from_amount (&melt->melt_fee),
+                                              "rc", GNUNET_JSON_from_data_auto 
(&melt->session.rc),
+                                              "coin_sig", 
GNUNET_JSON_from_data_auto (&melt->session.coin_sig))))
+        {
+          GNUNET_break (0);
+          json_decref (history);
+          return NULL;
+        }
       }
       break;
     case TALER_EXCHANGEDB_TT_REFUND:
       {
         struct TALER_RefundRequestPS rr;
         const struct TALER_EXCHANGEDB_Refund *refund = pos->details.refund;
-       struct TALER_Amount value;
+        struct TALER_Amount value;
 
         if (GNUNET_OK !=
             TALER_amount_subtract (&value,
                                    &refund->refund_amount,
                                    &refund->refund_fee))
         {
-         GNUNET_break (0);
-         json_decref (history);
-         return NULL;
+          GNUNET_break (0);
+          json_decref (history);
+          return NULL;
         }
         rr.purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_REFUND);
         rr.purpose.size = htonl (sizeof (struct TALER_RefundRequestPS));
@@ -580,30 +602,80 @@ TEH_RESPONSE_compile_transaction_history (const struct 
TALER_EXCHANGEDB_Transact
                            &refund->refund_amount);
         TALER_amount_hton (&rr.refund_fee,
                            &refund->refund_fee);
-       /* internal sanity check before we hand out a bogus sig... */
+#if SANITY_CHECKS_ON
+        /* internal sanity check before we hand out a bogus sig... */
         if (GNUNET_OK !=
             GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_REFUND,
                                         &rr.purpose,
                                         &refund->merchant_sig.eddsa_sig,
                                         &refund->merchant_pub.eddsa_pub))
-       {
-         GNUNET_break (0);
-         json_decref (history);
-         return NULL;
-       }
-
-       GNUNET_assert (0 ==
-                      json_array_append_new (history,
-                                             json_pack ("{s:s, s:o, s:o, s:o, 
s:o, s:I, s:o}",
-                                                        "type", "REFUND",
-                                                        "amount", 
TALER_JSON_from_amount (&value),
-                                                        "refund_fee", 
TALER_JSON_from_amount (&refund->refund_fee),
-                                                        "h_contract_terms", 
GNUNET_JSON_from_data_auto (&refund->h_contract_terms),
-                                                        "merchant_pub", 
GNUNET_JSON_from_data_auto (&refund->merchant_pub),
-                                                        "rtransaction_id", 
(json_int_t) refund->rtransaction_id,
-                                                        "merchant_sig", 
GNUNET_JSON_from_data_auto (&refund->merchant_sig))));
+        {
+          GNUNET_break (0);
+          json_decref (history);
+          return NULL;
+        }
+#endif
+        if (0 !=
+            json_array_append_new (history,
+                                   json_pack ("{s:s, s:o, s:o, s:o, s:o, s:I, 
s:o}",
+                                              "type", "REFUND",
+                                              "amount", TALER_JSON_from_amount 
(&value),
+                                              "refund_fee", 
TALER_JSON_from_amount (&refund->refund_fee),
+                                              "h_contract_terms", 
GNUNET_JSON_from_data_auto (&refund->h_contract_terms),
+                                              "merchant_pub", 
GNUNET_JSON_from_data_auto (&refund->merchant_pub),
+                                              "rtransaction_id", (json_int_t) 
refund->rtransaction_id,
+                                              "merchant_sig", 
GNUNET_JSON_from_data_auto (&refund->merchant_sig))))
+        {
+          GNUNET_break (0);
+          json_decref (history);
+          return NULL;
+        }
       }
       break;
+    case TALER_EXCHANGEDB_TT_OLD_COIN_PAYBACK:
+      {
+        struct TALER_EXCHANGEDB_PaybackRefresh *pr = 
pos->details.old_coin_payback;
+        struct TALER_PaybackRefreshConfirmationPS pc;
+        struct TALER_ExchangePublicKeyP epub;
+        struct TALER_ExchangeSignatureP esig;
+
+        pc.purpose.purpose = htonl 
(TALER_SIGNATURE_EXCHANGE_CONFIRM_PAYBACK_REFRESH);
+        pc.purpose.size = htonl (sizeof (pc));
+        pc.timestamp = GNUNET_TIME_absolute_hton (pr->timestamp);
+        TALER_amount_hton (&pc.payback_amount,
+                           &pr->value);
+        pc.coin_pub = pr->coin.coin_pub;
+        pc.old_coin_pub = pr->old_coin_pub;
+        if (GNUNET_OK !=
+            TEH_KS_sign (&pc.purpose,
+                         &epub,
+                         &esig))
+        {
+          GNUNET_break (0);
+          json_decref (history);
+          return NULL;
+        }
+        /* NOTE: we could also provide coin_pub's coin_sig, denomination key 
hash and
+           the denomination key's RSA signature over coin_pub, but as the
+           wallet should really already have this information (and cannot
+           check or do anything with it anyway if it doesn't), it seems
+           strictly unnecessary. */
+        if (0 !=
+            json_array_append_new (history,
+                                   json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
+                                              "type", "OLD-COIN-PAYBACK",
+                                              "amount", TALER_JSON_from_amount 
(&pr->value),
+                                              "exchange_sig", 
GNUNET_JSON_from_data_auto (&esig),
+                                              "exchange_pub", 
GNUNET_JSON_from_data_auto (&epub),
+                                              "coin_pub", 
GNUNET_JSON_from_data_auto (&pr->coin.coin_pub),
+                                              "timestamp", 
GNUNET_JSON_from_time_abs (pr->timestamp))))
+        {
+          GNUNET_break (0);
+          json_decref (history);
+          return NULL;
+        }
+        break;
+      }
     case TALER_EXCHANGEDB_TT_PAYBACK:
       {
         const struct TALER_EXCHANGEDB_Payback *payback = pos->details.payback;
@@ -619,25 +691,74 @@ TEH_RESPONSE_compile_transaction_history (const struct 
TALER_EXCHANGEDB_Transact
         pc.coin_pub = payback->coin.coin_pub;
         pc.reserve_pub = payback->reserve_pub;
         if (GNUNET_OK !=
-           TEH_KS_sign (&pc.purpose,
-                        &epub,
-                        &esig))
-       {
-         GNUNET_break (0);
-         json_decref (history);
-         return NULL;
-       }
-        GNUNET_assert (0 ==
-                       json_array_append_new (history,
-                                              json_pack ("{s:s, s:o, s:o, s:o, 
s:o, s:o}",
-                                                         "type", "PAYBACK",
-                                                         "amount", 
TALER_JSON_from_amount (&payback->value),
-                                                         "exchange_sig", 
GNUNET_JSON_from_data_auto (&esig),
-                                                         "exchange_pub", 
GNUNET_JSON_from_data_auto (&epub),
-                                                        "reserve_pub", 
GNUNET_JSON_from_data_auto (&payback->reserve_pub),
-                                                        "timestamp", 
GNUNET_JSON_from_time_abs (payback->timestamp))));
+            TEH_KS_sign (&pc.purpose,
+                         &epub,
+                         &esig))
+        {
+          GNUNET_break (0);
+          json_decref (history);
+          return NULL;
+        }
+        if (0 !=
+            json_array_append_new (history,
+                                   json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
+                                              "type", "PAYBACK",
+                                              "amount", TALER_JSON_from_amount 
(&payback->value),
+                                              "exchange_sig", 
GNUNET_JSON_from_data_auto (&esig),
+                                              "exchange_pub", 
GNUNET_JSON_from_data_auto (&epub),
+                                              "reserve_pub", 
GNUNET_JSON_from_data_auto (&payback->reserve_pub),
+                                              "timestamp", 
GNUNET_JSON_from_time_abs (payback->timestamp))))
+        {
+          GNUNET_break (0);
+          json_decref (history);
+          return NULL;
+        }
       }
       break;
+    case TALER_EXCHANGEDB_TT_PAYBACK_REFRESH:
+      {
+        struct TALER_EXCHANGEDB_PaybackRefresh *pr = 
pos->details.payback_refresh;
+        struct TALER_PaybackRefreshConfirmationPS pc;
+        struct TALER_ExchangePublicKeyP epub;
+        struct TALER_ExchangeSignatureP esig;
+
+        pc.purpose.purpose = htonl 
(TALER_SIGNATURE_EXCHANGE_CONFIRM_PAYBACK_REFRESH);
+        pc.purpose.size = htonl (sizeof (pc));
+        pc.timestamp = GNUNET_TIME_absolute_hton (pr->timestamp);
+        TALER_amount_hton (&pc.payback_amount,
+                           &pr->value);
+        pc.coin_pub = pr->coin.coin_pub;
+        pc.old_coin_pub = pr->old_coin_pub;
+        if (GNUNET_OK !=
+            TEH_KS_sign (&pc.purpose,
+                         &epub,
+                         &esig))
+        {
+          GNUNET_break (0);
+          json_decref (history);
+          return NULL;
+        }
+        /* NOTE: we could also provide coin_pub's coin_sig, denomination key
+           hash and the denomination key's RSA signature over coin_pub, but as
+           the wallet should really already have this information (and cannot
+           check or do anything with it anyway if it doesn't), it seems
+           strictly unnecessary. */
+        if (0 !=
+            json_array_append_new (history,
+                                   json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
+                                              "type", "PAYBACK-REFRESH",
+                                              "amount", TALER_JSON_from_amount 
(&pr->value),
+                                              "exchange_sig", 
GNUNET_JSON_from_data_auto (&esig),
+                                              "exchange_pub", 
GNUNET_JSON_from_data_auto (&epub),
+                                              "old_coin_pub", 
GNUNET_JSON_from_data_auto (&pr->old_coin_pub),
+                                              "timestamp", 
GNUNET_JSON_from_time_abs (pr->timestamp))))
+        {
+          GNUNET_break (0);
+          json_decref (history);
+          return NULL;
+        }
+        break;
+      }
     default:
       GNUNET_assert (0);
     }
@@ -673,7 +794,7 @@ TEH_RESPONSE_reply_coin_insufficient_funds (struct 
MHD_Connection *connection,
                                        MHD_HTTP_FORBIDDEN,
                                        "{s:s, s:I, s:o}",
                                        "error", "insufficient funds",
-                                      "code", (json_int_t) ec,
+                                       "code", (json_int_t) ec,
                                        "history", history);
 }
 
@@ -688,7 +809,7 @@ TEH_RESPONSE_reply_coin_insufficient_funds (struct 
MHD_Connection *connection,
  */
 json_t *
 TEH_RESPONSE_compile_reserve_history (const struct 
TALER_EXCHANGEDB_ReserveHistory *rh,
-                                     struct TALER_Amount *balance)
+                                      struct TALER_Amount *balance)
 {
   struct TALER_Amount deposit_total;
   struct TALER_Amount withdraw_total;
@@ -717,155 +838,175 @@ TEH_RESPONSE_compile_reserve_history (const struct 
TALER_EXCHANGEDB_ReserveHisto
           return NULL;
         }
       ret |= 1;
-      GNUNET_assert (0 ==
-                     json_array_append_new (json_history,
-                                            json_pack ("{s:s, s:o, s:s, s:o, 
s:o}",
-                                                       "type", "DEPOSIT",
-                                                       "timestamp", 
GNUNET_JSON_from_time_abs (pos->details.bank->execution_date),
-                                                       "sender_account_url", 
pos->details.bank->sender_account_details,
-                                                       "wire_reference", 
GNUNET_JSON_from_data (pos->details.bank->wire_reference,
-                                                                               
                 pos->details.bank->wire_reference_size),
-                                                       "amount", 
TALER_JSON_from_amount (&pos->details.bank->amount))));
+      if (0 !=
+          json_array_append_new (json_history,
+                                 json_pack ("{s:s, s:o, s:s, s:o, s:o}",
+                                            "type", "DEPOSIT",
+                                            "timestamp", 
GNUNET_JSON_from_time_abs (pos->details.bank->execution_date),
+                                            "sender_account_url", 
pos->details.bank->sender_account_details,
+                                            "wire_reference", 
GNUNET_JSON_from_data (pos->details.bank->wire_reference,
+                                                                               
      pos->details.bank->wire_reference_size),
+                                            "amount", TALER_JSON_from_amount 
(&pos->details.bank->amount))))
+      {
+        GNUNET_break (0);
+           json_decref (json_history);
+           return NULL;
+      }
       break;
     case TALER_EXCHANGEDB_RO_WITHDRAW_COIN:
       {
-       struct TALER_Amount value;
-
-       value = pos->details.withdraw->amount_with_fee;
-       if (0 == (2 & ret))
-       {
-         withdraw_total = value;
-       }
-       else
-       {
-         if (GNUNET_OK !=
-             TALER_amount_add (&withdraw_total,
-                               &withdraw_total,
-                               &value))
-         {
+        struct TALER_Amount value;
+
+        value = pos->details.withdraw->amount_with_fee;
+        if (0 == (2 & ret))
+        {
+          withdraw_total = value;
+        }
+        else
+        {
+          if (GNUNET_OK !=
+              TALER_amount_add (&withdraw_total,
+                                &withdraw_total,
+                                &value))
+          {
             GNUNET_break (0);
-           json_decref (json_history);
-           return NULL;
-         }
-       }
-       ret |= 2;
-       GNUNET_assert (0 ==
-                      json_array_append_new (json_history,
-                                             json_pack ("{s:s, s:o, s:o, s:o, 
s:o, s:o}",
-                                                        "type", "WITHDRAW",
-                                                        "reserve_sig", 
GNUNET_JSON_from_data_auto (&pos->details.withdraw->reserve_sig),
-                                                        "h_coin_envelope", 
GNUNET_JSON_from_data_auto (&pos->details.withdraw->h_coin_envelope),
-                                                        "h_denom_pub", 
GNUNET_JSON_from_data_auto (&pos->details.withdraw->denom_pub_hash),
-                                                        "withdraw_fee", 
TALER_JSON_from_amount (&pos->details.withdraw->withdraw_fee),
-                                                        "amount", 
TALER_JSON_from_amount (&value))));
+            json_decref (json_history);
+            return NULL;
+          }
+        }
+        ret |= 2;
+        if (0 !=
+            json_array_append_new (json_history,
+                                   json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
+                                              "type", "WITHDRAW",
+                                              "reserve_sig", 
GNUNET_JSON_from_data_auto (&pos->details.withdraw->reserve_sig),
+                                              "h_coin_envelope", 
GNUNET_JSON_from_data_auto (&pos->details.withdraw->h_coin_envelope),
+                                              "h_denom_pub", 
GNUNET_JSON_from_data_auto (&pos->details.withdraw->denom_pub_hash),
+                                              "withdraw_fee", 
TALER_JSON_from_amount (&pos->details.withdraw->withdraw_fee),
+                                              "amount", TALER_JSON_from_amount 
(&value))))
+        {
+          GNUNET_break (0);
+          json_decref (json_history);
+          return NULL;
+        }
       }
       break;
     case TALER_EXCHANGEDB_RO_PAYBACK_COIN:
       {
-       const struct TALER_EXCHANGEDB_Payback *payback;
-       struct TALER_PaybackConfirmationPS pc;
-       struct TALER_ExchangePublicKeyP pub;
-       struct TALER_ExchangeSignatureP sig;
-
-       payback = pos->details.payback;
-       if (0 == (1 & ret))
-         deposit_total = payback->value;
-       else
-         if (GNUNET_OK !=
-             TALER_amount_add (&deposit_total,
-                               &deposit_total,
-                               &payback->value))
-         {
+        const struct TALER_EXCHANGEDB_Payback *payback;
+        struct TALER_PaybackConfirmationPS pc;
+        struct TALER_ExchangePublicKeyP pub;
+        struct TALER_ExchangeSignatureP sig;
+
+        payback = pos->details.payback;
+        if (0 == (1 & ret))
+          deposit_total = payback->value;
+        else
+          if (GNUNET_OK !=
+              TALER_amount_add (&deposit_total,
+                                &deposit_total,
+                                &payback->value))
+          {
             GNUNET_break (0);
-           json_decref (json_history);
-           return NULL;
-         }
-       ret |= 1;
-       pc.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_PAYBACK);
-       pc.purpose.size = htonl (sizeof (struct TALER_PaybackConfirmationPS));
-       pc.timestamp = GNUNET_TIME_absolute_hton (payback->timestamp);
-       TALER_amount_hton (&pc.payback_amount,
-                          &payback->value);
-       pc.coin_pub = payback->coin.coin_pub;
-       pc.reserve_pub = payback->reserve_pub;
-       if (GNUNET_OK !=
-           TEH_KS_sign (&pc.purpose,
-                        &pub,
-                        &sig))
-       {
-         GNUNET_break (0);
-         json_decref (json_history);
-         return NULL;
-       }
-
-        GNUNET_assert (0 ==
-                      json_array_append_new (json_history,
-                                             json_pack ("{s:s, s:o, s:o, s:o, 
s:o, s:o}",
-                                                        "type", "PAYBACK",
-                                                        "exchange_pub", 
GNUNET_JSON_from_data_auto (&pub),
-                                                        "exchange_sig", 
GNUNET_JSON_from_data_auto (&sig),
-                                                        "timestamp", 
GNUNET_JSON_from_time_abs (payback->timestamp),
-                                                        "amount", 
TALER_JSON_from_amount (&payback->value),
-                                                        "coin_pub", 
GNUNET_JSON_from_data_auto (&payback->coin.coin_pub))));
+            json_decref (json_history);
+            return NULL;
+          }
+        ret |= 1;
+        pc.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_PAYBACK);
+        pc.purpose.size = htonl (sizeof (struct TALER_PaybackConfirmationPS));
+        pc.timestamp = GNUNET_TIME_absolute_hton (payback->timestamp);
+        TALER_amount_hton (&pc.payback_amount,
+                           &payback->value);
+        pc.coin_pub = payback->coin.coin_pub;
+        pc.reserve_pub = payback->reserve_pub;
+        if (GNUNET_OK !=
+            TEH_KS_sign (&pc.purpose,
+                         &pub,
+                         &sig))
+        {
+          GNUNET_break (0);
+          json_decref (json_history);
+          return NULL;
+        }
+
+        if (0 !=
+            json_array_append_new (json_history,
+                                   json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
+                                              "type", "PAYBACK",
+                                              "exchange_pub", 
GNUNET_JSON_from_data_auto (&pub),
+                                              "exchange_sig", 
GNUNET_JSON_from_data_auto (&sig),
+                                              "timestamp", 
GNUNET_JSON_from_time_abs (payback->timestamp),
+                                              "amount", TALER_JSON_from_amount 
(&payback->value),
+                                              "coin_pub", 
GNUNET_JSON_from_data_auto (&payback->coin.coin_pub))))
+        {
+          GNUNET_break (0);
+          json_decref (json_history);
+          return NULL;
+        }
       }
       break;
     case TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK:
       {
+        struct TALER_ReserveCloseConfirmationPS rcc;
+        struct TALER_ExchangePublicKeyP pub;
+        struct TALER_ExchangeSignatureP sig;
+        struct TALER_Amount value;
 
-       struct TALER_ReserveCloseConfirmationPS rcc;
-       struct TALER_ExchangePublicKeyP pub;
-       struct TALER_ExchangeSignatureP sig;
-       struct TALER_Amount value;
-
-       value = pos->details.closing->amount;
-       if (0 == (2 & ret))
-       {
-         withdraw_total = value;
-       }
-       else
-       {
-         if (GNUNET_OK !=
-             TALER_amount_add (&withdraw_total,
-                               &withdraw_total,
-                               &value))
-         {
-           json_decref (json_history);
-           return NULL;
-         }
-       }
-       ret |= 2;
+        value = pos->details.closing->amount;
+        if (0 == (2 & ret))
+        {
+          withdraw_total = value;
+        }
+        else
+        {
+          if (GNUNET_OK !=
+              TALER_amount_add (&withdraw_total,
+                                &withdraw_total,
+                                &value))
+          {
+            GNUNET_break (0);
+            json_decref (json_history);
+            return NULL;
+          }
+        }
+        ret |= 2;
         rcc.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_RESERVE_CLOSED);
-       rcc.purpose.size = htonl (sizeof (struct 
TALER_ReserveCloseConfirmationPS));
-       rcc.timestamp = GNUNET_TIME_absolute_hton 
(pos->details.closing->execution_date);
-       TALER_amount_hton (&rcc.closing_amount,
-                          &value);
-       TALER_amount_hton (&rcc.closing_fee,
-                          &pos->details.closing->closing_fee);
-       rcc.reserve_pub = pos->details.closing->reserve_pub;
+        rcc.purpose.size = htonl (sizeof (struct 
TALER_ReserveCloseConfirmationPS));
+        rcc.timestamp = GNUNET_TIME_absolute_hton 
(pos->details.closing->execution_date);
+        TALER_amount_hton (&rcc.closing_amount,
+                           &value);
+        TALER_amount_hton (&rcc.closing_fee,
+                           &pos->details.closing->closing_fee);
+        rcc.reserve_pub = pos->details.closing->reserve_pub;
         GNUNET_CRYPTO_hash (pos->details.closing->receiver_account_details,
                             strlen 
(pos->details.closing->receiver_account_details) + 1,
                             &rcc.h_wire);
-       rcc.wtid = pos->details.closing->wtid;
-       if (GNUNET_OK !=
-           TEH_KS_sign (&rcc.purpose,
-                        &pub,
-                        &sig))
-       {
+        rcc.wtid = pos->details.closing->wtid;
+        if (GNUNET_OK !=
+            TEH_KS_sign (&rcc.purpose,
+                         &pub,
+                         &sig))
+        {
+          GNUNET_break (0);
+          json_decref (json_history);
+          return NULL;
+        }
+        if (0 !=
+            json_array_append_new (json_history,
+                                   json_pack ("{s:s, s:s, s:o, s:o, s:o, s:o, 
s:o, s:o}",
+                                              "type", "CLOSING",
+                                              "receiver_account_details", 
pos->details.closing->receiver_account_details,
+                                              "wtid", 
GNUNET_JSON_from_data_auto (&pos->details.closing->wtid),
+                                              "exchange_pub", 
GNUNET_JSON_from_data_auto (&pub),
+                                              "exchange_sig", 
GNUNET_JSON_from_data_auto (&sig),
+                                              "timestamp", 
GNUNET_JSON_from_time_abs (pos->details.closing->execution_date),
+                                              "amount", TALER_JSON_from_amount 
(&value),
+                                              "closing_fee", 
TALER_JSON_from_amount (&pos->details.closing->closing_fee))))
+        {
           GNUNET_break (0);
           json_decref (json_history);
           return NULL;
-       }
-       GNUNET_assert (0 ==
-                      json_array_append_new (json_history,
-                                             json_pack ("{s:s, s:s, s:o, s:o, 
s:o, s:o, s:o, s:o}",
-                                                        "type", "CLOSING",
-                                                        
"receiver_account_details", pos->details.closing->receiver_account_details,
-                                                        "wtid", 
GNUNET_JSON_from_data_auto (&pos->details.closing->wtid),
-                                                        "exchange_pub", 
GNUNET_JSON_from_data_auto (&pub),
-                                                        "exchange_sig", 
GNUNET_JSON_from_data_auto (&sig),
-                                                        "timestamp", 
GNUNET_JSON_from_time_abs (pos->details.closing->execution_date),
-                                                        "amount", 
TALER_JSON_from_amount (&value),
-                                                        "closing_fee", 
TALER_JSON_from_amount (&pos->details.closing->closing_fee))));
+        }
       }
       break;
     }
@@ -909,14 +1050,13 @@ TEH_RESPONSE_compile_reserve_history (const struct 
TALER_EXCHANGEDB_ReserveHisto
  */
 int
 TEH_RESPONSE_reply_transaction_unknown (struct MHD_Connection *connection,
-                                       enum TALER_ErrorCode ec)
+                                        enum TALER_ErrorCode ec)
 {
   return TEH_RESPONSE_reply_json_pack (connection,
                                        MHD_HTTP_NOT_FOUND,
                                        "{s:s, s:I}",
                                        "error", "Deposit unknown",
-                                      "code", (json_int_t) ec);
+                                       "code", (json_int_t) ec);
 }
 
-
 /* end of taler-exchange-httpd_responses.c */
diff --git a/src/exchangedb/plugin_exchangedb_common.c 
b/src/exchangedb/plugin_exchangedb_common.c
index 4a72f546..4c381586 100644
--- a/src/exchangedb/plugin_exchangedb_common.c
+++ b/src/exchangedb/plugin_exchangedb_common.c
@@ -100,6 +100,8 @@ common_free_coin_transaction_list (void *cls,
       GNUNET_free (list->details.melt);
       break;
     case TALER_EXCHANGEDB_TT_OLD_COIN_PAYBACK:
+      if (NULL != list->details.payback_refresh->coin.denom_sig.rsa_signature)
+        GNUNET_CRYPTO_rsa_signature_free 
(list->details.payback_refresh->coin.denom_sig.rsa_signature);
       GNUNET_free (list->details.old_coin_payback);
       break;
     case TALER_EXCHANGEDB_TT_REFUND:
@@ -113,6 +115,8 @@ common_free_coin_transaction_list (void *cls,
       GNUNET_free (list->details.payback);
       break;
     case TALER_EXCHANGEDB_TT_PAYBACK_REFRESH:
+      if (NULL != list->details.payback_refresh->coin.denom_sig.rsa_signature)
+        GNUNET_CRYPTO_rsa_signature_free 
(list->details.payback_refresh->coin.denom_sig.rsa_signature);
       GNUNET_free (list->details.payback_refresh);
       break;
     }
diff --git a/src/include/taler_signatures.h b/src/include/taler_signatures.h
index b738e315..aedf93e3 100644
--- a/src/include/taler_signatures.h
+++ b/src/include/taler_signatures.h
@@ -129,6 +129,11 @@
  */
 #define TALER_SIGNATURE_EXCHANGE_RESERVE_CLOSED 1040
 
+/**
+ * Signature where the Exchange confirms a payback-refresh operation.
+ */
+#define TALER_SIGNATURE_EXCHANGE_CONFIRM_PAYBACK_REFRESH 1041
+
 
 /**********************/
 /* Auditor signatures */
@@ -1229,7 +1234,7 @@ struct TALER_PaybackRequestPS
 /**
  * Response by which the exchange affirms that it will
  * refund a coin as part of the emergency /payback
- * protocol.  The refund will go back to the bank
+ * protocol.  The payback will go back to the bank
  * account that created the reserve.
  */
 struct TALER_PaybackConfirmationPS
@@ -1266,6 +1271,44 @@ struct TALER_PaybackConfirmationPS
 
 
 /**
+ * Response by which the exchange affirms that it will refund a refreshed coin
+ * as part of the emergency /payback protocol.  The payback will go back to the
+ * old coin's balance.
+ */
+struct TALER_PaybackRefreshConfirmationPS
+{
+
+  /**
+   * Purpose is #TALER_SIGNATURE_EXCHANGE_CONFIRM_PAYBACK_REFRESH
+   */
+  struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
+
+  /**
+   * When did the exchange receive the payback request?
+   * Indirectly determines when the wire transfer is (likely)
+   * to happen.
+   */
+  struct GNUNET_TIME_AbsoluteNBO timestamp;
+
+  /**
+   * How much of the coin's value will the exchange transfer?
+   * (Needed in case the coin was partially spent.)
+   */
+  struct TALER_AmountNBO payback_amount;
+
+  /**
+   * Public key of the refreshed coin.
+   */
+  struct TALER_CoinSpendPublicKeyP coin_pub;
+
+  /**
+   * Public key of the old coin that will receive the payback.
+   */
+  struct TALER_CoinSpendPublicKeyP old_coin_pub;
+};
+
+
+/**
  * Response by which the exchange affirms that it has
  * closed a reserve and send back the funds.
  */

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



reply via email to

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