donau

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

commit a75ce444954b6d10c48b94ae6950bfab56363533
parent 52e2d2c22b1d86b65cf2ed823a4057a9ab7f7f84
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Fri,  5 Jan 2024 21:52:01 +0100

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

Diffstat:
Asrc/donau/donau-httpd_get-charity.c | 118+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/pg_lookup_charity.c | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/pg_lookup_charity.h | 40++++++++++++++++++++++++++++++++++++++++
Msrc/include/donau_crypto_lib.h | 4++--
Msrc/include/donaudb_plugin.h | 26+++++++++++++-------------
Msrc/util/donau_signatures.c | 2+-
6 files changed, 231 insertions(+), 16 deletions(-)

diff --git a/src/donau/donau-httpd_get-charity.c b/src/donau/donau-httpd_get-charity.c @@ -0,0 +1,118 @@ +/* + This file is part of TALER + Copyright (C) 2023 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_charity-get.c + * @brief Return summary information about AML decision + * @author Johannes Casaburi + */ +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler/taler_json_lib.h" +#include "taler/taler_mhd_lib.h" +#include "taler/taler_signatures.h" +#include "donau-httpd.h" +#include "donaudb_plugin.h" +#include "donau-httpd_aml-decision.h" +#include "donau-httpd_metrics.h" + + +/** + * Maximum number of records we return per request. + */ +#define MAX_RECORDS 1024 + +MHD_RESULT +DH_handler_charity_get ( + struct DH_RequestContext *rc, + const char *const args[]) +{ + unsigned long long charity_id; + + if ( (NULL == args[0]) || + (1 != sscanf (args[0], "%llu", &charity_id))) + { + GNUNET_break_op (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "charity_id"); + } + + if (NULL != args[1]) + { + GNUNET_break_op (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_ENDPOINT_UNKNOWN, + args[1]); + } + + { + char *charity_url; + char *charity_name; + enum GNUNET_DB_QueryStatus qs; + bool none = false; + MHD_RESULT result; + + GNUNET_assert (NULL != charity_info); + qs = DH_plugin->select_charity_info (DH_plugin->cls, + charity_id, + &charity_url, + &charity_name); + switch (qs) + { + case GNUNET_DB_STATUS_HARD_ERROR: + case GNUNET_DB_STATUS_SOFT_ERROR: + GNUNET_break (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: + if (none) + { + return TALER_MHD_reply_static ( + rc->connection, + MHD_HTTP_NO_CONTENT, + NULL, + NULL, + 0); + } + break; + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + break; + } + + result = TALER_MHD_REPLY_JSON_PACK ( + connection, + http_status, + TALER_MHD_PACK_EC (ec), + GNUNET_JSON_pack_string ("url", + charity_url), + GNUNET_JSON_pack_string ("name", + charity_name)); + + GNUNET_free (charity_url); + GNUNET_free (charity_name); + return result; + } +} + + +/* end of donau-httpd_aml-decision_get.c */ diff --git a/src/donaudb/pg_lookup_charity.c b/src/donaudb/pg_lookup_charity.c @@ -0,0 +1,57 @@ +/* + This file is part of TALER + 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 + 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 CHARITYABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file donaudb/pg_lookup_donation_unit_key.c + * @brief Implementation of the lookup_donation_unit_key function for Postgres + * @author Johannes Casaburi + */ +#include "taler/platform.h" +#include "taler/taler_error_codes.h" +#include "taler/taler_dbevents.h" +#include "taler/taler_pq_lib.h" +#include "pg_lookup_charity.h" +#include "pg_helper.h" + +enum GNUNET_DB_QueryStatus +DH_PG_lookup_charity ( + void *cls, + struct DONAUDB_CharityMetaData *meta) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (charity_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_query_param_string ("charity_url", + &meta->charity_url), + GNUNET_PQ_query_param_string ("charity_name", + &meta->charity_name), + GNUNET_PQ_result_spec_end + }; + + PREPARE (pg, + "lookup_charity", + "SELECT " + " charity_name" + " ,charity_url" + " FROM charities" + " WHERE charity_id=$1;"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "lookup_charity", + params, + rs); +} diff --git a/src/donaudb/pg_lookup_charity.h b/src/donaudb/pg_lookup_charity.h @@ -0,0 +1,40 @@ +/* + This file is part of TALER + 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 + 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 CHARITYABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file donaudb/pg_lookup_charity.h + * @brief implementation of the lookup_charity function for Postgres + * @author Johannes Casaburi + */ +#ifndef PG_GET_DONATION_UNIT_INFO_H +#define PG_GET_DONATION_UNIT_INFO_H + +#include <taler/taler_util.h> +#include "taler/taler_json_lib.h" +#include "donaudb_plugin.h" +/** + * Fetch information about a donation unit key. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param donation_unit_pub_hash hash of the public key + * @param[out] info information with value and other info about the coin + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DH_PG_lookup_charity ( + void *cls, + struct DONAUDB_CharityMetaData *meta); + +#endif diff --git a/src/include/donau_crypto_lib.h b/src/include/donau_crypto_lib.h @@ -40,7 +40,7 @@ /** * Regular online message signing key used by Donau. */ -struct DONAU_EddsaPublicKeyP +struct DONAU_DonauPublicKeyP { /** * Donau uses EdDSA for non-blind signing. @@ -277,7 +277,7 @@ DONAU_donation_statement_verify ( const struct TALER_Amount *amount_tot, const unsigned int year, const struct DONAU_HashDonorTaxId *i, - const struct DONAU_EddsaPublicKeyP *donau_pub, + const struct DONAU_DonauPublicKeyP *donau_pub, const struct DONAU_DonauSignatureP *statement_sig); diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h @@ -119,7 +119,7 @@ typedef void typedef void (*DONAUDB_ActiveSignkeysCallback)( void *cls, - const struct DONAU_EddsaPublicKeyP *donau_pub, + const struct DONAU_DonauPublicKeyP *donau_pub, const struct DONAUDB_SignkeyMetaData *meta); @@ -149,7 +149,7 @@ struct DONAUDB_Plugin * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure */ enum GNUNET_GenericReturnValue - (*drop_tables)(void *cls); + (*drop_tables)(void *cls); /** * Create the necessary tables if they are not present @@ -162,9 +162,9 @@ struct DONAUDB_Plugin * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure */ enum GNUNET_GenericReturnValue - (*create_tables)(void *cls, - bool support_partitions, - uint32_t num_partitions); + (*create_tables)(void *cls, + bool support_partitions, + uint32_t num_partitions); /** @@ -176,8 +176,8 @@ struct DONAUDB_Plugin * @return #GNUNET_OK on success */ enum GNUNET_GenericReturnValue - (*start)(void *cls, - const char *name); + (*start)(void *cls, + const char *name); /** @@ -189,8 +189,8 @@ struct DONAUDB_Plugin * @return #GNUNET_OK on success */ enum GNUNET_GenericReturnValue - (*start_read_committed)(void *cls, - const char *name); + (*start_read_committed)(void *cls, + const char *name); /** * Start a READ ONLY serializable transaction. @@ -201,8 +201,8 @@ struct DONAUDB_Plugin * @return #GNUNET_OK on success */ enum GNUNET_GenericReturnValue - (*start_read_only)(void *cls, - const char *name); + (*start_read_only)(void *cls, + const char *name); /** @@ -212,7 +212,7 @@ struct DONAUDB_Plugin * @return transaction status */ enum GNUNET_DB_QueryStatus - (*commit)(void *cls); + (*commit)(void *cls); /** @@ -226,7 +226,7 @@ struct DONAUDB_Plugin * #GNUNET_SYSERR on hard errors */ enum GNUNET_GenericReturnValue - (*preflight)(void *cls); + (*preflight)(void *cls); /** diff --git a/src/util/donau_signatures.c b/src/util/donau_signatures.c @@ -89,7 +89,7 @@ DONAU_donation_statement_verify ( const struct TALER_Amount *amount_tot, const unsigned int year, const struct DONAU_HashDonorTaxId *i, - const struct DONAU_EddsaPublicKeyP *donau_pub, + const struct DONAU_DonauPublicKeyP *donau_pub, const struct DONAU_DonauSignatureP *statement_sig) { struct DONAU_DonationStatementConfirmationPS tps = {