gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated (260e2876 -> ca66a1d1)


From: gnunet
Subject: [taler-exchange] branch master updated (260e2876 -> ca66a1d1)
Date: Sun, 10 Jan 2021 00:54:32 +0100

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

grothoff pushed a change to branch master
in repository exchange.

    from 260e2876 change wire_reference to be uint64_t always; more work on 
lrbt_callbacks
     new 02ecf68a more optimizations of tables with foreign keys
     new ca66a1d1 fix major bug with SQL statement missing ORDER BY 
freshcoin_index resulting in possible link failures (but usually lucky with old 
DB schema)

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_link.c           |   4 +-
 .../taler-exchange-httpd_refreshes_reveal.c        |  42 +++---
 src/exchangedb/exchange-0002.sql                   |  49 +++++++
 src/exchangedb/plugin_exchangedb_postgres.c        |  92 +++++++-----
 src/include/taler_crypto_lib.h                     |  41 ++++++
 src/include/taler_exchangedb_plugin.h              | 155 ++++++++++++++++-----
 src/lib/exchange_api_link.c                        |  41 +++---
 src/lib/exchange_api_refreshes_reveal.c            |  30 ++--
 src/util/Makefile.am                               |   1 +
 src/util/wallet_signatures.c                       |  80 +++++++++++
 10 files changed, 391 insertions(+), 144 deletions(-)
 create mode 100644 src/util/wallet_signatures.c

