From 1962ed6b0b44c6c7d3503b3340da1be147e25f87 Mon Sep 17 00:00:00 2001 From: Özgür Kesim Date: Sat, 22 Jan 2022 00:26:43 +0100 Subject: improvements in extension handling - extensions_sig is needed globally - keep original json with config of extension - fixed various bugs re: extension handling --- src/exchange/taler-exchange-httpd_keys.c | 92 ++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 22 deletions(-) (limited to 'src/exchange/taler-exchange-httpd_keys.c') diff --git a/src/exchange/taler-exchange-httpd_keys.c b/src/exchange/taler-exchange-httpd_keys.c index 30bbe8ebb..7c64cdb75 100644 --- a/src/exchange/taler-exchange-httpd_keys.c +++ b/src/exchange/taler-exchange-httpd_keys.c @@ -1703,29 +1703,79 @@ create_krd (struct TEH_KeyStateHandle *ksh, &TEH_kyc_config.wallet_balance_limit))); } - // Signal support for the age-restriction extension, if so configured, and - // add the array of age-restricted denominations. - if (TEH_extension_enabled (TALER_Extension_AgeRestriction) && - NULL != age_restricted_denoms) + // Signal support for the configured, enabled extensions. { - struct TALER_AgeMask *mask; - json_t *config; - - mask = (struct - TALER_AgeMask *) TEH_extensions[TALER_Extension_AgeRestriction]-> - config; - config = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_bool ("critical", false), - GNUNET_JSON_pack_string ("version", "1"), - GNUNET_JSON_pack_string ("age_groups", TALER_age_mask_to_string (mask))); - GNUNET_assert (NULL != config); - GNUNET_assert ( - 0 == - json_object_set_new ( + json_t *extensions = json_object (); + bool has_extensions; + + /* Fill in the configurations of the enabled extensions */ + for (struct TALER_Extension **it = TEH_extensions; + NULL != *it; + it++) + { + const struct TALER_Extension *extension = *it; + json_t *ext; + json_t *config_json; + int r; + + /* skip if not configured == disabled */ + if (NULL == extension->config) + continue; + + has_extensions = true; + + GNUNET_assert (NULL != extension->config_json); + + config_json = json_copy (extension->config_json); + GNUNET_assert (NULL != config_json); + + ext = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_bool ("critical", + extension->critical), + GNUNET_JSON_pack_string ("version", + extension->version), + GNUNET_JSON_pack_object_steal ("config", + config_json) + ); + GNUNET_assert (NULL != ext); + + r = json_object_set_new ( + extensions, + extension->name, + ext); + + GNUNET_assert (0 == r); + } + + /* Update the keys object with the extensions */ + if (has_extensions) + { + json_t *sig; + int r; + + r = json_object_set_new ( keys, - "age_restriction", - config)); + "extensions", + extensions); + GNUNET_assert (0 == r); + + /* add extensions_sig */ + sig = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_data_auto ("extensions_sig", + &TEH_extensions_sig)); + + /* update the keys object with extensions_sig */ + r = json_object_update (keys, sig); + GNUNET_assert (0 == r); + } + } + + // Special case for age restrictions: if enabled, provide the lits of + // age-restricted denominations. + if (TEH_extension_enabled (TALER_Extension_AgeRestriction) && + NULL != age_restricted_denoms) + { GNUNET_assert ( 0 == json_object_set_new ( @@ -1734,8 +1784,6 @@ create_krd (struct TEH_KeyStateHandle *ksh, age_restricted_denoms)); } - // TODO: signal support and configuration for the P2P extension, once - // implemented. { char *keys_json; -- cgit v1.2.3