From c1a5a932980452c18252ab38e4fb270ee69211a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Kesim?= Date: Tue, 8 Feb 2022 10:53:16 +0100 Subject: [PATCH] Added global TEH_age_restriction_enabled and TEH_age_mask Both flags are set when the DB-event for extensions triggers and the type is TALER_Extension_AgeRestriction. --- src/exchange/taler-exchange-httpd.c | 6 +++++ src/exchange/taler-exchange-httpd.h | 6 +++++ .../taler-exchange-httpd_extensions.c | 22 ++++++++++++++----- src/exchange/taler-exchange-httpd_keys.c | 19 +++++++++------- 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c index 6a6e7aae7..52224655f 100644 --- a/src/exchange/taler-exchange-httpd.c +++ b/src/exchange/taler-exchange-httpd.c @@ -126,6 +126,12 @@ char *TEH_currency; */ char *TEH_base_url; +/** + * Age restriction flags and mask + */ +bool TEH_age_restriction_enabled = false; +struct TALER_AgeMask TEH_age_mask = {0}; + /** * Default timeout in seconds for HTTP requests. */ diff --git a/src/exchange/taler-exchange-httpd.h b/src/exchange/taler-exchange-httpd.h index d3b1ba84a..ffbce0e9b 100644 --- a/src/exchange/taler-exchange-httpd.h +++ b/src/exchange/taler-exchange-httpd.h @@ -186,6 +186,12 @@ extern struct TALER_EXCHANGEDB_Plugin *TEH_plugin; */ extern char *TEH_currency; +/* + * Age restriction extension state + */ +extern bool TEH_age_restriction_enabled; +extern struct TALER_AgeMask TEH_age_mask; + /** * Our (externally visible) base URL. */ diff --git a/src/exchange/taler-exchange-httpd_extensions.c b/src/exchange/taler-exchange-httpd_extensions.c index e46fc1b45..6894a0762 100644 --- a/src/exchange/taler-exchange-httpd_extensions.c +++ b/src/exchange/taler-exchange-httpd_extensions.c @@ -127,6 +127,16 @@ extension_update_event_cb (void *cls, GNUNET_break (0); } } + + /* Special case age restriction: Update global flag and mask */ + if (TALER_Extension_AgeRestriction == type) + { + TEH_age_mask.mask = 0; + TEH_age_restriction_enabled = + TALER_extensions_age_restriction_is_enabled (); + if (TEH_age_restriction_enabled) + TEH_age_mask = TALER_extensions_age_restriction_ageMask (); + } } @@ -151,18 +161,18 @@ TEH_extensions_init () return GNUNET_SYSERR; } - /* Trigger the initial load of configuration from the db */ - for (const struct TALER_Extension *it = TALER_extensions_get_head (); - NULL != it->next; - it = it->next) - extension_update_event_cb (NULL, &it->type, sizeof(it->type)); - /* FIXME: shall we load the extensions from the config right away? * We do have to for now, as otherwise denominations with age restriction * will not have the age mask set right upon initial generation. */ TALER_extensions_load_taler_config (TEH_cfg); + /* Trigger the initial load of configuration from the db */ + for (const struct TALER_Extension *it = TALER_extensions_get_head (); + NULL != it->next; + it = it->next) + extension_update_event_cb (NULL, &it->type, sizeof(it->type)); + return GNUNET_OK; } diff --git a/src/exchange/taler-exchange-httpd_keys.c b/src/exchange/taler-exchange-httpd_keys.c index 2696a6bc6..4a68ef56a 100644 --- a/src/exchange/taler-exchange-httpd_keys.c +++ b/src/exchange/taler-exchange-httpd_keys.c @@ -1708,7 +1708,8 @@ create_krd (struct TEH_KeyStateHandle *ksh, int r; /* skip if not configured == disabled */ - if (NULL == extension->config) + if (NULL == extension->config || + NULL == extension->config_json) continue; /* flag our findings so far */ @@ -1848,8 +1849,6 @@ finish_keys_response (struct TEH_KeyStateHandle *ksh) struct GNUNET_CONTAINER_Heap *heap; struct GNUNET_HashContext *hash_context = NULL; struct GNUNET_HashContext *hash_context_restricted = NULL; - bool age_restriction_active = - TALER_extensions_is_enabled_type (TALER_Extension_AgeRestriction); bool have_age_restricted_denoms = false; sctx.signkeys = json_array (); @@ -1883,11 +1882,10 @@ finish_keys_response (struct TEH_KeyStateHandle *ksh) /* If age restriction is enabled, initialize the array of age restricted denoms and prepare a hash for them, separate from the others. We will join those hashes afterwards.*/ - if (age_restriction_active) + if (TEH_age_restriction_enabled) { age_restricted_denoms = json_array (); GNUNET_assert (NULL != age_restricted_denoms); - hash_context_restricted = GNUNET_CRYPTO_hash_context_start (); } @@ -1906,6 +1904,11 @@ finish_keys_response (struct TEH_KeyStateHandle *ksh) { struct GNUNET_HashCode hc; + /* FIXME-oec: Do we need to take hash_context_restricted into account + * in this if-branch!? Current tests suggests: no, (they don't fail). + * But something seems to be odd about only finishing hash_context. + */ + GNUNET_CRYPTO_hash_context_finish ( GNUNET_CRYPTO_hash_context_copy (hash_context), &hc); @@ -1971,7 +1974,7 @@ finish_keys_response (struct TEH_KeyStateHandle *ksh) /* Put the denom into the correct array depending on the settings and * the properties of the denomination. Also, we build up the right * hash for the corresponding array. */ - if (age_restriction_active && + if (TEH_age_restriction_enabled && (0 != dk->denom_pub.age_mask.mask)) { have_age_restricted_denoms = true; @@ -2005,7 +2008,7 @@ finish_keys_response (struct TEH_KeyStateHandle *ksh) /* If age restriction is active and we had at least one denomination of * that sort, we simply add the hash of all age restricted denominations at * the end of the others. */ - if (age_restriction_active && have_age_restricted_denoms) + if (TEH_age_restriction_enabled && have_age_restricted_denoms) { struct GNUNET_HashCode hcr; GNUNET_CRYPTO_hash_context_finish (hash_context_restricted, &hcr); @@ -2030,7 +2033,7 @@ finish_keys_response (struct TEH_KeyStateHandle *ksh) "Failed to generate key response data for %s\n", GNUNET_TIME_timestamp2s (last_cpd)); json_decref (denoms); - if (age_restriction_active && NULL != age_restricted_denoms) + if (TEH_age_restriction_enabled && NULL != age_restricted_denoms) json_decref (age_restricted_denoms); json_decref (sctx.signkeys); json_decref (recoup);