commit 3461dced6502bba0bc661c09fee74add564139d5
parent 8097a08ab24e9b705a01c520df7b0aca852ef057
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
Date: Wed, 1 May 2024 15:21:24 +0200
added donau-httpd_donation-statement route
Diffstat:
8 files changed, 231 insertions(+), 26 deletions(-)
diff --git a/src/donau/Makefile.am b/src/donau/Makefile.am
@@ -47,6 +47,7 @@ donau_httpd_SOURCES = \
donau-httpd_charity_delete.c \
donau-httpd_charity_get.c donau-httpd_charity_insert.c \
donau-httpd_history_get.c \
+ 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_batch-issue.c donau_httpd_batch-issue.h
diff --git a/src/donau/donau-httpd.c b/src/donau/donau-httpd.c
@@ -32,6 +32,7 @@
#include "donau-httpd_config.h"
#include "donau-httpd_keys.h"
#include "donau-httpd_charity.h"
+#include "donau-httpd_donation-statement.h"
#include "donau-httpd_batch-issue.h"
#include "donau-httpd_batch-submit.h"
#include "donau-httpd_history.h"
@@ -510,6 +511,14 @@ handle_mhd_request (void *cls,
.method = MHD_HTTP_METHOD_POST,
.handler.post = &DH_handler_submit_receipts_post
},
+ /* GET donation statement */
+ {
+ .url = "donation-statement",
+ .method = MHD_HTTP_METHOD_GET,
+ .handler.get = &DH_handler_donation_statement_get,
+ .nargs = 2,
+ .nargs_is_upper_bound = true
+ },
/* mark end of list */
{
.url = NULL
diff --git a/src/donau/donau-httpd_batch-submit.c b/src/donau/donau-httpd_batch-submit.c
@@ -59,6 +59,7 @@ 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_end ()
@@ -67,7 +68,8 @@ parse_json_dr (struct DONAU_DonationReceipt *dr,
if (GNUNET_OK !=
GNUNET_JSON_parse (dr_obj,
spec,
- NULL, NULL))
+ NULL,
+ NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -115,8 +117,7 @@ DH_handler_submit_receipts_post (struct DH_RequestContext *rc,
if (0 == num_dr)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Empty array of donation receipts!\n");
+ GNUNET_break_op (0);
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_BAD_REQUEST,
TALER_EC_GENERIC_PARAMETER_MALFORMED,
@@ -170,6 +171,8 @@ DH_handler_submit_receipts_post (struct DH_RequestContext *rc,
&udi_hash,
&irc.donation_receipts[i].donation_unit_sig))
{
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Donation receipt signature invalid!\n");
// FIXME change error message
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_NOT_FOUND,
diff --git a/src/donau/donau-httpd_charity_get.c b/src/donau/donau-httpd_charity_get.c
@@ -14,8 +14,8 @@
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
+ * @file donau-httpd_charity_get.c
+ * @brief Return summary information about a charity
* @author Johannes Casaburi
*/
#include <taler/platform.h>
@@ -28,8 +28,6 @@
#include <taler/taler_signatures.h>
#include "donaudb_plugin.h"
#include "donau-httpd_charity.h"
-// #include "donau-httpd.h"
-// #include "donau-httpd_metrics.h"
/**
diff --git a/src/donau/donau-httpd_donation-statement.c b/src/donau/donau-httpd_donation-statement.c
@@ -0,0 +1,133 @@
+/*
+ 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 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_donation-statement_get.c
+ * @brief Return donation statement
+ * @author Johannes Casaburi
+ */
+#include <taler/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 "donaudb_plugin.h"
+#include "donau-httpd_keys.h"
+#include "donau-httpd_donation-statement.h"
+
+
+/**
+ * Maximum number of records we return per request.
+ */
+#define MAX_RECORDS 1024
+
+MHD_RESULT
+DH_handler_donation_statement_get (
+ struct DH_RequestContext *rc,
+ const char *const args[2])
+{
+ unsigned long long donation_year;
+ struct DONAU_HashDonorTaxId h_donor_tax_id;
+ char dummy;
+
+ if ( (NULL == args[0]) ||
+ (1 != sscanf (args[0],
+ "%llu%c",
+ &donation_year,
+ &dummy)) )
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "donation_year");
+ }
+
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[1],
+ strlen (args[1]),
+ &h_donor_tax_id,
+ sizeof (h_donor_tax_id)))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "h_donor_tax_id");
+ }
+
+ {
+ struct DONAU_DonauSignatureP ds;
+ struct TALER_Amount total_donations;
+ struct DONAU_DonauPublicKeyP donau_pub;
+ struct DONAU_DonauSignatureP donau_sig;
+ enum GNUNET_DB_QueryStatus qs;
+ MHD_RESULT result;
+
+ qs = DH_plugin->iterate_submitted_receipts (DH_plugin->cls,
+ (uint64_t) donation_year,
+ &h_donor_tax_id,
+ &total_donations);
+ 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:
+ return TALER_MHD_reply_static (
+ rc->connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+ break;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ if (TALER_EC_NONE !=
+ DONAU_donation_statement_sign (
+ &DH_keys_donau_sign_,
+ &total_donations,
+ donation_year,
+ &h_donor_tax_id,
+ &donau_pub,
+ &donau_sig))
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ NULL);
+ }
+ break;
+ }
+
+ result = TALER_MHD_REPLY_JSON_PACK (
+ rc->connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_data_auto ("donation_statement",
+ &ds));
+
+ return result;
+ }
+}
+
+
+/* end of donau-httpd_aml-decision_get.c */
diff --git a/src/donau/donau-httpd_donation-statement.h b/src/donau/donau-httpd_donation-statement.h
@@ -0,0 +1,41 @@
+/*
+ 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 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_donation-statement.h
+ * @brief Handle /donation-statement requests
+ * @author Johannes Casaburi
+ */
+#ifndef DONAU_HTTPD_DONATION_STATEMENT_H
+#define DONAU_HTTPD_DONATION_STATEMENT_H
+
+#include <microhttpd.h>
+#include "donau-httpd.h"
+#include "donaudb_plugin.h"
+
+
+/**
+ * Handle a GET "/charities/$YEAR/$H_DONOR_TAX_ID" request.
+ *
+ * @param rc request context
+ * @param args GET arguments (should be two)
+ * @return MHD result code
+ */
+MHD_RESULT
+DH_handler_donation_statement_get (
+ struct DH_RequestContext *rc,
+ const char *const args[2]);
+
+#endif
diff --git a/src/include/donau_crypto_lib.h b/src/include/donau_crypto_lib.h
@@ -410,24 +410,43 @@ DONAU_charity_bkp_verify (
/* ********************* donau eddsa signing ************************** */
+/**
+ * Signature of a function that signs the message in @a purpose with the
+ * exchange'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. *
+ * @param purpose the message to sign
+ * @param[out] pub set to the current public signing key of the exchange
+ * @param[out] sig signature over purpose using current signing key
+ * @return #TALER_EC_NONE on success
+ */
+typedef enum TALER_ErrorCode
+(*DONAU_DonauSignCallback)(
+ const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
+ struct DONAU_DonauPublicKeyP *pub,
+ struct DONAU_DonauSignatureP *sig);
/**
* Create donau eddsa signature. Another name for this
* is the donation statement.
*
+ * @param scb function to call to create the signature
* @param amount_tot total donated amount of @a year
* @param year
* @param i hash value, the identifier of the donor
- * @param donau_priv private key of the donau
- * @param[out] statement_sig where to write the signature
+ * @param donau_pub public key of the donau
+ * @param[out] donau_sig where to write the signature
*/
-void
+enum TALER_ErrorCode
DONAU_donation_statement_sign (
+ DONAU_DonauSignCallback scb,
const struct TALER_Amount *amount_tot,
- const uint32_t year,
+ const uint64_t year,
const struct DONAU_HashDonorTaxId *i,
- const struct DONAU_PrivateKeyP *donau_priv,
- struct DONAU_DonauSignatureP *statement_sig);
+ struct DONAU_DonauPublicKeyP *donau_pub,
+ struct DONAU_DonauSignatureP *donau_sig);
/**
@@ -657,8 +676,8 @@ DONAU_donation_unit_blind (
const struct DONAU_DonationUnitPublicKey *du_pub,
const union GNUNET_CRYPTO_BlindingSecretP *budi_secret,
const union GNUNET_CRYPTO_BlindSessionNonce *cs_nonce,
- const struct DONAU_UniqueDonorIdentifierNonce *udi_nonce,//message
- const struct DONAU_HashDonorTaxId *h_tax_id, //message
+ const struct DONAU_UniqueDonorIdentifierNonce *udi_nonce,// message
+ const struct DONAU_HashDonorTaxId *h_tax_id, // message
const struct DONAU_BatchIssueValues *alg_values,
struct DONAU_UniqueDonorIdentifierHashP *udi_hash,
struct DONAU_BlindedUniqueDonorIdentifier *budi);
diff --git a/src/util/donau_signatures.c b/src/util/donau_signatures.c
@@ -59,28 +59,28 @@ struct DONAU_DonationStatementConfirmationPS
GNUNET_NETWORK_STRUCT_END
-void
+enum TALER_ErrorCode
DONAU_donation_statement_sign (
+ DONAU_DonauSignCallback scb,
const struct TALER_Amount *amount_tot,
- const uint32_t year,
+ const uint64_t year,
const struct DONAU_HashDonorTaxId *i,
- const struct DONAU_PrivateKeyP *donau_priv,
- struct DONAU_DonauSignatureP *statement_sig)
+ struct DONAU_DonauPublicKeyP *donau_pub,
+ struct DONAU_DonauSignatureP *donau_sig)
{
- struct DONAU_DonationStatementConfirmationPS tps = {
- .purpose.size = htonl (sizeof (struct
- DONAU_DonationStatementConfirmationPS)),
+ struct DONAU_DonationStatementConfirmationPS confirm = {
.purpose.purpose = htonl (DONAU_SIGNATURE_DONAU_DONATION_STATEMENT),
+ .purpose.size = htonl (sizeof (confirm)),
.year = htonl (year),
.i = *i
};
- TALER_amount_hton (&tps.amount_tot,
+ TALER_amount_hton (&confirm.amount_tot,
amount_tot);
- GNUNET_CRYPTO_eddsa_sign (&donau_priv->eddsa_priv,
- &tps,
- &statement_sig->eddsa_sig);
+ return scb (&confirm.purpose,
+ donau_pub,
+ donau_sig);
}
@@ -110,4 +110,5 @@ DONAU_donation_statement_verify (
&donau_pub->eddsa_pub);
}
+
/* end of donau_signatures.c */