From bb15fdd21532cf24772e7f57a0b997002c288911 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 28 Mar 2015 17:27:08 +0100 Subject: [PATCH] fix use of struct TALER_RefreshMeltCoinAffirmationPS --- src/include/taler_mintdb_plugin.h | 11 +++++ src/mint/taler-mint-httpd_refresh.c | 58 ++++++++++++++------------- src/mint/taler-mint-httpd_responses.c | 12 +++--- 3 files changed, 48 insertions(+), 33 deletions(-) diff --git a/src/include/taler_mintdb_plugin.h b/src/include/taler_mintdb_plugin.h index 67ef3895b..505e86bb3 100644 --- a/src/include/taler_mintdb_plugin.h +++ b/src/include/taler_mintdb_plugin.h @@ -332,6 +332,17 @@ struct TALER_MINTDB_RefreshMelt */ struct TALER_Amount amount_with_fee; + /** + * Melting fee charged by the mint. This must match the Mint's + * denomination key's melting fee. If the client puts in an invalid + * melting fee (too high or too low) that does not match the Mint's + * denomination key, the melting operation is invalid and will be + * rejected by the mint. The @e amount_with_fee minus the @e + * melt_fee is the amount that will be credited to the melting + * session. + */ + struct TALER_Amount melt_fee; + }; diff --git a/src/mint/taler-mint-httpd_refresh.c b/src/mint/taler-mint-httpd_refresh.c index 8a2232e25..5673adb19 100644 --- a/src/mint/taler-mint-httpd_refresh.c +++ b/src/mint/taler-mint-httpd_refresh.c @@ -242,12 +242,39 @@ verify_coin_public_info (struct MHD_Connection *connection, struct TALER_MINTDB_DenominationKeyIssueInformation *dki; struct TALER_Amount fee_refresh; + key_state = TMH_KS_acquire (); + dki = TMH_KS_denomination_key_lookup (key_state, + &r_public_info->denom_pub); + if (NULL == dki) + { + TMH_KS_release (key_state); + TALER_LOG_WARNING ("Unknown denomination key in /refresh/melt request\n"); + return TMH_RESPONSE_reply_arg_invalid (connection, + "denom_pub"); + } + /* FIXME: need to check if denomination key is still + valid for issuing! (#3634) */ + TALER_amount_ntoh (&fee_refresh, + &dki->issue.fee_refresh); body.purpose.size = htonl (sizeof (struct TALER_RefreshMeltCoinAffirmationPS)); body.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_MELT); body.session_hash = *session_hash; TALER_amount_hton (&body.amount_with_fee, &r_melt_detail->melt_amount_with_fee); + TALER_amount_hton (&body.melt_fee, + &fee_refresh); body.coin_pub = r_public_info->coin_pub; + if (TALER_amount_cmp (&fee_refresh, + &r_melt_detail->melt_amount_with_fee) < 0) + { + TMH_KS_release (key_state); + return (MHD_YES == + TMH_RESPONSE_reply_external_error (connection, + "melt amount smaller than melting fee")) + ? GNUNET_NO : GNUNET_SYSERR; + } + + TMH_KS_release (key_state); if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify (TALER_SIGNATURE_WALLET_COIN_MELT, &body.purpose, @@ -256,37 +283,12 @@ verify_coin_public_info (struct MHD_Connection *connection, { if (MHD_YES != TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_UNAUTHORIZED, - "{s:s}", - "error", "signature invalid")) + MHD_HTTP_UNAUTHORIZED, + "{s:s}", + "error", "signature invalid")) return GNUNET_SYSERR; return GNUNET_NO; } - key_state = TMH_KS_acquire (); - dki = TMH_KS_denomination_key_lookup (key_state, - &r_public_info->denom_pub); - if (NULL == dki) - { - TMH_KS_release (key_state); - TALER_LOG_WARNING ("Unknown denomination key in /refresh/melt request\n"); - return TMH_RESPONSE_reply_arg_invalid (connection, - "denom_pub"); - } - /* FIXME: need to check if denomination key is still - valid for issuing! (#3634) */ - TALER_amount_ntoh (&fee_refresh, - &dki->issue.fee_refresh); - if (TALER_amount_cmp (&fee_refresh, - &r_melt_detail->melt_amount_with_fee) < 0) - { - TMH_KS_release (key_state); - return (MHD_YES == - TMH_RESPONSE_reply_external_error (connection, - "melt amount smaller than melting fee")) - ? GNUNET_NO : GNUNET_SYSERR; - } - - TMH_KS_release (key_state); return GNUNET_OK; } diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c index 0fe3f4700..6367c6bd8 100644 --- a/src/mint/taler-mint-httpd_responses.c +++ b/src/mint/taler-mint-httpd_responses.c @@ -377,6 +377,8 @@ compile_transaction_history (const struct TALER_MINTDB_TransactionList *tl) ms.session_hash = melt->session_hash; TALER_amount_hton (&ms.amount_with_fee, &melt->amount_with_fee); + TALER_amount_hton (&ms.melt_fee, + &melt->melt_fee); ms.coin_pub = melt->coin.coin_pub; transaction = TALER_json_from_ecdsa_sig (&ms.purpose, &melt->coin_sig.ecdsa_signature); @@ -414,16 +416,16 @@ compile_transaction_history (const struct TALER_MINTDB_TransactionList *tl) */ int TMH_RESPONSE_reply_deposit_insufficient_funds (struct MHD_Connection *connection, - const struct TALER_MINTDB_TransactionList *tl) + const struct TALER_MINTDB_TransactionList *tl) { json_t *history; history = compile_transaction_history (tl); return TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_FORBIDDEN, - "{s:s, s:o}", - "error", "insufficient funds", - "history", history); + MHD_HTTP_FORBIDDEN, + "{s:s, s:o}", + "error", "insufficient funds", + "history", history); }