donau

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

commit b2688530270fd4ad906d4760724b30071e38cad4
parent 17a70bd391732802e13e5639e387048fa869fff2
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Tue, 14 May 2024 20:20:44 +0200

Merge remote-tracking branch 'refs/remotes/origin/master'

Diffstat:
Msrc/donau/Makefile.am | 2+-
Msrc/donau/donau-httpd.c | 44++++++++------------------------------------
Msrc/donau/donau-httpd_batch-issue.c | 18++++++++++--------
Msrc/donau/donau-httpd_batch-submit.c | 5++---
Msrc/donau/donau-httpd_batch-submit.h | 2+-
Msrc/donau/donau-httpd_charity_delete.c | 8+-------
Msrc/donau/donau-httpd_charity_insert.c | 2--
Msrc/donau/donau-httpd_csr.c | 83++++++++++++++++++++-----------------------------------------------------------
Msrc/donau/donau-httpd_csr.h | 3+--
Msrc/donau/donau-httpd_db.c | 8++------
Msrc/donau/donau-httpd_db.h | 24++----------------------
Msrc/donau/donau-httpd_history_get.c | 3+--
Msrc/donau/donau-httpd_keys.c | 35+++++++++++++++++++++++++++++++++--
Msrc/donau/donau-httpd_keys.h | 26++++++++++++++++++--------
Dsrc/donau/donau-httpd_metrics.c | 165-------------------------------------------------------------------------------
Dsrc/donau/donau-httpd_metrics.h | 136-------------------------------------------------------------------------------
Msrc/donau/donau-httpd_mhd.c | 2+-
Msrc/donau/donau-httpd_mhd.h | 2+-
Msrc/donau/donau-httpd_terms.c | 3+--
Msrc/donau/donau-httpd_terms.h | 3+--
Msrc/donaudb/0002-donation_units.sql | 4----
Msrc/donaudb/donau-0001.sql | 2+-
Msrc/donaudb/donau-0002.sql.in | 2+-
Msrc/donaudb/donau_do_amount_specific.sql | 2+-
Msrc/donaudb/pg_commit.c | 2+-
Msrc/donaudb/pg_commit.h | 2+-
Msrc/donaudb/pg_create_tables.c | 4++--
Msrc/donaudb/pg_create_tables.h | 4++--
Msrc/donaudb/pg_get_history.c | 2+-
Msrc/donaudb/pg_get_history.h | 8++++----
Msrc/donaudb/pg_insert_donation_unit.h | 4++--
Msrc/donaudb/pg_insert_submitted_receipts.h | 1+
Msrc/donaudb/pg_iterate_submitted_receipts.h | 3+--
Msrc/donaudb/pg_lookup_charity.h | 5+++--
Msrc/donaudb/pg_lookup_issued_receipts.h | 4+++-
Msrc/donaudb/test_donaudb.c | 22++++++++++------------
36 files changed, 139 insertions(+), 506 deletions(-)

