donau

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

commit 678b9b47f3994e4c6af6ae31a115385accc3b892
parent 3bbdce24b02452530b08c02058c411fd4ca4ac2f
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Sun, 28 Apr 2024 17:17:25 +0200

merge

Diffstat:
Msrc/donau/donau-httpd_batch-submit.c | 53++++++++++++++++++++++++++++++++++++++++++-----------
Msrc/donau/donau-httpd_keys.c | 4----
Msrc/donaudb/0002-donau_receipts_submitted.sql | 2+-
Msrc/donaudb/pg_insert_submitted_receipts.c | 11++++++-----
Msrc/donaudb/pg_insert_submitted_receipts.h | 4++--
Msrc/donaudb/test_donaudb.c | 6+++---
Msrc/include/donau_crypto_lib.h | 58+++++++++++++++++++++++++++++++++++++++++++++++-----------
Msrc/include/donau_service.h | 6+++---
Msrc/include/donaudb_plugin.h | 4++--
Msrc/lib/donau_api_batch_submit_receipts.c | 16++++++++--------
Msrc/util/donau_crypto.c | 38+++++++++++++++++++++++++++++++++++++-
11 files changed, 151 insertions(+), 51 deletions(-)

diff --git a/src/donau/donau-httpd_batch-submit.c b/src/donau/donau-httpd_batch-submit.c @@ -29,8 +29,7 @@ #include "taler/taler_signatures.h" #include "donaudb_plugin.h" #include "donau-httpd_batch-submit.h" -#include "donau-httpd_db.h" -#include "donau-httpd_metrics.h" +#include "donau-httpd_keys.h" /** @@ -38,7 +37,7 @@ */ struct InsertReceiptContext { - struct DONAU_HashDonorTaxId *h_tax_number; + struct DONAU_HashDonorTaxId *h_donor_tax_id; struct DONAU_DonationReceipt *donation_receipts; uint64_t donation_year; }; @@ -60,8 +59,8 @@ parse_json_dr (struct DONAU_DonationReceipt *dr, &dr->h_donation_unit_pub), GNUNET_JSON_spec_fixed_auto ("nonce", &dr->nonce), - GNUNET_JSON_spec_fixed_auto ("donau_sig", - &dr->du_sig), + GNUNET_JSON_spec_fixed_auto ("donation_unit_sig", + &dr->donation_unit_sig), GNUNET_JSON_spec_end () }; @@ -87,8 +86,8 @@ DH_handler_submit_receipts_post (struct DH_RequestContext *rc, 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 ("h_donor_tax_id", + &irc.h_donor_tax_id), GNUNET_JSON_spec_array_const ("donation_receipts", &donation_receipts), GNUNET_JSON_spec_uint64 ("donation_year", @@ -146,14 +145,48 @@ DH_handler_submit_receipts_post (struct DH_RequestContext *rc, for (size_t i = 0; i < num_dr; i++) { - // FIXME Check sigs, Donation unit hashes, nonce + // FIXME Check nonce + struct DONAU_UniqueDonorIdentifierHashP udi_hash; + struct DH_DonationUnitKey *dk; + + if (NULL == (dk = DH_keys_donation_unit_by_hash ( + &irc.donation_receipts[i].h_donation_unit_pub))) + { + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_NOT_FOUND, + TALER_EC_DONAU_GENERIC_KEYS_MISSING, + NULL); + } + + DONAU_unique_donor_id_hash ( + irc.h_donor_tax_id, + &irc.donation_receipts[i].nonce, + &udi_hash); + + /* Check signature*/ + if (GNUNET_OK != DONAU_donation_receipt_verify ( + &dk->donation_unit_pub, + &udi_hash, + &irc.donation_receipts[i].donation_unit_sig)) + { + // FIXME change error message + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_NOT_FOUND, + TALER_EC_DONAU_GENERIC_KEYS_MISSING, + NULL); + + } } + // FIXME + // Fetch donation receipts and join with donation units to get amount + // then create donation statement + enum GNUNET_DB_QueryStatus qs; qs = DH_plugin->insert_submitted_receipts ( DH_plugin->cls, - irc.h_tax_number, + irc.h_donor_tax_id, num_dr, irc.donation_receipts, irc.donation_year); @@ -169,8 +202,6 @@ DH_handler_submit_receipts_post (struct DH_RequestContext *rc, } // FIXME - // Fetch donation receipts and join with donation units to get amount - // then create donation statement // Send back DS return MHD_HTTP_OK; diff --git a/src/donau/donau-httpd_keys.c b/src/donau/donau-httpd_keys.c @@ -1253,8 +1253,6 @@ DH_keys_donau_sign_ ( .eddsa_signature = sig->eddsa_sig }; - // FIXME NEEDED? - // TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_EDDSA]++; ec = TALER_CRYPTO_helper_esign_sign_ (esh, purpose, &donau_pub, @@ -1380,7 +1378,6 @@ DH_keys_donation_unit_batch_sign ( } return ec; } - // TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_CS] += csrs_pos; } if (0 != rsrs_pos) { @@ -1409,7 +1406,6 @@ DH_keys_donation_unit_batch_sign ( } return ec; } - // TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_RSA] += rsrs_pos; } rsrs_pos = 0; diff --git a/src/donaudb/0002-donau_receipts_submitted.sql b/src/donaudb/0002-donau_receipts_submitted.sql @@ -19,7 +19,7 @@ CREATE TABLE receipts_submitted ,h_tax_number BYTEA NOT NULL ,nonce BYTEA NOT NULL UNIQUE CHECK (LENGTH(nonce)=32) ,donation_unit_pub BYTEA NOT NULL REFERENCES donation_units (donation_unit_pub) - ,donau_sig BYTEA NOT NULL UNIQUE + ,donation_unit_sig BYTEA NOT NULL UNIQUE ,donation_year INT8 NOT NULL ); COMMENT ON TABLE receipts_submitted diff --git a/src/donaudb/pg_insert_submitted_receipts.c b/src/donaudb/pg_insert_submitted_receipts.c @@ -29,7 +29,7 @@ enum GNUNET_DB_QueryStatus DH_PG_insert_submitted_receipts ( void *cls, - struct DONAU_HashDonorTaxId *h_tax_number, + struct DONAU_HashDonorTaxId *h_donor_tax_id, size_t num_dr, const struct DONAU_DonationReceipt donation_receipts[static num_dr], uint64_t donation_year) @@ -38,9 +38,10 @@ DH_PG_insert_submitted_receipts ( const struct DONAU_DonationUnitHashP *h_donation_unit_pubs[GNUNET_NZL (num_dr) ]; const struct DONAU_UniqueDonorIdentifierNonce *nonces[GNUNET_NZL (num_dr)]; - const struct DONAU_DonauSignatureP *donau_sigs[GNUNET_NZL (num_dr)]; + const struct DONAU_DonationUnitSignature *donation_unit_sigs[GNUNET_NZL ( + num_dr)]; struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (h_tax_number), + GNUNET_PQ_query_param_auto_from_type (h_donor_tax_id), GNUNET_PQ_query_param_array_ptrs_auto_from_type (num_dr, h_donation_unit_pubs, pg->conn), @@ -48,7 +49,7 @@ DH_PG_insert_submitted_receipts ( nonces, pg->conn), GNUNET_PQ_query_param_array_ptrs_auto_from_type (num_dr, - donau_sigs, + donation_unit_sigs, pg->conn), GNUNET_PQ_query_param_uint64 (&donation_year), GNUNET_PQ_query_param_end @@ -61,7 +62,7 @@ DH_PG_insert_submitted_receipts ( h_donation_unit_pubs[i] = &dr->h_donation_unit_pub; nonces[i] = &dr->nonce; - donau_sigs[i] = &dr->du_sig; + donation_unit_sigs[i] = &dr->donation_unit_sig; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Do insert submitted receipt\n"); diff --git a/src/donaudb/pg_insert_submitted_receipts.h b/src/donaudb/pg_insert_submitted_receipts.h @@ -30,7 +30,7 @@ * Insert submitted donation receipt from the donor. * * @param cls closure - * @param h_tax_number salted hash of the donors tax number + * @param h_donor_tax_id salted hash of the donors tax number * @param donation_receipts array of donation receipts * @param donation_year year of the donation * @return transaction status code @@ -38,7 +38,7 @@ enum GNUNET_DB_QueryStatus DH_PG_insert_submitted_receipts ( void *cls, - struct DONAU_HashDonorTaxId *h_tax_number, + struct DONAU_HashDonorTaxId *h_donor_tax_id, size_t num_dr, const struct DONAU_DonationReceipt donation_receipts[static num_dr], uint64_t donation_year diff --git a/src/donaudb/test_donaudb.c b/src/donaudb/test_donaudb.c @@ -168,7 +168,7 @@ run (void *cls) struct DONAUDB_IssuedReceiptsMetaData ir_meta; // Submitted receipts information - struct DONAU_HashDonorTaxId h_tax_number; + struct DONAU_HashDonorTaxId h_donor_tax_id; size_t num_dr = 1; struct DONAU_DonationReceipt donation_receipts[num_dr]; @@ -307,13 +307,13 @@ run (void *cls) // &ir_meta)); /* test insert submitted receipts */ - // RND_BLK (&h_tax_number); + // RND_BLK (&h_donor_tax_id); // RND_BLK (&donation_receipts[0].h_donation_unit_pub); // RND_BLK (&donation_receipts[0].nonce); // RND_BLK (&donation_receipts[0].donau_sig); // FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != // plugin->insert_submitted_receipts (plugin->cls, - // &h_tax_number, + // &h_donor_tax_id, // num_dr, // donation_receipts, // current_year)); diff --git a/src/include/donau_crypto_lib.h b/src/include/donau_crypto_lib.h @@ -210,7 +210,7 @@ struct DONAU_BlindedDonationUnitSignature /** - * @brief Type of (unblinded) donation receipts signatures for Taler. + * @brief Type of (unblinded) donation receipts signatures for Donau. */ struct DONAU_DonationUnitSignature { @@ -303,7 +303,7 @@ struct DONAU_DonationReceipt /** * Unblinded donation unit signature from the donau. */ - struct DONAU_DonationUnitSignature du_sig; + struct DONAU_DonationUnitSignature donation_unit_sig; }; @@ -322,7 +322,8 @@ struct DONAU_BkpSignData */ const struct DONAU_BlindedUniqueDonorIdentifier *budi; }; -/** + +/** USED? * Hash of a budikeypair array */ // struct DONAU_BudiKeyPairsHashP @@ -330,10 +331,18 @@ struct DONAU_BkpSignData // struct GNUNET_HashCode hash; // }; -/** +/** USED? * Hash of a budikeypair array */ -struct DONAU_BudiHashP +// struct DONAU_BudiHashP +// { +// struct GNUNET_HashCode hash; +// }; + +/** + * Hash of a Unique Donor Identifier (h_donor_tax_id + nonce) + */ +struct DONAU_UniqueDonorIdentifierHashP { struct GNUNET_HashCode hash; }; @@ -418,6 +427,20 @@ DONAU_donation_statement_verify ( ///* ********************* donau blind signing ************************** */ +/** + * Verify donation receipt. + * + * @param donation_unit_pub public key of the donation_unit + * @param h_udi hash of h_donor_tax_id + nonce + * @param donation_unit_sig signature to verify + * @return #GNUNET_OK if the signature is valid + */ +enum GNUNET_GenericReturnValue +DONAU_donation_receipt_verify ( + const struct DONAU_DonationUnitPublicKey *donation_unit_pub, + const struct DONAU_UniqueDonorIdentifierHashP *h_udi, + const struct DONAU_DonationUnitSignature *donation_unit_sig); + /** * Free internals of @a donation_unit_sig, but not @a donation_unit_sig itself. @@ -438,12 +461,12 @@ DONAU_blinded_donation_unit_sig_free ( * @param budi_hash hash over the budi * @return #GNUNET_OK if the signature is valid */ -enum GNUNET_GenericReturnValue -TALER_donation_unit_pub_verify (const struct - DONAU_DonationUnitPublicKey *du_pub, - const struct - DONAU_DonationUnitSignature *du_sig, - const struct DONAU_BudiHashP *budi_hash); +// enum GNUNET_GenericReturnValue +// TALER_donation_unit_pub_verify ( +// const struct DONAU_DonationUnitPublicKey *du_pub, +// const struct +// DONAU_DonationUnitSignature *du_sig, +// const struct DONAU_BudiHashP *budi_hash); // FIXME: Copied from taler_crypto_lib.h, is anything of this necessary? @@ -603,5 +626,18 @@ struct TALER_DonauBatchIssueValues struct GNUNET_CRYPTO_BlindingInputValues *blinding_inputs; }; +/** + * Compute the hash of a Unique Donor Identifier. + * + * @param h_donor_tax_id hash of the tax id + * @param nonce that makes the Donor Identifier unique + * @param[out] h_udi where to write the hash + */ +void +DONAU_unique_donor_id_hash (const struct DONAU_HashDonorTaxId *h_donor_tax_id, + const struct DONAU_UniqueDonorIdentifierNonce *nonce + , + struct DONAU_UniqueDonorIdentifierHashP *h_udi); + #endif diff --git a/src/include/donau_service.h b/src/include/donau_service.h @@ -476,7 +476,7 @@ struct DONAU_BatchIssueResponse struct DONAU_BlindedDonationUnitSignature *donau_sigs; /** - * total issued amount over all donation receipts of a donation specified + * total issued amount over all donation receipts of a donation specified * by the request (confirmation). */ struct TALER_Amount issued_amount; @@ -642,7 +642,7 @@ typedef void * @param num_drs length of the @a drs array * @param drs array with details about the donation receipts * @param year corresponding year - * @param h_tax_id salted and hashed tax id + * @param h_donor_tax_id salted and hashed tax id * @param cb the callback to call when a reply for this request is available * @param cls closure for the above callback * @param[out] ec if NULL is returned, set to the error code explaining why the operation failed @@ -656,7 +656,7 @@ DONAU_donor_receipts_to_statement ( const size_t num_drs, const struct DONAU_DonationReceipt drs[num_drs], const uint64_t year, - const struct DONAU_HashDonorTaxId *h_tax_id, + const struct DONAU_HashDonorTaxId *h_donor_tax_id, DONAU_DonorReceiptsToStatementResultCallback cb, void *cls); diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h @@ -519,7 +519,7 @@ struct DONAUDB_Plugin * Insert submitted donation receipt from the donor. * * @param cls closure - * @param h_tax_number salted hash of the donors tax number + * @param h_donor_tax_id salted hash of the donors tax number * @param nonce nonce that is part of the unique donation identifier * @param donation_unit_pub donation unit public key * @param donau_sig donau signature in case the sign keys changed @@ -529,7 +529,7 @@ struct DONAUDB_Plugin enum GNUNET_DB_QueryStatus (*insert_submitted_receipts)( void *cls, - struct DONAU_HashDonorTaxId *h_tax_number, + struct DONAU_HashDonorTaxId *h_donor_tax_id, size_t num_dr, const struct DONAU_DonationReceipt donation_receipts[static num_dr], uint64_t donation_year); diff --git a/src/lib/donau_api_batch_submit_receipts.c b/src/lib/donau_api_batch_submit_receipts.c @@ -74,14 +74,14 @@ struct DONAU_DonorReceiptsToStatementHandle * @param num_drs number of donation receipts in @drs * @param drs donation receipts array * @param year corresponding year - * @param h_tax_id salted and hashed tax id + * @param h_donor_tax_id salted and hashed tax id */ json_t * submit_request_body_to_json (const size_t num_drs, const struct DONAU_DonationReceipt drs[num_drs], const uint64_t year, - const struct DONAU_HashDonorTaxId *h_tax_id) + const struct DONAU_HashDonorTaxId *h_donor_tax_id) { json_t *donation_receipts = json_array (); GNUNET_assert (NULL != donation_receipts); @@ -93,8 +93,8 @@ submit_request_body_to_json (const size_t num_drs, &drs[i].h_donation_unit_pub), GNUNET_JSON_pack_data_auto ("nonce", &drs[i].nonce), - DONAU_JSON_pack_donation_unit_sig ("donau_sig", - &drs[i].du_sig)); + DONAU_JSON_pack_donation_unit_sig ("donation_unit_sig", + &drs[i].donation_unit_sig)); GNUNET_assert (0 == json_array_append_new (donation_receipts, receipt)); @@ -102,8 +102,8 @@ submit_request_body_to_json (const size_t num_drs, return GNUNET_JSON_PACK ( GNUNET_JSON_pack_array_steal ("donation_receipts", donation_receipts), - GNUNET_JSON_pack_data_auto ("h_tax_number", - h_tax_id), + GNUNET_JSON_pack_data_auto ("h_donor_tax_id", + h_donor_tax_id), GNUNET_JSON_pack_uint64 ("donation_year", year)); } @@ -187,7 +187,7 @@ DONAU_donor_receipts_to_statement ( const size_t num_drs, const struct DONAU_DonationReceipt drs[num_drs], const uint64_t year, - const struct DONAU_HashDonorTaxId *h_tax_id, + const struct DONAU_HashDonorTaxId *h_donor_tax_id, DONAU_DonorReceiptsToStatementResultCallback cb, void *cls) { @@ -215,7 +215,7 @@ DONAU_donor_receipts_to_statement ( GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "submit_receipts_with_URL `%s'.\n", birh->url); - body = submit_request_body_to_json (num_drs, drs, year, h_tax_id); + body = submit_request_body_to_json (num_drs, drs, year, h_donor_tax_id); eh = DONAU_curl_easy_get_ (birh->url); if ( (NULL == eh) || (GNUNET_OK != diff --git a/src/util/donau_crypto.c b/src/util/donau_crypto.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2022 Taler Systems SA + Copyright (C) 2024 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -136,3 +136,39 @@ DONAU_donation_unit_pub_hash ( GNUNET_assert (0); } } + + +void +DONAU_unique_donor_id_hash (const struct DONAU_HashDonorTaxId *h_donor_tax_id, + const struct DONAU_UniqueDonorIdentifierNonce *nonce + , + struct DONAU_UniqueDonorIdentifierHashP *h_udi) +{ + struct GNUNET_HashContext *hash_context; + hash_context = GNUNET_CRYPTO_hash_context_start (); + + GNUNET_CRYPTO_hash_context_read ( + hash_context, + h_donor_tax_id, + sizeof(struct DONAU_HashDonorTaxId)); + GNUNET_CRYPTO_hash_context_read ( + hash_context, + nonce, + sizeof(struct DONAU_UniqueDonorIdentifierNonce)); + GNUNET_CRYPTO_hash_context_finish ( + hash_context, + &h_udi->hash); +} + + +enum GNUNET_GenericReturnValue +DONAU_donation_receipt_verify ( + const struct DONAU_DonationUnitPublicKey *donation_unit_pub, + const struct DONAU_UniqueDonorIdentifierHashP *h_udi, + const struct DONAU_DonationUnitSignature *donation_unit_sig) +{ + return GNUNET_CRYPTO_blind_sig_verify (donation_unit_pub->bsign_pub_key, + donation_unit_sig->unblinded_sig, + h_udi, + sizeof (*h_udi)); +}