donau

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

commit 71f81b737c12268d3b58a281182678b86bc7e90c
parent c02a91ecf5098342af10869465cb3e09b20d81d2
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Wed, 20 Mar 2024 10:29:32 +0100

[donau] work on issue receitps blind signatures

Diffstat:
Msrc/donau/donau-httpd_post-batch-issue.c | 137++++++++++++++++++++++++++++---------------------------------------------------
1 file changed, 48 insertions(+), 89 deletions(-)

diff --git a/src/donau/donau-httpd_post-batch-issue.c b/src/donau/donau-httpd_post-batch-issue.c @@ -15,7 +15,7 @@ */ /** * @file donau-httpd_post-batch-issue.c - * @brief Handle request to insert a charity. + * @brief Handle request to issue receipts. * @author Lukas Matyja */ #include <taler/platform.h> @@ -34,7 +34,7 @@ /** - * Closure for #insert_charity() + * Closure for #issue_receipts() */ struct IssueReceiptsContext { @@ -75,53 +75,6 @@ parse_json_bkp (struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkp, return GNUNET_OK; } -/** - * Function implementing insert charity transaction. - * - * Runs the transaction logic; IF it returns a non-error code, the - * transaction logic MUST NOT queue a MHD response. IF it returns an hard - * error, the transaction logic MUST queue a MHD response and set @a mhd_ret. - * IF it returns the soft error code, the function MAY be called again to - * retry and MUST not queue a MHD response. - * - * @param cls closure with a `struct InsertCharityContext` - * @param connection MHD request which triggered the transaction - * @param[out] mhd_ret set to MHD response status for @a connection, - * if transaction failed (!) - * @return transaction status - */ -//static enum GNUNET_DB_QueryStatus -//issue_receipts (void *cls, -// struct MHD_Connection *connection, -// MHD_RESULT *mhd_ret) -//{ -// struct InsertCharityContext *icc = cls; -// enum GNUNET_DB_QueryStatus qs; -// -// qs = DH_plugin->insert_charity (DH_plugin->cls, -// &icc->charity_pub, -// icc->charity_name, -// icc->charity_url, -// &icc->max_per_year, -// &icc->receipts_to_date, -// &icc->current_year, -// &icc->charity_id); -// if (qs <= 0) -// { -// if (GNUNET_DB_STATUS_SOFT_ERROR != qs) -// { -// GNUNET_break (0); -// *mhd_ret = TALER_MHD_reply_with_error (connection, -// MHD_HTTP_INTERNAL_SERVER_ERROR, -// TALER_EC_GENERIC_DB_STORE_FAILED, -// "insert_charity"); -// return GNUNET_DB_STATUS_HARD_ERROR; -// } -// return qs; -// } -// -// return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; -//} MHD_RESULT @@ -129,6 +82,9 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, const json_t *root, const char *const args[1]) { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "issue receipts request! \n"); + unsigned long long charity_id; char dummy; @@ -176,6 +132,8 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, } } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "parse some values!"); /* parse the budikeypairs array */ const uint64_t num_bkp = json_array_size (budikeypairs); @@ -197,12 +155,16 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, } irc.bkp = bkp; } else { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "empty array of budi key pairs!"); return TALER_MHD_reply_with_error (rc->connection, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MALFORMED, "budikeypairs"); } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "budi key pairs array is parsed!"); // Get charity pub struct DONAUDB_CharityMetaData charity_meta; enum GNUNET_DB_QueryStatus qs_charity; @@ -230,6 +192,8 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, break; } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "got charity from db!"); /* verify charity signature */ if (GNUNET_OK != DONAU_charity_budi_key_pair_verify(num_bkp, &irc.bkp, @@ -244,6 +208,8 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, NULL); } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "charity signature valid!"); /* request already made? -> idempotent */ enum GNUNET_DB_QueryStatus qs_check_receipts; struct DONAUDB_IssuedReceiptsMetaData check_receipts_meta; @@ -265,55 +231,48 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, TALER_EC_GENERIC_DB_FETCH_FAILED, NULL); case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "request have not been made yet (first time)!"); break; // it's the first request from the charity, we can proceed case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "request have been made already!"); // A request was already made. We do not change the annual limit break; } /* check annual limit and change it -> Rollback if we could not save the request*/ /* save Request (charity signature, charity id, amount, hash over bkps) and make it idempotent*/ /* sign budis and send the signatures back */ + int i = 0; + json_t *blind_signatures; + blind_signatures = json_array (); + while (i < num_bkp) { + struct DONAU_BlindedDonationUnitSignature du_sig; + // TODO: get donation unit private key + const struct DONAU_DonationUnitPrivateKey du_priv; + const struct DONAU_BlindedUniqueDonationIdentifier budi = irc.bkp[i].blinded_udi; + if (GNUNET_SYSERR == TALER_donation_unit_sign_blinded(&du_sig, &du_priv, &budi)) { + GNUNET_break (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + NULL); + } + GNUNET_assert ( + 0 == json_array_append ( + blind_signatures, + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_data_auto ("du_sig", + &du_sig)))); + } -// { -// MHD_RESULT mhd_ret; -// -// if (GNUNET_OK != -// DH_DB_run_transaction (rc->connection, -// "issue_receipts", -// DH_MT_REQUEST_OTHER, -// &mhd_ret, -// &issue_receipts, -// &irc)) -// { -// return mhd_ret; -// } -// } -// -// GNUNET_log (GNUNET_ERROR_TYPE_INFO, -// "receipts were successfully issued\n"); -// -// result = TALER_MHD_REPLY_JSON_PACK ( -// rc->connection, -// MHD_HTTP_OK, -// GNUNET_JSON_pack_data_auto ("charity_pub", -// &meta.charity_pub), -// GNUNET_JSON_pack_string ("url", -// meta.charity_url), -// GNUNET_JSON_pack_string ("name", -// meta.charity_name), -// TALER_JSON_pack_amount ("max_per_year", -// &meta.max_per_year), -// TALER_JSON_pack_amount ("receipts_to_date", -// &meta.receipts_to_date), -// GNUNET_JSON_pack_uint64 ("current_year", -// meta.current_year)); - - - return TALER_MHD_reply_with_error ( - rc->connection, - MHD_HTTP_NOT_FOUND, - TALER_EC_DONAU_CHARITY_NOT_FOUND, - NULL); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "made blind signatures!"); + return TALER_MHD_REPLY_JSON_PACK ( + rc->connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ("blind_signatures", + blind_signatures)); }