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.
This commit is contained in:
Özgür Kesim 2022-02-08 10:53:16 +01:00
parent a172610ce2
commit c1a5a93298
Signed by: oec
GPG Key ID: 3D76A56D79EDD9D7
4 changed files with 39 additions and 14 deletions

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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;
}

View File

@ -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);