donau

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

commit 76fa63265e0b90a7e10120a7605d8a749b9e6230
parent dc30ef2ae7ba4c4169ce6a8da3d7af81b3612913
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Sun,  7 Jan 2024 17:35:25 +0100

[lib] implementation key api roughly completed

Diffstat:
Msrc/include/donau_crypto_lib.h | 11+++++++++++
Msrc/lib/donau_api_handle.c | 299+++++++------------------------------------------------------------------------
Msrc/util/donau_crypto.c | 36++++++++++++++++++++++++++++++++++++
3 files changed, 71 insertions(+), 275 deletions(-)

diff --git a/src/include/donau_crypto_lib.h b/src/include/donau_crypto_lib.h @@ -334,6 +334,17 @@ struct DONAU_DonationUnitGroup }; /** + * Compute a unique key for the meta data of a donation unit group. + * + * @param dg donation unit group to evaluate + * @param[out] key key to set + */ +void +DONAU_donation_unit_group_get_key ( + const struct DONAU_DonationUnitGroup *dg, + struct GNUNET_HashCode *key); + +/** * @brief Inputs needed from the donau for blind signing. */ struct TALER_DonauBatchIssueValues diff --git a/src/lib/donau_api_handle.c b/src/lib/donau_api_handle.c @@ -205,7 +205,7 @@ decode_keys_json (const json_t *resp_obj, struct DONAU_Keys *key_data, enum DONAU_VersionCompatibility *vc) { - //struct DONAU_DonauPublicKeyP pub; + //struct DONAU_SigningPublicKeyAndValidity donau_pub; const json_t *sign_keys_array; const json_t *donation_units_by_group; @@ -269,9 +269,9 @@ decode_keys_json (const json_t *resp_obj, { const char *currency; struct GNUNET_JSON_Specification mspec[] = { - // GNUNET_JSON_spec_fixed_auto ( - // "eddsa_pub", - // &pub), + // GNUNET_JSON_spec_fixed_auto ( // already in signkeys? + // "donau_pub", + // &donau_pub), GNUNET_JSON_spec_array_const ( "signkeys", // naming convention? &sign_keys_array), @@ -288,7 +288,7 @@ decode_keys_json (const json_t *resp_obj, if (GNUNET_OK != GNUNET_JSON_parse (resp_obj, - mspec, // ask how this is done + mspec, &emsg, &eline)) { @@ -326,7 +326,7 @@ decode_keys_json (const json_t *resp_obj, key_data->sign_keys = GNUNET_new_array (key_data->num_sign_keys, - struct DONAU_SigningPublicKey); + struct DONAU_SigningPublicKeyAndValidity); json_array_foreach (sign_keys_array, index, sign_key_obj) { EXITIF (GNUNET_SYSERR == parse_json_signkey (&key_data->sign_keys[index], @@ -350,13 +350,13 @@ decode_keys_json (const json_t *resp_obj, { /* First, parse { cipher, value, hash } of the current group. */ - struct DONAU_DonationUnitGroup group = {0}; + struct DONAU_DonationUnitGroup group = {0}; // what must be given to be a part of a group? const json_t *donation_unit_keys_array; struct GNUNET_JSON_Specification group_spec[] = { - TALER_JSON_spec_denomination_group (NULL, // TODO: check method + TALER_JSON_spec_denomination_group (NULL, // TODO: write method key_data->currency, &group), - GNUNET_JSON_spec_array_const ("donation_units", // TODO: check method + GNUNET_JSON_spec_array_const ("donation_units", &donation_unit_keys_array), GNUNET_JSON_spec_end () }; @@ -836,21 +836,19 @@ add_grp (void *cls, switch (gd->meta.cipher) { case GNUNET_CRYPTO_BSA_RSA: - cipher = age_restricted ? "RSA+age_restricted" : "RSA"; + cipher = "RSA"; break; case GNUNET_CRYPTO_BSA_CS: - cipher = age_restricted ? "CS+age_restricted" : "CS"; + cipher = "CS"; break; default: GNUNET_assert (false); } ge = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_data_auto ("hash", - &gd->meta.hash), GNUNET_JSON_pack_string ("cipher", cipher), - GNUNET_JSON_pack_array_steal ("denoms", + GNUNET_JSON_pack_array_steal ("donation_units", gd->json), TALER_JSON_pack_amount ("value", &gd->meta.value)); @@ -862,80 +860,18 @@ add_grp (void *cls, } -/** - * Convert array of account restrictions @a ars to JSON. - * - * @param ar_len length of @a ars - * @param ars account restrictions to convert - * @return JSON representation - */ -static json_t * -ar_to_json (unsigned int ar_len, - const struct TALER_DONAU_AccountRestriction ars[static ar_len]) -{ - json_t *rval; - - rval = json_array (); - GNUNET_assert (NULL != rval); - for (unsigned int i = 0; i<ar_len; i++) - { - const struct TALER_DONAU_AccountRestriction *ar = &ars[i]; - - switch (ar->type) - { - case TALER_DONAU_AR_INVALID: - GNUNET_break (0); - json_decref (rval); - return NULL; - case TALER_DONAU_AR_DENY: - GNUNET_assert ( - 0 == - json_array_append_new ( - rval, - GNUNET_JSON_PACK ( - GNUNET_JSON_pack_string ("type", - "deny")))); - break; - case TALER_DONAU_AR_REGEX: - GNUNET_assert ( - 0 == - json_array_append_new ( - rval, - GNUNET_JSON_PACK ( - GNUNET_JSON_pack_string ( - "type", - "regex"), - GNUNET_JSON_pack_string ( - "regex", - ar->details.regex.posix_egrep), - GNUNET_JSON_pack_string ( - "human_hint", - ar->details.regex.human_hint), - GNUNET_JSON_pack_object_incref ( - "human_hint_i18n", - (json_t *) ar->details.regex.human_hint_i18n) - ))); - break; - } - } - return rval; -} - - json_t * DONAU_keys_to_json (const struct DONAU_Keys *kd) { json_t *keys; json_t *signkeys; json_t *donation_units; - json_t *accounts; - now = GNUNET_TIME_timestamp_get (); signkeys = json_array (); GNUNET_assert (NULL != signkeys); for (unsigned int i = 0; i<kd->num_sign_keys; i++) { - const struct TALER_DONAU_SigningPublicKey *sk = &kd->sign_keys[i]; + const struct DONAU_SigningPublicKeyAndValidity *sk = &kd->sign_keys[i]; json_t *signkey; signkey = GNUNET_JSON_PACK ( @@ -954,24 +890,22 @@ DONAU_keys_to_json (const struct DONAU_Keys *kd) { struct GNUNET_CONTAINER_MultiHashMap *dbg; - dbg = GNUNET_CONTAINER_multihashmap_create (128, + dbg = GNUNET_CONTAINER_multihashmap_create (128, // why 128 and why do we need a multihashmap (remove doubles?), why are the timestamps not included? false); for (unsigned int i = 0; i<kd->num_donation_unit_keys; i++) { const struct DONAU_DonationUnitInformation *dk = &kd->donation_unit_keys[i]; - struct TALER_DenominationGroup meta = { - .cipher = dk->key.cipher, - .value = dk->value, - .year = dk->year + struct DONAU_DonationUnitGroup meta = { + .cipher = dk->key.bsign_pub_key->cipher, + .value = dk->value + //.year = dk->year ?? }; struct GNUNET_HashCode key; struct GroupData *gd; json_t *donation_unit; struct GNUNET_JSON_PackSpec key_spec; - //TODO: check year - - TALER_donation_unit_group_get_key (&meta, + DONAU_donation_unit_group_get_key (&meta, &key); gd = GNUNET_CONTAINER_multihashmap_get (dbg, &key); @@ -1009,16 +943,8 @@ DONAU_keys_to_json (const struct DONAU_Keys *kd) GNUNET_assert (false); } donation_unit = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_timestamp ("stamp_expire_deposit", - dk->expire_deposit), - GNUNET_JSON_pack_timestamp ("stamp_expire_withdraw", - dk->withdraw_valid_until), - GNUNET_JSON_pack_timestamp ("stamp_start", - dk->valid_from), - GNUNET_JSON_pack_timestamp ("stamp_expire_legal", - dk->expire_legal), - GNUNET_JSON_pack_data_auto ("master_sig", - &dk->master_sig), + GNUNET_JSON_pack_data_varsize ("year", + dk->year), key_spec ); GNUNET_assert (0 == @@ -1031,191 +957,14 @@ DONAU_keys_to_json (const struct DONAU_Keys *kd) GNUNET_CONTAINER_multihashmap_destroy (dbg); } - auditors = json_array (); - GNUNET_assert (NULL != auditors); - for (unsigned int i = 0; i<kd->num_auditors; i++) - { - const struct TALER_DONAU_AuditorInformation *ai = &kd->auditors[i]; - json_t *a; - json_t *adenoms; - - adenoms = json_array (); - GNUNET_assert (NULL != adenoms); - for (unsigned int j = 0; j<ai->num_donation_unit_keys; j++) - { - const struct TALER_DONAU_AuditorDenominationInfo *adi = - &ai->donation_unit_keys[j]; - const struct DONAU_DonationUnitInformation *dk = - &kd->donation_unit_keys[adi->denom_key_offset]; - json_t *k; - - GNUNET_assert (adi->denom_key_offset < kd->num_donation_unit_keys); - if (GNUNET_TIME_timestamp_cmp (now, - >, - dk->expire_deposit)) - continue; /* skip auditor signatures for donation unit keys that have expired */ - GNUNET_assert (adi->denom_key_offset < kd->num_donation_unit_keys); - k = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_data_auto ("denom_pub_h", - &dk->h_key), - GNUNET_JSON_pack_data_auto ("auditor_sig", - &adi->auditor_sig)); - GNUNET_assert (0 == - json_array_append_new (adenoms, - k)); - } - - a = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_data_auto ("auditor_pub", - &ai->auditor_pub), - GNUNET_JSON_pack_string ("auditor_url", - ai->auditor_url), - GNUNET_JSON_pack_array_steal ("donation_unit_keys", - adenoms)); - GNUNET_assert (0 == - json_array_append_new (auditors, - a)); - } - - global_fees = json_array (); - GNUNET_assert (NULL != global_fees); - for (unsigned int i = 0; i<kd->num_global_fees; i++) - { - const struct TALER_DONAU_GlobalFee *gf - = &kd->global_fees[i]; - - if (GNUNET_TIME_absolute_is_past (gf->end_date.abs_time)) - continue; - GNUNET_assert ( - 0 == - json_array_append_new ( - global_fees, - GNUNET_JSON_PACK ( - GNUNET_JSON_pack_timestamp ("start_date", - gf->start_date), - GNUNET_JSON_pack_timestamp ("end_date", - gf->end_date), - TALER_JSON_PACK_GLOBAL_FEES (&gf->fees), - GNUNET_JSON_pack_time_rel ("history_expiration", - gf->history_expiration), - GNUNET_JSON_pack_time_rel ("purse_timeout", - gf->purse_timeout), - GNUNET_JSON_pack_uint64 ("purse_account_limit", - gf->purse_account_limit), - GNUNET_JSON_pack_data_auto ("master_sig", - &gf->master_sig)))); - } - - accounts = json_array (); - GNUNET_assert (NULL != accounts); - for (unsigned int i = 0; i<kd->accounts_len; i++) - { - const struct TALER_DONAU_WireAccount *acc - = &kd->accounts[i]; - json_t *credit_restrictions; - json_t *debit_restrictions; - - credit_restrictions - = ar_to_json (acc->credit_restrictions_length, - acc->credit_restrictions); - GNUNET_assert (NULL != credit_restrictions); - debit_restrictions - = ar_to_json (acc->debit_restrictions_length, - acc->debit_restrictions); - GNUNET_assert (NULL != debit_restrictions); - GNUNET_assert ( - 0 == - json_array_append_new ( - accounts, - GNUNET_JSON_PACK ( - GNUNET_JSON_pack_string ("payto_uri", - acc->payto_uri), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("conversion_url", - acc->conversion_url)), - GNUNET_JSON_pack_array_steal ("debit_restrictions", - debit_restrictions), - GNUNET_JSON_pack_array_steal ("credit_restrictions", - credit_restrictions), - GNUNET_JSON_pack_data_auto ("master_sig", - &acc->master_sig)))); - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Serialized %u/%u wire accounts to JSON\n", - (unsigned int) json_array_size (accounts), - kd->accounts_len); - - wire_fees = json_object (); - GNUNET_assert (NULL != wire_fees); - for (unsigned int i = 0; i<kd->fees_len; i++) - { - const struct TALER_DONAU_WireFeesByMethod *fbw - = &kd->fees[i]; - json_t *wf; - - wf = json_array (); - GNUNET_assert (NULL != wf); - for (struct TALER_DONAU_WireAggregateFees *p = fbw->fees_head; - NULL != p; - p = p->next) - { - GNUNET_assert ( - 0 == - json_array_append_new ( - wf, - GNUNET_JSON_PACK ( - TALER_JSON_pack_amount ("wire_fee", - &p->fees.wire), - TALER_JSON_pack_amount ("closing_fee", - &p->fees.closing), - GNUNET_JSON_pack_timestamp ("start_date", - p->start_date), - GNUNET_JSON_pack_timestamp ("end_date", - p->end_date), - GNUNET_JSON_pack_data_auto ("sig", - &p->master_sig)))); - } - GNUNET_assert (0 == - json_object_set_new (wire_fees, - fbw->method, - wf)); - } - - recoup = json_array (); - GNUNET_assert (NULL != recoup); - for (unsigned int i = 0; i<kd->num_donation_unit_keys; i++) - { - const struct DONAU_DonationUnitInformation *dk - = &kd->donation_unit_keys[i]; - if (! dk->revoked) - continue; - GNUNET_assert (0 == - json_array_append_new ( - recoup, - GNUNET_JSON_PACK ( - GNUNET_JSON_pack_data_auto ("h_denom_pub", - &dk->h_key)))); - } - - wblwk = json_array (); - GNUNET_assert (NULL != wblwk); - for (unsigned int i = 0; i<kd->wblwk_length; i++) - { - const struct TALER_Amount *a = &kd->wallet_balance_limit_without_kyc[i]; - - GNUNET_assert (0 == - json_array_append_new ( - wblwk, - TALER_JSON_from_amount (a))); - } - keys = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("version", kd->version), GNUNET_JSON_pack_string ("currency", kd->currency), - GNUNET_JSON_pack_uint64 ("currency_fraction_digits", - kd->currency_fraction_digits), + GNUNET_JSON_pack_object_steal ("currency_specification", + TALER_CONFIG_currency_specs_to_json ( + &kd->currency_specification)), GNUNET_JSON_pack_array_steal ("signkeys", signkeys), GNUNET_JSON_pack_array_steal ("donation_units", diff --git a/src/util/donau_crypto.c b/src/util/donau_crypto.c @@ -90,4 +90,40 @@ DONAU_donation_unit_pub_free (struct DONAU_DonationUnitPublicKey *donation_unit_ GNUNET_CRYPTO_blind_sign_pub_decref (donation_unit_pub->bsign_pub_key); donation_unit_pub->bsign_pub_key = NULL; } +} + + +GNUNET_NETWORK_STRUCT_BEGIN +/** + * Structure we hash to compute the group key for + * a donation unit group. + */ +struct DonationUnitGroupP +{ + /** + * Value of coins in this donation unit group. + */ + struct TALER_AmountNBO value; + + /** + * Cipher used for the denomination, in NBO. + */ + uint32_t cipher GNUNET_PACKED; +}; +GNUNET_NETWORK_STRUCT_END + +void +DONAU_donatin_unit_group_get_key ( + const struct DONAU_DonationUnitGroup *dg, + struct GNUNET_HashCode *key) +{ + struct DonationUnitGroupP dgp = { + .cipher = htonl (dg->cipher) + }; + + TALER_amount_hton (&dgp.value, + &dg->value); + GNUNET_CRYPTO_hash (&dgp, + sizeof (dgp), + key); } \ No newline at end of file