From 6d323a50d2387a74f5822d83cb81c45682eae478 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 21 Jun 2015 21:49:05 +0200 Subject: marking remaining FIXMEs for #3516 --- src/mint-lib/mint_api_deposit.c | 105 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 96 insertions(+), 9 deletions(-) (limited to 'src/mint-lib/mint_api_deposit.c') diff --git a/src/mint-lib/mint_api_deposit.c b/src/mint-lib/mint_api_deposit.c index c404676a..c7868075 100644 --- a/src/mint-lib/mint_api_deposit.c +++ b/src/mint-lib/mint_api_deposit.c @@ -92,6 +92,16 @@ struct TALER_MINT_DepositHandle */ struct TALER_DepositConfirmationPS depconf; + /** + * Value of the /deposit transaction, including fee. + */ + struct TALER_Amount amount_with_fee; + + /** + * Total value of the coin being transacted with. + */ + struct TALER_Amount coin_value; + /** * The size of the download buffer */ @@ -160,19 +170,95 @@ static int verify_deposit_signature_forbidden (const struct TALER_MINT_DepositHandle *dh, json_t *json) { - struct MAJ_Specification spec[] = { - MAJ_spec_end - }; - - if (GNUNET_OK != - MAJ_parse_json (json, - spec)) + json_t *history; + size_t len; + size_t off; + struct TALER_Amount total; + + history = json_object_get (json, + "history"); + if (NULL == history) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + len = json_array_size (history); + if (0 == len) { GNUNET_break_op (0); return GNUNET_SYSERR; } + TALER_amount_get_zero (dh->coin_value.currency, + &total); + for (off=0;offdepconf.coin_pub.eddsa_pub), + MAJ_spec_end + }; + + transaction = json_array_get (history, + off); + if (GNUNET_OK != + MAJ_parse_json (transaction, + spec)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + switch (purpose->purpose) + { + case TALER_SIGNATURE_WALLET_COIN_DEPOSIT: + GNUNET_break (0); + /* FIXME: check amount! #3516 */ + break; + case TALER_SIGNATURE_WALLET_COIN_MELT: + GNUNET_break (0); + /* FIXME: check amount! #3516 */ + break; + default: + /* signature not supported, new version on server? */ + GNUNET_break (0); + MAJ_parse_free (spec); + return GNUNET_SYSERR; + } + if (GNUNET_OK != + TALER_amount_add (&total, + &total, + &amount)) + { + /* overflow in history already!? inconceivable! */ + GNUNET_break_op (0); + MAJ_parse_free (spec); + return GNUNET_SYSERR; + } + MAJ_parse_free (spec); + } + if (GNUNET_OK != + TALER_amount_add (&total, + &total, + &dh->amount_with_fee)) + { + /* clearly not OK if our transaction would have caused + the overflow... */ + return GNUNET_OK; + } - GNUNET_break (0); // not implemented + if (0 >= TALER_amount_cmp (&total, + &dh->coin_value)) + { + /* transaction should have still fit */ + GNUNET_break (0); + return GNUNET_SYSERR; + } + /* everything OK, proof of double-spending was provided */ return GNUNET_OK; } @@ -530,7 +616,8 @@ TALER_MINT_deposit (struct TALER_MINT_Handle *mint, &amount_without_fee); dh->depconf.coin_pub = *coin_pub; dh->depconf.merchant = *merchant_pub; - + dh->amount_with_fee = *amount; + dh->coin_value = dki->value; eh = curl_easy_init (); GNUNET_assert (NULL != (dh->json_enc = -- cgit v1.2.3