From 7fe8d89d75eed6495b7e24c98cc8dc92a93d15a2 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 29 Jun 2022 19:30:12 +0200 Subject: [PATCH] -update deposit API in preparation for batch deposits --- src/include/taler_exchange_service.h | 158 ++++++---- src/lib/exchange_api_deposit.c | 398 ++++++++++---------------- src/testing/testing_api_cmd_deposit.c | 45 +-- 3 files changed, 285 insertions(+), 316 deletions(-) diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h index 328e68fee..bd2a5bcaa 100644 --- a/src/include/taler_exchange_service.h +++ b/src/include/taler_exchange_service.h @@ -821,35 +821,101 @@ TALER_EXCHANGE_wire_cancel (struct TALER_EXCHANGE_WireHandle *wh); /** - * 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 h_extensions hash over the extensions - * @param h_denom_pub hash of the coin denomination's public key - * @param coin_priv coin’s private key - * @param age_commitment age commitment that went into the making of the coin, might be NULL - * @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 + * Information needed for a coin to be deposited. */ -void -TALER_EXCHANGE_deposit_permission_sign ( - const struct TALER_Amount *amount, - const struct TALER_Amount *deposit_fee, - const struct TALER_MerchantWireHashP *h_wire, - const struct TALER_PrivateContractHashP *h_contract_terms, - const struct TALER_ExtensionContractHashP *h_extensions, - const struct TALER_DenominationHashP *h_denom_pub, - const struct TALER_CoinSpendPrivateKeyP *coin_priv, - const struct TALER_AgeCommitment *age_commitment, - struct GNUNET_TIME_Timestamp wallet_timestamp, - const struct TALER_MerchantPublicKeyP *merchant_pub, - struct GNUNET_TIME_Timestamp refund_deadline, - struct TALER_CoinSpendSignatureP *coin_sig); +struct TALER_EXCHANGE_CoinDepositDetail +{ + + /** + * The amount to be deposited. + */ + struct TALER_Amount amount; + + /** + * Hash over the age commitment of the coin. + */ + struct TALER_AgeCommitmentHash h_age_commitment; + + /** + * The coin’s public key. + */ + struct TALER_CoinSpendPublicKeyP coin_pub; + + /** + * The signature made with purpose #TALER_SIGNATURE_WALLET_COIN_DEPOSIT made + * by the customer with the coin’s private key. + */ + struct TALER_CoinSpendSignatureP coin_sig; + + /** + * Exchange’s unblinded signature of the coin. + */ + struct TALER_DenominationSignature denom_sig; + + /** + * Hash of the public key of the coin. + */ + struct TALER_DenominationHashP h_denom_pub; +}; + + +/** + * Meta information about the contract relevant for a coin's deposit + * operation. + */ +struct TALER_EXCHANGE_DepositContractDetail +{ + + /** + * Execution date, until which the merchant would like the exchange to + * settle the balance (advisory, the exchange cannot be forced to settle in + * the past or upon very short notice, but of course a well-behaved exchange + * will limit aggregation based on the advice received). + */ + struct GNUNET_TIME_Timestamp wire_deadline; + + /** + * The merchant’s account details, in the payto://-format supported by the + * exchange. + */ + const char *merchant_payto_uri; + + /** + * Salt used to hash the @e merchant_payto_uri. + */ + struct TALER_WireSaltP wire_salt; + + /** + * Hash of the contact of the merchant with the customer (further details + * are never disclosed to the exchange) + */ + struct TALER_PrivateContractHashP h_contract_terms; + + /** + * Extension-specific details about the deposit relevant to the exchange. + */ + const json_t *extension_details; + + /** + * Timestamp when the contract was finalized, must match approximately the + * current time of the exchange. + */ + struct GNUNET_TIME_Timestamp timestamp; + + /** + * The public key of the merchant (used to identify the merchant for refund + * requests). + */ + struct TALER_MerchantPublicKeyP merchant_pub; + + /** + * 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 + * @e wire_deadline. + */ + struct GNUNET_TIME_Timestamp refund_deadline; + +}; /** @@ -936,27 +1002,15 @@ typedef void * the exchange's reply is not well-formed, we return an HTTP status code * of zero to @a cb. * - * We also verify that the @a coin_sig is valid for this deposit - * request, and that the @a ub_sig is a valid signature for @a + * We also verify that the @a cdd.coin_sig is valid for this deposit + * request, and that the @a cdd.ub_sig is a valid signature for @a * coin_pub. Also, the @a exchange must be ready to operate (i.e. have * finished processing the /keys reply). If either check fails, we do * NOT initiate the transaction with the exchange and instead return NULL. * * @param exchange the exchange handle; the exchange must be ready to operate - * @param amount the amount to be deposited - * @param wire_deadline execution date, until which the merchant would like the exchange to settle the balance (advisory, the exchange cannot be - * forced to settle in the past or upon very short notice, but of course a well-behaved exchange will limit aggregation based on the advice received) - * @param merchant_payto_uri the merchant’s account details, in the payto://-format supported by the exchange - * @param wire_salt salt used to hash the @a merchant_payto_uri - * @param h_contract_terms hash of the contact of the merchant with the customer (further details are never disclosed to the exchange) - * @param extension_details extension-specific details about the deposit relevant to the exchange - * @param coin_pub coin’s public key - * @param denom_pub denomination key with which the coin is signed - * @param denom_sig exchange’s unblinded signature of the coin - * @param timestamp timestamp when the contract was finalized, must match approximately the current time of the exchange - * @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 coin_sig the signature made with purpose #TALER_SIGNATURE_WALLET_COIN_DEPOSIT made by the customer with the coin’s private key. + * @param dcd details about the contract the deposit is for + * @param cdd details about the coin to be deposited * @param cb the callback to call when a reply for this request is available * @param cb_cls closure for the above callback * @param[out] ec if NULL is returned, set to the error code explaining why the operation failed @@ -966,20 +1020,8 @@ typedef void struct TALER_EXCHANGE_DepositHandle * TALER_EXCHANGE_deposit ( struct TALER_EXCHANGE_Handle *exchange, - const struct TALER_Amount *amount, - struct GNUNET_TIME_Timestamp wire_deadline, - const char *merchant_payto_uri, - const struct TALER_WireSaltP *wire_salt, - const struct TALER_PrivateContractHashP *h_contract_terms, - const struct TALER_AgeCommitmentHash *h_age_commitment, - const json_t *extension_details, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - const struct TALER_DenominationSignature *denom_sig, - const struct TALER_DenominationPublicKey *denom_pub, - struct GNUNET_TIME_Timestamp timestamp, - const struct TALER_MerchantPublicKeyP *merchant_pub, - struct GNUNET_TIME_Timestamp refund_deadline, - const struct TALER_CoinSpendSignatureP *coin_sig, + const struct TALER_EXCHANGE_DepositContractDetail *dcd, + const struct TALER_EXCHANGE_CoinDepositDetail *cdd, TALER_EXCHANGE_DepositResultCallback cb, void *cb_cls, enum TALER_ErrorCode *ec); diff --git a/src/lib/exchange_api_deposit.c b/src/lib/exchange_api_deposit.c index 58b1c3a4a..7e8246170 100644 --- a/src/lib/exchange_api_deposit.c +++ b/src/lib/exchange_api_deposit.c @@ -82,20 +82,24 @@ struct TALER_EXCHANGE_DepositHandle void *cb_cls; /** - * Hash over the contract for which this deposit is made. + * Details about the contract. */ - struct TALER_PrivateContractHashP h_contract_terms GNUNET_PACKED; + struct TALER_EXCHANGE_DepositContractDetail dcd; /** - * Hash over the wiring information of the merchant. + * Details about the coin. */ - struct TALER_MerchantWireHashP h_wire GNUNET_PACKED; + struct TALER_EXCHANGE_CoinDepositDetail cdd; /** - * Hash over the extension options of the deposit, 0 if there - * were not extension options. + * Hash of the merchant's wire details. */ - struct TALER_ExtensionContractHashP h_extensions GNUNET_PACKED; + struct TALER_MerchantWireHashP h_wire; + + /** + * Hash over the extensions, or all zero. + */ + struct TALER_ExtensionContractHashP h_extensions; /** * Time when this confirmation was generated / when the exchange received @@ -103,43 +107,6 @@ struct TALER_EXCHANGE_DepositHandle */ struct GNUNET_TIME_Timestamp exchange_timestamp; - /** - * By when does the exchange expect to pay the merchant - * (as per the merchant's request). - */ - struct GNUNET_TIME_Timestamp wire_deadline; - - /** - * How much time does the @e merchant have to issue a refund - * request? Zero if refunds are not allowed. After this time, the - * coin cannot be refunded. Note that the wire transfer will not be - * performed by the exchange until the refund deadline. This value - * is taken from the original deposit request. - */ - struct GNUNET_TIME_Timestamp refund_deadline; - - /** - * Amount to be deposited, excluding fee. Calculated from the - * amount with fee and the fee from the deposit request. - */ - struct TALER_Amount amount_without_fee; - - /** - * The public key of the coin that was deposited. - */ - struct TALER_CoinSpendPublicKeyP coin_pub; - - /** - * Our signature for the deposit operation. - */ - struct TALER_CoinSpendSignatureP coin_sig; - - /** - * The Merchant's public key. Allows the merchant to later refund - * the transaction or to inquire about the wire transfer identifier. - */ - struct TALER_MerchantPublicKeyP merchant_pub; - /** * Exchange signature, set for #auditor_cb. */ @@ -150,17 +117,6 @@ struct TALER_EXCHANGE_DepositHandle */ struct TALER_ExchangePublicKeyP exchange_pub; - /** - * Value of the /deposit transaction, including fee. - */ - struct TALER_Amount amount_with_fee; - - /** - * @brief Public information about the coin's denomination key. - * Note that the "key" field itself has been zero'ed out. - */ - struct TALER_EXCHANGE_DenomPublicKey dki; - /** * Chance that we will inform the auditor about the deposit * is 1:n, where the value of this field is "n". @@ -188,9 +144,12 @@ auditor_cb (void *cls, const struct TALER_EXCHANGE_Keys *key_state; const struct TALER_EXCHANGE_SigningPublicKey *spk; struct TEAH_AuditorInteractionEntry *aie; + struct TALER_Amount amount_without_fee; + const struct TALER_EXCHANGE_DenomPublicKey *dki; - if (0 != GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - dh->auditor_chance)) + if (0 != + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + dh->auditor_chance)) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Not providing deposit confirmation to auditor\n"); @@ -200,6 +159,9 @@ auditor_cb (void *cls, "Will provide deposit confirmation to auditor `%s'\n", TALER_B2S (auditor_pub)); key_state = TALER_EXCHANGE_get_keys (dh->exchange); + dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state, + &dh->cdd.h_denom_pub); + GNUNET_assert (NULL != dki); spk = TALER_EXCHANGE_get_signing_key_info (key_state, &dh->exchange_pub); if (NULL == spk) @@ -207,18 +169,22 @@ auditor_cb (void *cls, GNUNET_break_op (0); return NULL; } + GNUNET_assert (0 <= + TALER_amount_subtract (&amount_without_fee, + &dh->cdd.amount, + &dki->fees.deposit)); aie = GNUNET_new (struct TEAH_AuditorInteractionEntry); aie->dch = TALER_AUDITOR_deposit_confirmation ( ah, &dh->h_wire, &dh->h_extensions, - &dh->h_contract_terms, + &dh->dcd.h_contract_terms, dh->exchange_timestamp, - dh->wire_deadline, - dh->refund_deadline, - &dh->amount_without_fee, - &dh->coin_pub, - &dh->merchant_pub, + dh->dcd.wire_deadline, + dh->dcd.refund_deadline, + &amount_without_fee, + &dh->cdd.coin_pub, + &dh->dcd.merchant_pub, &dh->exchange_pub, &dh->exchange_sig, &key_state->master_pub, @@ -276,6 +242,8 @@ handle_deposit_finished (void *cls, &dh->exchange_timestamp), GNUNET_JSON_spec_end () }; + struct TALER_Amount amount_without_fee; + const struct TALER_EXCHANGE_DenomPublicKey *dki; if (GNUNET_OK != GNUNET_JSON_parse (j, @@ -288,6 +256,9 @@ handle_deposit_finished (void *cls, break; } key_state = TALER_EXCHANGE_get_keys (dh->exchange); + dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state, + &dh->cdd.h_denom_pub); + GNUNET_assert (NULL != dki); if (GNUNET_OK != TALER_EXCHANGE_test_signing_key (key_state, &dh->exchange_pub)) @@ -297,18 +268,22 @@ handle_deposit_finished (void *cls, dr.hr.ec = TALER_EC_EXCHANGE_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE; break; } + GNUNET_assert (0 <= + TALER_amount_subtract (&amount_without_fee, + &dh->cdd.amount, + &dki->fees.deposit)); if (GNUNET_OK != TALER_exchange_online_deposit_confirmation_verify ( - &dh->h_contract_terms, + &dh->dcd.h_contract_terms, &dh->h_wire, &dh->h_extensions, dh->exchange_timestamp, - dh->wire_deadline, - dh->refund_deadline, - &dh->amount_without_fee, - &dh->coin_pub, - &dh->merchant_pub, + dh->dcd.wire_deadline, + dh->dcd.refund_deadline, + &amount_without_fee, + &dh->cdd.coin_pub, + &dh->dcd.merchant_pub, &dh->exchange_pub, &dh->exchange_sig)) { @@ -346,21 +321,30 @@ handle_deposit_finished (void *cls, happen, we should pass the JSON reply to the application */ break; case MHD_HTTP_CONFLICT: - dr.hr.ec = TALER_JSON_get_error_code (j); - dr.hr.hint = TALER_JSON_get_error_hint (j); - if (GNUNET_OK != - TALER_EXCHANGE_check_coin_conflict_ ( - keys, - j, - &dh->dki, - &dh->coin_pub, - &dh->coin_sig, - &dh->amount_with_fee)) { - GNUNET_break_op (0); - dr.hr.http_status = 0; - dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; - break; + const struct TALER_EXCHANGE_Keys *key_state; + const struct TALER_EXCHANGE_DenomPublicKey *dki; + + key_state = TALER_EXCHANGE_get_keys (dh->exchange); + dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state, + &dh->cdd.h_denom_pub); + GNUNET_assert (NULL != dki); + dr.hr.ec = TALER_JSON_get_error_code (j); + dr.hr.hint = TALER_JSON_get_error_hint (j); + if (GNUNET_OK != + TALER_EXCHANGE_check_coin_conflict_ ( + keys, + j, + dki, + &dh->cdd.coin_pub, + &dh->cdd.coin_sig, + &dh->cdd.amount)) + { + GNUNET_break_op (0); + dr.hr.http_status = 0; + dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + break; + } } break; case MHD_HTTP_GONE: @@ -397,56 +381,38 @@ handle_deposit_finished (void *cls, /** * Verify signature information about the deposit. * - * @param dki public key information - * @param amount the amount to be deposited - * @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 ech hash over contract extensions - * @param coin_pub coin’s public key - * @param h_age_commitment coin’s hash of age commitment, might be NULL - * @param denom_sig exchange’s unblinded signature of the coin - * @param denom_pub denomination key with which the coin is signed - * @param denom_pub_hash hash of @a denom_pub - * @param timestamp timestamp when the deposit was finalized - * @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) - * @param coin_sig the signature made with purpose #TALER_SIGNATURE_WALLET_COIN_DEPOSIT made by the customer with the coin’s private key. + * @param dcd contract details + * @param ech hashed contract (passed to avoid recomputation) + * @param h_wire hashed wire details (passed to avoid recomputation) + * @param cdd coin-specific details + * @param dki denomination of the coin * @return #GNUNET_OK if signatures are OK, #GNUNET_SYSERR if not */ static enum GNUNET_GenericReturnValue -verify_signatures (const struct TALER_EXCHANGE_DenomPublicKey *dki, - const struct TALER_Amount *amount, - const struct TALER_MerchantWireHashP *h_wire, - const struct TALER_PrivateContractHashP *h_contract_terms, +verify_signatures (const struct TALER_EXCHANGE_DepositContractDetail *dcd, const struct TALER_ExtensionContractHashP *ech, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - const struct TALER_AgeCommitmentHash *h_age_commitment, - const struct TALER_DenominationSignature *denom_sig, - const struct TALER_DenominationPublicKey *denom_pub, - const struct TALER_DenominationHashP *denom_pub_hash, - struct GNUNET_TIME_Timestamp timestamp, - const struct TALER_MerchantPublicKeyP *merchant_pub, - struct GNUNET_TIME_Timestamp refund_deadline, - const struct TALER_CoinSpendSignatureP *coin_sig) + const struct TALER_MerchantWireHashP *h_wire, + const struct TALER_EXCHANGE_CoinDepositDetail *cdd, + const struct TALER_EXCHANGE_DenomPublicKey *dki) { if (GNUNET_OK != - TALER_wallet_deposit_verify (amount, + TALER_wallet_deposit_verify (&cdd->amount, &dki->fees.deposit, h_wire, - h_contract_terms, - h_age_commitment, + &dcd->h_contract_terms, + &cdd->h_age_commitment, ech, - denom_pub_hash, - timestamp, - merchant_pub, - refund_deadline, - coin_pub, - coin_sig)) + &cdd->h_denom_pub, + dcd->timestamp, + &dcd->merchant_pub, + dcd->refund_deadline, + &cdd->coin_pub, + &cdd->coin_sig)) { GNUNET_break_op (0); TALER_LOG_WARNING ("Invalid coin signature on /deposit request!\n"); TALER_LOG_DEBUG ("... amount_with_fee was %s\n", - TALER_amount2s (amount)); + TALER_amount2s (&cdd->amount)); TALER_LOG_DEBUG ("... deposit_fee was %s\n", TALER_amount2s (&dki->fees.deposit)); return GNUNET_SYSERR; @@ -455,19 +421,15 @@ verify_signatures (const struct TALER_EXCHANGE_DenomPublicKey *dki, /* check coin signature */ { struct TALER_CoinPublicInfo coin_info = { - .coin_pub = *coin_pub, - .denom_pub_hash = *denom_pub_hash, - .denom_sig = *denom_sig, - .h_age_commitment = {{{0}}} + .coin_pub = cdd->coin_pub, + .denom_pub_hash = cdd->h_denom_pub, + .denom_sig = cdd->denom_sig, + .h_age_commitment = cdd->h_age_commitment, }; - if (NULL != h_age_commitment) - { - coin_info.h_age_commitment = *h_age_commitment; - } if (GNUNET_YES != TALER_test_coin_valid (&coin_info, - denom_pub)) + &dki->key)) { GNUNET_break_op (0); TALER_LOG_WARNING ("Invalid coin passed for /deposit\n"); @@ -477,7 +439,7 @@ verify_signatures (const struct TALER_EXCHANGE_DenomPublicKey *dki, /* Check coin does make a contribution */ if (0 < TALER_amount_cmp (&dki->fees.deposit, - amount)) + &cdd->amount)) { GNUNET_break_op (0); TALER_LOG_WARNING ("Deposit amount smaller than fee\n"); @@ -490,45 +452,37 @@ verify_signatures (const struct TALER_EXCHANGE_DenomPublicKey *dki, struct TALER_EXCHANGE_DepositHandle * TALER_EXCHANGE_deposit ( struct TALER_EXCHANGE_Handle *exchange, - const struct TALER_Amount *amount, - struct GNUNET_TIME_Timestamp wire_deadline, - const char *merchant_payto_uri, - const struct TALER_WireSaltP *wire_salt, - const struct TALER_PrivateContractHashP *h_contract_terms, - const struct TALER_AgeCommitmentHash *h_age_commitment, - const json_t *extension_details, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - const struct TALER_DenominationSignature *denom_sig, - const struct TALER_DenominationPublicKey *denom_pub, - struct GNUNET_TIME_Timestamp timestamp, - const struct TALER_MerchantPublicKeyP *merchant_pub, - struct GNUNET_TIME_Timestamp refund_deadline, - const struct TALER_CoinSpendSignatureP *coin_sig, + const struct TALER_EXCHANGE_DepositContractDetail *dcd, + const struct TALER_EXCHANGE_CoinDepositDetail *cdd, TALER_EXCHANGE_DepositResultCallback cb, void *cb_cls, enum TALER_ErrorCode *ec) { const struct TALER_EXCHANGE_Keys *key_state; - const struct TALER_EXCHANGE_DenomPublicKey *dki; struct TALER_EXCHANGE_DepositHandle *dh; struct GNUNET_CURL_Context *ctx; json_t *deposit_obj; CURL *eh; - struct TALER_MerchantWireHashP h_wire; - struct TALER_DenominationHashP denom_pub_hash; + const struct TALER_EXCHANGE_DenomPublicKey *dki; struct TALER_Amount amount_without_fee; - struct TALER_ExtensionContractHashP ech; char arg_str[sizeof (struct TALER_CoinSpendPublicKeyP) * 2 + 32]; - if (NULL != extension_details) - TALER_deposit_extension_hash (extension_details, - &ech); + GNUNET_assert (GNUNET_YES == + TEAH_handle_is_ready (exchange)); + if (GNUNET_TIME_timestamp_cmp (dcd->refund_deadline, + >, + dcd->wire_deadline)) + { + GNUNET_break_op (0); + *ec = TALER_EC_EXCHANGE_DEPOSIT_REFUND_DEADLINE_AFTER_WIRE_DEADLINE; + return NULL; + } { char pub_str[sizeof (struct TALER_CoinSpendPublicKeyP) * 2]; char *end; end = GNUNET_STRINGS_data_to_string ( - coin_pub, + &cdd->coin_pub, sizeof (struct TALER_CoinSpendPublicKeyP), pub_str, sizeof (pub_str)); @@ -538,26 +492,10 @@ TALER_EXCHANGE_deposit ( "/coins/%s/deposit", pub_str); } - if (GNUNET_TIME_timestamp_cmp (refund_deadline, - >, - wire_deadline)) - { - GNUNET_break_op (0); - *ec = TALER_EC_EXCHANGE_DEPOSIT_REFUND_DEADLINE_AFTER_WIRE_DEADLINE; - return NULL; - } - GNUNET_assert (GNUNET_YES == - TEAH_handle_is_ready (exchange)); - - /* initialize h_wire */ - TALER_merchant_wire_signature_hash (merchant_payto_uri, - wire_salt, - &h_wire); key_state = TALER_EXCHANGE_get_keys (exchange); - - dki = TALER_EXCHANGE_get_denomination_key (key_state, - denom_pub); + dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state, + &cdd->h_denom_pub); if (NULL == dki) { *ec = TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN; @@ -567,97 +505,77 @@ TALER_EXCHANGE_deposit ( if (0 > TALER_amount_subtract (&amount_without_fee, - amount, + &cdd->amount, &dki->fees.deposit)) { *ec = TALER_EC_EXCHANGE_DEPOSIT_FEE_ABOVE_AMOUNT; GNUNET_break_op (0); return NULL; } - - TALER_denom_pub_hash (denom_pub, - &denom_pub_hash); - - if (GNUNET_OK != - verify_signatures (dki, - amount, - &h_wire, - h_contract_terms, - (NULL != extension_details) ? &ech : NULL, - coin_pub, - h_age_commitment, - denom_sig, - denom_pub, - &denom_pub_hash, - timestamp, - merchant_pub, - refund_deadline, - coin_sig)) - { - *ec = TALER_EC_EXCHANGE_DEPOSIT_COIN_SIGNATURE_INVALID; - GNUNET_break_op (0); - return NULL; - } - - deposit_obj = GNUNET_JSON_PACK ( - TALER_JSON_pack_amount ("contribution", - amount), - GNUNET_JSON_pack_string ("merchant_payto_uri", - merchant_payto_uri), - GNUNET_JSON_pack_data_auto ("wire_salt", - wire_salt), - GNUNET_JSON_pack_data_auto ("h_contract_terms", - h_contract_terms), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_data_auto ("h_age_commitment", - h_age_commitment)), - GNUNET_JSON_pack_data_auto ("denom_pub_hash", - &denom_pub_hash), - TALER_JSON_pack_denom_sig ("ub_sig", - denom_sig), - GNUNET_JSON_pack_timestamp ("timestamp", - timestamp), - GNUNET_JSON_pack_data_auto ("merchant_pub", - merchant_pub), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_timestamp ("refund_deadline", - refund_deadline)), - GNUNET_JSON_pack_timestamp ("wire_transfer_deadline", - wire_deadline), - GNUNET_JSON_pack_data_auto ("coin_sig", - coin_sig)); dh = GNUNET_new (struct TALER_EXCHANGE_DepositHandle); dh->auditor_chance = AUDITOR_CHANCE; dh->exchange = exchange; dh->cb = cb; dh->cb_cls = cb_cls; - dh->coin_sig = *coin_sig; - dh->coin_pub = *coin_pub; + dh->cdd = *cdd; + dh->dcd = *dcd; + if (NULL != dcd->extension_details) + TALER_deposit_extension_hash (dcd->extension_details, + &dh->h_extensions); + TALER_merchant_wire_signature_hash (dcd->merchant_payto_uri, + &dcd->wire_salt, + &dh->h_wire); + if (GNUNET_OK != + verify_signatures (dcd, + &dh->h_extensions, + &dh->h_wire, + cdd, + dki)) + { + *ec = TALER_EC_EXCHANGE_DEPOSIT_COIN_SIGNATURE_INVALID; + GNUNET_break_op (0); + GNUNET_free (dh); + return NULL; + } dh->url = TEAH_path_to_url (exchange, arg_str); if (NULL == dh->url) { GNUNET_break (0); *ec = TALER_EC_GENERIC_ALLOCATION_FAILURE; + GNUNET_free (dh->url); GNUNET_free (dh); - json_decref (deposit_obj); return NULL; } - dh->h_contract_terms = *h_contract_terms; - dh->h_wire = h_wire; - /* dh->h_extensions = ... */ - dh->refund_deadline = refund_deadline; - dh->wire_deadline = wire_deadline; - dh->amount_without_fee = amount_without_fee; - dh->coin_pub = *coin_pub; - dh->merchant_pub = *merchant_pub; - dh->amount_with_fee = *amount; - dh->dki = *dki; - memset (&dh->dki.key, - 0, - sizeof (dh->dki.key)); /* lifetime not warranted, so better - not copy the contents! */ + deposit_obj = GNUNET_JSON_PACK ( + TALER_JSON_pack_amount ("contribution", + &cdd->amount), + GNUNET_JSON_pack_string ("merchant_payto_uri", + dcd->merchant_payto_uri), + GNUNET_JSON_pack_data_auto ("wire_salt", + &dcd->wire_salt), + GNUNET_JSON_pack_data_auto ("h_contract_terms", + &dcd->h_contract_terms), + GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_data_auto ("h_age_commitment", + &cdd->h_age_commitment)), + GNUNET_JSON_pack_data_auto ("denom_pub_hash", + &cdd->h_denom_pub), + TALER_JSON_pack_denom_sig ("ub_sig", + &cdd->denom_sig), + GNUNET_JSON_pack_timestamp ("timestamp", + dcd->timestamp), + GNUNET_JSON_pack_data_auto ("merchant_pub", + &dcd->merchant_pub), + GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_timestamp ("refund_deadline", + dcd->refund_deadline)), + GNUNET_JSON_pack_timestamp ("wire_transfer_deadline", + dcd->wire_deadline), + GNUNET_JSON_pack_data_auto ("coin_sig", + &cdd->coin_sig)); + GNUNET_assert (NULL != deposit_obj); eh = TALER_EXCHANGE_curl_easy_get_ (dh->url); if ( (NULL == eh) || (GNUNET_OK != diff --git a/src/testing/testing_api_cmd_deposit.c b/src/testing/testing_api_cmd_deposit.c index 4edc6f217..deaff4dbc 100644 --- a/src/testing/testing_api_cmd_deposit.c +++ b/src/testing/testing_api_cmd_deposit.c @@ -454,24 +454,33 @@ deposit_run (void *cls, &coin_sig); } GNUNET_assert (NULL == ds->dh); - ds->dh = TALER_EXCHANGE_deposit (is->exchange, - &ds->amount, - ds->wire_deadline, - payto_uri, - &wire_salt, - &h_contract_terms, - &h_age_commitment, - NULL, /* FIXME: add hash of extensions */ - &coin_pub, - denom_pub_sig, - &denom_pub->key, - ds->wallet_timestamp, - &merchant_pub, - ds->refund_deadline, - &coin_sig, - &deposit_cb, - ds, - &ec); + { + struct TALER_EXCHANGE_CoinDepositDetail cdd = { + .amount = ds->amount, + .h_age_commitment = h_age_commitment, + .coin_pub = coin_pub, + .coin_sig = coin_sig, + .denom_sig = *denom_pub_sig, + .h_denom_pub = denom_pub->h_key + }; + struct TALER_EXCHANGE_DepositContractDetail dcd = { + .wire_deadline = ds->wire_deadline, + .merchant_payto_uri = payto_uri, + .wire_salt = wire_salt, + .h_contract_terms = h_contract_terms, + .extension_details = NULL /* FIXME-OEC */, + .timestamp = ds->wallet_timestamp, + .merchant_pub = merchant_pub, + .refund_deadline = ds->refund_deadline + }; + + ds->dh = TALER_EXCHANGE_deposit (is->exchange, + &dcd, + &cdd, + &deposit_cb, + ds, + &ec); + } if (NULL == ds->dh) { GNUNET_break (0);