diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-09-05 01:25:54 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-09-05 01:25:54 +0200 |
commit | c0f992290a61e67f08e720649673951ef86638b5 (patch) | |
tree | b73593dd384219770c3c2276a4956cb5a39f68d6 | |
parent | 3e6e6feb9e17f8511f3422ce79917bb2f1677d59 (diff) | |
download | merchant-c0f992290a61e67f08e720649673951ef86638b5.tar.gz merchant-c0f992290a61e67f08e720649673951ef86638b5.tar.bz2 merchant-c0f992290a61e67f08e720649673951ef86638b5.zip |
fix #6568
-rw-r--r-- | src/backend/taler-merchant-httpd_post-orders-ID-abort.c | 53 | ||||
-rw-r--r-- | src/lib/merchant_api_post_order_abort.c | 50 |
2 files changed, 68 insertions, 35 deletions
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c index 7ac1665d..1498bcac 100644 --- a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c +++ b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c @@ -57,6 +57,18 @@ struct RefundDetails struct TALER_CoinSpendPublicKeyP coin_pub; /** + * Signature from the exchange confirming the refund. + * Set if we were successful (status 200). + */ + struct TALER_ExchangeSignatureP exchange_sig; + + /** + * Public key used for @e exchange_sig. + * Set if we were successful (status 200). + */ + struct TALER_ExchangePublicKeyP exchange_pub; + + /** * Reference to the main AbortContext */ struct AbortContext *ac; @@ -348,15 +360,31 @@ generate_success_response (struct AbortContext *ac) for (unsigned int i = 0; i<ac->coins_cnt; i++) { struct RefundDetails *rdi = &ac->rd[i]; - - if (0 != - json_array_append_new ( - refunds, - json_pack ("{s:I, s:O}", - "exchange_http_status", - (json_int_t) rdi->http_status, - "exchange_reply", - rdi->exchange_reply))) + json_t *detail; + + detail = (MHD_HTTP_OK != rdi->http_status) + ? json_pack ("{s:s, s:I, s:I, s:O}", + "type", + "failure", + "exchange_status", + (json_int_t) rdi->http_status, + "exchange_code", + (json_int_t) TALER_JSON_get_error_code ( + rdi->exchange_reply), + "exchange_reply", + rdi->exchange_reply) + : json_pack ("{s:s, s:I, s:o, s:o}", + "type", + "success", + "exchange_status", + (json_int_t) rdi->http_status, + "exchange_sig", + GNUNET_JSON_from_data_auto (&rdi->exchange_sig), + "exchange_pub", + GNUNET_JSON_from_data_auto (&rdi->exchange_pub)); + if ( (NULL == detail) || + (0 != json_array_append_new (refunds, + detail)) ) { json_decref (refunds); GNUNET_break (0); @@ -455,6 +483,13 @@ refund_cb (void *cls, rd->rh = NULL; rd->http_status = hr->http_status; rd->exchange_reply = json_incref ((json_t*) hr->reply); + if (MHD_HTTP_OK == hr->http_status) + { + GNUNET_assert (NULL != sign_key); + GNUNET_assert (NULL != signature); + rd->exchange_pub = *sign_key; + rd->exchange_sig = *signature; + } ac->pending_at_ce--; if (0 == ac->pending_at_ce) find_next_exchange (ac); diff --git a/src/lib/merchant_api_post_order_abort.c b/src/lib/merchant_api_post_order_abort.c index 98752af6..05896d47 100644 --- a/src/lib/merchant_api_post_order_abort.c +++ b/src/lib/merchant_api_post_order_abort.c @@ -136,12 +136,9 @@ check_abort_refund (struct TALER_MERCHANT_OrderAbortHandle *oah, { json_t *refund = json_array_get (refunds, i); uint32_t exchange_status; - json_t *exchange_reply; struct GNUNET_JSON_Specification spec_es[] = { - GNUNET_JSON_spec_uint32 ("exchange_http_status", + GNUNET_JSON_spec_uint32 ("exchange_status", &exchange_status), - GNUNET_JSON_spec_json ("exchange_reply", - &exchange_reply), GNUNET_JSON_spec_end () }; @@ -165,7 +162,7 @@ check_abort_refund (struct TALER_MERCHANT_OrderAbortHandle *oah, }; if (GNUNET_OK != - GNUNET_JSON_parse (exchange_reply, + GNUNET_JSON_parse (refund, spec_detail, NULL, NULL)) { @@ -173,29 +170,30 @@ check_abort_refund (struct TALER_MERCHANT_OrderAbortHandle *oah, GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } - } - - { - struct TALER_RefundConfirmationPS rr = { - .purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_REFUND), - .purpose.size = htonl (sizeof (rr)), - .h_contract_terms = oah->h_contract_terms, - .coin_pub = oah->coins[i].coin_pub, - .merchant = oah->merchant_pub, - .rtransaction_id = GNUNET_htonll (0) - }; - TALER_amount_hton (&rr.refund_amount, - &oah->coins[i].amount_with_fee); - if (GNUNET_OK != - GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_EXCHANGE_CONFIRM_REFUND, - &rr, - &res[i].exchange_sig.eddsa_signature, - &res[i].exchange_pub.eddsa_pub)) { - GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); - return GNUNET_SYSERR; + struct TALER_RefundConfirmationPS rr = { + .purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_REFUND), + .purpose.size = htonl (sizeof (rr)), + .h_contract_terms = oah->h_contract_terms, + .coin_pub = oah->coins[i].coin_pub, + .merchant = oah->merchant_pub, + .rtransaction_id = GNUNET_htonll (0) + }; + + TALER_amount_hton (&rr.refund_amount, + &oah->coins[i].amount_with_fee); + if (GNUNET_OK != + GNUNET_CRYPTO_eddsa_verify ( + TALER_SIGNATURE_EXCHANGE_CONFIRM_REFUND, + &rr, + &res[i].exchange_sig.eddsa_signature, + &res[i].exchange_pub.eddsa_pub)) + { + GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); + return GNUNET_SYSERR; + } } } } |