donau

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

commit 2b508fdb5c3a939d3b1fc6670fb3b1ae11f7ec00
parent f1014f718dac51fff865244f7a526bdc2328d3ee
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Sat, 13 Apr 2024 11:47:24 +0200

[donau] work on issue receipts

Diffstat:
Msrc/donau/donau-httpd_keys.c | 274++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/donau/donau-httpd_keys.h | 2+-
Msrc/donau/donau-httpd_post-batch-issue.c | 104++++++++++++++++++++++++++++++++++----------------------------------------------
Msrc/donaudb/pg_insert_issued_receipt.c | 6+++---
Msrc/donaudb/pg_lookup_issued_receipts.c | 4++--
Msrc/donaudb/pg_lookup_issued_receipts.h | 2+-
Msrc/include/donaudb_plugin.h | 2+-
7 files changed, 189 insertions(+), 205 deletions(-)

diff --git a/src/donau/donau-httpd_keys.c b/src/donau/donau-httpd_keys.c @@ -1288,148 +1288,148 @@ DH_keys_donau_sign_ ( enum TALER_ErrorCode -DH_keys_donation_batch_sign ( +DH_keys_donation_unit_batch_sign ( unsigned int budis_length, const struct BUDIKeyPair_sign_data bkps[budis_length], struct DONAU_BlindedDonationUnitSignature du_sigs[budis_length]) { return TALER_EC_NONE; -// struct DH_KeyStateHandle *ksh; -// struct DH_DonationUnitKey *du; -// struct TALER_CRYPTO_RsaSignRequest rsrs[csds_length]; -// struct TALER_CRYPTO_CsSignRequest csrs[csds_length]; -// struct TALER_BlindedDenominationSignature rs[csds_length]; -// struct TALER_BlindedDenominationSignature cs[csds_length]; -// unsigned int rsrs_pos = 0; -// unsigned int csrs_pos = 0; -// enum TALER_ErrorCode ec; - -// ksh = DH_keys_get_state (); -// if (NULL == ksh) -// // FIXME change error code -// return TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING; -// 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; - -// du = GNUNET_CONTAINER_multihashmap_get (du_keys, -// &h_du_pub->hash); -// if (NULL == du) -// // FIXME change error code -// return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN; -// if (budi->blinded_message->cipher != -// du->donation_unit_pub.bsign_pub_key->cipher) -// return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; -// switch (du->donation_unit_pub.bsign_pub_key->cipher) -// { -// case GNUNET_CRYPTO_BSA_RSA: -// /* See DONAU_donation_unit_pub_hash: we guarantee that these -// hashes are equivalent! */ -// rsrs[rsrs_pos].h_rsa -// = (const struct TALER_RsaPubHashP *) &du->h_donation_unit_pub; -// rsrs[rsrs_pos].msg -// = budi->blinded_message->details.rsa_blinded_message.blinded_msg; -// rsrs[rsrs_pos].msg_size -// = budi->blinded_message->details.rsa_blinded_message.blinded_msg_size; -// rsrs_pos++; -// break; -// case GNUNET_CRYPTO_BSA_CS: -// /* See DONAU_donation_unit_pub_hash: we guarantee that these -// hashes are equivalent! */ -// csrs[csrs_pos].h_cs -// = (const struct TALER_CsPubHashP *) &du->h_donation_unit_pub; -// csrs[csrs_pos].blinded_planchet -// = &budi->blinded_message->details.cs_blinded_message; -// csrs_pos++; -// break; -// default: -// return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; -// } -// } - -// if ( (0 != csrs_pos) && -// (0 != rsrs_pos) ) -// { -// memset (rs, -// 0, -// sizeof (rs)); -// memset (cs, -// 0, -// sizeof (cs)); -// } -// ec = TALER_EC_NONE; -// if (0 != csrs_pos) -// { -// ec = TALER_CRYPTO_helper_cs_batch_sign ( -// csdh, -// csrs_pos, -// csrs, -// false, // for_melt -// cs); -// if (TALER_EC_NONE != ec) -// { -// for (unsigned int i = 0; i<csrs_pos; i++) -// { -// if (NULL != cs[i].blinded_sig) -// { -// GNUNET_CRYPTO_blinded_sig_decref (cs[i].blinded_sig); -// cs[i].blinded_sig = NULL; -// } -// } -// return ec; -// } -// // TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_CS] += csrs_pos; -// } -// if (0 != rsrs_pos) -// { -// ec = TALER_CRYPTO_helper_rsa_batch_sign ( -// rsadh, -// rsrs_pos, -// rsrs, -// rs); -// if (TALER_EC_NONE != ec) -// { -// for (unsigned int i = 0; i<csrs_pos; i++) -// { -// if (NULL != cs[i].blinded_sig) -// { -// GNUNET_CRYPTO_blinded_sig_decref (cs[i].blinded_sig); -// cs[i].blinded_sig = NULL; -// } -// } -// for (unsigned int i = 0; i<rsrs_pos; i++) -// { -// if (NULL != rs[i].blinded_sig) -// { -// GNUNET_CRYPTO_blinded_sig_decref (rs[i].blinded_sig); -// rs[i].blinded_sig = NULL; -// } -// } -// return ec; -// } -// // TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_RSA] += rsrs_pos; -// } - -// rsrs_pos = 0; -// csrs_pos = 0; -// for (unsigned int i = 0; i<csds_length; i++) -// { -// const struct DONAU_BlindedUniqueDonationIdentifier *budi = csds[i].budi; - -// switch (budi->blinded_message->cipher) -// { -// case GNUNET_CRYPTO_BSA_RSA: -// bss[i].blinded_sig = rs[rsrs_pos++].blinded_sig; -// break; -// case GNUNET_CRYPTO_BSA_CS: -// bss[i].blinded_sig = cs[csrs_pos++].blinded_sig; -// break; -// default: -// GNUNET_assert (0); -// } -// } -// return TALER_EC_NONE; + // struct DH_KeyStateHandle *ksh; + // struct DH_DonationUnitKey *du; + // struct TALER_CRYPTO_RsaSignRequest rsrs[csds_length]; + // struct TALER_CRYPTO_CsSignRequest csrs[csds_length]; + // struct TALER_BlindedDenominationSignature rs[csds_length]; + // struct TALER_BlindedDenominationSignature cs[csds_length]; + // unsigned int rsrs_pos = 0; + // unsigned int csrs_pos = 0; + // enum TALER_ErrorCode ec; + + // ksh = DH_keys_get_state (); + // if (NULL == ksh) + // // FIXME change error code + // return TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING; + // 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; + + // du = GNUNET_CONTAINER_multihashmap_get (du_keys, + // &h_du_pub->hash); + // if (NULL == du) + // // FIXME change error code + // return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN; + // if (budi->blinded_message->cipher != + // du->donation_unit_pub.bsign_pub_key->cipher) + // return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; + // switch (du->donation_unit_pub.bsign_pub_key->cipher) + // { + // case GNUNET_CRYPTO_BSA_RSA: + // /* See DONAU_donation_unit_pub_hash: we guarantee that these + // hashes are equivalent! */ + // rsrs[rsrs_pos].h_rsa + // = (const struct TALER_RsaPubHashP *) &du->h_donation_unit_pub; + // rsrs[rsrs_pos].msg + // = budi->blinded_message->details.rsa_blinded_message.blinded_msg; + // rsrs[rsrs_pos].msg_size + // = budi->blinded_message->details.rsa_blinded_message.blinded_msg_size; + // rsrs_pos++; + // break; + // case GNUNET_CRYPTO_BSA_CS: + // /* See DONAU_donation_unit_pub_hash: we guarantee that these + // hashes are equivalent! */ + // csrs[csrs_pos].h_cs + // = (const struct TALER_CsPubHashP *) &du->h_donation_unit_pub; + // csrs[csrs_pos].blinded_planchet + // = &budi->blinded_message->details.cs_blinded_message; + // csrs_pos++; + // break; + // default: + // return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; + // } + // } + + // if ( (0 != csrs_pos) && + // (0 != rsrs_pos) ) + // { + // memset (rs, + // 0, + // sizeof (rs)); + // memset (cs, + // 0, + // sizeof (cs)); + // } + // ec = TALER_EC_NONE; + // if (0 != csrs_pos) + // { + // ec = TALER_CRYPTO_helper_cs_batch_sign ( + // csdh, + // csrs_pos, + // csrs, + // false, // for_melt + // cs); + // if (TALER_EC_NONE != ec) + // { + // for (unsigned int i = 0; i<csrs_pos; i++) + // { + // if (NULL != cs[i].blinded_sig) + // { + // GNUNET_CRYPTO_blinded_sig_decref (cs[i].blinded_sig); + // cs[i].blinded_sig = NULL; + // } + // } + // return ec; + // } + // // TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_CS] += csrs_pos; + // } + // if (0 != rsrs_pos) + // { + // ec = TALER_CRYPTO_helper_rsa_batch_sign ( + // rsadh, + // rsrs_pos, + // rsrs, + // rs); + // if (TALER_EC_NONE != ec) + // { + // for (unsigned int i = 0; i<csrs_pos; i++) + // { + // if (NULL != cs[i].blinded_sig) + // { + // GNUNET_CRYPTO_blinded_sig_decref (cs[i].blinded_sig); + // cs[i].blinded_sig = NULL; + // } + // } + // for (unsigned int i = 0; i<rsrs_pos; i++) + // { + // if (NULL != rs[i].blinded_sig) + // { + // GNUNET_CRYPTO_blinded_sig_decref (rs[i].blinded_sig); + // rs[i].blinded_sig = NULL; + // } + // } + // return ec; + // } + // // TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_RSA] += rsrs_pos; + // } + + // rsrs_pos = 0; + // csrs_pos = 0; + // for (unsigned int i = 0; i<csds_length; i++) + // { + // const struct DONAU_BlindedUniqueDonationIdentifier *budi = csds[i].budi; + + // switch (budi->blinded_message->cipher) + // { + // case GNUNET_CRYPTO_BSA_RSA: + // bss[i].blinded_sig = rs[rsrs_pos++].blinded_sig; + // break; + // case GNUNET_CRYPTO_BSA_CS: + // bss[i].blinded_sig = cs[csrs_pos++].blinded_sig; + // break; + // default: + // GNUNET_assert (0); + // } + // } + // return TALER_EC_NONE; } diff --git a/src/donau/donau-httpd_keys.h b/src/donau/donau-httpd_keys.h @@ -185,7 +185,7 @@ DH_keys_finished (void); * @return #TALER_EC_NONE on success */ enum TALER_ErrorCode -DH_keys_donation_batch_sign ( +DH_keys_donation_unit_batch_sign ( unsigned int budis_length, const struct BUDIKeyPair_sign_data bkps[budis_length], struct DONAU_BlindedDonationUnitSignature du_sigs[budis_length]); diff --git a/src/donau/donau-httpd_post-batch-issue.c b/src/donau/donau-httpd_post-batch-issue.c @@ -35,16 +35,6 @@ #include "donau-httpd_keys.h" -/** - * Closure for #issue_receipts() - */ -struct IssueReceiptsContext -{ - struct DONAU_CharityPublicKeyP charity_pub; - struct DONAU_CharitySignatureP charity_sig; - const struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkp; - uint64_t year; -}; /** * Parse a bkp encoded in JSON. @@ -111,6 +101,8 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, const json_t *root, const char *const args[1]) { + struct DONAU_CharitySignatureP charity_sig; + uint64_t year; bool second_time = false; unsigned long long charity_id; char dummy; @@ -134,16 +126,14 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, "issue receipts for charity id: %llu\n", charity_id); - struct IssueReceiptsContext irc; const json_t *budikeypairs; - struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_array_const ("budikeypairs", &budikeypairs), GNUNET_JSON_spec_fixed_auto ("charity_sig", - &irc.charity_sig), + &charity_sig), GNUNET_JSON_spec_uint64 ("year", - &irc.year), + &year), GNUNET_JSON_spec_end () }; @@ -165,21 +155,22 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, GNUNET_log (GNUNET_ERROR_TYPE_INFO, "parse some values!\n"); /* parse the budikeypairs array */ - const size_t num_bkp + const size_t num_bkps = json_array_size (budikeypairs); - if (0 != num_bkp) + struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkps; + if (0 != num_bkps) { json_t *bkp_obj; size_t index; - struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkp - = GNUNET_new_array - (num_bkp, + + bkps = GNUNET_new_array + (num_bkps, struct DONAU_BlindedUniqueDonationIdentifierKeyPair); json_array_foreach (budikeypairs, index, bkp_obj) { if (GNUNET_SYSERR == - parse_json_bkp (&bkp[index], bkp_obj)) + parse_json_bkp (&bkps[index], bkp_obj)) { GNUNET_break_op (0); return TALER_MHD_reply_with_error (rc->connection, @@ -188,7 +179,6 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, "budikeypairs"); } } - irc.bkp = bkp; } else { @@ -232,12 +222,11 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, GNUNET_log (GNUNET_ERROR_TYPE_INFO, "got charity from db!\n"); /* verify charity signature */ - // FIXME if (GNUNET_OK != - DONAU_charity_budi_key_pair_verify (num_bkp, - irc.bkp, + DONAU_charity_budi_key_pair_verify (num_bkps, + bkps, &charity_meta.charity_pub, - &irc.charity_sig)) + &charity_sig)) { GNUNET_break_op (0); return TALER_MHD_reply_with_error ( @@ -256,34 +245,29 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, json_t *blind_signatures = json_array (); GNUNET_assert (NULL != blind_signatures); - for (size_t i = 0; i < num_bkp; i++) + struct GNUNET_HashContext *hc; + hc = GNUNET_CRYPTO_hash_context_start (); + for (unsigned int i = 0; i < num_bkps; i++) { - struct GNUNET_HashCode temp_hash; - - GNUNET_CRYPTO_hash (&irc.bkp[i].blinded_udi, - sizeof (irc.bkp[0].blinded_udi), - &temp_hash); - GNUNET_CRYPTO_hash_xor (&h_receipts.hash, - &temp_hash, - &h_receipts.hash); - GNUNET_CRYPTO_hash_xor (&h_receipts.hash, - &irc.bkp[i].h_donation_unit_pub.hash, - &h_receipts.hash); - } - { - struct GNUNET_HashCode sig_hash; - - GNUNET_CRYPTO_hash (&irc.charity_sig, - sizeof (struct DONAU_CharitySignatureP), - &sig_hash); - GNUNET_CRYPTO_hash_xor (&h_receipts.hash, - &sig_hash, - &h_receipts.hash); + GNUNET_CRYPTO_hash_context_read (hc, + &bkps[i].h_donation_unit_pub, + sizeof (bkps[i].h_donation_unit_pub)); + GNUNET_CRYPTO_hash_context_read (hc, + bkps[i].blinded_udi.blinded_message, + sizeof (bkps[i].blinded_udi.blinded_message)); } + GNUNET_CRYPTO_hash_context_read (hc, + &charity_sig, + sizeof (struct DONAU_CharitySignatureP)); + GNUNET_CRYPTO_hash_context_read (hc, + &year, + sizeof (uint64_t)); + GNUNET_CRYPTO_hash_context_finish (hc, + &h_receipts.hash); + start: qs_check_receipts = DH_plugin->lookup_issued_receipts (DH_plugin->cls, - /* FIXME: & */ - h_receipts, + &h_receipts, &check_receipts_meta); switch (qs_check_receipts) { @@ -301,7 +285,7 @@ start: case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: GNUNET_log (GNUNET_ERROR_TYPE_INFO, "request has been made already!\n"); - signatures_to_JSON (num_bkp, check_receipts_meta.blinded_sig, + signatures_to_JSON (num_bkps, check_receipts_meta.blinded_sig, blind_signatures); return TALER_MHD_REPLY_JSON_PACK ( rc->connection, @@ -315,12 +299,12 @@ start: GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (DH_currency, &receipts_sum)); - for (size_t i = 0; i < num_bkp; i++) + for (size_t i = 0; i < num_bkps; i++) { struct DH_DonationUnitKey *dk; if (NULL == (dk = DH_keys_donation_unit_by_hash ( - &irc.bkp[i].h_donation_unit_pub))) + &bkps[i].h_donation_unit_pub))) return TALER_MHD_reply_with_error (rc->connection, MHD_HTTP_NOT_FOUND, TALER_EC_DONAU_GENERIC_KEYS_MISSING, @@ -353,15 +337,15 @@ start: "calculated the new receipts to date amount\n"); /* sign budis and send the signatures back */ - struct DONAU_BlindedDonationUnitSignature du_sigs[num_bkp]; - struct BUDIKeyPair_sign_data bkps_sign_data[num_bkp]; + struct DONAU_BlindedDonationUnitSignature du_sigs[num_bkps]; + struct BUDIKeyPair_sign_data bkps_sign_data[num_bkps]; - for (int i = 0; i < num_bkp; i++) + for (int i = 0; i < num_bkps; i++) { - bkps_sign_data[i].h_donation_unit_pub = &irc.bkp[i].h_donation_unit_pub; - bkps_sign_data[i].budi = &irc.bkp[i].blinded_udi; + bkps_sign_data[i].h_donation_unit_pub = &bkps[i].h_donation_unit_pub; + bkps_sign_data[i].budi = &bkps[i].blinded_udi; } - if (TALER_EC_NONE != DH_keys_donation_batch_sign (num_bkp, bkps_sign_data, + if (TALER_EC_NONE != DH_keys_donation_unit_batch_sign (num_bkps, bkps_sign_data, du_sigs)) return TALER_MHD_reply_with_error (rc->connection, MHD_HTTP_INTERNAL_SERVER_ERROR, @@ -374,7 +358,7 @@ start: enum GNUNET_DB_QueryStatus qs_insert_ir; qs_insert_ir = DH_plugin->insert_issued_receipt ( DH_plugin->cls, - num_bkp, + num_bkps, du_sigs, (uint64_t) charity_id, &h_receipts, @@ -399,7 +383,7 @@ start: GNUNET_log (GNUNET_ERROR_TYPE_INFO, "issue receipts request is saved! (idempotent)\n"); - signatures_to_JSON (num_bkp, du_sigs, blind_signatures); + signatures_to_JSON (num_bkps, du_sigs, blind_signatures); return TALER_MHD_REPLY_JSON_PACK ( rc->connection, MHD_HTTP_OK, diff --git a/src/donaudb/pg_insert_issued_receipt.c b/src/donaudb/pg_insert_issued_receipt.c @@ -63,9 +63,9 @@ DH_PG_insert_issued_receipt (void *cls, " ($1,$2,$3,$4);"); qs = GNUNET_PQ_eval_prepared_multi_select (pc->conn, - "insert_issued_receipts_request", - params, - NULL, NULL); + "insert_issued_receipts_request", + params, + NULL, NULL); GNUNET_PQ_cleanup_query_params_closures (params); return qs; } diff --git a/src/donaudb/pg_lookup_issued_receipts.c b/src/donaudb/pg_lookup_issued_receipts.c @@ -29,12 +29,12 @@ enum GNUNET_DB_QueryStatus DH_PG_lookup_issued_receipts ( void *cls, - struct DONAU_DonationReceiptHashP h_receipts, + struct DONAU_DonationReceiptHashP *h_receipts, struct DONAUDB_IssuedReceiptsMetaData *meta) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (&h_receipts), + GNUNET_PQ_query_param_auto_from_type (h_receipts), GNUNET_PQ_query_param_end }; struct GNUNET_PQ_ResultSpec rs[] = { diff --git a/src/donaudb/pg_lookup_issued_receipts.h b/src/donaudb/pg_lookup_issued_receipts.h @@ -34,6 +34,6 @@ enum GNUNET_DB_QueryStatus DH_PG_lookup_issued_receipts ( void *cls, - struct DONAU_DonationReceiptHashP h_receipts, + struct DONAU_DonationReceiptHashP *h_receipts, struct DONAUDB_IssuedReceiptsMetaData *meta); #endif diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h @@ -546,7 +546,7 @@ struct DONAUDB_Plugin enum GNUNET_DB_QueryStatus (*lookup_issued_receipts)( void *cls, - struct DONAU_DonationReceiptHashP h_receitps, + struct DONAU_DonationReceiptHashP *h_receitps, struct DONAUDB_IssuedReceiptsMetaData *meta); /**