donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit 1bcb159fc7671acfb1862b8b7d52a021c2e3d54d
parent 6d720683ec55a5e4c9373996493dc290689db1b3
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Mon, 29 Apr 2024 00:07:49 +0200

[testing] send blinded receipts back to caller

Diffstat:
Msrc/donau/donau-httpd_batch-issue.c | 6+++---
Msrc/include/donau_service.h | 4++--
Msrc/lib/donau_api_batch_issue_receipts.c | 126+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
Msrc/testing/testing_api_cmd_issue_receipts.c | 3+++
4 files changed, 80 insertions(+), 59 deletions(-)

diff --git a/src/donau/donau-httpd_batch-issue.c b/src/donau/donau-httpd_batch-issue.c @@ -376,11 +376,11 @@ start: signatures_to_JSON (num_bkps, du_sigs, blind_signatures); return TALER_MHD_REPLY_JSON_PACK ( rc->connection, - MHD_HTTP_CREATED, + MHD_HTTP_CREATED, GNUNET_JSON_pack_array_steal ("blind_signatures", blind_signatures), - TALER_JSON_pack_amount("issued_amount", - &receipts_sum)); + TALER_JSON_pack_amount ("issued_amount", + &receipts_sum)); } diff --git a/src/include/donau_service.h b/src/include/donau_service.h @@ -469,11 +469,11 @@ struct DONAU_BatchIssueResponse */ struct { - + /** * Blind signature provided by the donau */ - struct DONAU_BlindedDonationUnitSignature *donau_sigs; + struct DONAU_BlindedDonationUnitSignature *blinded_sigs; /** * total issued amount over all donation receipts of a donation specified diff --git a/src/lib/donau_api_batch_issue_receipts.c b/src/lib/donau_api_batch_issue_receipts.c @@ -62,6 +62,10 @@ struct DONAU_BatchIssueReceiptHandle struct DONAU_CharitySignatureP charity_sig; /** + * number of requested signatures. + */ + size_t num_blinded_sigs; + /** * Closure to pass to @e cb. */ void *cb_cls; @@ -87,63 +91,76 @@ struct DONAU_BatchIssueReceiptHandle static enum GNUNET_GenericReturnValue handle_batch_issue_ok (const json_t *resp_obj, struct DONAU_BatchIssueReceiptHandle *birh, - struct DONAU_BatchIssueResponse *biresp) + struct DONAU_BatchIssueResponse *biresp) { struct TALER_Amount issued_amount = biresp->details.ok.issued_amount; - if (!json_is_object(resp_obj)) + if (JSON_OBJECT != json_typeof (resp_obj)) { GNUNET_break_op (0); return GNUNET_SYSERR; } - const json_t *j_blind_signatures = NULL; + const json_t *j_blind_signatures; struct GNUNET_JSON_Specification spec[] = { - TALER_JSON_spec_amount_any ("issued_amount", - &issued_amount), - GNUNET_JSON_spec_array_const ("blind_signatures", - &j_blind_signatures), - GNUNET_JSON_spec_end () + TALER_JSON_spec_amount_any ("issued_amount", + &issued_amount), + GNUNET_JSON_spec_array_const ("blind_signatures", + &j_blind_signatures), + GNUNET_JSON_spec_end () }; if (GNUNET_OK != - GNUNET_JSON_parse (resp_obj, - spec, - NULL, - NULL)) + GNUNET_JSON_parse (resp_obj, + spec, + NULL, + NULL)) { - GNUNET_break_op (0); - return GNUNET_SYSERR; + GNUNET_break_op (0); + return GNUNET_SYSERR; } - const unsigned long long num_du_sigs - = json_array_size (j_blind_signatures); - if (0 != num_du_sigs) +// const unsigned long long num_du_sigs +// = json_array_size (j_blind_signatures); + if ( (NULL == j_blind_signatures) || + (! json_is_array (j_blind_signatures)) || + (birh->num_blinded_sigs != json_array_size (j_blind_signatures)) ) { - struct DONAU_BlindedDonationUnitSignature du_sigs[num_du_sigs]; - unsigned int index; - json_t *du_sig_obj; - json_array_foreach (j_blind_signatures, - index, - du_sig_obj) - { - struct GNUNET_JSON_Specification spec[] = { - DONAU_JSON_spec_blinded_donation_unit_sig ("blinded_signature", - &du_sigs[index]), - GNUNET_JSON_spec_end () - }; - if (GNUNET_OK != - GNUNET_JSON_parse (du_sig_obj, - spec, - NULL, - NULL)) - { - GNUNET_break_op (0); - for (size_t i = 0; i<index; i++) - DONAU_blinded_donation_unit_sig_free (&du_sigs[i]); - return GNUNET_SYSERR; - } - } + GNUNET_break (0); + return GNUNET_SYSERR; } +// if (0 != num_du_sigs) +// { + biresp->details.ok.blinded_sigs = + GNUNET_malloc(sizeof(struct DONAU_BlindedDonationUnitSignature) + * birh->num_blinded_sigs); + struct DONAU_BlindedDonationUnitSignature du_sigs[birh->num_blinded_sigs]; + size_t index; + json_t *du_sig_obj; + json_array_foreach (j_blind_signatures, + index, + du_sig_obj) + { + struct GNUNET_JSON_Specification spec[] = { + DONAU_JSON_spec_blinded_donation_unit_sig ("blinded_signature", + &biresp->details.ok.blinded_sigs[index]), + GNUNET_JSON_spec_end () + }; + if (GNUNET_OK != + GNUNET_JSON_parse (du_sig_obj, + spec, + NULL, + NULL)) + { + GNUNET_break_op (0); + for (size_t i = 0; i<index; i++) + DONAU_blinded_donation_unit_sig_free (&du_sigs[i]); + return GNUNET_SYSERR; + } +// GNUNET_memcpy(&biresp->details.ok.blinded_sigs[index], &du_sigs[index], +// sizeof(struct DONAU_BlindedDonationUnitSignature)); + } + + //} birh->cb (birh->cb_cls, - biresp); + biresp); birh->cb = NULL; return GNUNET_OK; } @@ -213,25 +230,25 @@ handle_batch_issue_finished (void *cls, switch (response_code) { case MHD_HTTP_CREATED: - if (GNUNET_OK != - handle_batch_issue_ok (j, - birh, - &biresp)) - { - biresp.hr.http_status = 0; - biresp.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; - } + if (GNUNET_OK != + handle_batch_issue_ok (j, + birh, + &biresp)) + { + biresp.hr.http_status = 0; + biresp.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + } break; case MHD_HTTP_NO_CONTENT: biresp.hr.ec = TALER_JSON_get_error_code (j); biresp.hr.hint = TALER_JSON_get_error_hint (j); break; - //invalid charity signature + // invalid charity signature case MHD_HTTP_FORBIDDEN: biresp.hr.ec = TALER_JSON_get_error_code (j); biresp.hr.hint = TALER_JSON_get_error_hint (j); break; - //one or more donation units are not known to the Donau + // one or more donation units are not known to the Donau case MHD_HTTP_NOT_FOUND: biresp.hr.ec = TALER_JSON_get_error_code (j); biresp.hr.hint = TALER_JSON_get_error_hint (j); @@ -240,12 +257,12 @@ handle_batch_issue_finished (void *cls, biresp.hr.ec = TALER_JSON_get_error_code (j); biresp.hr.hint = TALER_JSON_get_error_hint (j); break; - //Donation limit is not sufficent + // Donation limit is not sufficent case MHD_HTTP_CONFLICT: biresp.hr.ec = TALER_JSON_get_error_code (j); biresp.hr.hint = TALER_JSON_get_error_hint (j); break; - // donation unit key is no longer valid + // donation unit key is no longer valid case MHD_HTTP_GONE: biresp.hr.ec = TALER_JSON_get_error_code (j); biresp.hr.hint = TALER_JSON_get_error_hint (j); @@ -286,6 +303,7 @@ DONAU_charity_issue_receipt ( { struct DONAU_BatchIssueReceiptHandle *birh; birh = GNUNET_new (struct DONAU_BatchIssueReceiptHandle); + birh->num_blinded_sigs = num_bkp; CURL *eh; json_t *body; diff --git a/src/testing/testing_api_cmd_issue_receipts.c b/src/testing/testing_api_cmd_issue_receipts.c @@ -115,7 +115,9 @@ issue_receipts_status_cb (void *cls, TALER_TESTING_interpreter_fail (ss->is); return; } + //struct DONAU_BlindedDonationUnitSignature *blinded_sigs = biresp->details.ok.blinded_sigs; + //GNUNET_free (blinded_sigs); TALER_TESTING_interpreter_next (ss->is); } @@ -236,6 +238,7 @@ cleanup (void *cls, DONAU_charity_issue_receipt_cancel (ss->birh); ss->birh = NULL; } + // if (NULL != revealed_coins) // { // for (unsigned int cnt = 0; cnt < MELT_NEW_COINS; cnt++)