aboutsummaryrefslogtreecommitdiff
path: root/src/exchange/taler-exchange-httpd_refresh_melt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchange/taler-exchange-httpd_refresh_melt.c')
-rw-r--r--src/exchange/taler-exchange-httpd_refresh_melt.c53
1 files changed, 33 insertions, 20 deletions
diff --git a/src/exchange/taler-exchange-httpd_refresh_melt.c b/src/exchange/taler-exchange-httpd_refresh_melt.c
index 8677d6270..702857b8c 100644
--- a/src/exchange/taler-exchange-httpd_refresh_melt.c
+++ b/src/exchange/taler-exchange-httpd_refresh_melt.c
@@ -48,9 +48,11 @@
48 */ 48 */
49static int 49static int
50reply_refresh_melt_insufficient_funds (struct MHD_Connection *connection, 50reply_refresh_melt_insufficient_funds (struct MHD_Connection *connection,
51 const struct TALER_CoinSpendPublicKeyP *coin_pub, 51 const struct
52 TALER_CoinSpendPublicKeyP *coin_pub,
52 struct TALER_Amount coin_value, 53 struct TALER_Amount coin_value,
53 struct TALER_EXCHANGEDB_TransactionList *tl, 54 struct TALER_EXCHANGEDB_TransactionList *
55 tl,
54 const struct TALER_Amount *requested, 56 const struct TALER_Amount *requested,
55 const struct TALER_Amount *residual) 57 const struct TALER_Amount *residual)
56{ 58{
@@ -59,14 +61,15 @@ reply_refresh_melt_insufficient_funds (struct MHD_Connection *connection,
59 history = TEH_RESPONSE_compile_transaction_history (tl); 61 history = TEH_RESPONSE_compile_transaction_history (tl);
60 if (NULL == history) 62 if (NULL == history)
61 return TEH_RESPONSE_reply_internal_db_error (connection, 63 return TEH_RESPONSE_reply_internal_db_error (connection,
62 TALER_EC_REFRESH_MELT_HISTORY_DB_ERROR_INSUFFICIENT_FUNDS); 64 TALER_EC_REFRESH_MELT_HISTORY_DB_ERROR_INSUFFICIENT_FUNDS);
63 return TEH_RESPONSE_reply_json_pack (connection, 65 return TEH_RESPONSE_reply_json_pack (connection,
64 MHD_HTTP_FORBIDDEN, 66 MHD_HTTP_FORBIDDEN,
65 "{s:s, s:I, s:o, s:o, s:o, s:o, s:o}", 67 "{s:s, s:I, s:o, s:o, s:o, s:o, s:o}",
66 "error", 68 "error",
67 "insufficient funds", 69 "insufficient funds",
68 "code", 70 "code",
69 (json_int_t) TALER_EC_REFRESH_MELT_INSUFFICIENT_FUNDS, 71 (json_int_t)
72 TALER_EC_REFRESH_MELT_INSUFFICIENT_FUNDS,
70 "coin_pub", 73 "coin_pub",
71 GNUNET_JSON_from_data_auto (coin_pub), 74 GNUNET_JSON_from_data_auto (coin_pub),
72 "original_value", 75 "original_value",
@@ -104,8 +107,8 @@ reply_refresh_melt_success (struct MHD_Connection *connection,
104 body.noreveal_index = htonl (noreveal_index); 107 body.noreveal_index = htonl (noreveal_index);
105 if (GNUNET_OK != 108 if (GNUNET_OK !=
106 TEH_KS_sign (&body.purpose, 109 TEH_KS_sign (&body.purpose,
107 &pub, 110 &pub,
108 &sig)) 111 &sig))
109 { 112 {
110 return TEH_RESPONSE_reply_internal_error (connection, 113 return TEH_RESPONSE_reply_internal_error (connection,
111 TALER_EC_EXCHANGE_BAD_CONFIGURATION, 114 TALER_EC_EXCHANGE_BAD_CONFIGURATION,
@@ -118,7 +121,8 @@ reply_refresh_melt_success (struct MHD_Connection *connection,
118 "{s:i, s:o, s:o}", 121 "{s:i, s:o, s:o}",
119 "noreveal_index", (int) noreveal_index, 122 "noreveal_index", (int) noreveal_index,
120 "exchange_sig", sig_json, 123 "exchange_sig", sig_json,
121 "exchange_pub", GNUNET_JSON_from_data_auto (&pub)); 124 "exchange_pub",
125 GNUNET_JSON_from_data_auto (&pub));
122} 126}
123 127
124 128
@@ -238,10 +242,12 @@ refresh_check_melt (struct MHD_Connection *connection,
238 &spent, 242 &spent,
239 &rmc->refresh_session.amount_with_fee)); 243 &rmc->refresh_session.amount_with_fee));
240 *mhd_ret = reply_refresh_melt_insufficient_funds (connection, 244 *mhd_ret = reply_refresh_melt_insufficient_funds (connection,
241 &rmc->refresh_session.coin.coin_pub, 245 &rmc->refresh_session.coin
246 .coin_pub,
242 coin_value, 247 coin_value,
243 tl, 248 tl,
244 &rmc->refresh_session.amount_with_fee, 249 &rmc->refresh_session.
250 amount_with_fee,
245 &coin_residual); 251 &coin_residual);
246 TEH_plugin->free_coin_transaction_list (TEH_plugin->cls, 252 TEH_plugin->free_coin_transaction_list (TEH_plugin->cls,
247 tl); 253 tl);
@@ -365,8 +371,8 @@ handle_refresh_melt (struct MHD_Connection *connection,
365 { 371 {
366 GNUNET_break_op (0); 372 GNUNET_break_op (0);
367 return TEH_RESPONSE_reply_external_error (connection, 373 return TEH_RESPONSE_reply_external_error (connection,
368 TALER_EC_REFRESH_MELT_FEES_EXCEED_CONTRIBUTION, 374 TALER_EC_REFRESH_MELT_FEES_EXCEED_CONTRIBUTION,
369 "melt amount smaller than melting fee"); 375 "melt amount smaller than melting fee");
370 } 376 }
371 } 377 }
372 378
@@ -374,19 +380,22 @@ handle_refresh_melt (struct MHD_Connection *connection,
374 { 380 {
375 struct TALER_RefreshMeltCoinAffirmationPS body; 381 struct TALER_RefreshMeltCoinAffirmationPS body;
376 382
377 body.purpose.size = htonl (sizeof (struct TALER_RefreshMeltCoinAffirmationPS)); 383 body.purpose.size = htonl (sizeof (struct
384 TALER_RefreshMeltCoinAffirmationPS));
378 body.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_MELT); 385 body.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_MELT);
379 body.rc = rmc->refresh_session.rc; 386 body.rc = rmc->refresh_session.rc;
380 TALER_amount_hton (&body.amount_with_fee, 387 TALER_amount_hton (&body.amount_with_fee,
381 &rmc->refresh_session.amount_with_fee); 388 &rmc->refresh_session.amount_with_fee);
382 body.melt_fee = rmc->dki->issue.properties.fee_refresh; 389 body.melt_fee = rmc->dki->issue.properties.fee_refresh;
383 body.coin_pub = rmc->refresh_session.coin.coin_pub; 390 body.coin_pub = rmc->refresh_session.coin.coin_pub;
384 391
385 if (GNUNET_OK != 392 if (GNUNET_OK !=
386 GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_MELT, 393 GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_MELT,
387 &body.purpose, 394 &body.purpose,
388 &rmc->refresh_session.coin_sig.eddsa_signature, 395 &rmc->refresh_session.coin_sig.
389 &rmc->refresh_session.coin.coin_pub.eddsa_pub)) 396 eddsa_signature,
397 &rmc->refresh_session.coin.coin_pub.
398 eddsa_pub))
390 { 399 {
391 GNUNET_break_op (0); 400 GNUNET_break_op (0);
392 return TEH_RESPONSE_reply_signature_invalid (connection, 401 return TEH_RESPONSE_reply_signature_invalid (connection,
@@ -489,7 +498,8 @@ TEH_REFRESH_handler_refresh_melt (struct TEH_RequestHandler *rh,
489 /* Baseline: check if deposits/refreshs are generally 498 /* Baseline: check if deposits/refreshs are generally
490 simply still allowed for this denomination */ 499 simply still allowed for this denomination */
491 rmc.dki = TEH_KS_denomination_key_lookup_by_hash (key_state, 500 rmc.dki = TEH_KS_denomination_key_lookup_by_hash (key_state,
492 &rmc.refresh_session.coin.denom_pub_hash, 501 &rmc.refresh_session.coin.
502 denom_pub_hash,
493 TEH_KS_DKU_DEPOSIT); 503 TEH_KS_DKU_DEPOSIT);
494 /* Consider case that denomination was revoked but 504 /* Consider case that denomination was revoked but
495 this coin was already seen and thus refresh is OK. */ 505 this coin was already seen and thus refresh is OK. */
@@ -498,7 +508,8 @@ TEH_REFRESH_handler_refresh_melt (struct TEH_RequestHandler *rh,
498 struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki; 508 struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki;
499 509
500 dki = TEH_KS_denomination_key_lookup_by_hash (key_state, 510 dki = TEH_KS_denomination_key_lookup_by_hash (key_state,
501 &rmc.refresh_session.coin.denom_pub_hash, 511 &rmc.refresh_session.coin.
512 denom_pub_hash,
502 TEH_KS_DKU_PAYBACK); 513 TEH_KS_DKU_PAYBACK);
503 if (NULL != dki) 514 if (NULL != dki)
504 { 515 {
@@ -533,7 +544,8 @@ TEH_REFRESH_handler_refresh_melt (struct TEH_RequestHandler *rh,
533 struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki; 544 struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki;
534 545
535 dki = TEH_KS_denomination_key_lookup_by_hash (key_state, 546 dki = TEH_KS_denomination_key_lookup_by_hash (key_state,
536 &rmc.refresh_session.coin.denom_pub_hash, 547 &rmc.refresh_session.coin.
548 denom_pub_hash,
537 TEH_KS_DKU_ZOMBIE); 549 TEH_KS_DKU_ZOMBIE);
538 if (NULL != dki) 550 if (NULL != dki)
539 { 551 {
@@ -585,7 +597,7 @@ TEH_REFRESH_handler_refresh_melt (struct TEH_RequestHandler *rh,
585 &rmc); 597 &rmc);
586 598
587 599
588 cleanup: 600 cleanup:
589 if (NULL != key_state) 601 if (NULL != key_state)
590 { 602 {
591 TEH_KS_release (key_state); 603 TEH_KS_release (key_state);
@@ -593,7 +605,8 @@ TEH_REFRESH_handler_refresh_melt (struct TEH_RequestHandler *rh,
593 } 605 }
594 if (NULL != rmc.refresh_session.coin.denom_sig.rsa_signature) 606 if (NULL != rmc.refresh_session.coin.denom_sig.rsa_signature)
595 { 607 {
596 GNUNET_CRYPTO_rsa_signature_free (rmc.refresh_session.coin.denom_sig.rsa_signature); 608 GNUNET_CRYPTO_rsa_signature_free (
609 rmc.refresh_session.coin.denom_sig.rsa_signature);
597 rmc.refresh_session.coin.denom_sig.rsa_signature = NULL; 610 rmc.refresh_session.coin.denom_sig.rsa_signature = NULL;
598 } 611 }
599 GNUNET_JSON_parse_free (spec); 612 GNUNET_JSON_parse_free (spec);