diff options
Diffstat (limited to 'src/mint')
-rw-r--r-- | src/mint/taler-mint-httpd_db.c | 15 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_db.h | 8 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_parsing.c | 17 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_refresh.c | 56 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_responses.c | 24 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_responses.h | 2 |
6 files changed, 88 insertions, 34 deletions
diff --git a/src/mint/taler-mint-httpd_db.c b/src/mint/taler-mint-httpd_db.c index 4e91e7e76..2a4c16748 100644 --- a/src/mint/taler-mint-httpd_db.c +++ b/src/mint/taler-mint-httpd_db.c @@ -550,7 +550,9 @@ refresh_accept_melts (struct MHD_Connection *connection, GNUNET_break (0); TMH_plugin->free_coin_transaction_list (TMH_plugin->cls, tl); - return TMH_RESPONSE_reply_internal_db_error (connection); + return (MHD_YES == + TMH_RESPONSE_reply_internal_db_error (connection)) + ? GNUNET_NO : GNUNET_SYSERR; } /* Refuse to refresh when the coin's value is insufficient for the cost of all transactions. */ @@ -580,6 +582,7 @@ refresh_accept_melts (struct MHD_Connection *connection, melt.coin_sig = coin_details->melt_sig; melt.session_hash = *session_hash; melt.amount_with_fee = coin_details->melt_amount_with_fee; + melt.melt_fee = coin_details->melt_fee; if (GNUNET_OK != TMH_plugin->insert_refresh_melt (TMH_plugin->cls, session, @@ -587,7 +590,9 @@ refresh_accept_melts (struct MHD_Connection *connection, &melt)) { GNUNET_break (0); - return GNUNET_SYSERR; + return (MHD_YES == + TMH_RESPONSE_reply_internal_db_error (connection)) + ? GNUNET_NO : GNUNET_SYSERR; } return GNUNET_OK; } @@ -623,7 +628,7 @@ TMH_DB_execute_refresh_melt (struct MHD_Connection *connection, unsigned int coin_count, const struct TMH_DB_MeltDetails *coin_melt_details, struct TALER_MINTDB_RefreshCommitCoin *const* commit_coin, - struct TALER_MINTDB_RefreshCommitLinkP *const* commit_link) + struct TALER_RefreshCommitLinkP *const* commit_link) { struct TMH_KS_StateHandle *key_state; struct TALER_MINTDB_RefreshSession refresh_session; @@ -839,11 +844,11 @@ check_commitment (struct MHD_Connection *connection, unsigned int j; struct TALER_LinkSecretP last_shared_secret; int secret_initialized = GNUNET_NO; - struct TALER_MINTDB_RefreshCommitLinkP *commit_links; + struct TALER_RefreshCommitLinkP *commit_links; struct TALER_MINTDB_RefreshCommitCoin *commit_coins; commit_links = GNUNET_malloc (num_oldcoins * - sizeof (struct TALER_MINTDB_RefreshCommitLinkP)); + sizeof (struct TALER_RefreshCommitLinkP)); if (GNUNET_OK != TMH_plugin->get_refresh_commit_links (TMH_plugin->cls, session, diff --git a/src/mint/taler-mint-httpd_db.h b/src/mint/taler-mint-httpd_db.h index 8a171153a..599762179 100644 --- a/src/mint/taler-mint-httpd_db.h +++ b/src/mint/taler-mint-httpd_db.h @@ -99,6 +99,12 @@ struct TMH_DB_MeltDetails * to the melt is this value minus the fee for melting the coin. */ struct TALER_Amount melt_amount_with_fee; + + /** + * What fee is earned by the mint? Set delayed during + * #verify_coin_public_info(). + */ + struct TALER_Amount melt_fee; }; @@ -130,7 +136,7 @@ TMH_DB_execute_refresh_melt (struct MHD_Connection *connection, unsigned int coin_count, const struct TMH_DB_MeltDetails *coin_melt_details, struct TALER_MINTDB_RefreshCommitCoin *const* commit_coin, - struct TALER_MINTDB_RefreshCommitLinkP *const* commit_link); + struct TALER_RefreshCommitLinkP *const* commit_link); /** diff --git a/src/mint/taler-mint-httpd_parsing.c b/src/mint/taler-mint-httpd_parsing.c index 1844fa881..4e7020bfe 100644 --- a/src/mint/taler-mint-httpd_parsing.c +++ b/src/mint/taler-mint-httpd_parsing.c @@ -490,6 +490,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, fname); if (NULL == root) { + GNUNET_break_op (0); ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, @@ -513,6 +514,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, fnum); if (NULL == root) { + GNUNET_break_op (0); ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, @@ -535,6 +537,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, str = json_string_value (root); if (NULL == str) { + GNUNET_break_op (0); ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, @@ -548,6 +551,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, where, len); if (GNUNET_OK != res) { + GNUNET_break_op (0); ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, @@ -571,6 +575,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, str = json_string_value (root); if (NULL == str) { + GNUNET_break_op (0); ret = (MHD_YES == TMH_RESPONSE_reply_internal_error (connection, "json_string_value() failed")) @@ -587,6 +592,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, *len); if (GNUNET_OK != res) { + GNUNET_break_op (0); GNUNET_free (*where); *where = NULL; *len = 0; @@ -613,6 +619,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, ( (-1 != typ) && (json_typeof (root) != typ)) ) { + GNUNET_break_op (0); *r_json = NULL; ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, @@ -637,6 +644,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, if (json_typeof (root) != JSON_INTEGER) { + GNUNET_break_op (0); ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, @@ -666,6 +674,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, str = json_string_value (root); if (NULL == str) { + GNUNET_break_op (0); ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, @@ -683,6 +692,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, len); if (GNUNET_OK != res) { + GNUNET_break_op (0); GNUNET_free (buf); ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, @@ -698,6 +708,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, GNUNET_free (buf); if (NULL == where->rsa_public_key) { + GNUNET_break_op (0); ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, @@ -724,6 +735,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, str = json_string_value (root); if (NULL == str) { + GNUNET_break_op (0); ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, @@ -741,6 +753,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, len); if (GNUNET_OK != res) { + GNUNET_break_op (0); GNUNET_free (buf); ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, @@ -756,6 +769,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, GNUNET_free (buf); if (NULL == where->rsa_signature) { + GNUNET_break_op (0); ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, @@ -777,6 +791,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, TALER_json_to_amount ((json_t *) root, where)) { + GNUNET_break_op (0); if (MHD_YES != TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, @@ -789,6 +804,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, if (0 != strcmp (where->currency, TMH_mint_currency_string)) { + GNUNET_break_op (0); if (MHD_YES != TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, @@ -815,6 +831,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, TALER_json_to_abs ((json_t *) root, where)) { + GNUNET_break_op (0); if (MHD_YES != TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, diff --git a/src/mint/taler-mint-httpd_refresh.c b/src/mint/taler-mint-httpd_refresh.c index 687fb998d..fcd843083 100644 --- a/src/mint/taler-mint-httpd_refresh.c +++ b/src/mint/taler-mint-httpd_refresh.c @@ -57,7 +57,7 @@ handle_refresh_melt_binary (struct MHD_Connection *connection, const struct TMH_DB_MeltDetails *coin_melt_details, const struct GNUNET_HashCode *session_hash, struct TALER_MINTDB_RefreshCommitCoin *const* commit_coin, - struct TALER_MINTDB_RefreshCommitLinkP *const* commit_link) + struct TALER_RefreshCommitLinkP *const* commit_link) { unsigned int i; struct TMH_KS_StateHandle *key_state; @@ -92,6 +92,7 @@ handle_refresh_melt_binary (struct MHD_Connection *connection, &cost, &total_cost)) ) { + GNUNET_break_op (0); TMH_KS_release (key_state); return TMH_RESPONSE_reply_internal_error (connection, "cost calculation failure"); @@ -115,6 +116,7 @@ handle_refresh_melt_binary (struct MHD_Connection *connection, &coin_melt_details->melt_amount_with_fee, &fee_melt)) { + GNUNET_break_op (0); TMH_KS_release (key_state); return TMH_RESPONSE_reply_external_error (connection, "Melt contribution below melting fee"); @@ -124,6 +126,7 @@ handle_refresh_melt_binary (struct MHD_Connection *connection, &melt, &total_melt)) { + GNUNET_break_op (0); TMH_KS_release (key_state); return TMH_RESPONSE_reply_internal_error (connection, "balance calculation failure"); @@ -134,6 +137,7 @@ handle_refresh_melt_binary (struct MHD_Connection *connection, TALER_amount_cmp (&total_cost, &total_melt)) { + GNUNET_break_op (0); /* We require total value of coins being melted and total value of coins being generated to match! */ return TMH_RESPONSE_reply_json_pack (connection, @@ -185,13 +189,17 @@ get_coin_public_info (struct MHD_Connection *connection, coin_info, spec); if (GNUNET_OK != ret) + { + GNUNET_break_op (0); return ret; + } /* check mint signature on the coin */ r_melt_detail->coin_info.denom_sig = sig; r_melt_detail->coin_info.denom_pub = pk; if (GNUNET_OK != TALER_test_coin_valid (&r_melt_detail->coin_info)) { + GNUNET_break_op (0); TMH_PARSE_release_data (spec); r_melt_detail->coin_info.denom_sig.rsa_signature = NULL; r_melt_detail->coin_info.denom_pub.rsa_public_key = NULL; @@ -202,21 +210,21 @@ get_coin_public_info (struct MHD_Connection *connection, } r_melt_detail->melt_sig = melt_sig; r_melt_detail->melt_amount_with_fee = amount; - TMH_PARSE_release_data (spec); return GNUNET_OK; } /** * Verify that the signature shows that this coin is to be melted into - * the given @a session_pub melting session, and that this is a valid + * the given @a session_hash melting session, and that this is a valid * coin (we know the denomination key and the signature on it is * valid). Essentially, this does all of the per-coin checks that can * be done before the transaction starts. * * @param connection the connection to send error responses to * @param session_hash hash over refresh session the coin is melted into - * @param melt_detail details about the coin's melting permission (if valid) + * @param[in,out] melt_detail details about the coin's melting permission, + * the `melt_fee` is updated * @return #GNUNET_YES if coin public info in JSON was valid * #GNUNET_NO JSON was invalid, response was generated * #GNUNET_SYSERR on internal error @@ -224,7 +232,7 @@ get_coin_public_info (struct MHD_Connection *connection, static int verify_coin_public_info (struct MHD_Connection *connection, const struct GNUNET_HashCode *session_hash, - const struct TMH_DB_MeltDetails *melt_detail) + struct TMH_DB_MeltDetails *melt_detail) { struct TALER_RefreshMeltCoinAffirmationPS body; struct TMH_KS_StateHandle *key_state; @@ -246,17 +254,20 @@ verify_coin_public_info (struct MHD_Connection *connection, valid for issuing! (#3634) */ TALER_amount_ntoh (&fee_refresh, &dki->issue.properties.fee_refresh); + melt_detail->melt_fee = 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, &melt_detail->melt_amount_with_fee); TALER_amount_hton (&body.melt_fee, &fee_refresh); body.coin_pub = melt_detail->coin_info.coin_pub; if (TALER_amount_cmp (&fee_refresh, - &melt_detail->melt_amount_with_fee) < 0) + &melt_detail->melt_amount_with_fee) > 0) { + GNUNET_break_op (0); TMH_KS_release (key_state); return (MHD_YES == TMH_RESPONSE_reply_external_error (connection, @@ -271,6 +282,7 @@ verify_coin_public_info (struct MHD_Connection *connection, &melt_detail->melt_sig.eddsa_signature, &melt_detail->coin_info.coin_pub.eddsa_pub)) { + GNUNET_break_op (0); if (MHD_YES != TMH_RESPONSE_reply_signature_invalid (connection, "confirm_sig")) @@ -318,7 +330,7 @@ free_commit_coins (struct TALER_MINTDB_RefreshCommitCoin **commit_coin, * @param num_old_coins size of 2nd dimension */ static void -free_commit_links (struct TALER_MINTDB_RefreshCommitLinkP **commit_link, +free_commit_links (struct TALER_RefreshCommitLinkP **commit_link, unsigned int kappa, unsigned int num_old_coins) { @@ -361,7 +373,6 @@ handle_refresh_melt_json (struct MHD_Connection *connection, unsigned int num_newcoins, const json_t *coin_evs, const json_t *link_encs) - { int res; unsigned int i; @@ -373,7 +384,7 @@ handle_refresh_melt_json (struct MHD_Connection *connection, struct GNUNET_HashCode session_hash; struct GNUNET_HashContext *hash_context; struct TALER_MINTDB_RefreshCommitCoin *commit_coin[TALER_CNC_KAPPA]; - struct TALER_MINTDB_RefreshCommitLinkP *commit_link[TALER_CNC_KAPPA]; + struct TALER_RefreshCommitLinkP *commit_link[TALER_CNC_KAPPA]; /* For the signature check, we hash most of the inputs together (except for the signatures on the coins). */ @@ -407,8 +418,8 @@ handle_refresh_melt_json (struct MHD_Connection *connection, } coin_count = json_array_size (melt_coins); - coin_melt_details = GNUNET_malloc (coin_count * - sizeof (struct TMH_DB_MeltDetails)); + coin_melt_details = GNUNET_new_array (coin_count, + struct TMH_DB_MeltDetails); for (i=0;i<coin_count;i++) { /* decode JSON data on coin to melt */ @@ -419,6 +430,7 @@ handle_refresh_melt_json (struct MHD_Connection *connection, &coin_melt_details[i]); if (GNUNET_OK != res) { + GNUNET_break_op (0); for (j=0;j<i;j++) { GNUNET_CRYPTO_rsa_public_key_free (coin_melt_details[j].coin_info.denom_pub.rsa_public_key); @@ -438,6 +450,7 @@ handle_refresh_melt_json (struct MHD_Connection *connection, &coin_melt_details[j].coin_info.coin_pub, sizeof (struct TALER_CoinSpendPublicKeyP))) { + GNUNET_break_op (0); for (j=0;j<i;j++) { GNUNET_CRYPTO_rsa_public_key_free (coin_melt_details[j].coin_info.denom_pub.rsa_public_key); @@ -459,7 +472,6 @@ handle_refresh_melt_json (struct MHD_Connection *connection, GNUNET_CRYPTO_hash_context_read (hash_context, &melt_amount, sizeof (struct TALER_AmountNBO)); - } /* parse JSON arrays into 2d binary arrays and hash everything @@ -486,6 +498,7 @@ handle_refresh_melt_json (struct MHD_Connection *connection, if (GNUNET_OK != res) { + GNUNET_break_op (0); GNUNET_CRYPTO_hash_context_abort (hash_context); free_commit_coins (commit_coin, TALER_CNC_KAPPA, @@ -504,6 +517,7 @@ handle_refresh_melt_json (struct MHD_Connection *connection, &link_enc_size); if (GNUNET_OK != res) { + GNUNET_break_op (0); GNUNET_CRYPTO_hash_context_abort (hash_context); free_commit_coins (commit_coin, TALER_CNC_KAPPA, @@ -524,10 +538,10 @@ handle_refresh_melt_json (struct MHD_Connection *connection, for (i = 0; i < TALER_CNC_KAPPA; i++) { commit_link[i] = GNUNET_malloc (num_oldcoins * - sizeof (struct TALER_MINTDB_RefreshCommitLinkP)); + sizeof (struct TALER_RefreshCommitLinkP)); for (j = 0; j < num_oldcoins; j++) { - struct TALER_MINTDB_RefreshCommitLinkP *rcl = &commit_link[i][j]; + struct TALER_RefreshCommitLinkP *rcl = &commit_link[i][j]; res = TMH_PARSE_navigate_json (connection, transfer_pubs, @@ -539,6 +553,7 @@ handle_refresh_melt_json (struct MHD_Connection *connection, if (GNUNET_OK != res) { + GNUNET_break_op (0); GNUNET_break (GNUNET_SYSERR != res); GNUNET_CRYPTO_hash_context_abort (hash_context); free_commit_coins (commit_coin, @@ -559,6 +574,7 @@ handle_refresh_melt_json (struct MHD_Connection *connection, if (GNUNET_OK != res) { + GNUNET_break_op (0); GNUNET_break (GNUNET_SYSERR != res); GNUNET_CRYPTO_hash_context_abort (hash_context); free_commit_coins (commit_coin, @@ -572,7 +588,7 @@ handle_refresh_melt_json (struct MHD_Connection *connection, GNUNET_CRYPTO_hash_context_read (hash_context, rcl, - sizeof (struct TALER_MINTDB_RefreshCommitLinkP)); + sizeof (struct TALER_RefreshCommitLinkP)); } } @@ -587,6 +603,7 @@ handle_refresh_melt_json (struct MHD_Connection *connection, &coin_melt_details[i]); if (GNUNET_OK != res) { + GNUNET_break_op (0); res = (GNUNET_NO == res) ? MHD_YES : MHD_NO; goto cleanup; } @@ -694,12 +711,14 @@ TMH_REFRESH_handler_refresh_melt (struct TMH_RequestHandler *rh, return TMH_RESPONSE_reply_arg_invalid (connection, "transfer_pubs"); } - res = TMH_PARSE_navigate_json (connection, coin_evs, + res = TMH_PARSE_navigate_json (connection, + coin_evs, TMH_PARSE_JNC_INDEX, (int) 0, - TMH_PARSE_JNC_RET_DATA, + TMH_PARSE_JNC_RET_TYPED_JSON, JSON_ARRAY, &coin_detail); if (GNUNET_OK != res) { + GNUNET_break_op (0); TMH_PARSE_release_data (spec); return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES; } @@ -707,10 +726,11 @@ TMH_REFRESH_handler_refresh_melt (struct TMH_RequestHandler *rh, res = TMH_PARSE_navigate_json (connection, transfer_pubs, TMH_PARSE_JNC_INDEX, (int) 0, - TMH_PARSE_JNC_RET_DATA, + TMH_PARSE_JNC_RET_TYPED_JSON, JSON_ARRAY, &coin_detail); if (GNUNET_OK != res) { + GNUNET_break_op (0); TMH_PARSE_release_data (spec); return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES; } diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c index 57b233e73..9a6813f1d 100644 --- a/src/mint/taler-mint-httpd_responses.c +++ b/src/mint/taler-mint-httpd_responses.c @@ -695,7 +695,7 @@ TMH_RESPONSE_reply_withdraw_sign_success (struct MHD_Connection *connection, * @param coin_pub public key of the coin * @param coin_value original value of the coin * @param tl transaction history for the coin - * @param requested how much this coin was supposed to contribute + * @param requested how much this coin was supposed to contribute, including fee * @param residual remaining value of the coin (after subtracting @a tl) * @return a MHD result code */ @@ -713,13 +713,19 @@ TMH_RESPONSE_reply_refresh_melt_insufficient_funds (struct MHD_Connection *conne return TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_NOT_FOUND, "{s:s, s:o, s:o, s:o, s:o, s:o}", - "error", "insufficient funds", - "coin-pub", TALER_json_from_data (coin_pub, - sizeof (struct TALER_CoinSpendPublicKeyP)), - "original-value", TALER_json_from_amount (&coin_value), - "residual-value", TALER_json_from_amount (&residual), - "requested-value", TALER_json_from_amount (&requested), - "history", history); + "error", + "insufficient funds", + "coin_pub", + TALER_json_from_data (coin_pub, + sizeof (struct TALER_CoinSpendPublicKeyP)), + "original_value", + TALER_json_from_amount (&coin_value), + "residual_value", + TALER_json_from_amount (&residual), + "requested_value", + TALER_json_from_amount (&requested), + "history", + history); } @@ -894,7 +900,7 @@ TMH_RESPONSE_reply_refresh_reveal_missmatch (struct MHD_Connection *connection, info_link_k = json_array (); for (i=0;i<mc->num_newcoins;i++) { - const struct TALER_MINTDB_RefreshCommitLinkP *cl; + const struct TALER_RefreshCommitLinkP *cl; json_t *cl_json; cl = &mc->commit_links[k][i]; diff --git a/src/mint/taler-mint-httpd_responses.h b/src/mint/taler-mint-httpd_responses.h index 7afd01884..a35356389 100644 --- a/src/mint/taler-mint-httpd_responses.h +++ b/src/mint/taler-mint-httpd_responses.h @@ -350,7 +350,7 @@ TMH_RESPONSE_reply_refresh_reveal_missmatch (struct MHD_Connection *connection, /** - * Information for each session a coin was melted into. + * @brief Information for each session a coin was melted into. */ struct TMH_RESPONSE_LinkSessionInfo { |