diff --git a/src/exchange/taler-exchange-httpd_link.c 
b/src/exchange/taler-exchange-httpd_link.c
index 3edb25b2..b93d2e71 100644
--- a/src/exchange/taler-exchange-httpd_link.c
+++ b/src/exchange/taler-exchange-httpd_link.c
@@ -83,8 +83,8 @@ handle_link_data (void *cls,
 
     obj = json_pack ("{s:o, s:o, s:o}",
                      "denom_pub",
-                     GNUNET_JSON_from_rsa_public_key
-                       (pos->denom_pub.rsa_public_key),
+                     GNUNET_JSON_from_rsa_public_key (
+                       pos->denom_pub.rsa_public_key),
                      "ev_sig",
                      GNUNET_JSON_from_rsa_signature
                        (pos->ev_sig.rsa_signature),
diff --git a/src/exchange/taler-exchange-httpd_refreshes_reveal.c 
b/src/exchange/taler-exchange-httpd_refreshes_reveal.c
index 930de082..d7ec02c8 100644
--- a/src/exchange/taler-exchange-httpd_refreshes_reveal.c
+++ b/src/exchange/taler-exchange-httpd_refreshes_reveal.c
@@ -349,7 +349,7 @@ refreshes_reveal_transaction (void *cls,
       else
       {
         /* Reconstruct coin envelopes from transfer private key */
-        struct TALER_TransferPrivateKeyP *tpriv
+        const struct TALER_TransferPrivateKeyP *tpriv
           = &rctx->transfer_privs[i - off];
         struct TALER_TransferSecretP ts;
 
@@ -695,32 +695,22 @@ resolve_refreshes_reveal_denominations (struct 
MHD_Connection *connection,
     if (GNUNET_OK != res)
       return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
     /* Check link_sigs[i] signature */
+    if (GNUNET_OK !=
+        TALER_wallet_link_verify (
+          &dk_h[i],
+          &rctx->gamma_tp,
+          rcds[i].coin_ev,
+          rcds[i].coin_ev_size,
+          &melt.session.coin.coin_pub,
+          &link_sigs[i]))
     {
-      struct TALER_LinkDataPS ldp = {
-        .purpose.size = htonl (sizeof (ldp)),
-        .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_LINK),
-        .h_denom_pub = dk_h[i],
-        .old_coin_pub = melt.session.coin.coin_pub,
-        .transfer_pub = rctx->gamma_tp
-      };
-
-      GNUNET_CRYPTO_hash (rcds[i].coin_ev,
-                          rcds[i].coin_ev_size,
-                          &ldp.coin_envelope_hash);
-      if (GNUNET_OK !=
-          GNUNET_CRYPTO_eddsa_verify (
-            TALER_SIGNATURE_WALLET_COIN_LINK,
-            &ldp,
-            &link_sigs[i].eddsa_signature,
-            &melt.session.coin.coin_pub.eddsa_pub))
-      {
-        GNUNET_break_op (0);
-        ret = TALER_MHD_reply_with_error (connection,
-                                          MHD_HTTP_FORBIDDEN,
-                                          
TALER_EC_EXCHANGE_REFRESHES_REVEAL_LINK_SIGNATURE_INVALID,
-                                          NULL);
-        goto cleanup;
-      }
+      GNUNET_break_op (0);
+      ret = TALER_MHD_reply_with_error (
+        connection,
+        MHD_HTTP_FORBIDDEN,
+        TALER_EC_EXCHANGE_REFRESHES_REVEAL_LINK_SIGNATURE_INVALID,
+        NULL);
+      goto cleanup;
     }
   }
 
diff --git a/src/exchangedb/exchange-0002.sql b/src/exchangedb/exchange-0002.sql
index 26724708..9b66d4d1 100644
--- a/src/exchangedb/exchange-0002.sql
+++ b/src/exchangedb/exchange-0002.sql
@@ -231,6 +231,55 @@ COMMENT ON COLUMN recoup_refresh.rrc_serial
   IS 'Identifies the h_blind_ev of the recouped coin (as h_coin_ev).';
 
 
+-- Change 'rc' in refresh_transfer_keys and refresh_revealed_coins tables to 
'melt_serial_id'
+ALTER TABLE refresh_transfer_keys
+  ADD COLUMN melt_serial_id INT8 REFERENCES refresh_commitments 
(melt_serial_id) ON DELETE CASCADE;
+UPDATE refresh_transfer_keys
+  SET melt_serial_id=d.melt_serial_id
+  FROM refresh_transfer_keys o
+  INNER JOIN refresh_commitments d ON (d.rc = o.rc);
+ALTER TABLE refresh_transfer_keys
+  ALTER COLUMN melt_serial_id SET NOT NULL;
+ALTER TABLE refresh_transfer_keys
+  DROP COLUMN rc;
+COMMENT ON COLUMN refresh_transfer_keys.melt_serial_id
+  IS 'Identifies the refresh commitment (rc) of the operation.';
+
+ALTER TABLE refresh_revealed_coins
+  ADD COLUMN melt_serial_id INT8 REFERENCES refresh_commitments 
(melt_serial_id) ON DELETE CASCADE;
+UPDATE refresh_revealed_coins
+  SET melt_serial_id=d.melt_serial_id
+  FROM refresh_revealed_coins o
+  INNER JOIN refresh_commitments d ON (d.rc = o.rc);
+ALTER TABLE refresh_revealed_coins
+  ALTER COLUMN melt_serial_id SET NOT NULL;
+ALTER TABLE refresh_revealed_coins
+  DROP COLUMN rc;
+COMMENT ON COLUMN refresh_revealed_coins.melt_serial_id
+  IS 'Identifies the refresh commitment (rc) of the operation.';
+
+
+-- Change 'merchant_pub' and 'h_contract_terms' and 'known_coin_id' in 
'refunds' table
+-- to 'deposit_serial_id' instead!
+ALTER TABLE refunds
+  ADD COLUMN deposit_serial_id INT8 REFERENCES deposits (deposit_serial_id) ON 
DELETE CASCADE;
+UPDATE refunds
+  SET deposit_serial_id=d.deposit_serial_id
+  FROM refunds o
+  INNER JOIN deposits d
+    ON ( (d.known_coin_id = o.known_coin_id) AND
+         (d.h_contract_terms = o.h_contract_terms) AND
+         (d.merchant_pub = o.merchant_pub) );
+ALTER TABLE refunds
+  ALTER COLUMN deposit_serial_id SET NOT NULL;
+ALTER TABLE refunds
+  DROP COLUMN merchant_pub,
+  DROP COLUMN h_contract_terms,
+  DROP COLUMN known_coin_id;
+COMMENT ON COLUMN refunds.deposit_serial_id
+  IS 'Identifies ONLY the merchant_pub, h_contract_terms and known_coin_id. 
Multiple deposits may match a refund, this only identifies one of them.';
+
+
 -- Create additional tables...
 
 CREATE TABLE IF NOT EXISTS auditors
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c 
b/src/exchangedb/plugin_exchangedb_postgres.c
index 6d8e7273..b81fb7c1 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -781,16 +781,22 @@ postgres_get_session (void *cls)
       /* Store information about the desired denominations for a
          refresh operation, used in #postgres_insert_refresh_reveal() */
       GNUNET_PQ_make_prepare ("insert_refresh_revealed_coin",
+                              "WITH rcx AS"
+                              " (SELECT melt_serial_id"
+                              "    FROM refresh_commitments"
+                              "   WHERE rc=$1)"
                               "INSERT INTO refresh_revealed_coins "
-                              "(rc "
+                              "(melt_serial_id "
                               ",freshcoin_index "
                               ",link_sig "
                               ",denominations_serial "
                               ",coin_ev"
                               ",h_coin_ev"
                               ",ev_sig"
-                              ") SELECT $1, $2, $3, denominations_serial, $5, 
$6, $7 "
+                              ") SELECT rcx.melt_serial_id, $2, $3, "
+                              "         denominations_serial, $5, $6, $7"
                               "    FROM denominations"
+                              "   CROSS JOIN rcx"
                               "   WHERE denom_pub_hash=$4;",
                               7),
       /* Obtain information about the coins created in a refresh
@@ -805,6 +811,8 @@ postgres_get_session (void *cls)
                               " FROM refresh_revealed_coins"
                               "    JOIN denominations denom "
                               "      USING (denominations_serial)"
+                              "    JOIN refresh_commitments"
+                              "      USING (melt_serial_id)"
                               " WHERE rc=$1"
                               "   ORDER BY freshcoin_index ASC;",
                               1),
@@ -813,11 +821,12 @@ postgres_get_session (void *cls)
          keys we learned */
       GNUNET_PQ_make_prepare ("insert_refresh_transfer_keys",
                               "INSERT INTO refresh_transfer_keys "
-                              "(rc"
+                              "(melt_serial_id"
                               ",transfer_pub"
                               ",transfer_privs"
-                              ") VALUES "
-                              "($1, $2, $3);",
+                              ") SELECT melt_serial_id, $2, $3"
+                              "    FROM refresh_commitments"
+                              "   WHERE rc=$1",
                               3),
       /* Used in #postgres_get_refresh_reveal() to retrieve transfer
          keys from /refresh/reveal */
@@ -826,23 +835,24 @@ postgres_get_session (void *cls)
                               " transfer_pub"
                               ",transfer_privs"
                               " FROM refresh_transfer_keys"
+                              " JOIN refresh_commitments"
+                              "   USING (melt_serial_id)"
                               " WHERE rc=$1;",
                               1),
-
-
       /* Used in #postgres_insert_refund() to store refund information */
       GNUNET_PQ_make_prepare ("insert_refund",
                               "INSERT INTO refunds "
-                              "(known_coin_id "
-                              ",merchant_pub "
+                              "(deposit_serial_id "
                               ",merchant_sig "
-                              ",h_contract_terms "
                               ",rtransaction_id "
                               ",amount_with_fee_val "
                               ",amount_with_fee_frac "
-                              ") SELECT known_coin_id, $2, $3, $4, $5, $6, $7"
-                              "    FROM known_coins"
-                              "   WHERE coin_pub=$1",
+                              ") SELECT deposit_serial_id, $3, $5, $6, $7"
+                              "    FROM deposits"
+                              "    JOIN known_coins USING (known_coin_id)"
+                              "   WHERE coin_pub=$1"
+                              "     AND h_contract_terms=$4"
+                              "     AND merchant_pub=$2",
                               7),
       /* Query the 'refunds' by coin public key */
       GNUNET_PQ_make_prepare ("get_refunds_by_coin",
@@ -851,12 +861,13 @@ postgres_get_session (void *cls)
                               ",merchant_sig"
                               ",h_contract_terms"
                               ",rtransaction_id"
-                              ",amount_with_fee_val"
-                              ",amount_with_fee_frac"
+                              ",refunds.amount_with_fee_val"
+                              ",refunds.amount_with_fee_frac"
                               ",denom.fee_refund_val "
                               ",denom.fee_refund_frac "
                               ",refund_serial_id"
                               " FROM refunds"
+                              " JOIN deposits USING (deposit_serial_id)"
                               " JOIN known_coins USING (known_coin_id)"
                               " JOIN denominations denom USING 
(denominations_serial)"
                               " WHERE coin_pub=$1;",
@@ -864,9 +875,10 @@ postgres_get_session (void *cls)
       /* Query the 'refunds' by coin public key, merchant_pub and contract 
hash */
       GNUNET_PQ_make_prepare ("get_refunds_by_coin_and_contract",
                               "SELECT"
-                              " amount_with_fee_val"
-                              ",amount_with_fee_frac"
+                              " refunds.amount_with_fee_val"
+                              ",refunds.amount_with_fee_frac"
                               " FROM refunds"
+                              " JOIN deposits USING (deposit_serial_id)"
                               " JOIN known_coins USING (known_coin_id)"
                               " WHERE coin_pub=$1"
                               "   AND merchant_pub=$2"
@@ -881,10 +893,11 @@ postgres_get_session (void *cls)
                               ",rtransaction_id"
                               ",denom.denom_pub"
                               ",kc.coin_pub"
-                              ",amount_with_fee_val"
-                              ",amount_with_fee_frac"
+                              ",refunds.amount_with_fee_val"
+                              ",refunds.amount_with_fee_frac"
                               ",refund_serial_id"
                               " FROM refunds"
+                              "   JOIN deposits USING (deposit_serial_id)"
                               "   JOIN known_coins kc USING (known_coin_id)"
                               "   JOIN denominations denom ON 
(kc.denominations_serial = denom.denominations_serial)"
                               " WHERE refund_serial_id>=$1"
@@ -1086,16 +1099,16 @@ postgres_get_session (void *cls)
                               ",rrc.link_sig"
                               " FROM refresh_commitments"
                               "     JOIN refresh_revealed_coins rrc"
-                              "       USING (rc)"
+                              "       USING (melt_serial_id)"
                               "     JOIN refresh_transfer_keys tp"
-                              "       USING (rc)"
+                              "       USING (melt_serial_id)"
                               "     JOIN denominations denoms"
                               "       ON (rrc.denominations_serial = 
denoms.denominations_serial)"
                               " WHERE old_known_coin_id="
                               "   (SELECT known_coin_id "
                               "      FROM known_coins"
                               "     WHERE coin_pub=$1)"
-                              " ORDER BY tp.transfer_pub",
+                              " ORDER BY tp.transfer_pub, rrc.freshcoin_index 
ASC",
                               1),
       /* Used in #postgres_lookup_wire_transfer */
       GNUNET_PQ_make_prepare ("lookup_transactions",
@@ -1239,16 +1252,17 @@ postgres_get_session (void *cls)
                               ",wire_deadline"
                               ",tiny"
                               ",done"
-                              " FROM deposits"
+                              " FROM deposits d"
                               " JOIN known_coins USING (known_coin_id)"
                               " WHERE wire_deadline >= $1"
                               " AND wire_deadline < $2"
                               " AND NOT (EXISTS (SELECT 1"
                               "            FROM refunds"
-                              "            WHERE (refunds.known_coin_id = 
deposits.known_coin_id))"
+                              "            JOIN deposits dx USING 
(deposit_serial_id)"
+                              "            WHERE (dx.known_coin_id = 
d.known_coin_id))"
                               "       OR EXISTS (SELECT 1"
                               "            FROM aggregation_tracking"
