From f8b1c3f8db15acc441097950bed13532854e45f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Kesim?= Date: Mon, 7 Feb 2022 09:06:51 +0100 Subject: [PATCH] Debugging session of withdraw with age restriction --- src/exchange/taler-exchange-httpd_keys.c | 33 +++++++++------------ src/exchangedb/plugin_exchangedb_postgres.c | 8 ++--- src/extensions/extension_age_restriction.c | 14 +++++++++ src/include/taler_exchangedb_plugin.h | 2 +- src/include/taler_extensions.h | 7 +++++ src/lib/exchange_api_handle.c | 3 ++ src/testing/Makefile.am | 1 + src/testing/test_exchange_api.c | 8 +++-- src/testing/testing_api_helpers_exchange.c | 1 + 9 files changed, 51 insertions(+), 26 deletions(-) diff --git a/src/exchange/taler-exchange-httpd_keys.c b/src/exchange/taler-exchange-httpd_keys.c index 98242e869..542140f28 100644 --- a/src/exchange/taler-exchange-httpd_keys.c +++ b/src/exchange/taler-exchange-httpd_keys.c @@ -743,23 +743,13 @@ static struct TALER_AgeMask load_age_mask (const char*section_name) { static const struct TALER_AgeMask null_mask = {0}; - struct TALER_AgeMask age_mask = {0}; - /* TODO: optimize by putting this into global? */ - const struct TALER_Extension *age_ext = - TALER_extensions_get_by_type (TALER_Extension_AgeRestriction); + struct TALER_AgeMask age_mask; - // Get the age mask from the extension, if configured - /* TODO: optimize by putting this into global? */ - if (TALER_extensions_is_enabled (age_ext)) - age_mask = *(struct TALER_AgeMask *) age_ext->config; + TALER_extensions_init (); + age_mask = TALER_extensions_age_restriction_ageMask (); if (age_mask.mask == 0) - { - /* Age restriction support is not enabled. Ignore the AGE_RESTRICTED field - * for the particular denomination and simply return the null_mask - */ return null_mask; - } if (GNUNET_OK == (GNUNET_CONFIGURATION_have_value ( TEH_cfg, @@ -1771,7 +1761,7 @@ create_krd (struct TEH_KeyStateHandle *ksh, GNUNET_assert (0 == r); } - // Special case for age restrictions: if enabled, provide the lits of + // Special case for age restrictions: if enabled, provide the list of // age-restricted denominations. if (age_restriction_enabled && NULL != age_restricted_denoms) @@ -1975,12 +1965,14 @@ finish_keys_response (struct TEH_KeyStateHandle *ksh) /* Put the denom into the correct array - denoms or age_restricted_denoms - * depending on the settings and the properties of the denomination */ if (age_restriction_active && - (0 != dk->denom_pub.age_mask.mask)) + (0 != dk->meta.age_mask.mask)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "got agerestricted denom %p with mask %d\n", + "got agerestricted denom %p (mask %d) with mask %x (%s)\n", &dk->denom_pub, - dk->denom_pub.age_mask.mask); + dk->denom_pub.age_mask.mask, + dk->meta.age_mask.mask, + TALER_age_mask_to_string (&dk->meta.age_mask)); array = age_restricted_denoms; } else @@ -2672,7 +2664,10 @@ load_extension_data (const char *section_name, TEH_currency); return GNUNET_SYSERR; } - meta->age_restrictions = load_age_mask (section_name); + meta->age_mask = load_age_mask (section_name); + if (0 != meta->age_mask.mask) + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "XXXX age mask is NON zero: %s!\n", + TALER_age_mask_to_string (&meta->age_mask)); return GNUNET_OK; } @@ -2799,7 +2794,7 @@ add_future_denomkey_cb (void *cls, struct FutureBuilderContext *fbc = cls; struct HelperDenomination *hd = value; struct TEH_DenominationKey *dk; - struct TALER_EXCHANGEDB_DenominationKeyMetaData meta; + struct TALER_EXCHANGEDB_DenominationKeyMetaData meta = {0}; dk = GNUNET_CONTAINER_multihashmap_get (fbc->ksh->denomkey_map, h_denom_pub); diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 1a99c56e0..cb28a9bf8 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -3357,10 +3357,10 @@ dominations_cb_helper (void *cls, for (unsigned int i = 0; iconfig = &_config; @@ -277,6 +280,10 @@ age_restriction_load_json_config ( this->config_json = jconfig; + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "loaded new age restriction config with age groups: %s\n", + TALER_age_mask_to_string (&mask)); + return GNUNET_OK; } @@ -350,6 +357,13 @@ TALER_extensions_age_restriction_enabled () } +struct TALER_AgeMask +TALER_extensions_age_restriction_ageMask () +{ + return _config.mask; +} + + size_t TALER_extensions_age_restriction_num_groups () { diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index 4efc95724..8fbd1b77e 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -643,7 +643,7 @@ struct TALER_EXCHANGEDB_DenominationKeyMetaData * A value of 0 means that the denomination does not support the extension for * age-restriction. */ - struct TALER_AgeMask age_restrictions; + struct TALER_AgeMask age_mask; }; diff --git a/src/include/taler_extensions.h b/src/include/taler_extensions.h index cb09297b5..b95f3e7f3 100644 --- a/src/include/taler_extensions.h +++ b/src/include/taler_extensions.h @@ -238,6 +238,13 @@ TALER_age_mask_to_string ( bool TALER_extensions_age_restriction_enabled (); +/** + * Returns the currently set age mask + */ +struct TALER_AgeMask +TALER_extensions_age_restriction_ageMask (); + + /** * Returns the amount of age groups defined. 0 means no age restriction * enabled. diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index c76845f5c..26c0c5d53 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -829,6 +829,9 @@ decode_keys_json (const json_t *resp_obj, EXITIF (GNUNET_OK != TALER_extensions_load_json_config (extensions)); } + + /* 4. assuming we might have now a new value for age_mask, set it in key_data */ + key_data->age_mask = TALER_extensions_age_restriction_ageMask (); } /* parse the denomination keys, merging with the diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index af456bb77..5b9e0294d 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -209,6 +209,7 @@ test_exchange_api_LDADD = \ -lgnunetcurl \ -lgnunetutil \ -ljansson \ + -ltalerextensions \ $(XLIB) test_exchange_management_api_SOURCES = \ diff --git a/src/testing/test_exchange_api.c b/src/testing/test_exchange_api.c index 83f7cb4b7..e5ff061f6 100644 --- a/src/testing/test_exchange_api.c +++ b/src/testing/test_exchange_api.c @@ -33,6 +33,7 @@ #include "taler_bank_service.h" #include "taler_fakebank_lib.h" #include "taler_testing_lib.h" +#include "taler_extensions.h" /** * Configuration file we use. One (big) configuration is used @@ -983,12 +984,12 @@ run (void *cls, TALER_TESTING_cmd_auditor_add ("add-auditor-OK", MHD_HTTP_NO_CONTENT, false), + TALER_TESTING_cmd_exec_offline_sign_extensions ("offline-sign-extensions", + CONFIG_FILE), TALER_TESTING_cmd_wire_add ("add-wire-account", "payto://x-taler-bank/localhost/2", MHD_HTTP_NO_CONTENT, false), - TALER_TESTING_cmd_exec_offline_sign_extensions ("offline-sign-extensions", - CONFIG_FILE), TALER_TESTING_cmd_exec_offline_sign_keys ("offline-sign-future-keys", CONFIG_FILE), TALER_TESTING_cmd_exec_offline_sign_fees ("offline-sign-fees", @@ -1042,6 +1043,9 @@ main (int argc, GNUNET_log_setup ("test-exchange-api", "INFO", NULL); + + TALER_extensions_init (); + /* Check fakebank port is available and get config */ if (GNUNET_OK != TALER_TESTING_prepare_fakebank (CONFIG_FILE, diff --git a/src/testing/testing_api_helpers_exchange.c b/src/testing/testing_api_helpers_exchange.c index 382e4f05a..06531453f 100644 --- a/src/testing/testing_api_helpers_exchange.c +++ b/src/testing/testing_api_helpers_exchange.c @@ -27,6 +27,7 @@ #include "taler_json_lib.h" #include #include "taler_signatures.h" +#include "taler_extensions.h" #include "taler_testing_lib.h" /**