From 4f82885560d5d468ef5230f7ec383c612cc9625c Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 7 May 2020 20:22:02 +0200 Subject: towards changing timestamp in deposit confirmation (tests failing) --- src/testing/testing_api_cmd_deposit.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'src/testing/testing_api_cmd_deposit.c') diff --git a/src/testing/testing_api_cmd_deposit.c b/src/testing/testing_api_cmd_deposit.c index 9468e7ac..049f36f2 100644 --- a/src/testing/testing_api_cmd_deposit.c +++ b/src/testing/testing_api_cmd_deposit.c @@ -91,9 +91,9 @@ struct DepositState struct TALER_EXCHANGE_DepositHandle *dh; /** - * Timestamp of the /deposit operation. + * Timestamp of the /deposit operation in the wallet (contract signing time). */ - struct GNUNET_TIME_Absolute timestamp; + struct GNUNET_TIME_Absolute wallet_timestamp; /** * Interpreter state. @@ -126,6 +126,11 @@ struct DepositState */ int deposit_succeeded; + /** + * When did the exchange receive the deposit? + */ + struct GNUNET_TIME_Absolute exchange_timestamp; + /** * Signing key used by the exchange to sign the * deposit confirmation. @@ -198,6 +203,7 @@ do_retry (void *cls) * * @param cls closure. * @param hr HTTP response details + * @param exchange_timestamp when did the exchange receive the deposit permission * @param exchange_sig signature provided by the exchange * (NULL on errors) * @param exchange_pub public key of the exchange, @@ -206,6 +212,7 @@ do_retry (void *cls) static void deposit_cb (void *cls, const struct TALER_EXCHANGE_HttpResponse *hr, + const struct GNUNET_TIME_Absolute exchange_timestamp, const struct TALER_ExchangeSignatureP *exchange_sig, const struct TALER_ExchangePublicKeyP *exchange_pub) { @@ -254,6 +261,7 @@ deposit_cb (void *cls, if (MHD_HTTP_OK == hr->http_status) { ds->deposit_succeeded = GNUNET_YES; + ds->exchange_timestamp = exchange_timestamp; ds->exchange_pub = *exchange_pub; ds->exchange_sig = *exchange_sig; } @@ -305,7 +313,7 @@ deposit_run (void *cls, ds->coin_index = ods->coin_index; ds->wire_details = json_incref (ods->wire_details); ds->contract_terms = json_incref (ods->contract_terms); - ds->timestamp = ods->timestamp; + ds->wallet_timestamp = ods->wallet_timestamp; ds->refund_deadline = ods->refund_deadline; ds->amount = ods->amount; ds->merchant_priv = ods->merchant_priv; @@ -379,7 +387,7 @@ deposit_run (void *cls, } else { - ds->refund_deadline = ds->timestamp; + ds->refund_deadline = ds->wallet_timestamp; wire_deadline = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_ZERO); } @@ -388,6 +396,7 @@ deposit_run (void *cls, (void) GNUNET_TIME_round_abs (&wire_deadline); + // FIXME: This should be part of TALER_EXCHANGE_deposit()! { struct TALER_DepositRequestPS dr; @@ -400,7 +409,7 @@ deposit_run (void *cls, GNUNET_assert (GNUNET_OK == TALER_JSON_merchant_wire_signature_hash (ds->wire_details, &dr.h_wire)); - dr.timestamp = GNUNET_TIME_absolute_hton (ds->timestamp); + dr.wallet_timestamp = GNUNET_TIME_absolute_hton (ds->wallet_timestamp); dr.refund_deadline = GNUNET_TIME_absolute_hton (ds->refund_deadline); TALER_amount_hton (&dr.amount_with_fee, @@ -421,7 +430,7 @@ deposit_run (void *cls, &coin_pub, denom_pub_sig, &denom_pub->key, - ds->timestamp, + ds->wallet_timestamp, &merchant_pub, ds->refund_deadline, &coin_sig, @@ -534,6 +543,8 @@ deposit_traits (void *cls, &ds->merchant_priv), TALER_TESTING_make_trait_amount_obj (0, &ds->amount), + TALER_TESTING_make_trait_absolute_time (0, + &ds->exchange_timestamp), TALER_TESTING_trait_end () }; @@ -599,12 +610,12 @@ TALER_TESTING_cmd_deposit (const char *label, label); GNUNET_assert (0); } - ds->timestamp = GNUNET_TIME_absolute_get (); - (void) GNUNET_TIME_round_abs (&ds->timestamp); + ds->wallet_timestamp = GNUNET_TIME_absolute_get (); + (void) GNUNET_TIME_round_abs (&ds->wallet_timestamp); json_object_set_new (ds->contract_terms, "timestamp", - GNUNET_JSON_from_time_abs (ds->timestamp)); + GNUNET_JSON_from_time_abs (ds->wallet_timestamp)); if (0 != refund_deadline.rel_value_us) { ds->refund_deadline = GNUNET_TIME_relative_to_absolute (refund_deadline); @@ -687,12 +698,12 @@ TALER_TESTING_cmd_deposit_with_ref (const char *label, label); GNUNET_assert (0); } - ds->timestamp = GNUNET_TIME_absolute_get (); - (void) GNUNET_TIME_round_abs (&ds->timestamp); + ds->wallet_timestamp = GNUNET_TIME_absolute_get (); + (void) GNUNET_TIME_round_abs (&ds->wallet_timestamp); json_object_set_new (ds->contract_terms, "timestamp", - GNUNET_JSON_from_time_abs (ds->timestamp)); + GNUNET_JSON_from_time_abs (ds->wallet_timestamp)); if (0 != refund_deadline.rel_value_us) { ds->refund_deadline = GNUNET_TIME_relative_to_absolute (refund_deadline); -- cgit v1.2.3 From c88af6df724a47919fd8b0fc1d25f1273120c4e6 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 27 Jun 2020 18:30:25 +0200 Subject: fix #6236 --- src/include/taler_testing_lib.h | 10 ++++++++++ src/testing/testing_api_cmd_deposit.c | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src/testing/testing_api_cmd_deposit.c') diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h index 3f834657..7779ca2b 100644 --- a/src/include/taler_testing_lib.h +++ b/src/include/taler_testing_lib.h @@ -1345,6 +1345,16 @@ TALER_TESTING_cmd_status (const char *label, const char *expected_balance, unsigned int expected_response_code); +/** + * Index of the deposit value trait of a deposit command. + */ +#define TALER_TESTING_CMD_DEPOSIT_TRAIT_IDX_DEPOSIT_VALUE 0 + +/** + * Index of the deposit fee trait of a deposit command. + */ +#define TALER_TESTING_CMD_DEPOSIT_TRAIT_IDX_DEPOSIT_FEE 1 + /** * Create a "deposit" command. * diff --git a/src/testing/testing_api_cmd_deposit.c b/src/testing/testing_api_cmd_deposit.c index 049f36f2..f302a218 100644 --- a/src/testing/testing_api_cmd_deposit.c +++ b/src/testing/testing_api_cmd_deposit.c @@ -52,6 +52,11 @@ struct DepositState */ struct TALER_Amount amount; + /** + * Deposit fee. + */ + struct TALER_Amount deposit_fee; + /** * Reference to any command that is able to provide a coin. */ @@ -374,6 +379,7 @@ deposit_run (void *cls, TALER_TESTING_interpreter_fail (is); return; } + ds->deposit_fee = denom_pub->fee_deposit; GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv, &coin_pub.eddsa_pub); @@ -541,8 +547,12 @@ deposit_traits (void *cls, ds->contract_terms), TALER_TESTING_make_trait_merchant_priv (0, &ds->merchant_priv), - TALER_TESTING_make_trait_amount_obj (0, - &ds->amount), + TALER_TESTING_make_trait_amount_obj ( + TALER_TESTING_CMD_DEPOSIT_TRAIT_IDX_DEPOSIT_VALUE, + &ds->amount), + TALER_TESTING_make_trait_amount_obj ( + TALER_TESTING_CMD_DEPOSIT_TRAIT_IDX_DEPOSIT_FEE, + &ds->deposit_fee), TALER_TESTING_make_trait_absolute_time (0, &ds->exchange_timestamp), TALER_TESTING_trait_end () -- cgit v1.2.3 From b0311807ff8c7702a87b99da1e21a963eb280633 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 27 Jun 2020 18:49:12 +0200 Subject: fix FIXME by exposing deposit permission signing in API instead of doing it inside of the testing logic --- src/include/taler_exchange_service.h | 26 +++++++++++++++++ src/lib/exchange_api_deposit.c | 53 +++++++++++++++++++++++++++++++++++ src/testing/testing_api_cmd_deposit.c | 39 +++++++++----------------- 3 files changed, 92 insertions(+), 26 deletions(-) (limited to 'src/testing/testing_api_cmd_deposit.c') diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h index e61a07c9..02ab182f 100644 --- a/src/include/taler_exchange_service.h +++ b/src/include/taler_exchange_service.h @@ -744,6 +744,32 @@ TALER_EXCHANGE_wire_cancel (struct TALER_EXCHANGE_WireHandle *wh); /* ********************* /coins/$COIN_PUB/deposit *********************** */ +/** + * Sign a deposit permission. Function for wallets. + * + * @param amount the amount to be deposited + * @param deposit_fee the deposit fee we expect to pay + * @param h_wire hash of the merchant’s account details + * @param h_contract_terms hash of the contact of the merchant with the customer (further details are never disclosed to the exchange) + * @param coin_priv coin’s private key + * @param wallet_timestamp timestamp when the contract was finalized, must not be too far in the future + * @param merchant_pub the public key of the merchant (used to identify the merchant for refund requests) + * @param refund_deadline date until which the merchant can issue a refund to the customer via the exchange (can be zero if refunds are not allowed); must not be after the @a wire_deadline + * @param[out] coin_sig set to the signature made with purpose #TALER_SIGNATURE_WALLET_COIN_DEPOSIT + */ +void +TALER_EXCHANGE_deposit_permission_sign ( + const struct TALER_Amount *amount, + const struct TALER_Amount *deposit_fee, + const struct GNUNET_HashCode *h_wire, + const struct GNUNET_HashCode *h_contract_terms, + const struct TALER_CoinSpendPrivateKeyP *coin_priv, + struct GNUNET_TIME_Absolute wallet_timestamp, + const struct TALER_MerchantPublicKeyP *merchant_pub, + struct GNUNET_TIME_Absolute refund_deadline, + struct TALER_CoinSpendSignatureP *coin_sig); + + /** * @brief A Deposit Handle */ diff --git a/src/lib/exchange_api_deposit.c b/src/lib/exchange_api_deposit.c index 27605365..351fa7a1 100644 --- a/src/lib/exchange_api_deposit.c +++ b/src/lib/exchange_api_deposit.c @@ -490,6 +490,59 @@ verify_signatures (const struct TALER_EXCHANGE_DenomPublicKey *dki, } +/** + * Sign a deposit permission. Function for wallets. + * + * @param amount the amount to be deposited + * @param deposit_fee the deposit fee we expect to pay + * @param h_wire hash of the merchant’s account details + * @param h_contract_terms hash of the contact of the merchant with the customer (further details are never disclosed to the exchange) + * @param coin_priv coin’s private key + * @param wallet_timestamp timestamp when the contract was finalized, must not be too far in the future + * @param merchant_pub the public key of the merchant (used to identify the merchant for refund requests) + * @param refund_deadline date until which the merchant can issue a refund to the customer via the exchange (can be zero if refunds are not allowed); must not be after the @a wire_deadline + * @param[out] coin_sig set to the signature made with purpose #TALER_SIGNATURE_WALLET_COIN_DEPOSIT + */ +void +TALER_EXCHANGE_deposit_permission_sign ( + const struct TALER_Amount *amount, + const struct TALER_Amount *deposit_fee, + const struct GNUNET_HashCode *h_wire, + const struct GNUNET_HashCode *h_contract_terms, + const struct TALER_CoinSpendPrivateKeyP *coin_priv, + struct GNUNET_TIME_Absolute wallet_timestamp, + const struct TALER_MerchantPublicKeyP *merchant_pub, + struct GNUNET_TIME_Absolute refund_deadline, + struct TALER_CoinSpendSignatureP *coin_sig) +{ + struct TALER_DepositRequestPS dr = { + .purpose.size = htonl + (sizeof (dr)), + .purpose.purpose = htonl + (TALER_SIGNATURE_WALLET_COIN_DEPOSIT), + .h_contract_terms = *h_contract_terms, + .h_wire = *h_wire, + .wallet_timestamp = GNUNET_TIME_absolute_hton (wallet_timestamp), + .refund_deadline = GNUNET_TIME_absolute_hton (refund_deadline), + .merchant = *merchant_pub + }; + + GNUNET_assert (GNUNET_OK == + GNUNET_TIME_round_abs (&wallet_timestamp)); + GNUNET_assert (GNUNET_OK == + GNUNET_TIME_round_abs (&refund_deadline)); + GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv, + &dr.coin_pub.eddsa_pub); + TALER_amount_hton (&dr.amount_with_fee, + amount); + TALER_amount_hton (&dr.deposit_fee, + deposit_fee); + GNUNET_CRYPTO_eddsa_sign (&coin_priv->eddsa_priv, + &dr, + &coin_sig->eddsa_signature); +} + + /** * Submit a deposit permission to the exchange and get the exchange's response. * Note that while we return the response verbatim to the caller for diff --git a/src/testing/testing_api_cmd_deposit.c b/src/testing/testing_api_cmd_deposit.c index f302a218..e7a4c298 100644 --- a/src/testing/testing_api_cmd_deposit.c +++ b/src/testing/testing_api_cmd_deposit.c @@ -394,39 +394,26 @@ deposit_run (void *cls, else { ds->refund_deadline = ds->wallet_timestamp; - wire_deadline = GNUNET_TIME_relative_to_absolute - (GNUNET_TIME_UNIT_ZERO); + wire_deadline = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_ZERO); } GNUNET_CRYPTO_eddsa_key_get_public (&ds->merchant_priv.eddsa_priv, &merchant_pub.eddsa_pub); - (void) GNUNET_TIME_round_abs (&wire_deadline); - - // FIXME: This should be part of TALER_EXCHANGE_deposit()! { - struct TALER_DepositRequestPS dr; - - memset (&dr, 0, sizeof (dr)); - dr.purpose.size = htonl - (sizeof (struct TALER_DepositRequestPS)); - dr.purpose.purpose = htonl - (TALER_SIGNATURE_WALLET_COIN_DEPOSIT); - dr.h_contract_terms = h_contract_terms; + struct GNUNET_HashCode h_wire; + GNUNET_assert (GNUNET_OK == TALER_JSON_merchant_wire_signature_hash (ds->wire_details, - &dr.h_wire)); - dr.wallet_timestamp = GNUNET_TIME_absolute_hton (ds->wallet_timestamp); - dr.refund_deadline = GNUNET_TIME_absolute_hton - (ds->refund_deadline); - TALER_amount_hton (&dr.amount_with_fee, - &ds->amount); - TALER_amount_hton (&dr.deposit_fee, - &denom_pub->fee_deposit); - dr.merchant = merchant_pub; - dr.coin_pub = coin_pub; - GNUNET_CRYPTO_eddsa_sign (&coin_priv->eddsa_priv, - &dr, - &coin_sig.eddsa_signature); + &h_wire)); + TALER_EXCHANGE_deposit_permission_sign (&ds->amount, + &denom_pub->fee_deposit, + &h_wire, + &h_contract_terms, + coin_priv, + ds->wallet_timestamp, + &merchant_pub, + ds->refund_deadline, + &coin_sig); } ds->dh = TALER_EXCHANGE_deposit (is->exchange, &ds->amount, -- cgit v1.2.3