-                              "            WHERE 
(aggregation_tracking.deposit_serial_id = deposits.deposit_serial_id)))"
+                              "            WHERE 
(aggregation_tracking.deposit_serial_id = d.deposit_serial_id)))"
                               " ORDER BY wire_deadline ASC",
                               2),
       /* Used in #postgres_select_wire_out_above_serial_id() */
@@ -1364,10 +1378,10 @@ postgres_get_session (void *cls)
                               " FROM recoup_refresh"
                               "    INNER JOIN refresh_revealed_coins rrc"
                               "      USING (rrc_serial)"
-                              "    INNER JOIN refresh_commitments rc"
-                              "      ON (rrc.rc = rc.rc)"
+                              "    INNER JOIN refresh_commitments rfc"
+                              "      ON (rrc.melt_serial_id = 
rfc.melt_serial_id)"
                               "    INNER JOIN known_coins old_coins"
-                              "      ON (rc.old_known_coin_id = 
old_coins.known_coin_id)"
+                              "      ON (rfc.old_known_coin_id = 
old_coins.known_coin_id)"
                               "    INNER JOIN known_coins new_coins"
                               "      ON (new_coins.known_coin_id = 
recoup_refresh.known_coin_id)"
                               "    INNER JOIN denominations new_denoms"
@@ -1442,7 +1456,7 @@ postgres_get_session (void *cls)
                               "   (SELECT rrc.rrc_serial"
                               "    FROM refresh_commitments"
                               "       JOIN refresh_revealed_coins rrc"
