commit db5ca33efd90ac28d84d74d8fec53e208a710967
parent f61103c3984b7f4d87a4e835e955ae79c0d8d5bb
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date: Tue, 18 Jun 2024 00:05:08 +0200
add qr prepare function
Diffstat:
7 files changed, 149 insertions(+), 2 deletions(-)
diff --git a/src/include/donau_crypto_lib.h b/src/include/donau_crypto_lib.h
@@ -381,6 +381,16 @@ struct DONAU_DonationStatement
struct DONAU_HashDonorTaxId *h_donor_tax_id;
/**
+ * The salt used for @h_donor_tax_id.
+ */
+ char *donor_tax_id;
+
+ /**
+ * The cleartext tax id of the user used for @h_donor_tax_id.
+ */
+ char *salt;
+
+ /**
* The total donated amount.
*/
struct TALER_Amount total_amount;
diff --git a/src/include/donau_util.h b/src/include/donau_util.h
@@ -42,4 +42,15 @@ DONAU_project_data_default (void);
void
DONAU_OS_init (void);
+// FIXME: remove public key, only needed for testing.
+/**
+ * Generates the String for the QR Code containing the donation statement.
+ *
+ * The returned string will be freshly allocated, and must be free'd
+ * with #GNUNET_free().
+ */
+char *
+generate_QR_string (struct DONAU_DonauPublicKeyP *pub_key,
+ struct DONAU_DonationStatement *donation_statement);
+
#endif
diff --git a/src/testing/testing_api_cmd_donation_statement_get.c b/src/testing/testing_api_cmd_donation_statement_get.c
@@ -122,6 +122,36 @@ donation_statement_status_cb (void *cls,
&ss->donation_statement.
donation_statement_sig))
{
+ char *end_pub;
+ char pub_str[sizeof (struct DONAU_DonauPublicKeyP) * 2];
+ end_pub = GNUNET_STRINGS_data_to_string (
+ &dsr->details.ok.donau_pub,
+ sizeof (struct DONAU_DonauPublicKeyP),
+ pub_str,
+ sizeof (pub_str));
+ *end_pub = '\0';
+
+ char *end_sig;
+ char sig_str[sizeof (struct DONAU_DonauSignatureP) * 2];
+ end_sig = GNUNET_STRINGS_data_to_string (
+ &ss->donation_statement.donation_statement_sig,
+ sizeof (struct DONAU_DonauSignatureP),
+ sig_str,
+ sizeof (sig_str));
+ *end_sig = '\0';
+// char *b64_pub;
+// GNUNET_STRINGS_base64_encode (&dsr->details.ok.donau_pub,
+// sizeof (struct DONAU_DonauPublicKeyP),
+// &b64_pub);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "eddsa_pub_key: %s\n", pub_str);
+// char *b64_sig;
+// GNUNET_STRINGS_base64_encode (&ss->donation_statement.
+// donation_statement_sig,
+// sizeof (struct DONAU_DonauSignatureP),
+// &b64_sig);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "sig: %s\n", sig_str);
TALER_TESTING_interpreter_next (ss->is);
return;
}
diff --git a/src/testing/testing_api_cmd_issue_receipts.c b/src/testing/testing_api_cmd_issue_receipts.c
@@ -462,7 +462,7 @@ cleanup (void *cls,
DONAU_charity_issue_receipt_cancel (ss->birh);
ss->birh = NULL;
}
-
+
GNUNET_free (ss);
}
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
@@ -23,7 +23,8 @@ libdonauutil_la_SOURCES = \
charity_signatures.c \
donau_signatures.c \
donau_os_installation.c \
- donau_crypto.c
+ donau_crypto.c \
+ qr.c
libdonauutil_la_LIBADD = \
-ltalerutil \
diff --git a/src/util/donau_signatures.c b/src/util/donau_signatures.c
@@ -102,6 +102,22 @@ DONAU_donation_statement_verify (
TALER_amount_hton (&confirm.amount_tot,
amount_tot);
+ // char *b64;
+ // GNUNET_STRINGS_base64_encode (&confirm,
+ // sizeof (struct DONAU_DonationStatementConfirmationPS),
+ // &b64);
+ char *end_message;
+ char message_str[sizeof (struct DONAU_DonationStatementConfirmationPS) * 2];
+ end_message = GNUNET_STRINGS_data_to_string (
+ &confirm,
+ sizeof (struct DONAU_DonationStatementConfirmationPS),
+ message_str,
+ sizeof (message_str));
+ *end_message = '\0';
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "message: %s\n message_size: %lu\n", message_str,
+ sizeof(confirm));
+
return
GNUNET_CRYPTO_eddsa_verify (DONAU_SIGNATURE_DONAU_DONATION_STATEMENT,
&confirm,
diff --git a/src/util/qr.c b/src/util/qr.c
@@ -0,0 +1,78 @@
+/*
+ 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 MERCHANTABILITY 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 qr.c
+ * @brief Utility functions for donation statement QR Code
+ * @author Lukas Matyja
+ */
+#include <taler/platform.h>
+#include <taler/taler_util.h>
+#include "donau_util.h"
+#include "donau_service.h"
+
+// FIXME: remove public key, only needed for testing.
+// The verification app should get the public key directly from the Donau.
+char *
+generate_QR_string (struct DONAU_DonauPublicKeyP *pub_key,
+ struct DONAU_DonationStatement *donation_statement)
+{
+ /* The string will be structured as follows: YEAR:TOTALAMOUNT:TAXID:TAXIDSALT:ED25519SIGNATURE:PUBKEY */
+ uint64_t total_size = 0;
+
+ char *total_amount_string = TALER_amount_to_string (
+ &donation_statement->total_amount);
+ total_size += strlen (total_amount_string);
+ total_size += strlen (donation_statement->donor_tax_id);
+ total_size += strlen (donation_statement->salt);
+
+ char *end_sig;
+ total_size += sizeof (struct DONAU_DonauSignatureP) * 2;
+ char sig_str[sizeof (struct DONAU_DonauSignatureP) * 2];
+ end_sig = GNUNET_STRINGS_data_to_string (
+ &donation_statement->donation_statement_sig,
+ sizeof (struct DONAU_DonauSignatureP),
+ sig_str,
+ sizeof (sig_str));
+ *end_sig = '\0';
+
+ char *end_pub;
+ total_size += sizeof (struct DONAU_DonauPublicKeyP) * 2;
+ char pub_str[sizeof (struct DONAU_DonauPublicKeyP) * 2];
+ end_pub = GNUNET_STRINGS_data_to_string (
+ pub_key,
+ sizeof (struct DONAU_DonauPublicKeyP),
+ pub_str,
+ sizeof (pub_str));
+ *end_pub = '\0';
+
+ char *qr_string = GNUNET_malloc (total_size + 1);
+ if (0 > GNUNET_snprintf (qr_string,
+ total_size,
+ "%llu:%s:%s:%s:%s:%s",
+ (unsigned long long)
+ donation_statement->year,
+ total_amount_string,
+ donation_statement->donor_tax_id,
+ donation_statement->salt,
+ sig_str,
+ pub_str))
+ {
+ return NULL;
+ }
+ ;
+
+ return qr_string;
+}
+\ No newline at end of file