diff --git a/src/donau/Makefile.am b/src/donau/Makefile.am @@ -39,7 +39,6 @@ donau_httpd_LDADD = \ donau_httpd_SOURCES = \ donau-httpd.c donau-httpd.h \ - donau-httpd_metrics.c donau-httpd_metrics.h \ donau-httpd_db.c donau-httpd_db.h \ donau-httpd_keys.c donau-httpd_keys.h \ donau-httpd_config.c donau-httpd_config.h \ @@ -50,6 +49,7 @@ donau_httpd_SOURCES = \ donau-httpd_donation-statement.c donau-httpd_donation-statement.h \ donau-httpd_batch-submit.c donau_httpd_batch-submit.h \ donau-httpd_terms.c donau-httpd_terms.h \ + donau-httpd_csr.c donau-httpd_csr.h \ donau-httpd_batch-issue.c donau_httpd_batch-issue.h # Testcases diff --git a/src/donau/donau-httpd.c b/src/donau/donau-httpd.c @@ -36,6 +36,7 @@ #include "donau-httpd_batch-issue.h" #include "donau-httpd_batch-submit.h" #include "donau-httpd_history.h" +#include "donau-httpd_csr.h" #include "donau-httpd_terms.h" #include "donaudb_plugin.h" #include <gnunet/gnunet_mhd_compat.h> @@ -80,11 +81,6 @@ const struct GNUNET_CONFIGURATION_Handle *DH_cfg; static struct MHD_Daemon *mhd; /** - * How long is caching /keys allowed at most? (global) - */ -// struct GNUNET_TIME_Relative DH_max_keys_caching; - -/** * Our DB plugin. (global) */ struct DONAUDB_Plugin *DH_plugin; @@ -137,11 +133,6 @@ int DH_global_ret; static uint16_t serve_port; /** - * Counter for the number of requests this HTTP has processed so far. - */ -// static unsigned long long req_count; - -/** * Counter for the number of open connections. */ static unsigned long long active_connections; @@ -177,25 +168,6 @@ typedef MHD_RESULT const struct TALER_CoinSpendPublicKeyP *coin_pub, const json_t *root); - -/** - * Generate a 404 "not found" reply on @a connection with - * the hint @a details. - * - * @param connection where to send the reply on - * @param details details for the error message, can be NULL - */ -// static MHD_RESULT -// r404 (struct MHD_Connection *connection, -// const char *details) -// { -// return TALER_MHD_reply_with_error (connection, -// MHD_HTTP_NOT_FOUND, -// TALER_EC_EXCHANGE_GENERIC_OPERATION_UNKNOWN, -// details); -// } - - /** * Function called whenever MHD is done with a request. If the * request was a POST, we may have stored a `struct Buffer *` in the @@ -496,13 +468,13 @@ handle_mhd_request (void *cls, .handler.delete = &DH_handler_charity_delete, .nargs = 1 }, - // /* POST get csr values*/ - // { - // .url = "csr-issue", - // .method = MHD_HTTP_METHOD_POST, - // .handler.post = &DH_handler_csr_issue, - // .nargs = 0 - // }, + /* POST get csr values*/ + { + .url = "csr-issue", + .method = MHD_HTTP_METHOD_POST, + .handler.post = &DH_handler_csr_issue, + .nargs = 0 + }, /* POST batch issue receipts */ { .url = "batch-issue", diff --git a/src/donau/donau-httpd_batch-issue.c b/src/donau/donau-httpd_batch-issue.c @@ -30,7 +30,6 @@ #include "donaudb_plugin.h" #include "donau-httpd_batch-issue.h" #include "donau-httpd_db.h" -#include "donau-httpd_metrics.h" #include "donau_json_lib.h" #include "donau-httpd_keys.h" @@ -72,7 +71,7 @@ parse_json_bkp (struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp, * Parse signatures to JSON. * * @param num_sig number of signatures - * @param signatures + * @param signatures Blinded donation unit signatures * @param[out] j_signatures JSON object * @return #GNUNET_OK if all is fine, #GNUNET_SYSERR if we could not parse * is malformed. @@ -202,13 +201,13 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc, { case GNUNET_DB_STATUS_HARD_ERROR: case GNUNET_DB_STATUS_SOFT_ERROR: - GNUNET_break_op (0); + 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); + GNUNET_break_op (0); return TALER_MHD_reply_with_error ( rc->connection, MHD_HTTP_NOT_FOUND, @@ -305,7 +304,8 @@ start: struct DH_DonationUnitKey *dk; if (NULL == (dk = DH_keys_donation_unit_by_hash ( - &bkps[i].h_donation_unit_pub))) { + &bkps[i].h_donation_unit_pub))) + { GNUNET_break_op (0); return TALER_MHD_reply_with_error (rc->connection, MHD_HTTP_NOT_FOUND, @@ -333,8 +333,9 @@ start: batch_sign_ec = DH_keys_donation_unit_batch_sign (num_bkps, bkps_sign_data, du_sigs); - if (TALER_EC_NONE != batch_sign_ec) { - GNUNET_break_op (0); + if (TALER_EC_NONE != batch_sign_ec) + { + GNUNET_break_op (0); return TALER_MHD_reply_with_error (rc->connection, MHD_HTTP_INTERNAL_SERVER_ERROR, batch_sign_ec, // TODO:other EC @@ -368,7 +369,8 @@ start: second_time = true; goto start; case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: - if (! smaller_than_max_per_year) { + if (! smaller_than_max_per_year) + { GNUNET_break_op (0); return TALER_MHD_reply_with_error (rc->connection, MHD_HTTP_BAD_REQUEST, diff --git a/src/donau/donau-httpd_batch-submit.c b/src/donau/donau-httpd_batch-submit.c @@ -59,9 +59,8 @@ parse_json_dr (struct DONAU_DonationReceipt *dr, &dr->h_donation_unit_pub), GNUNET_JSON_spec_fixed_auto ("nonce", &dr->nonce), - // FIXME Need GNUNET_JSON_spec_unblinded_signature - GNUNET_JSON_spec_fixed_auto ("donation_unit_sig", - &dr->donation_unit_sig), + GNUNET_JSON_spec_unblinded_signature ("donation_unit_sig", + &dr->donation_unit_sig), GNUNET_JSON_spec_end () }; diff --git a/src/donau/donau-httpd_batch-submit.h b/src/donau/donau-httpd_batch-submit.h @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donau-httpd_submit-receipts.h + * @file donau-httpd_batch-submit.h * @brief Handle /submit requests * @author Johannes Casaburi */ diff --git a/src/donau/donau-httpd_charity_delete.c b/src/donau/donau-httpd_charity_delete.c @@ -15,8 +15,7 @@ */ /** * @file donau-httpd_charity_delete.c - * @brief Handle DELETE /charitys/$PID requests; parses the request and - * verifies the signature before handing deletion to the database. + * @brief Handle DELETE /charitys/$CHARITY_ID requests. * @author Johannes Casaburi */ #include "taler/platform.h" @@ -27,12 +26,7 @@ #include "taler/taler_dbevents.h" #include "taler/taler_json_lib.h" #include "taler/taler_mhd_lib.h" -// #include "donau-httpd_common_deposit.h" #include "donau-httpd_charity.h" -// #include "donau-httpd_responses.h" -// #include "taler_exchangedb_lib.h" -// #include "donau-httpd_keys.h" - MHD_RESULT DH_handler_charity_delete ( diff --git a/src/donau/donau-httpd_charity_insert.c b/src/donau/donau-httpd_charity_insert.c @@ -30,7 +30,6 @@ #include "donaudb_plugin.h" #include "donau-httpd_charity.h" #include "donau-httpd_db.h" -#include "donau-httpd_metrics.h" /** @@ -143,7 +142,6 @@ DH_handler_charity_post (struct DH_RequestContext *rc, if (GNUNET_OK != DH_DB_run_transaction (rc->connection, "insert_charity", - DH_MT_REQUEST_OTHER, &mhd_ret, &insert_charity, &icc)) diff --git a/src/donau/donau-httpd_csr.c b/src/donau/donau-httpd_csr.c @@ -19,9 +19,7 @@ /** * @file donau-httpd_csr.c * @brief Handle /csr requests - * @author Lucien Heuzeveldt - * @author Gian Demarmles - * @author Christian Grothoff + * @author Johannes Casaburi */ #include <taler/platform.h> #include <gnunet/gnunet_util_lib.h> @@ -32,6 +30,7 @@ #include <taler/taler_mhd_lib.h> #include <taler/taler_signatures.h> #include "donaudb_plugin.h" +#include "donau-httpd_keys.h" #include "donau-httpd_csr.h" @@ -47,18 +46,18 @@ DH_handler_csr_issue (struct DH_RequestContext *rc, const char *const args[]) { struct GNUNET_CRYPTO_CsSessionNonce nonce; - struct TALER_DenominationHashP denom_pub_hash; + struct DONAU_DonationUnitHashP du_pub_hash; struct GNUNET_CRYPTO_BlindingInputValues ewv = { .cipher = GNUNET_CRYPTO_BSA_CS }; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_fixed_auto ("nonce", &nonce), - GNUNET_JSON_spec_fixed_auto ("denom_pub_hash", - &denom_pub_hash), + GNUNET_JSON_spec_fixed_auto ("du_pub_hash", + &du_pub_hash), GNUNET_JSON_spec_end () }; - struct TEH_DenominationKey *dk; + struct DH_DonationUnitKey *dk; (void) args; { @@ -72,74 +71,34 @@ DH_handler_csr_issue (struct DH_RequestContext *rc, } { - struct TEH_KeyStateHandle *ksh; - - ksh = TEH_keys_get_state (); - if (NULL == ksh) - { - return TALER_MHD_reply_with_error (rc->connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING, - NULL); - } - dk = TEH_keys_denomination_by_hash_from_state (ksh, - &denom_pub_hash, - NULL, - NULL); + dk = DH_keys_donation_unit_by_hash (&du_pub_hash); if (NULL == dk) { - return TEH_RESPONSE_reply_unknown_denom_pub_hash ( - rc->connection, - &denom_pub_hash); - } - if (GNUNET_TIME_absolute_is_past (dk->meta.expire_withdraw.abs_time)) - { - /* This denomination is past the expiration time for withdraws/refreshes*/ - return TEH_RESPONSE_reply_expired_denom_pub_hash ( - rc->connection, - &denom_pub_hash, - TALER_EC_EXCHANGE_GENERIC_DENOMINATION_EXPIRED, - "csr-withdraw"); - } - if (GNUNET_TIME_absolute_is_future (dk->meta.start.abs_time)) - { - /* This denomination is not yet valid, no need to check - for idempotency! */ - return TEH_RESPONSE_reply_expired_denom_pub_hash ( - rc->connection, - &denom_pub_hash, - TALER_EC_EXCHANGE_GENERIC_DENOMINATION_VALIDITY_IN_FUTURE, - "csr-withdraw"); - } - if (dk->recoup_possible) - { - /* This denomination has been revoked */ - return TEH_RESPONSE_reply_expired_denom_pub_hash ( + GNUNET_break (0); + return TALER_MHD_reply_with_error ( rc->connection, - &denom_pub_hash, - TALER_EC_EXCHANGE_GENERIC_DENOMINATION_REVOKED, - "csr-withdraw"); + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING, // FIXME + NULL); } if (GNUNET_CRYPTO_BSA_CS != - dk->denom_pub.bsign_pub_key->cipher) + dk->donation_unit_pub.bsign_pub_key->cipher) { - /* denomination is valid but not for CS */ - return TEH_RESPONSE_reply_invalid_denom_cipher_for_operation ( + /* donation_unit is valid but not for CS */ + GNUNET_break (0); + return TALER_MHD_reply_with_error ( rc->connection, - &denom_pub_hash); + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING, // FIXME + NULL); } } /* derive r_pub */ { enum TALER_ErrorCode ec; - const struct TEH_CsDeriveData cdd = { - .h_denom_pub = &denom_pub_hash, - .nonce = &nonce - }; - - ec = TEH_keys_denomination_cs_r_pub (&cdd, - false, + ec = DH_keys_donation_unit_cs_r_pub (&du_pub_hash, + &nonce, &ewv.details.cs_values); if (TALER_EC_NONE != ec) { diff --git a/src/donau/donau-httpd_csr.h b/src/donau/donau-httpd_csr.h @@ -16,8 +16,7 @@ /** * @file donau-httpd_csr.h * @brief Handle /csr-* requests - * @author Lucien Heuzeveldt - * @author Gian Demarmles + * @author Johannes Casaburi */ #ifndef DONAU_HTTPD_CSR_H #define DONAU_HTTPD_CSR_H diff --git a/src/donau/donau-httpd_db.c b/src/donau/donau-httpd_db.c @@ -16,7 +16,7 @@ /** * @file donau-httpd_db.c * @brief Generic database operations for the donau. - * @author Christian Grothoff + * @author Johannes Casaburi */ #include <taler/platform.h> #include <pthread.h> @@ -26,13 +26,12 @@ #include <taler/taler_mhd_lib.h> #include "donaudb_lib.h" #include "donau-httpd_db.h" -// #include "donau-httpd_responses.h" +#include "donau-httpd.h" enum GNUNET_GenericReturnValue DH_DB_run_transaction (struct MHD_Connection *connection, const char *name, - enum DH_MetricTypeRequest mt, MHD_RESULT *mhd_ret, DH_DB_TransactionCallback cb, void *cb_cls) @@ -50,8 +49,6 @@ DH_DB_run_transaction (struct MHD_Connection *connection, NULL); return GNUNET_SYSERR; } - GNUNET_assert (mt < DH_MT_REQUEST_COUNT); - DH_METRICS_num_requests[mt]++; for (unsigned int retries = 0; retries < MAX_TRANSACTION_COMMIT_RETRIES; retries++) @@ -100,7 +97,6 @@ DH_DB_run_transaction (struct MHD_Connection *connection, (-1 == (int) *mhd_ret) ); if (0 <= qs) return GNUNET_OK; - DH_METRICS_num_conflict[mt]++; } DH_plugin->rollback (DH_plugin->cls); TALER_LOG_ERROR ("Transaction `%s' commit failed %u times\n", diff --git a/src/donau/donau-httpd_db.h b/src/donau/donau-httpd_db.h @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2017 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 @@ -16,14 +16,12 @@ /** * @file donau/donau-httpd_db.h * @brief High-level (transactional-layer) database operations for the donau - * @author Chrisitan Grothoff + * @author Johannes Casaburi */ #ifndef DONAU_HTTPD_DB_H #define DONAU_HTTPD_DB_H #include <microhttpd.h> -// #include "donaudb_plugin.h" -#include "donau-httpd_metrics.h" #include <gnunet/gnunet_mhd_compat.h> @@ -41,22 +39,6 @@ /** - * Ensure coin is known in the database, and handle conflicts and errors. - * - * @param coin the coin to make known - * @param connection MHD request context - * @param[out] known_coin_id set to the unique ID for the coin in the DB - * @param[out] mhd_ret set to MHD status on error - * @return transaction status, negative on error (@a mhd_ret will be set in this case) - */ -enum GNUNET_DB_QueryStatus -DH_make_coin_known (const struct TALER_CoinPublicInfo *coin, - struct MHD_Connection *connection, - uint64_t *known_coin_id, - MHD_RESULT *mhd_ret); - - -/** * Function implementing a database 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 @@ -85,7 +67,6 @@ typedef enum GNUNET_DB_QueryStatus * * @param connection MHD connection to run @a cb for, can be NULL * @param name name of the transaction (for debugging) - * @param mt type of the requests, for metric generation * @param[out] mhd_ret set to MHD response code, if transaction failed (returned #GNUNET_SYSERR); * NULL if we are not running with a @a connection and thus * must not queue MHD replies @@ -96,7 +77,6 @@ typedef enum GNUNET_DB_QueryStatus enum GNUNET_GenericReturnValue DH_DB_run_transaction (struct MHD_Connection *connection, const char *name, - enum DH_MetricTypeRequest mt, MHD_RESULT *mhd_ret, DH_DB_TransactionCallback cb, void *cb_cls); diff --git a/src/donau/donau-httpd_history_get.c b/src/donau/donau-httpd_history_get.c @@ -28,13 +28,12 @@ #include "donau-httpd.h" #include "donaudb_plugin.h" #include "donau-httpd_history.h" -// #include "taler-exchange-httpd_metrics.h" /** * Maximum number of history we return per request. */ -#define MAX_RECORDS 1024 +// #define MAX_RECORDS 1024 /** * Return history information. diff --git a/src/donau/donau-httpd_keys.c b/src/donau/donau-httpd_keys.c @@ -326,7 +326,7 @@ struct KeysBuilderContext * Function called for all signing keys, used to build up the * respective JSON response. * - * @param cls a `struct SignKeyCtx *` with the array to append keys to + * @param cls a `struct KeysBuilderContext *` with the array to append keys to * @param pid the donau public key (in type disguise) * @param value a `struct SigningKey` * @return #GNUNET_OK (continue to iterate) @@ -361,7 +361,7 @@ add_sign_key_cb (void *cls, * and adds the remaining donation unit keys (with their configuration * data) to the JSON array. * - * @param cls the `struct FutureBuilderContext *` + * @param cls the `struct KeysBuilderContext *` * @param h_du_pub hash of the donation unit public key * @param value a `struct DH_DonationUnitKey` * @return #GNUNET_OK (continue to iterate) @@ -1441,4 +1441,35 @@ DH_keys_donation_unit_by_hash ( } +enum TALER_ErrorCode +DH_keys_donation_unit_cs_r_pub ( + const struct DONAU_DonationUnitHashP *h_donation_unit_pub, + const struct GNUNET_CRYPTO_CsSessionNonce *nonce, + struct GNUNET_CRYPTO_CSPublicRPairP *r_pub) +{ + struct DH_DonationUnitKey *dk; + dk = DH_keys_donation_unit_by_hash (&h_donation_unit_pub->hash); + if (NULL == dk) + { + return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN; + } + if (GNUNET_CRYPTO_BSA_CS != + dk->donation_unit_pub.bsign_pub_key->cipher) + { + return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; + } + + { + struct TALER_CRYPTO_CsDeriveRequest cdr = { + .h_cs = &dk->h_donation_unit_pub, + .nonce = nonce + }; + return TALER_CRYPTO_helper_cs_r_derive (csdh, + &cdr, + false, + r_pub); + } +} + + /* end of donau-httpd_keys.c */ diff --git a/src/donau/donau-httpd_keys.h b/src/donau/donau-httpd_keys.h @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2020-2023 Taler Systems SA + Copyright (C) 2023-2024 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -21,7 +21,6 @@ #include <taler/platform.h> #include <taler/taler_json_lib.h> #include <taler/taler_mhd_lib.h> -// #include "donau-httpd_responses.h" #include "donau_util.h" #include "donaudb_plugin.h" #include "donau-httpd.h" @@ -82,15 +81,15 @@ struct DH_BlindSignData }; /** - * Sign the message in @a purpose with the exchange's signing key. + * Sign the message in @a purpose with the doanu's signing key. * * The @a purpose data is the beginning of the data of which the signature is * to be created. The `size` field in @a purpose must correctly indicate the * number of bytes of the data structure, including its header. Use - * #TEH_keys_exchange_sign() instead of calling this function directly! + * #DH_keys_doanu_sign() instead of calling this function directly! * * @param purpose the message to sign - * @param[out] pub set to the current public signing key of the exchange + * @param[out] pub set to the current public signing key of the doanu * @param[out] sig signature over purpose using current signing key * @return #TALER_EC_NONE on success */ @@ -114,7 +113,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)); \ @@ -153,8 +152,6 @@ DH_handler_keys (struct DH_RequestContext *rc, * Look up the issue for a donation unit public key. * * @param h_du_pub hash of donation unit public key - * @param[in,out] conn used to return status message if NULL is returned - * @param[out] mret set to the MHD status if NULL is returned * @return the donation unit key issue, * or NULL if @a h_du_pub could not be found */ @@ -190,5 +187,18 @@ DH_keys_donation_unit_batch_sign ( const struct DONAU_BkpSignData bkps[num_bkps], struct DONAU_BlindedDonationUnitSignature du_sigs[num_bkps]); +/** + * Request to derive CS @a r_pub using the donation_unit and nonce from @a cdd. + * + * @param h_donation_unit_pub hash to compute @a r_pub from + * @param nonce + * @param[out] r_pub where to write the result + * @return #TALER_EC_NONE on success + */ +enum TALER_ErrorCode +DH_keys_donation_unit_cs_r_pub ( + const struct DONAU_DonationUnitHashP *h_donation_unit_pub, + const struct GNUNET_CRYPTO_CsSessionNonce *nonce, + struct GNUNET_CRYPTO_CSPublicRPairP *r_pub); #endif diff --git a/src/donau/donau-httpd_metrics.c b/src/donau/donau-httpd_metrics.c @@ -1,165 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2015-2021 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -*/ -/** - * @file donau-httpd_metrics.c - * @brief Handle /metrics requests - * @author Christian Grothoff - */ -#include <taler/platform.h> -#include <gnunet/gnunet_json_lib.h> -#include <taler/taler_dbevents.h> -// #include "donau-httpd_responses.h" -#include "donau-httpd_keys.h" -#include "donau-httpd_metrics.h" -#include <taler/taler_json_lib.h> -#include <taler/taler_mhd_lib.h> -#include <jansson.h> - - -unsigned long long DH_METRICS_num_requests[DH_MT_REQUEST_COUNT]; - -unsigned long long DH_METRICS_batch_withdraw_num_coins; - -unsigned long long DH_METRICS_num_conflict[DH_MT_REQUEST_COUNT]; - -unsigned long long DH_METRICS_num_signatures[DH_MT_SIGNATURE_COUNT]; - -unsigned long long DH_METRICS_num_verifications[DH_MT_SIGNATURE_COUNT]; - -unsigned long long DH_METRICS_num_keyexchanges[DH_MT_KEYX_COUNT]; - -unsigned long long DH_METRICS_num_success[DH_MT_SUCCESS_COUNT]; - - -MHD_RESULT -DH_handler_metrics (struct DH_RequestContext *rc, - const char *const args[]) -{ - char *reply; - struct MHD_Response *resp; - MHD_RESULT ret; - - (void) args; - GNUNET_asprintf (&reply, - "taler_exchange_success_transactions{type=\"%s\"} %llu\n" - "taler_exchange_success_transactions{type=\"%s\"} %llu\n" - "taler_exchange_success_transactions{type=\"%s\"} %llu\n" - "taler_exchange_success_transactions{type=\"%s\"} %llu\n" - "taler_exchange_success_transactions{type=\"%s\"} %llu\n" - "# HELP taler_exchange_serialization_failures " - " number of database serialization errors by type\n" - "# TYPE taler_exchange_serialization_failures counter\n" - "taler_exchange_serialization_failures{type=\"%s\"} %llu\n" - "taler_exchange_serialization_failures{type=\"%s\"} %llu\n" - "taler_exchange_serialization_failures{type=\"%s\"} %llu\n" - "taler_exchange_serialization_failures{type=\"%s\"} %llu\n" - "# HELP taler_exchange_received_requests " - " number of received requests by type\n" - "# TYPE taler_exchange_received_requests counter\n" - "taler_exchange_received_requests{type=\"%s\"} %llu\n" - "taler_exchange_received_requests{type=\"%s\"} %llu\n" - "taler_exchange_received_requests{type=\"%s\"} %llu\n" - "taler_exchange_received_requests{type=\"%s\"} %llu\n" - "taler_exchange_idempotent_requests{type=\"%s\"} %llu\n" -#if NOT_YET_IMPLEMENTED - "taler_exchange_idempotent_requests{type=\"%s\"} %llu\n" - "taler_exchange_idempotent_requests{type=\"%s\"} %llu\n" -#endif - "taler_exchange_idempotent_requests{type=\"%s\"} %llu\n" - "# HELP taler_exchange_num_signatures " - " number of signatures created by cipher\n" - "# TYPE taler_exchange_num_signatures counter\n" - "taler_exchange_num_signatures{type=\"%s\"} %llu\n" - "taler_exchange_num_signatures{type=\"%s\"} %llu\n" - "taler_exchange_num_signatures{type=\"%s\"} %llu\n" - "# HELP taler_exchange_num_signature_verifications " - " number of signatures verified by cipher\n" - "# TYPE taler_exchange_num_signature_verifications counter\n" - "taler_exchange_num_signature_verifications{type=\"%s\"} %llu\n" - "taler_exchange_num_signature_verifications{type=\"%s\"} %llu\n" - "taler_exchange_num_signature_verifications{type=\"%s\"} %llu\n" - "# HELP taler_exchange_num_keyexchanges " - " number of key exchanges done by cipher\n" - "# TYPE taler_exchange_num_keyexchanges counter\n" - "taler_exchange_num_keyexchanges{type=\"%s\"} %llu\n" - "# HELP taler_exchange_batch_withdraw_num_coins " - " number of coins withdrawn in a batch-withdraw request\n" - "# TYPE taler_exchange_batch_withdraw_num_coins counter\n" - "taler_exchange_batch_withdraw_num_coins{} %llu\n", - "deposit", - DH_METRICS_num_success[DH_MT_SUCCESS_DEPOSIT], - "withdraw", - DH_METRICS_num_success[DH_MT_SUCCESS_WITHDRAW], - "batch-withdraw", - DH_METRICS_num_success[DH_MT_SUCCESS_BATCH_WITHDRAW], - "melt", - DH_METRICS_num_success[DH_MT_SUCCESS_MELT], - "refresh-reveal", - DH_METRICS_num_success[DH_MT_SUCCESS_REFRESH_REVEAL], - "other", - DH_METRICS_num_conflict[DH_MT_REQUEST_OTHER], - "deposit", - DH_METRICS_num_conflict[DH_MT_REQUEST_DEPOSIT], - "withdraw", - DH_METRICS_num_conflict[DH_MT_REQUEST_WITHDRAW], - "melt", - DH_METRICS_num_conflict[DH_MT_REQUEST_MELT], - "other", - DH_METRICS_num_requests[DH_MT_REQUEST_OTHER], - "deposit", - DH_METRICS_num_requests[DH_MT_REQUEST_DEPOSIT], - "withdraw", - DH_METRICS_num_requests[DH_MT_REQUEST_WITHDRAW], - "melt", - DH_METRICS_num_requests[DH_MT_REQUEST_MELT], - "withdraw", - DH_METRICS_num_requests[DH_MT_REQUEST_IDEMPOTENT_WITHDRAW], -#if NOT_YET_IMPLEMENTED - "deposit", - DH_METRICS_num_requests[DH_MT_REQUEST_IDEMPOTENT_DEPOSIT], - "melt", - DH_METRICS_num_requests[DH_MT_REQUEST_IDEMPOTENT_MELT], -#endif - "batch-withdraw", - DH_METRICS_num_requests[ - DH_MT_REQUEST_IDEMPOTENT_BATCH_WITHDRAW], - "rsa", - DH_METRICS_num_signatures[DH_MT_SIGNATURE_RSA], - "cs", - DH_METRICS_num_signatures[DH_MT_SIGNATURE_CS], - "eddsa", - DH_METRICS_num_signatures[DH_MT_SIGNATURE_EDDSA], - "rsa", - DH_METRICS_num_verifications[DH_MT_SIGNATURE_RSA], - "cs", - DH_METRICS_num_verifications[DH_MT_SIGNATURE_CS], - "eddsa", - DH_METRICS_num_verifications[DH_MT_SIGNATURE_EDDSA], - "ecdh", - DH_METRICS_num_keyexchanges[DH_MT_KEYX_ECDH], - DH_METRICS_batch_withdraw_num_coins); - resp = MHD_create_response_from_buffer (strlen (reply), - reply, - MHD_RESPMEM_MUST_FREE); - ret = MHD_queue_response (rc->connection, - MHD_HTTP_OK, - resp); - MHD_destroy_response (resp); - return ret; -} - - -/* end of donau-httpd_metrics.c */ diff --git a/src/donau/donau-httpd_metrics.h b/src/donau/donau-httpd_metrics.h @@ -1,136 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2014--2021 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -*/ -/** - * @file donau-httpd_metrics.h - * @brief Handle /metrics requests - * @author Christian Grothoff - */ -#ifndef DONAU_HTTPD_METRICS_H -#define DONAU_HTTPD_METRICS_H - -#include <gnunet/gnunet_util_lib.h> -#include <microhttpd.h> -#include "donau-httpd.h" - - -/** - * Request types for which we collect metrics. - */ -enum DH_MetricTypeRequest -{ - DH_MT_REQUEST_OTHER = 0, - DH_MT_REQUEST_DEPOSIT = 1, - DH_MT_REQUEST_WITHDRAW = 2, - DH_MT_REQUEST_AGE_WITHDRAW = 3, - DH_MT_REQUEST_MELT = 4, - DH_MT_REQUEST_PURSE_CREATE = 5, - DH_MT_REQUEST_PURSE_MERGE = 6, - DH_MT_REQUEST_RESERVE_PURSE = 7, - DH_MT_REQUEST_PURSE_DEPOSIT = 8, - DH_MT_REQUEST_IDEMPOTENT_DEPOSIT = 9, - DH_MT_REQUEST_IDEMPOTENT_WITHDRAW = 10, - DH_MT_REQUEST_IDEMPOTENT_AGE_WITHDRAW = 11, - DH_MT_REQUEST_IDEMPOTENT_MELT = 12, - DH_MT_REQUEST_IDEMPOTENT_BATCH_WITHDRAW = 13, - DH_MT_REQUEST_BATCH_DEPOSIT = 14, - DH_MT_REQUEST_POLICY_FULFILLMENT = 15, - DH_MT_REQUEST_COUNT = 16 /* MUST BE LAST! */ -}; - -/** - * Success types for which we collect metrics. - */ -enum DH_MetricTypeSuccess -{ - DH_MT_SUCCESS_DEPOSIT = 0, - DH_MT_SUCCESS_WITHDRAW = 1, - DH_MT_SUCCESS_AGE_WITHDRAW = 2, - DH_MT_SUCCESS_BATCH_WITHDRAW = 3, - DH_MT_SUCCESS_MELT = 4, - DH_MT_SUCCESS_REFRESH_REVEAL = 5, - DH_MT_SUCCESS_AGE_WITHDRAW_REVEAL = 6, - DH_MT_SUCCESS_COUNT = 7 /* MUST BE LAST! */ -}; - -/** - * Cipher types for which we collect signature metrics. - */ -enum DH_MetricTypeSignature -{ - DH_MT_SIGNATURE_RSA = 0, - DH_MT_SIGNATURE_CS = 1, - DH_MT_SIGNATURE_EDDSA = 2, - DH_MT_SIGNATURE_COUNT = 3 -}; - -/** - * Cipher types for which we collect key exchange metrics. - */ -enum DH_MetricTypeKeyX -{ - DH_MT_KEYX_ECDH = 0, - DH_MT_KEYX_COUNT = 1 -}; - -/** - * Number of requests handled of the respective type. - */ -extern unsigned long long DH_METRICS_num_requests[DH_MT_REQUEST_COUNT]; - -/** - * Number of successful requests handled of the respective type. - */ -extern unsigned long long DH_METRICS_num_success[DH_MT_SUCCESS_COUNT]; - -/** - * Number of coins withdrawn in a batch-withdraw request - */ -extern unsigned long long DH_METRICS_batch_withdraw_num_coins; - -/** - * Number of serialization errors encountered when - * handling requests of the respective type. - */ -extern unsigned long long DH_METRICS_num_conflict[DH_MT_REQUEST_COUNT]; - -/** - * Number of signatures created by the respective cipher. - */ -extern unsigned long long DH_METRICS_num_signatures[DH_MT_SIGNATURE_COUNT]; - -/** - * Number of signatures verified by the respective cipher. - */ -extern unsigned long long DH_METRICS_num_verifications[DH_MT_SIGNATURE_COUNT]; - -/** - * Number of key exchanges done with the respective cipher. - */ -extern unsigned long long DH_METRICS_num_keyexchanges[DH_MT_KEYX_COUNT]; - -/** - * Handle a "/metrics" request. - * - * @param rc request context - * @param args array of additional options (must be empty for this function) - * @return MHD result code - */ -MHD_RESULT -DH_handler_metrics (struct DH_RequestContext *rc, - const char *const args[]); - - -#endif diff --git a/src/donau/donau-httpd_mhd.c b/src/donau/donau-httpd_mhd.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2020 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 Affero General Public License as published by the Free Software diff --git a/src/donau/donau-httpd_mhd.h b/src/donau/donau-httpd_mhd.h @@ -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 Affero General Public License as published by the Free Software diff --git a/src/donau/donau-httpd_terms.c b/src/donau/donau-httpd_terms.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2019, 2021 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 Affero General Public License as published by the Free Software @@ -25,7 +25,6 @@ #include <microhttpd.h> #include <taler/taler_mhd_lib.h> #include "donau-httpd_terms.h" -// #include "donau-httpd_responses.h" /** * Our terms of service. diff --git a/src/donau/donau-httpd_terms.h b/src/donau/donau-httpd_terms.h @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2019, 2021 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 Affero General Public License as published by the Free Software @@ -27,7 +27,6 @@ #include <microhttpd.h> #include <taler/taler_mhd_lib.h> #include "donau-httpd.h" -// #include "donau-httpd_responses.h" /** diff --git a/src/donaudb/0002-donation_units.sql b/src/donaudb/0002-donation_units.sql @@ -25,7 +25,3 @@ COMMENT ON TABLE donation_units IS 'Main donation_unit table. All the valid donation units the Donau knows about.'; COMMENT ON COLUMN donation_units.value IS 'Value the donation unit has in Taler amount'; - --- CREATE INDEX IF NOT EXISTS donation_units_by_validity_year --- ON donation_units --- (validity_year); diff --git a/src/donaudb/donau-0001.sql b/src/donaudb/donau-0001.sql @@ -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 diff --git a/src/donaudb/donau-0002.sql.in b/src/donaudb/donau-0002.sql.in @@ -1,6 +1,6 @@ -- -- This file is part of TALER --- Copyright (C) 2014--2023 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 diff --git a/src/donaudb/donau_do_amount_specific.sql b/src/donaudb/donau_do_amount_specific.sql @@ -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 diff --git a/src/donaudb/pg_commit.c b/src/donaudb/pg_commit.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 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 diff --git a/src/donaudb/pg_commit.h b/src/donaudb/pg_commit.h @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 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 diff --git a/src/donaudb/pg_create_tables.c b/src/donaudb/pg_create_tables.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 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 @@ -16,7 +16,7 @@ /** * @file donaudb/pg_create_tables.c * @brief Implementation of the create_tables function for Postgres - * @author Christian Grothoff + * @author Johannes Casaburi */ #include <taler/platform.h> #include <taler/taler_error_codes.h> diff --git a/src/donaudb/pg_create_tables.h b/src/donaudb/pg_create_tables.h @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 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 @@ -16,7 +16,7 @@ /** * @file donaudb/pg_create_tables.h * @brief implementation of the create_tables function for Postgres - * @author Christian Grothoff + * @author Johannes Casaburi */ #ifndef PG_CREATE_TABLES_H #define PG_CREATE_TABLES_H diff --git a/src/donaudb/pg_get_history.c b/src/donaudb/pg_get_history.c @@ -57,7 +57,7 @@ struct GetHistoryContext /** * Invoke the callback for each result. * - * @param cls a `struct MissingWireContext *` + * @param cls a `struct GetHistoryContext *` * @param result SQL result * @param num_results number of rows in @a result */ diff --git a/src/donaudb/pg_get_history.h b/src/donaudb/pg_get_history.h @@ -24,16 +24,16 @@ #include "donaudb_plugin.h" /** - * Obtain information about the enabled wire accounts of the exchange. + * Obtain history of charities. * * @param cls closure - * @param cb function to call on each account + * @param cb function to call on each result * @param cb_cls closure for @a cb * @return transaction status code */ enum GNUNET_DB_QueryStatus DH_PG_get_history (void *cls, - DONAUDB_GetHistoryCallback cb, - void *cb_cls); + DONAUDB_GetHistoryCallback cb, + void *cb_cls); #endif diff --git a/src/donaudb/pg_insert_donation_unit.h b/src/donaudb/pg_insert_donation_unit.h @@ -29,10 +29,10 @@ * Add donation unit key. * * @param cls closure - * @param donation_unit_pub the actual donation_unit key * @param donation_unit_hash hash of the public key - * @param value value that the donation unit represents + * @param donation_unit_pub the actual donation_unit key * @param validity_year validity year + * @param value value that the donation unit represents * @return transaction status code */ enum GNUNET_DB_QueryStatus diff --git a/src/donaudb/pg_insert_submitted_receipts.h b/src/donaudb/pg_insert_submitted_receipts.h @@ -31,6 +31,7 @@ * * @param cls closure * @param h_donor_tax_id salted hash of the donors tax number + * @param num_dr number of donation receipts * @param donation_receipts array of donation receipts * @param donation_year year of the donation * @return transaction status code diff --git a/src/donaudb/pg_iterate_submitted_receipts.h b/src/donaudb/pg_iterate_submitted_receipts.h @@ -29,8 +29,7 @@ * @param cls closure * @param donation_year donation year * @param h_donor_tax_id hash of donor tax id - * @param cb function to call on each account - * @param cb_cls closure for @a cb + * @param[out] total_donations amount of total donations * @return transaction status code */ enum GNUNET_DB_QueryStatus diff --git a/src/donaudb/pg_lookup_charity.h b/src/donaudb/pg_lookup_charity.h @@ -25,10 +25,11 @@ #include <taler/taler_json_lib.h> #include "donaudb_plugin.h" /** - * Fetch information about a donation unit key. + * Fetch information about a charity. * * @param cls the @e cls of this struct with the plugin-specific state - * @param[out] info information with value and other info about the coin + * @param charity_id the charity id + * @param meta charity meta data information * @return transaction status code */ enum GNUNET_DB_QueryStatus diff --git a/src/donaudb/pg_lookup_issued_receipts.h b/src/donaudb/pg_lookup_issued_receipts.h @@ -28,7 +28,8 @@ * Fetch information about an issued receipts request. * * @param cls the @e cls of this struct with the plugin-specific state - * @param[out] info information with value and other info about the issued receipts + * @param h_receipts hash over the issued receipt + * @param meta information with value and other info about the issued receipts * @return transaction status code */ enum GNUNET_DB_QueryStatus @@ -36,4 +37,5 @@ DH_PG_lookup_issued_receipts ( void *cls, struct DONAU_DonationReceiptHashP *h_receipts, struct DONAUDB_IssuedReceiptsMetaData *meta); + #endif diff --git a/src/donaudb/test_donaudb.c b/src/donaudb/test_donaudb.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2023 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 @@ -16,9 +16,7 @@ /** * @file donaudb/test_donaudb.c * @brief test cases for DB interaction functions - * @author Sree Harsha Totakura - * @author Christian Grothoff - * @author Marcello Stanisci + * @author Johannes Casaburi */ #include <taler/platform.h> #include <taler/taler_json_lib.h> @@ -34,25 +32,25 @@ static int result; * Report line of error if @a cond is true, and jump to label "drop". */ #define FAILIF(cond) \ - do { \ - if (! (cond)) { break;} \ - GNUNET_break (0); \ - goto drop; \ - } while (0) + do { \ + if (! (cond)) { break;} \ + GNUNET_break (0); \ + goto drop; \ + } while (0) /** * Initializes @a ptr with random data. */ #define RND_BLK(ptr) \ - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (* \ - ptr)) + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (* \ + ptr)) /** * Initializes @a ptr with zeros. */ #define ZR_BLK(ptr) \ - memset (ptr, 0, sizeof (*ptr)) + memset (ptr, 0, sizeof (*ptr)) /**