donau

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

commit 049cc4e526519c786da362222bc25eb73df591d9
parent ca4ca4622bb6d8293c30a43f2a08013427f344aa
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
Date:   Tue, 16 Apr 2024 23:16:19 +0200

rename, work on submit

Diffstat:
Msrc/donau/donau-httpd.c | 4+---
Msrc/donau/donau-httpd_batch-issue.c | 8++++----
Msrc/donau/donau-httpd_batch-submit.c | 89++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
Msrc/donau/donau-httpd_keys.c | 6+++---
Msrc/donau/donau-httpd_keys.h | 6+++---
Msrc/include/donau_crypto_lib.h | 37++++++++++++++++++++++++++++++-------
Msrc/include/donau_json_lib.h | 10++++------
Msrc/include/donau_service.h | 25+------------------------
Msrc/json/donau_json.c | 6+++---
Msrc/lib/donau_api_batch_issue_receipts.c | 4++--
Msrc/testing/testing_api_cmd_issue_receipts.c | 8++++----
Msrc/util/charity_signatures.c | 4++--
12 files changed, 134 insertions(+), 73 deletions(-)

diff --git a/src/donau/donau-httpd.c b/src/donau/donau-httpd.c @@ -508,9 +508,7 @@ handle_mhd_request (void *cls, { .url = "submit", .method = MHD_HTTP_METHOD_POST, - .handler.post = &DH_handler_submit_receipts_post, - .nargs = 1, - .nargs_is_upper_bound = true + .handler.post = &DH_handler_submit_receipts_post }, /* mark end of list */ { diff --git a/src/donau/donau-httpd_batch-issue.c b/src/donau/donau-httpd_batch-issue.c @@ -44,7 +44,7 @@ * is malformed. */ static enum GNUNET_GenericReturnValue -parse_json_bkp (struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkp, +parse_json_bkp (struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp, const json_t *bkp_key_obj) { struct GNUNET_JSON_Specification spec[] = { @@ -156,7 +156,7 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, /* parse the budikeypairs array */ const size_t num_bkps = json_array_size (budikeypairs); - struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkps; + struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkps; if (0 != num_bkps) { json_t *bkp_obj; @@ -165,7 +165,7 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, bkps = GNUNET_new_array (num_bkps, - struct DONAU_BlindedUniqueDonationIdentifierKeyPair); + struct DONAU_BlindedUniqueDonorIdentifierKeyPair); json_array_foreach (budikeypairs, index, bkp_obj) { if (GNUNET_SYSERR == @@ -338,7 +338,7 @@ start: /* sign budis and send the signatures back */ struct DONAU_BlindedDonationUnitSignature du_sigs[num_bkps]; - struct BUDIKeyPair_sign_data bkps_sign_data[num_bkps]; + struct DONAU_BkpSignData bkps_sign_data[num_bkps]; for (int i = 0; i < num_bkps; i++) { diff --git a/src/donau/donau-httpd_batch-submit.c b/src/donau/donau-httpd_batch-submit.c @@ -39,12 +39,44 @@ struct InsertReceiptContext { struct DONAU_HashDonorTaxId *h_tax_number; - union GNUNET_CRYPTO_BlindSessionNonce *nonce; - struct DONAU_DonationUnitPublicKey *donation_unit_pub; - struct DONAU_DonauSignatureP *donau_sig; + struct DONAU_DonationReceipt *donation_receipt; uint64_t donation_year; }; +/** + * Parse a donation receipt encoded in JSON. + * + * @param[out] dr where to return the result + * @param dr_obj json to parse + * @return #GNUNET_OK if all is fine, #GNUNET_SYSERR if @a dr_obj + * is malformed. + */ +static enum GNUNET_GenericReturnValue +parse_json_dr (struct DONAU_DonationReceipt *dr, + const json_t *dr_obj) +{ + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_fixed_auto ("h_donation_unit_pub", + &dr->h_donation_unit_pub), + GNUNET_JSON_spec_fixed_auto ("nonce", + &dr->nonce), + GNUNET_JSON_spec_fixed_auto ("donau_sig", + &dr->donau_sig), + GNUNET_JSON_spec_end () + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (dr_obj, + spec, + NULL, NULL)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + + return GNUNET_OK; +} + /** * Function implementing insert submit-receipt transaction. @@ -71,9 +103,10 @@ insert_submitted_receipt (void *cls, qs = DH_plugin->insert_submitted_receipt (DH_plugin->cls, irc->h_tax_number, - irc->nonce, - irc->donation_unit_pub, - irc->donau_sig, + irc->donation_receipt->nonce, + &irc->donation_receipt-> + h_donation_unit_pub, // FIXME + &irc->donation_receipt->donau_sig, irc->donation_year); if (qs <= 0) { @@ -99,16 +132,13 @@ DH_handler_submit_receipts_post (struct DH_RequestContext *rc, const char *const args[]) { struct InsertReceiptContext irc; + const json_t *donation_receipts; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_fixed_auto ("h_tax_number", &irc.h_tax_number), - GNUNET_JSON_spec_fixed_auto ("nonce", - &irc.nonce), - GNUNET_JSON_spec_fixed_auto ("donation_unit_pub", - &irc.donation_unit_pub), - GNUNET_JSON_spec_fixed_auto ("donau_sig", - &irc.donau_sig), + GNUNET_JSON_spec_array_const ("donation_receipts", + &donation_receipts), GNUNET_JSON_spec_uint64 ("donation_year", &irc.donation_year), GNUNET_JSON_spec_end () @@ -129,6 +159,41 @@ DH_handler_submit_receipts_post (struct DH_RequestContext *rc, } } + /* parse the donation receipts */ + const size_t num_dr = json_array_size (donation_receipts); + struct DONAU_DonationReceipt *dr; + + if (0 != num_dr) + { + json_t *dr_obj; + size_t index; + + dr = GNUNET_new_array (num_dr, + struct DONAU_DonationReceipt); + + json_array_foreach (donation_receipts, index, dr_obj) + { + if (GNUNET_SYSERR == + parse_json_dr (&dr[index], dr_obj)) + { + GNUNET_break_op (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "donation_receipts"); + } + } + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Empty array of donation receipts!\n"); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "donation_receipts"); + } + { MHD_RESULT mhd_ret; diff --git a/src/donau/donau-httpd_keys.c b/src/donau/donau-httpd_keys.c @@ -1290,7 +1290,7 @@ DH_keys_donau_sign_ ( enum TALER_ErrorCode DH_keys_donation_unit_batch_sign ( unsigned int budis_length, - const struct BUDIKeyPair_sign_data bkps[budis_length], + const struct DONAU_BkpSignData bkps[budis_length], struct DONAU_BlindedDonationUnitSignature du_sigs[budis_length]) { return TALER_EC_NONE; @@ -1311,7 +1311,7 @@ DH_keys_donation_unit_batch_sign ( // for (unsigned int i = 0; i<csds_length; i++) // { // const struct DONAU_DonationUnitHashP *h_du_pub = csds[i].h_du_pub; - // const struct DONAU_BlindedUniqueDonationIdentifier *budi = csds[i].budi; + // const struct DONAU_BlindedUniqueDonorIdentifier *budi = csds[i].budi; // du = GNUNET_CONTAINER_multihashmap_get (du_keys, // &h_du_pub->hash); @@ -1415,7 +1415,7 @@ DH_keys_donation_unit_batch_sign ( // csrs_pos = 0; // for (unsigned int i = 0; i<csds_length; i++) // { - // const struct DONAU_BlindedUniqueDonationIdentifier *budi = csds[i].budi; + // const struct DONAU_BlindedUniqueDonorIdentifier *budi = csds[i].budi; // switch (budi->blinded_message->cipher) // { diff --git a/src/donau/donau-httpd_keys.h b/src/donau/donau-httpd_keys.h @@ -78,7 +78,7 @@ struct DH_BlindSignData /** * Blinded planchet to sign over. */ - const struct DONAU_BlindedUniqueDonationIdentifier *budi; + const struct DONAU_BlindedUniqueDonorIdentifier *budi; }; /** @@ -114,7 +114,7 @@ DH_keys_donau_sign_ ( * @return #TALER_EC_NONE on success */ #define DH_keys_donau_sign(ps,pub,sig) \ - ({ \ + ({ \ /* check size is set correctly */ \ GNUNET_assert (htonl ((ps)->purpose.size) == \ sizeof (*ps)); \ @@ -187,7 +187,7 @@ DH_keys_finished (void); enum TALER_ErrorCode DH_keys_donation_unit_batch_sign ( unsigned int budis_length, - const struct BUDIKeyPair_sign_data bkps[budis_length], + const struct DONAU_BkpSignData bkps[budis_length], struct DONAU_BlindedDonationUnitSignature du_sigs[budis_length]); diff --git a/src/include/donau_crypto_lib.h b/src/include/donau_crypto_lib.h @@ -247,7 +247,7 @@ struct DONAU_BearerToken /* * @brief Wrapper around GNUNET primitive for the blinded unique donation identifier */ -struct DONAU_BlindedUniqueDonationIdentifier +struct DONAU_BlindedUniqueDonorIdentifier { /* * GNUNET primitive type representing a generic blinded message @@ -258,7 +258,7 @@ struct DONAU_BlindedUniqueDonationIdentifier /** * Information needed for a donation receipt to be signed. */ -struct DONAU_BlindedUniqueDonationIdentifierKeyPair +struct DONAU_BlindedUniqueDonorIdentifierKeyPair { /** @@ -270,14 +270,37 @@ struct DONAU_BlindedUniqueDonationIdentifierKeyPair * Donor's blinded donation identifier. It must be blindly signed * to become donation receipt. */ - struct DONAU_BlindedUniqueDonationIdentifier blinded_udi; + struct DONAU_BlindedUniqueDonorIdentifier blinded_udi; + +}; + +/** + * Donation Receipt + */ +struct DONAU_DonationReceipt +{ + + /** + * The hash of the donation unit's public key. + */ + struct DONAU_DonationUnitHashP h_donation_unit_pub; + + /** + * Nonce. + */ + const union GNUNET_CRYPTO_BlindSessionNonce *nonce; + + /** + * Unblinded donation unit signature from the donau. + */ + struct DONAU_DonauSignatureP donau_sig; }; /** * Information needed to create a blind signature. */ -struct BUDIKeyPair_sign_data +struct DONAU_BkpSignData { /** * Hash of key to sign with. @@ -287,7 +310,7 @@ struct BUDIKeyPair_sign_data /** * Blinded planchet to sign over. */ - const struct DONAU_BlindedUniqueDonationIdentifier *budi; + const struct DONAU_BlindedUniqueDonorIdentifier *budi; }; /** * Hash of a budikeypair array @@ -320,7 +343,7 @@ struct DONAU_BudiHashP void DONAU_charity_bkp_sign ( const size_t num_bkp, - const struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkp, + const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp, const struct DONAU_CharityPrivateKeyP *charity_priv, struct DONAU_CharitySignatureP *charity_sig); @@ -337,7 +360,7 @@ DONAU_charity_bkp_sign ( enum GNUNET_GenericReturnValue DONAU_charity_bkp_verify ( const size_t num_bkp, - const struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkp, + const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp, const struct DONAU_CharityPublicKeyP *charity_pub, const struct DONAU_CharitySignatureP *charity_sig); diff --git a/src/include/donau_json_lib.h b/src/include/donau_json_lib.h @@ -66,11 +66,9 @@ DONAU_JSON_spec_donation_unit_group (const char *field, * @return corresponding field spec */ struct GNUNET_JSON_Specification -DONAU_JSON_spec_blinded_donation_identifier (const char *field, - struct - DONAU_BlindedUniqueDonationIdentifier - * - blinded_udi); +DONAU_JSON_spec_blinded_donation_identifier ( + const char *field, + struct DONAU_BlindedUniqueDonorIdentifier *blinded_udi); /** @@ -123,6 +121,6 @@ DONAU_JSON_pack_blinded_donation_unit_sig ( struct GNUNET_JSON_PackSpec DONAU_JSON_pack_blinded_donation_identifier ( const char *name, - const struct DONAU_BlindedUniqueDonationIdentifier *blinded_udi); + const struct DONAU_BlindedUniqueDonorIdentifier *blinded_udi); #endif diff --git a/src/include/donau_service.h b/src/include/donau_service.h @@ -539,7 +539,7 @@ DONAU_charity_issue_receipt ( const uint64_t charity_id, const uint64_t year, const size_t num_bkp, - const struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkp, + const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp, DONAU_BatchIssueReceiptsCallback cb, void *cb_cls); @@ -566,29 +566,6 @@ struct TALER_DonationUnitSignature }; /** - * Donation Receipt - */ -struct DONAU_DonationReceipt -{ - - /** - * The hash of the donation unit's public key. - */ - struct DONAU_DonationUnitHashP h_donation_unit_pub; - - /** - * Donor's hashed and salted unique donation identifier. - */ - struct DONAU_HashDonorTaxId donor_id; - - /** - * Unblinded donation unit signature from the donau. - */ - struct TALER_DonationUnitSignature sig; - -}; - -/** * @brief A Batch Submit receipts Handle */ struct DONAU_DonorReceiptsToStatementHandle; diff --git a/src/json/donau_json.c b/src/json/donau_json.c @@ -245,7 +245,7 @@ parse_blinded_donation_identifier (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) { - struct DONAU_BlindedUniqueDonationIdentifier *blinded_udi = spec->ptr; + struct DONAU_BlindedUniqueDonorIdentifier *blinded_udi = spec->ptr; struct GNUNET_CRYPTO_BlindedMessage *blinded_message; const char *cipher; struct GNUNET_JSON_Specification dspec[] = { @@ -351,7 +351,7 @@ clean_blinded_donation_identifier (void *cls, struct GNUNET_JSON_Specification DONAU_JSON_spec_blinded_donation_identifier (const char *field, struct - DONAU_BlindedUniqueDonationIdentifier + DONAU_BlindedUniqueDonorIdentifier * blinded_udi) { @@ -409,7 +409,7 @@ DONAU_JSON_pack_blinded_donation_unit_sig ( struct GNUNET_JSON_PackSpec DONAU_JSON_pack_blinded_donation_identifier ( const char *name, - const struct DONAU_BlindedUniqueDonationIdentifier *blinded_udi) + const struct DONAU_BlindedUniqueDonorIdentifier *blinded_udi) { const struct GNUNET_CRYPTO_BlindedMessage *bm; struct GNUNET_JSON_PackSpec ps = { diff --git a/src/lib/donau_api_batch_issue_receipts.c b/src/lib/donau_api_batch_issue_receipts.c @@ -84,7 +84,7 @@ struct DONAU_BatchIssueReceiptHandle json_t * issue_receipt_body_to_json (const unsigned int num_bkp, const struct - DONAU_BlindedUniqueDonationIdentifierKeyPair *bkp, + DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp, const uint64_t year, const struct DONAU_CharitySignatureP *charity_sig) { @@ -185,7 +185,7 @@ DONAU_charity_issue_receipt ( const uint64_t charity_id, const uint64_t year, const size_t num_bkp, - const struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkp, + const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp, DONAU_BatchIssueReceiptsCallback cb, void *cb_cls) { diff --git a/src/testing/testing_api_cmd_issue_receipts.c b/src/testing/testing_api_cmd_issue_receipts.c @@ -76,7 +76,7 @@ struct StatusState /** * budi key pair array */ - struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkps; + struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkps; /** * donau keys @@ -182,11 +182,11 @@ status_run (void *cls, ss->bkps = GNUNET_new_array (ss->num_bkp, - struct DONAU_BlindedUniqueDonationIdentifierKeyPair); + struct DONAU_BlindedUniqueDonorIdentifierKeyPair); for (size_t cnt = 0; cnt < ss->num_bkp; cnt++) { struct GNUNET_CRYPTO_RsaBlindedMessage *rp; - struct DONAU_BlindedUniqueDonationIdentifier *bp = {0}; + struct DONAU_BlindedUniqueDonorIdentifier *bp = {0}; DONAU_donation_unit_pub_hash (&ss->keys->donation_unit_keys[0].key, &ss->bkps[cnt].h_donation_unit_pub); bp = &ss->bkps[cnt].blinded_udi; @@ -203,7 +203,7 @@ status_run (void *cls, rp->blinded_msg_size); } - const struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkps = ss->bkps; + const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkps = ss->bkps; ss->birh = DONAU_charity_issue_receipt ( TALER_TESTING_interpreter_get_context (is), TALER_TESTING_get_donau_url (is), diff --git a/src/util/charity_signatures.c b/src/util/charity_signatures.c @@ -59,7 +59,7 @@ GNUNET_NETWORK_STRUCT_END void DONAU_charity_bkp_sign ( const size_t num_bkp, - const struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkp, + const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp, const struct DONAU_CharityPrivateKeyP *charity_priv, struct DONAU_CharitySignatureP *charity_sig) { @@ -93,7 +93,7 @@ DONAU_charity_bkp_sign ( enum GNUNET_GenericReturnValue DONAU_charity_bkp_verify ( const size_t num_bkp, - const struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkp, + const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp, const struct DONAU_CharityPublicKeyP *charity_pub, const struct DONAU_CharitySignatureP *charity_sig) {