commit 28ccd7d082392e36a899a7f4d06bb357a2d329d8
parent 7b3ec79e5c40664723edb68b17400af77c33d0b6
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date: Sat, 1 Jun 2024 15:00:39 +0200
fix donation statement route
Diffstat:
10 files changed, 84 insertions(+), 66 deletions(-)
diff --git a/src/donau/donau-httpd_batch-submit.c b/src/donau/donau-httpd_batch-submit.c
@@ -214,14 +214,14 @@ DH_handler_submit_receipts_post (struct DH_RequestContext *rc,
}
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "submitted receipts inserted!\n");
+ "submitted receipts inserted!\n");
return TALER_MHD_reply_static (
- rc->connection,
- MHD_HTTP_CREATED,
- NULL,
- NULL,
- 0);
+ rc->connection,
+ MHD_HTTP_CREATED,
+ NULL,
+ NULL,
+ 0);
}
diff --git a/src/donau/donau-httpd_donation-statement.c b/src/donau/donau-httpd_donation-statement.c
@@ -123,7 +123,8 @@ DH_handler_donation_statement_get (
MHD_HTTP_OK,
TALER_JSON_pack_amount ("total", &total_donations),
GNUNET_JSON_pack_data_auto ("donation_statement",
- &donau_sig));
+ &donau_sig),
+ GNUNET_JSON_pack_data_auto ("donau_pub", &donau_pub));
return result;
}
diff --git a/src/donau/donau-httpd_keys.c b/src/donau/donau-httpd_keys.c
@@ -1257,31 +1257,32 @@ DH_keys_donau_sign_ (
purpose,
&donau_pub,
&donau_sig);
- if (TALER_EC_NONE != ec)
- return ec;
- {
- /* Here we check here that 'pub' is set to an exchange public key that is
- actually signed by the master key! Otherwise, we happily continue to
- use key material even if the offline signatures have not been made
- yet! */
- struct GNUNET_PeerIdentity pid;
- struct SigningKey *sk;
-
- pid.public_key = pub->eddsa_pub;
- sk = GNUNET_CONTAINER_multipeermap_get (esign_keys,
- &pid);
- if (NULL == sk)
- {
- /* just to be safe, zero out the (valid) signature, as the key
- should not or no longer be used */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Cannot sign, offline key signatures are missing!\n");
- memset (sig,
- 0,
- sizeof (*sig));
- return TALER_EC_DONAU_SIGNKEY_HELPER_BUG;
- }
- }
+ // FIXME: To delete: We dont have offline keys!
+ // if (TALER_EC_NONE != ec)
+ // return ec;
+ // {
+ // /* Here we check here that 'pub' is set to an exchange public key that is
+ // actually signed by the master key! Otherwise, we happily continue to
+ // use key material even if the offline signatures have not been made
+ // yet! */
+ // struct GNUNET_PeerIdentity pid;
+ // struct SigningKey *sk;
+
+ // pid.public_key = pub->eddsa_pub;
+ // sk = GNUNET_CONTAINER_multipeermap_get (esign_keys,
+ // &pid);
+ // if (NULL == sk)
+ // {
+ // /* just to be safe, zero out the (valid) signature, as the key
+ // should not or no longer be used */
+ // GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ // "Cannot sign, offline key signatures are missing!\n");
+ // memset (sig,
+ // 0,
+ // sizeof (*sig));
+ // return TALER_EC_DONAU_SIGNKEY_HELPER_BUG;
+ // }
+ //}
return ec;
}
diff --git a/src/donaudb/donau_do_insert_submitted_receipts.sql b/src/donaudb/donau_do_insert_submitted_receipts.sql
@@ -39,7 +39,7 @@ LOOP
ini_h_donation_unit_pub = ina_h_donation_unit_pubs[i];
ini_donation_unit_sig = ina_donation_unit_sigs[i];
- out_conflict[i] = TRUE;
+ out_conflict[i] = FALSE;
INSERT INTO receipts_submitted
(h_tax_number
@@ -56,7 +56,6 @@ LOOP
,in_donation_year
)
ON CONFLICT DO NOTHING;
- out_conflict[i] = FALSE;
IF NOT FOUND
THEN
PERFORM FROM receipts_submitted
diff --git a/src/donaudb/pg_iterate_submitted_receipts.c b/src/donaudb/pg_iterate_submitted_receipts.c
@@ -38,16 +38,16 @@ DH_PG_iterate_submitted_receipts (
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint64 (&donation_year),
- GNUNET_PQ_query_param_auto_from_type (&h_donor_tax_id),
+ //GNUNET_PQ_query_param_auto_from_type (&h_donor_tax_id),
GNUNET_PQ_query_param_end
};
- uint64_t value;
- uint64_t fraction;
+ uint64_t valueSum = 0;
+ uint64_t fractionSum = 0;
struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("value",
- &value),
- GNUNET_PQ_result_spec_uint64 ("fraction",
- &fraction),
+ GNUNET_PQ_result_spec_uint64 ("valueSum",
+ &valueSum),
+ GNUNET_PQ_result_spec_uint64 ("fractionSum",
+ &fractionSum),
GNUNET_PQ_result_spec_end
};
enum GNUNET_DB_QueryStatus qs;
@@ -55,23 +55,23 @@ DH_PG_iterate_submitted_receipts (
PREPARE (pg,
"lookup_submitted_receipts",
"SELECT "
- " CAST(SUM((ref.amount_with_fee).val) AS INT8) AS value"
- ",CAST(SUM(CAST((value.amount_with_fee).frac AS INT8)) AS INT8) AS fraction"
- " FROM receipts_submitted"
- " JOIN donation_units USING (donation_unit_pub)"
- " WHERE donation_year=$1"
- " AND h_tax_number=$2");
+ " CAST(SUM((donation_units.value).val) AS INT8) AS valueSum"
+ ",CAST(SUM(CAST((donation_units.value).frac AS INT8)) AS INT8) AS fractionSum"
+ " FROM receipts_submitted ref"
+ " JOIN donation_units USING (h_donation_unit_pub)"
+ " WHERE donation_year=$1");
+ //" AND h_tax_number=$2");
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "iterate_submitted_receipts",
+ "lookup_submitted_receipts",
params,
rs);
if (qs < 0)
return qs;
- value += fraction / TALER_AMOUNT_FRAC_BASE;
- fraction %= TALER_AMOUNT_FRAC_BASE;
+ valueSum += fractionSum / TALER_AMOUNT_FRAC_BASE;
+ fractionSum %= TALER_AMOUNT_FRAC_BASE;
TALER_amount_set_zero (pg->currency,
total_donations);
- total_donations->value = value;
- total_donations->fraction = fraction;
+ total_donations->value = valueSum;
+ total_donations->fraction = fractionSum;
return qs;
}
diff --git a/src/include/donau_crypto_lib.h b/src/include/donau_crypto_lib.h
@@ -388,7 +388,7 @@ struct DONAU_DonationStatement
/**
* The donation statement signature over @year, @h_donor_tax_id and @total_amount.
*/
- struct DONAU_DonauSignatureP *donation_statement_sig;
+ struct DONAU_DonauSignatureP donation_statement_sig;
};
@@ -482,7 +482,7 @@ DONAU_donation_statement_sign (
enum GNUNET_GenericReturnValue
DONAU_donation_statement_verify (
const struct TALER_Amount *amount_tot,
- const uint32_t year,
+ const uint64_t year,
const struct DONAU_HashDonorTaxId *i,
const struct DONAU_DonauPublicKeyP *donau_pub,
const struct DONAU_DonauSignatureP *statement_sig);
diff --git a/src/include/donau_service.h b/src/include/donau_service.h
@@ -685,7 +685,12 @@ struct DONAU_DonationStatementResponse
* The donation statment for a requested year. Signature over the total amount,
* the year, the unique identifier hash
*/
- struct DONAU_DonauSignatureP *donation_statement_sig;
+ struct DONAU_DonauSignatureP donation_statement_sig;
+
+ /**
+ * The donau public to verify the signature.
+ */
+ struct DONAU_DonauPublicKeyP donau_pub;
} ok;
diff --git a/src/lib/donau_api_donation_statement_get.c b/src/lib/donau_api_donation_statement_get.c
@@ -97,9 +97,11 @@ handle_donation_statement_get_finished (void *cls,
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto (
"donation_statement",
- dsresp.details.ok.donation_statement_sig),
- TALER_JSON_spec_amount_any ("total_amount",
+ &dsresp.details.ok.donation_statement_sig),
+ TALER_JSON_spec_amount_any ("total",
&dsresp.details.ok.total_amount),
+ GNUNET_JSON_spec_fixed_auto("donau_pub",
+ &dsresp.details.ok.donau_pub),
GNUNET_JSON_spec_end ()
};
if (GNUNET_OK !=
@@ -170,7 +172,7 @@ prepare_url (
const char *donau_url)
{
char arg_str[sizeof (struct DONAU_HashDonorTaxId) * 2 + 32];
- char donor_id_hash_str[sizeof (struct DONAU_HashDonorTaxId) * 2];
+ char donor_id_hash_str[sizeof (struct DONAU_HashDonorTaxId) * 2 + 32];
char *end;
end = GNUNET_STRINGS_data_to_string (
diff --git a/src/testing/testing_api_cmd_donation_statement_get.c b/src/testing/testing_api_cmd_donation_statement_get.c
@@ -64,7 +64,7 @@ struct StatusState
* @param dsr HTTP response details
*/
static void
-charity_status_cb (void *cls,
+donation_statement_status_cb (void *cls,
const struct DONAU_DonationStatementResponse *dsr)
{
struct StatusState *ss = cls;
@@ -83,6 +83,17 @@ charity_status_cb (void *cls,
TALER_TESTING_interpreter_fail (ss->is);
return;
}
+ ss->donation_statement.total_amount = dsr->details.ok.total_amount;
+ ss->donation_statement.donation_statement_sig = dsr->details.ok.donation_statement_sig;
+ if (GNUNET_OK != DONAU_donation_statement_verify(&ss->donation_statement.total_amount,
+ ss->donation_statement.year,
+ ss->donation_statement.h_donor_tax_id,
+ &dsr->details.ok.donau_pub,
+ &ss->donation_statement.donation_statement_sig)) {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Verify donation statement signature failed!");
+ }
TALER_TESTING_interpreter_next (ss->is);
}
@@ -128,7 +139,7 @@ status_run (void *cls,
TALER_TESTING_get_donau_url (is),
ss->donation_statement.year,
ss->donation_statement.h_donor_tax_id,
- &charity_status_cb,
+ &donation_statement_status_cb,
ss);
}
diff --git a/src/util/donau_signatures.c b/src/util/donau_signatures.c
@@ -87,25 +87,24 @@ DONAU_donation_statement_sign (
enum GNUNET_GenericReturnValue
DONAU_donation_statement_verify (
const struct TALER_Amount *amount_tot,
- const uint32_t year,
+ const uint64_t year,
const struct DONAU_HashDonorTaxId *i,
const struct DONAU_DonauPublicKeyP *donau_pub,
const struct DONAU_DonauSignatureP *statement_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);
return
GNUNET_CRYPTO_eddsa_verify (DONAU_SIGNATURE_DONAU_DONATION_STATEMENT,
- &tps,
+ &confirm,
&statement_sig->eddsa_sig,
&donau_pub->eddsa_pub);
}