donau

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

commit eefa711d3289fb444411452a4985946fa56c721e
parent 3420b088d28c5e8579ddcf46621508f599cb6757
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
Date:   Tue, 28 May 2024 23:49:01 +0200

fix tests for donaudb

Diffstat:
Msrc/donaudb/test_donaudb.c | 176++++++++++++++++++++++++++-----------------------------------------------------
1 file changed, 57 insertions(+), 119 deletions(-)

diff --git a/src/donaudb/test_donaudb.c b/src/donaudb/test_donaudb.c @@ -52,6 +52,10 @@ static int result; #define ZR_BLK(ptr) \ memset (ptr, 0, sizeof (*ptr)) +/** + * How big do we make the RSA keys? + */ +#define RSA_KEY_SIZE 1024 /** * Currency we use. Must match test-donau-db-*.conf. @@ -134,99 +138,6 @@ iterate_active_signing_keys_cb ( } -#if 0 -struct DenomKeyPair -{ - struct TALER_DenominationPrivateKey priv; - struct TALER_DenominationPublicKey pub; -}; - - -/** - * Create a denomination key pair by registering the denomination in the DB. - * - * @param size the size of the denomination key - * @param now time to use for key generation, legal expiration will be 3h later. - * @param fees fees to use - * @return the denominaiton key pair; NULL upon error - */ -static struct DenomKeyPair * -create_denom_key_pair (unsigned int size, - struct GNUNET_TIME_Timestamp now, - const struct TALER_Amount *value, - const struct TALER_DenomFeeSet *fees) -{ - struct DenomKeyPair *dkp; - struct TALER_EXCHANGEDB_DenominationKey dki; - struct TALER_EXCHANGEDB_DenominationKeyInformation issue2; - - dkp = GNUNET_new (struct DenomKeyPair); - GNUNET_assert (GNUNET_OK == - TALER_denom_priv_create (&dkp->priv, - &dkp->pub, - GNUNET_CRYPTO_BSA_RSA, - size)); - /* Using memset() as fields like master key and signature - are not properly initialized for this test. */ - memset (&dki, - 0, - sizeof (struct TALER_EXCHANGEDB_DenominationKey)); - dki.denom_pub = dkp->pub; - dki.issue.start = now; - dki.issue.expire_withdraw - = GNUNET_TIME_absolute_to_timestamp ( - GNUNET_TIME_absolute_add ( - now.abs_time, - GNUNET_TIME_UNIT_HOURS)); - dki.issue.expire_deposit - = GNUNET_TIME_absolute_to_timestamp ( - GNUNET_TIME_absolute_add ( - now.abs_time, - GNUNET_TIME_relative_multiply ( - GNUNET_TIME_UNIT_HOURS, 2))); - dki.issue.expire_legal - = GNUNET_TIME_absolute_to_timestamp ( - GNUNET_TIME_absolute_add ( - now.abs_time, - GNUNET_TIME_relative_multiply ( - GNUNET_TIME_UNIT_HOURS, 3))); - dki.issue.value = *value; - dki.issue.fees = *fees; - TALER_denom_pub_hash (&dkp->pub, - &dki.issue.denom_hash); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - plugin->insert_denomination_info (plugin->cls, - &dki.denom_pub, - &dki.issue)) - { - GNUNET_break (0); - destroy_denom_key_pair (dkp); - return NULL; - } - memset (&issue2, 0, sizeof (issue2)); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - plugin->get_denomination_info (plugin->cls, - &dki.issue.denom_hash, - &issue2)) - { - GNUNET_break (0); - destroy_denom_key_pair (dkp); - return NULL; - } - if (0 != GNUNET_memcmp (&dki.issue, - &issue2)) - { - GNUNET_break (0); - destroy_denom_key_pair (dkp); - return NULL; - } - return dkp; -} - - -#endif - - /** * Main function that will be run by the scheduler. * @@ -251,7 +162,6 @@ run (void *cls) // Donation unit information struct DONAU_DonationUnitHashP h_donation_unit_pub; - struct DONAU_DonationUnitPublicKey donation_unit_pub; uint64_t validity_year; struct TALER_Amount du_value; @@ -339,8 +249,17 @@ run (void *cls) charity_id)); /* test insert donation unit */ - RND_BLK (&donation_unit_pub); RND_BLK (&h_donation_unit_pub); + struct TALER_DenominationPrivateKey denom_priv; + struct TALER_DenominationPublicKey denom_pub; + GNUNET_assert (GNUNET_OK == + TALER_denom_priv_create (&denom_priv, + &denom_pub, + GNUNET_CRYPTO_BSA_RSA, + RSA_KEY_SIZE)); + struct DONAU_DonationUnitPublicKey du_pub = { + .bsign_pub_key = denom_pub.bsign_pub_key + }; validity_year = 2024; GNUNET_assert (GNUNET_OK == @@ -353,19 +272,20 @@ run (void *cls) &donation_unit_info_cb, NULL)); - // FIXME - // FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - // plugin->insert_donation_unit (plugin->cls, - // &h_donation_unit_pub, - // &donation_unit_pub, - // validity_year, - // &du_value)); + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->insert_donation_unit (plugin->cls, + &h_donation_unit_pub, + &du_pub, + validity_year, + &du_value)); - // /* test iterate donation units */ - // FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - // plugin->iterate_donation_units (plugin->cls, - // &donation_unit_info_cb, - // NULL)); + /* test iterate donation units */ + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->iterate_donation_units (plugin->cls, + &donation_unit_info_cb, + NULL)); + + TALER_denom_pub_free (&denom_pub); /* test insert signing key */ RND_BLK (&donau_pub); @@ -386,22 +306,40 @@ run (void *cls) NULL)); /* test insert issued receipt */ - RND_BLK (&du_sigs); - RND_BLK (&h_receipt); + struct GNUNET_CRYPTO_BlindedMessage *rp; + struct GNUNET_CRYPTO_RsaBlindedMessage *rsa; + rp = GNUNET_new (struct GNUNET_CRYPTO_BlindedMessage); + rp->cipher = GNUNET_CRYPTO_BSA_RSA; + rp->rc = 1; + rsa = &rp->details.rsa_blinded_message; + rsa->blinded_msg_size = 1 + (size_t) GNUNET_CRYPTO_random_u64 ( + GNUNET_CRYPTO_QUALITY_WEAK, + (RSA_KEY_SIZE / 8) - 1); + rsa->blinded_msg = GNUNET_malloc (rsa->blinded_msg_size); + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, + rsa->blinded_msg, + rsa->blinded_msg_size); smaller_than_max_per_year = false; GNUNET_assert (GNUNET_OK == TALER_string_to_amount (CURRENCY ":1.000010", &amount_receipts)); - // FIXME - // FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - // plugin->insert_issued_receipt (plugin->cls, - // num_b_sigs, - // du_sigs, - // charity_id, - // &h_receipt, - // &amount_receipts, - // &smaller_than_max_per_year)); + du_sigs[0].blinded_sig = + GNUNET_CRYPTO_blind_sign (denom_priv.bsign_priv_key, + "rw", + rp); + + GNUNET_assert (NULL != du_sigs[0].blinded_sig); + TALER_denom_priv_free (&denom_priv); + + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->insert_issued_receipt (plugin->cls, + num_b_sigs, + du_sigs, + charity_id, + &h_receipt, + &amount_receipts, + &smaller_than_max_per_year)); // FIXME // FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != @@ -413,7 +351,7 @@ run (void *cls) // RND_BLK (&h_donor_tax_id); // RND_BLK (&donation_receipts[0].h_donation_unit_pub); // RND_BLK (&donation_receipts[0].nonce); - // RND_BLK (&donation_receipts[0].donau_sig); + // RND_BLK (&donation_receipts[0].donation_unit_sig); // FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != // plugin->insert_submitted_receipts (plugin->cls, // &h_donor_tax_id,