donau

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

commit 0ea9c8eb941066f3b07bc86e640205bf3a766ea5
parent 20986aeb20cdf35daee4dc7d34fd7afd45531d75
Author: Christian Grothoff <grothoff@gnunet.org>
Date:   Sun, 18 Aug 2024 23:22:57 +0200

misc. small bugfixes

Diffstat:
Msrc/donau/donau-httpd_batch-issue.c | 115+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/include/donau_service.h | 13+++++++------
Msrc/lib/donau_api_batch_issue_receipts.c | 47+++++++++++++++++++++++------------------------
Msrc/lib/donau_api_csr_post.c | 1+
Msrc/lib/donau_api_donation_statement_get.c | 1+
5 files changed, 91 insertions(+), 86 deletions(-)

diff --git a/src/donau/donau-httpd_batch-issue.c b/src/donau/donau-httpd_batch-issue.c @@ -104,6 +104,10 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, bool second_time = false; unsigned long long charity_id; char dummy; + const json_t *budikeypairs; + size_t num_bkps; + struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkps; + struct DONAUDB_CharityMetaData charity_meta; if ( (NULL == args[0]) || (1 != sscanf (args[0], @@ -121,18 +125,17 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, "issue receipts for charity id: %llu\n", charity_id); - const json_t *budikeypairs; - struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_array_const ("budikeypairs", - &budikeypairs), - GNUNET_JSON_spec_fixed_auto ("charity_sig", - &charity_sig), - GNUNET_JSON_spec_uint64 ("year", - &year), - GNUNET_JSON_spec_end () - }; { + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_array_const ("budikeypairs", + &budikeypairs), + GNUNET_JSON_spec_fixed_auto ("charity_sig", + &charity_sig), + GNUNET_JSON_spec_uint64 ("year", + &year), + GNUNET_JSON_spec_end () + }; enum GNUNET_GenericReturnValue res; res = TALER_MHD_parse_json_data (rc->connection, @@ -148,21 +151,28 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, } /* parse the budikeypairs array */ - const size_t num_bkps - = json_array_size (budikeypairs); - struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkps; - if (0 != num_bkps) + num_bkps = json_array_size (budikeypairs); + if (0 == num_bkps) + { + GNUNET_break_op (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "budikeypairs"); + + } + + bkps = GNUNET_new_array + (num_bkps, + struct DONAU_BlindedUniqueDonorIdentifierKeyPair); { json_t *bkp_obj; size_t index; - - bkps = GNUNET_new_array - (num_bkps, - struct DONAU_BlindedUniqueDonorIdentifierKeyPair); json_array_foreach (budikeypairs, index, bkp_obj) { if (GNUNET_SYSERR == - parse_json_bkp (&bkps[index], bkp_obj)) + parse_json_bkp (&bkps[index], + bkp_obj)) { GNUNET_break_op (0); return TALER_MHD_reply_with_error (rc->connection, @@ -172,42 +182,33 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, } } } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Empty array of budi key pairs!\n"); - return TALER_MHD_reply_with_error (rc->connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "budikeypairs"); - } - // Get charity pub - struct DONAUDB_CharityMetaData charity_meta; - enum GNUNET_DB_QueryStatus qs_charity; - - qs_charity = DH_plugin->lookup_charity (DH_plugin->cls, - (uint64_t) charity_id, - &charity_meta); - switch (qs_charity) { - case GNUNET_DB_STATUS_HARD_ERROR: - case GNUNET_DB_STATUS_SOFT_ERROR: - GNUNET_break_op (0); - return TALER_MHD_reply_with_error (rc->connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_FETCH_FAILED, - NULL); - case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: - GNUNET_break_op (0); - return TALER_MHD_reply_with_error ( - rc->connection, - MHD_HTTP_NOT_FOUND, - TALER_EC_DONAU_CHARITY_NOT_FOUND, - NULL); - break; - case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: - break; + enum GNUNET_DB_QueryStatus qs_charity; + + qs_charity = DH_plugin->lookup_charity (DH_plugin->cls, + charity_id, + &charity_meta); + switch (qs_charity) + { + case GNUNET_DB_STATUS_HARD_ERROR: + case GNUNET_DB_STATUS_SOFT_ERROR: + GNUNET_break_op (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + NULL); + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + GNUNET_break_op (0); + return TALER_MHD_reply_with_error ( + rc->connection, + MHD_HTTP_NOT_FOUND, + TALER_EC_DONAU_CHARITY_NOT_FOUND, + NULL); + break; + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + break; + } } /* verify charity signature */ @@ -234,7 +235,7 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, struct GNUNET_HashContext *hc; hc = GNUNET_CRYPTO_hash_context_start (); - for (unsigned int i = 0; i < num_bkps; i++) + for (size_t i = 0; i < num_bkps; i++) { GNUNET_CRYPTO_hash_context_read (hc, &bkps[i].h_donation_unit_pub, @@ -312,7 +313,7 @@ start: struct DONAU_BlindedDonationUnitSignature du_sigs[num_bkps]; struct DONAU_BkpSignData bkps_sign_data[num_bkps]; - for (int i = 0; i < num_bkps; i++) + for (size_t i = 0; i < num_bkps; i++) { bkps_sign_data[i].h_donation_unit_pub = &bkps[i].h_donation_unit_pub; bkps_sign_data[i].budi = &bkps[i].blinded_udi; @@ -371,7 +372,9 @@ start: GNUNET_log (GNUNET_ERROR_TYPE_INFO, "issue receipts request is saved! (idempotent)\n"); - signatures_to_JSON (num_bkps, du_sigs, blind_signatures); + signatures_to_JSON (num_bkps, + du_sigs, + blind_signatures); return TALER_MHD_REPLY_JSON_PACK ( rc->connection, MHD_HTTP_CREATED, diff --git a/src/include/donau_service.h b/src/include/donau_service.h @@ -518,7 +518,8 @@ typedef void * * @param ctx curl context * @param url donau base URL - * @param charity_priv details about the contract the is for + * @param charity_priv private key of the charity + * @param charity_id unique (row ID) of the charity at the DONAU * @param num_bkp length of the @a bkp array * @param bkp array with details about the blinded donation envelopes * @param cb the callback to call when a reply for this request is available @@ -532,9 +533,9 @@ DONAU_charity_issue_receipt ( struct GNUNET_CURL_Context *ctx, const char *url, const struct DONAU_CharityPrivateKeyP *charity_priv, - const uint64_t charity_id, - const uint64_t year, - const size_t num_bkp, + uint64_t charity_id, + uint64_t year, + size_t num_bkp, const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp, DONAU_BatchIssueReceiptsCallback cb, void *cb_cls); @@ -543,11 +544,11 @@ DONAU_charity_issue_receipt ( * Cancel a batch issue receipt request. This function cannot be used * on a request handle if a response is already served for it. * - * @param[in] the issue receipt request handle + * @param[in] birh the issue receipt request handle */ void DONAU_charity_issue_receipt_cancel ( - struct DONAU_BatchIssueReceiptHandle *); + struct DONAU_BatchIssueReceiptHandle *birh); /** * unblinded donation unit signature from Donau diff --git a/src/lib/donau_api_batch_issue_receipts.c b/src/lib/donau_api_batch_issue_receipts.c @@ -65,6 +65,7 @@ struct DONAU_BatchIssueReceiptHandle * number of requested signatures. */ size_t num_blinded_sigs; + /** * Closure to pass to @e cb. */ @@ -126,8 +127,8 @@ handle_batch_issue_ok (const json_t *resp_obj, return GNUNET_SYSERR; } biresp->details.ok.blinded_sigs = - GNUNET_malloc (sizeof(struct DONAU_BlindedDonationUnitSignature) - * birh->num_blinded_sigs); + GNUNET_new_array (birh->num_blinded_sigs, + struct DONAU_BlindedDonationUnitSignature); size_t index; json_t *du_sig_obj; json_array_foreach (j_blind_signatures, @@ -135,9 +136,9 @@ handle_batch_issue_ok (const json_t *resp_obj, du_sig_obj) { struct GNUNET_JSON_Specification spec[] = { - DONAU_JSON_spec_blinded_donation_unit_sig ("blinded_signature", - &biresp->details.ok. - blinded_sigs[index]), + DONAU_JSON_spec_blinded_donation_unit_sig ( + "blinded_signature", + &biresp->details.ok.blinded_sigs[index]), GNUNET_JSON_spec_end () }; if (GNUNET_OK != @@ -166,12 +167,12 @@ handle_batch_issue_ok (const json_t *resp_obj, * @param year corresponding year * @param charity_sig signature from charity over @bkp */ -json_t * -issue_receipt_body_to_json (const unsigned int num_bkp, - const struct - DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp, - const uint64_t year, - const struct DONAU_CharitySignatureP *charity_sig) +static json_t * +issue_receipt_body_to_json ( + const unsigned int num_bkp, + const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp, + const uint64_t year, + const struct DONAU_CharitySignatureP *charity_sig) { json_t *budikeypairs = json_array (); GNUNET_assert (NULL != budikeypairs); @@ -294,29 +295,24 @@ DONAU_charity_issue_receipt ( DONAU_BatchIssueReceiptsCallback cb, void *cb_cls) { - struct DONAU_BatchIssueReceiptHandle *birh; - birh = GNUNET_new (struct DONAU_BatchIssueReceiptHandle); - birh->num_blinded_sigs = num_bkp; CURL *eh; json_t *body; + char arg_str[sizeof (charity_id) * 2 + 32]; + struct DONAU_BatchIssueReceiptHandle *birh; - // make signature over budi-key-pair - DONAU_charity_bkp_sign (num_bkp, bkp, charity_priv, + birh = GNUNET_new (struct DONAU_BatchIssueReceiptHandle); + birh->num_blinded_sigs = num_bkp; + DONAU_charity_bkp_sign (num_bkp, bkp, + charity_priv, &birh->charity_sig); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Made charity signature\n"); - TALER_LOG_DEBUG ("Connecting to the donau (%s)\n", - url); birh->url = GNUNET_strdup (url); birh->cb = cb; birh->cb_cls = cb_cls; birh->ctx = ctx; - char arg_str[sizeof (charity_id) * 2 + 32]; GNUNET_snprintf (arg_str, sizeof (arg_str), "batch-issue/%llu", - (unsigned long long) - charity_id); + (unsigned long long) charity_id); birh->url = TALER_url_join (url, arg_str, NULL); @@ -330,7 +326,10 @@ DONAU_charity_issue_receipt ( GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "issue_receipts_with_URL `%s'.\n", birh->url); - body = issue_receipt_body_to_json (num_bkp, bkp, year, &birh->charity_sig); + body = issue_receipt_body_to_json (num_bkp, + bkp, + year, + &birh->charity_sig); eh = DONAU_curl_easy_get_ (birh->url); if ( (NULL == eh) || (GNUNET_OK != diff --git a/src/lib/donau_api_csr_post.c b/src/lib/donau_api_csr_post.c @@ -111,6 +111,7 @@ handle_csr_issue_post_finished (void *cls, csrh->cb (csrh->cb_cls, &csrresp); csrh->cb = NULL; + break; // Donation unit was revoked. case MHD_HTTP_GONE: csrresp.hr.ec = TALER_JSON_get_error_code (j); diff --git a/src/lib/donau_api_donation_statement_get.c b/src/lib/donau_api_donation_statement_get.c @@ -119,6 +119,7 @@ handle_donation_statement_get_finished (void *cls, dsgh->cb (dsgh->cb_cls, &dsresp); dsgh->cb = NULL; + break; case MHD_HTTP_BAD_REQUEST: /* This should never happen, either us or the donau is buggy (or API version conflict); just pass JSON reply to the application */