-                              "           USING (rc)"
+                              "           USING (melt_serial_id)"
                               "    WHERE old_known_coin_id="
                               "       (SELECT known_coin_id"
                               "          FROM known_coins"
@@ -1518,10 +1532,10 @@ postgres_get_session (void *cls)
                               " FROM recoup_refresh"
                               "    JOIN refresh_revealed_coins rrc"
                               "      USING (rrc_serial)"
-                              "    JOIN refresh_commitments rc"
-                              "      ON (rrc.rc = rc.rc)"
+                              "    JOIN refresh_commitments rfc"
+                              "      ON (rrc.melt_serial_id = 
rfc.melt_serial_id)"
                               "    JOIN known_coins old_coins"
-                              "      ON (rc.old_known_coin_id = 
old_coins.known_coin_id)"
+                              "      ON (rfc.old_known_coin_id = 
old_coins.known_coin_id)"
                               "    JOIN known_coins coins"
                               "      ON (recoup_refresh.known_coin_id = 
coins.known_coin_id)"
                               "    JOIN denominations denoms"
@@ -1543,7 +1557,7 @@ postgres_get_session (void *cls)
                               "SELECT"
                               " okc.coin_pub AS old_coin_pub"
                               " FROM refresh_revealed_coins rrc"
-                              " JOIN refresh_commitments rcom USING (rc)"
+                              " JOIN refresh_commitments rcom USING 
(melt_serial_id)"
                               " JOIN known_coins okc ON 
(rcom.old_known_coin_id = okc.known_coin_id)"
                               " WHERE h_coin_ev=$1"
                               " LIMIT 1;",
@@ -2041,6 +2055,7 @@ postgres_get_session (void *cls)
         ",rrc_serial"
         ",denominations_serial"
         " FROM refresh_revealed_coins"
+        " JOIN refresh_commitments USING (melt_serial_id)"
         " ORDER BY rrc_serial ASC;",
         0),
       GNUNET_PQ_make_prepare (
@@ -2051,6 +2066,7 @@ postgres_get_session (void *cls)
         ",transfer_pub"
         ",transfer_privs"
         " FROM refresh_transfer_keys"
+        " JOIN refresh_commitments USING (melt_serial_id)"
         " ORDER BY rtc_serial ASC;",
         0),
       GNUNET_PQ_make_prepare ("select_above_serial_by_table_deposits",
@@ -2080,10 +2096,11 @@ postgres_get_session (void *cls)
                               ",merchant_sig"
                               ",h_contract_terms"
                               ",rtransaction_id"
-                              ",amount_with_fee_val"
-                              ",amount_with_fee_frac"
+                              ",refunds.amount_with_fee_val"
+                              ",refunds.amount_with_fee_frac"
                               ",known_coin_id"
                               " FROM refunds"
+                              " JOIN deposits USING (deposit_serial_id)"
                               " ORDER BY refund_serial_id ASC;",
                               0),
       GNUNET_PQ_make_prepare ("select_above_serial_by_table_wire_out",
@@ -2306,6 +2323,11 @@ postgres_preflight (void *cls,
   };
 
   (void) cls;
+  if (NULL == session)
+  {
+    GNUNET_break (0);
+    return;
+  }
   if (NULL == session->transaction_name)
     return; /* all good */
   if (GNUNET_OK ==
diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h
index 70e49697..4ea845b4 100644
--- a/src/include/taler_crypto_lib.h
+++ b/src/include/taler_crypto_lib.h
@@ -1050,6 +1050,47 @@ TALER_CRYPTO_helper_esign_disconnect (
   struct TALER_CRYPTO_ExchangeSignHelper *esh);
 
 
+/* ********************* wallet signing ************************** */
+
+/**
+ * Sign link data.
+ *
+ * @param h_denom_pub hash of the denomiantion public key of the new coin
+ * @param transfer_pub transfer public key
+ * @param coin_ev coin envelope
+ * @param coin_ev_size number of bytes in @a coin_ev
+ * @param old_coin_priv private key to sign with
+ * @param[out] coin_sig resulting signature
+ */
+void
+TALER_wallet_link_sign (const struct GNUNET_HashCode *h_denom_pub,
+                        const struct TALER_TransferPublicKeyP *transfer_pub,
+                        const void *coin_ev,
+                        size_t coin_ev_size,
+                        const struct TALER_CoinSpendPrivateKeyP *old_coin_priv,
+                        struct TALER_CoinSpendSignatureP *coin_sig);
+
+
+/**
+ * Verify link signature.
+ *
+ * @param h_denom_pub hash of the denomiantion public key of the new coin
+ * @param transfer_pub transfer public key
+ * @param coin_ev coin envelope
+ * @param coin_ev_size number of bytes in @a coin_ev
+ * @param old_coin_priv private key to sign with
+ * @param coin_sig resulting signature
+ * @return #GNUNET_OK if the signature is valid
+ */
+enum GNUNET_GenericReturnValue
+TALER_wallet_link_verify (
+  const struct GNUNET_HashCode *h_denom_pub,
+  const struct TALER_TransferPublicKeyP *transfer_pub,
+  const void *coin_ev,
+  size_t coin_ev_size,
+  const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
+  const struct TALER_CoinSpendSignatureP *coin_sig);
+
 /* ********************* offline signing ************************** */
 
 
diff --git a/src/include/taler_exchangedb_plugin.h 
b/src/include/taler_exchangedb_plugin.h
index e26a2096..da320d39 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -75,6 +75,32 @@ struct TALER_EXCHANGEDB_DenominationKeyInformationP
 
 GNUNET_NETWORK_STRUCT_END
 
+/**
+ * Meta data about an exchange online signing key.
+ */
+struct TALER_EXCHANGEDB_SignkeyMetaData
+{
+  /**
+   * Start time of the validity period for this key.
+   */
+  struct GNUNET_TIME_Absolute start;
+
+  /**
+   * The exchange will sign messages with this key between @e start and this 
time.
+   */
+  struct GNUNET_TIME_Absolute expire_sign;
+
+  /**
+   * When do signatures with this sign key become invalid?
+   * After this point, these signatures cannot be used in (legal)
+   * disputes anymore, as the Exchange is then allowed to destroy its side
+   * of the evidence.  @e expire_legal is expected to be significantly
+   * larger than @e expire_sign (by a year or more).
+   */
+  struct GNUNET_TIME_Absolute expire_legal;
+
+};
+
 
 /**
  * Enumeration of all of the tables replicated by exchange-auditor
@@ -194,16 +220,97 @@ struct TALER_EXCHANGEDB_TableData
       uint64_t denominations_serial;
     } reserves_out;
 
-    struct {} auditors;
-    struct {} auditor_denom_sigs;
-    struct {} exchange_sign_keys;
-    struct {} signkey_revocations;
-    struct {} known_coins;
-    struct {} refresh_commitments;
-    struct {} refresh_revealed_coins;
-    struct {} refresh_transfer_keys;
-    struct {} deposits;
-    struct {} refunds;
+    struct
+    {
+      struct TALER_AuditorPublicKeyP auditor_pub;
+      char *auditor_url;
+      char *auditor_name;
+      bool is_active;
+      struct GNUNET_TIME_Absolute last_change;
+    } auditors;
+
+    struct
+    {
+      uint64_t auditor_uuid;
+      uint64_t denominations_serial;
+      struct TALER_AuditorSignatureP auditor_sig;
+    } auditor_denom_sigs;
+
+    struct
+    {
+      struct TALER_ExchangePublicKeyP exchange_pub;
+      struct TALER_MasterSignatureP master_sig;
+      struct TALER_EXCHANGEDB_SignkeyMetaData meta;
+    } exchange_sign_keys;
+
+    struct
+    {
+      uint64_t esk_serial;
+      struct TALER_MasterSignatureP master_sig;
+    } signkey_revocations;
+
+    struct
+    {
+      struct TALER_CoinSpendPublicKeyP coin_pub;
+      struct TALER_DenominationSignature denom_sig;
+      uint64_t denominations_serial;
+    } known_coins;
+
+    struct
+    {
+      struct TALER_RefreshCommitmentP rc;
+      struct TALER_CoinSpendSignatureP old_coin_sig;
+      struct TALER_Amount amount_with_fee;
+      uint32_t noreveal_index;
+      uint64_t old_known_coin_id;
+    } refresh_commitments;
+
+    struct
+    {
+      uint64_t freshcoin_index;
+      struct TALER_CoinSpendSignatureP link_sig;
+      void *coin_ev;
+      size_t coin_ev_size;
+      // h_coin_ev omitted, to be recomputed!
+      struct TALER_DenominationSignature ev_sig;
+      uint64_t denominations_serial;
+      uint64_t melt_serial_id;
+    } refresh_revealed_coins;
+
+    struct
+    {
+      struct TALER_TransferPublicKeyP tp;
+      struct TALER_TransferPrivateKeyP tprivs[TALER_CNC_KAPPA - 1];
+      uint64_t melt_serial_id;
+    } refresh_transfer_keys;
+
+    struct
+    {
+      struct TALER_Amount amount_with_fee;
+      struct GNUNET_TIME_Absolute wallet_timestamp;
+      struct GNUNET_TIME_Absolute exchange_timestamp;
+      struct GNUNET_TIME_Absolute refund_deadline;
+      struct GNUNET_TIME_Absolute wire_deadline;
+      struct TALER_MerchantPublicKeyP merchant_pub;
+      struct GNUNET_HashCode h_contract_terms;
+      // h_wire omitted, to be recomputed!
+      struct TALER_CoinSpendSignatureP coin_sig;
+      json_t *wire;
+      bool tiny;
+      bool done;
+      uint64_t known_coin_id;
+    } deposits;
+
+    struct
+    {
+      struct TALER_MerchantPublicKeyP merchant_pub; // FIXME
+      struct TALER_MerchantSignatureP merchant_sig;
+      struct GNUNET_HashCode h_contract_terms; // FIXME
+      uint64_t rtransaction_id;
+      struct TALER_Amount amount_with_fee;
+      uint64_t known_coin_id;
+    } refunds;
+
     struct {} wire_out;
     struct {} aggregation_tracking;
     struct {} wire_fee;
@@ -463,33 +570,6 @@ typedef void
   bool recoup_possible);
 
 
-/**
- * Meta data about an exchange online signing key.
- */
-struct TALER_EXCHANGEDB_SignkeyMetaData
-{
-  /**
-   * Start time of the validity period for this key.
-   */
-  struct GNUNET_TIME_Absolute start;
-
-  /**
-   * The exchange will sign messages with this key between @e start and this 
time.
-   */
-  struct GNUNET_TIME_Absolute expire_sign;
-
-  /**
-   * When do signatures with this sign key become invalid?
-   * After this point, these signatures cannot be used in (legal)
-   * disputes anymore, as the Exchange is then allowed to destroy its side
-   * of the evidence.  @e expire_legal is expected to be significantly
-   * larger than @e expire_sign (by a year or more).
-   */
-  struct GNUNET_TIME_Absolute expire_legal;
-
-};
-
-
 /**
  * Signature of a function called with information about the exchange's
  * online signing keys.
@@ -1194,6 +1274,7 @@ struct TALER_EXCHANGEDB_LinkList
    * link data, of type #TALER_SIGNATURE_WALLET_COIN_LINK
    */
   struct TALER_CoinSpendSignatureP orig_coin_link_sig;
+
 };
 
 
diff --git a/src/lib/exchange_api_link.c b/src/lib/exchange_api_link.c
index 23a79d80..5deecada 100644
--- a/src/lib/exchange_api_link.c
+++ b/src/lib/exchange_api_link.c
@@ -75,7 +75,7 @@ struct TALER_EXCHANGE_LinkHandle
  *
  * @param lh link handle
  * @param json json reply with the data for one coin
- * @param coin_num number of the coin to decode
+ * @param coin_num number of the coin
  * @param trans_pub our transfer public key
  * @param[out] coin_priv where to return private coin key
  * @param[out] sig where to return private coin signature
@@ -85,7 +85,7 @@ struct TALER_EXCHANGE_LinkHandle
 static int
 parse_link_coin (const struct TALER_EXCHANGE_LinkHandle *lh,
                  const json_t *json,
-                 unsigned int coin_num,
+                 uint32_t coin_num,
                  const struct TALER_TransferPublicKeyP *trans_pub,
                  struct TALER_CoinSpendPrivateKeyP *coin_priv,
                  struct TALER_DenominationSignature *sig,
@@ -112,7 +112,6 @@ parse_link_coin (const struct TALER_EXCHANGE_LinkHandle *lh,
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
-
   TALER_link_recover_transfer_secret (trans_pub,
                                       &lh->coin_priv,
                                       &secret);
@@ -130,14 +129,10 @@ parse_link_coin (const struct TALER_EXCHANGE_LinkHandle 
*lh,
   {
     struct TALER_PlanchetDetail pd;
     struct GNUNET_HashCode c_hash;
-    struct TALER_LinkDataPS ldp = {
-      .purpose.size = htonl (sizeof (ldp)),
-      .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_LINK),
-      .transfer_pub = *trans_pub
-    };
+    struct TALER_CoinSpendPublicKeyP old_coin_pub;
 
     GNUNET_CRYPTO_eddsa_key_get_public (&lh->coin_priv.eddsa_priv,
-                                        &ldp.old_coin_pub.eddsa_pub);
+                                        &old_coin_pub.eddsa_pub);
     pub->rsa_public_key = rpub;
     if (GNUNET_OK !=
         TALER_planchet_prepare (pub,
@@ -149,22 +144,20 @@ parse_link_coin (const struct TALER_EXCHANGE_LinkHandle 
*lh,
       GNUNET_JSON_parse_free (spec);
       return GNUNET_SYSERR;
     }
-    ldp.h_denom_pub = pd.denom_pub_hash;
-    GNUNET_CRYPTO_hash (pd.coin_ev,
-                        pd.coin_ev_size,
-                        &ldp.coin_envelope_hash);
-    GNUNET_free (pd.coin_ev);
-
     if (GNUNET_OK !=
-        GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_LINK,
-                                    &ldp,
-                                    &link_sig.eddsa_signature,
-                                    &ldp.old_coin_pub.eddsa_pub))
+        TALER_wallet_link_verify (&pd.denom_pub_hash,
+                                  trans_pub,
+                                  pd.coin_ev,
+                                  pd.coin_ev_size,
+                                  &old_coin_pub,
+                                  &link_sig))
     {
       GNUNET_break_op (0);
+      GNUNET_free (pd.coin_ev);
       GNUNET_JSON_parse_free (spec);
       return GNUNET_SYSERR;
     }
+    GNUNET_free (pd.coin_ev);
   }
 
   /* clean up */
@@ -457,11 +450,11 @@ TALER_EXCHANGE_link (struct TALER_EXCHANGE_Handle 
*exchange,
     char pub_str[sizeof (struct TALER_CoinSpendPublicKeyP) * 2];
     char *end;
 
-    end = GNUNET_STRINGS_data_to_string (&coin_pub,
-                                         sizeof (struct
-                                                 TALER_CoinSpendPublicKeyP),
-                                         pub_str,
-                                         sizeof (pub_str));
+    end = GNUNET_STRINGS_data_to_string (
+      &coin_pub,
+      sizeof (struct TALER_CoinSpendPublicKeyP),
+      pub_str,
+      sizeof (pub_str));
     *end = '\0';
     GNUNET_snprintf (arg_str,
                      sizeof (arg_str),
diff --git a/src/lib/exchange_api_refreshes_reveal.c 
b/src/lib/exchange_api_refreshes_reveal.c
index c51e30b0..e551b482 100644
--- a/src/lib/exchange_api_refreshes_reveal.c
+++ b/src/lib/exchange_api_refreshes_reveal.c
@@ -391,30 +391,20 @@ TALER_EXCHANGE_refreshes_reveal (
                    json_array_append_new (coin_evs,
                                           GNUNET_JSON_from_data (pd.coin_ev,
                                                                  
pd.coin_ev_size)));
-
-    /* compute link signature */
     {
       struct TALER_CoinSpendSignatureP link_sig;
-      struct TALER_LinkDataPS ldp;
-
-      ldp.purpose.size = htonl (sizeof (ldp));
-      ldp.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_LINK);
-      ldp.h_denom_pub = denom_hash;
-      GNUNET_CRYPTO_eddsa_key_get_public 
(&md->melted_coin.coin_priv.eddsa_priv,
-                                          &ldp.old_coin_pub.eddsa_pub);
-      ldp.transfer_pub = transfer_pub;
-      GNUNET_CRYPTO_hash (pd.coin_ev,
-                          pd.coin_ev_size,
-                          &ldp.coin_envelope_hash);
-      GNUNET_CRYPTO_eddsa_sign (&md->melted_coin.coin_priv.eddsa_priv,
-                                &ldp,
-                                &link_sig.eddsa_signature);
+
+      TALER_wallet_link_sign (&denom_hash,
+                              &transfer_pub,
+                              pd.coin_ev,
+                              pd.coin_ev_size,
+                              &md->melted_coin.coin_priv,
+                              &link_sig);
       GNUNET_assert (0 ==
-                     json_array_append_new (link_sigs,
-                                            GNUNET_JSON_from_data_auto (
-                                              &link_sig)));
+                     json_array_append_new (
+                       link_sigs,
+                       GNUNET_JSON_from_data_auto (&link_sig)));
     }
-
     GNUNET_free (pd.coin_ev);
   }
 
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index fcaab827..c4df708b 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -76,6 +76,7 @@ libtalerutil_la_SOURCES = \
   taler_error_codes.c \
   url.c \
   util.c \
+  wallet_signatures.c \
   yna.c \
   os_installation.c
 
diff --git a/src/util/wallet_signatures.c b/src/util/wallet_signatures.c
new file mode 100644
index 00000000..ef343d17
--- /dev/null
+++ b/src/util/wallet_signatures.c
@@ -0,0 +1,80 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2020 Taler Systems SA
+
+  TALER is free software; you can redistribute it and/or modify it under the
+  terms of the GNU General Public License as published by the Free Software
+  Foundation; either version 3, or (at your option) any later version.
+
+  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License along with
+  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file secmod_signatures.c
+ * @brief Utility functions for Taler security module signatures
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_util.h"
+#include "taler_signatures.h"
+
+
+void
+TALER_wallet_link_sign (const struct GNUNET_HashCode *h_denom_pub,
+                        const struct TALER_TransferPublicKeyP *transfer_pub,
+                        const void *coin_ev,
+                        size_t coin_ev_size,
+                        const struct TALER_CoinSpendPrivateKeyP *old_coin_priv,
+                        struct TALER_CoinSpendSignatureP *coin_sig)
+{
+  struct TALER_LinkDataPS ldp = {
+    .purpose.size = htonl (sizeof (ldp)),
+    .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_LINK),
+    .h_denom_pub = *h_denom_pub,
+    .transfer_pub = *transfer_pub
+  };
+
+  GNUNET_CRYPTO_hash (coin_ev,
+                      coin_ev_size,
+                      &ldp.coin_envelope_hash);
+  GNUNET_CRYPTO_eddsa_key_get_public (&old_coin_priv->eddsa_priv,
+                                      &ldp.old_coin_pub.eddsa_pub);
+  GNUNET_CRYPTO_eddsa_sign (&old_coin_priv->eddsa_priv,
+                            &ldp,
+                            &coin_sig->eddsa_signature);
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_wallet_link_verify (
+  const struct GNUNET_HashCode *h_denom_pub,
+  const struct TALER_TransferPublicKeyP *transfer_pub,
+  const void *coin_ev,
+  size_t coin_ev_size,
+  const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
+  const struct TALER_CoinSpendSignatureP *coin_sig)
+{
+  struct TALER_LinkDataPS ldp = {
+    .purpose.size = htonl (sizeof (ldp)),
+    .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_LINK),
+    .h_denom_pub = *h_denom_pub,
+    .old_coin_pub = *old_coin_pub,
+    .transfer_pub = *transfer_pub
+  };
+
+  GNUNET_CRYPTO_hash (coin_ev,
+                      coin_ev_size,
+                      &ldp.coin_envelope_hash);
+  return
+    GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_LINK,
+                                &ldp,
+                                &coin_sig->eddsa_signature,
+                                &old_coin_pub->eddsa_pub);
+}
+
+
+/* end of wallet_signatures.c */

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