From 8684a9bfea9223808e33edca9f91b8bd76379fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Kesim?= Date: Sun, 23 Jan 2022 01:31:02 +0100 Subject: [age_restriction] progress 13/n - major refactoring of extensions - extensions live now in a separate library, libtalerextensions - refactored all components using age_restriction accordingly - plumbing for plugin support for extensions roughly layed down --- src/lib/Makefile.am | 1 + src/lib/exchange_api_handle.c | 71 ++++++++++++++++++------------------------- 2 files changed, 31 insertions(+), 41 deletions(-) (limited to 'src/lib') diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index dd4c527d5..3398bdf14 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -57,6 +57,7 @@ libtalerexchange_la_LIBADD = \ $(top_builddir)/src/json/libtalerjson.la \ $(top_builddir)/src/curl/libtalercurl.la \ $(top_builddir)/src/util/libtalerutil.la \ + $(top_builddir)/src/extensions/libtalerextensions.la \ -lgnunetcurl \ -lgnunetjson \ -lgnunetutil \ diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index aea09a81f..cf3d69d6a 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -795,50 +795,39 @@ decode_keys_json (const json_t *resp_obj, } /* Parse the supported extension(s): age-restriction. */ - /* TODO: maybe lift this into a FP in TALER_Extension ? */ + /* TODO: maybe lift all this into a FP in TALER_Extension ? */ { - json_t *age_restriction = json_object_get (resp_obj, - "age_restriction"); - - if (NULL != age_restriction) - { - bool critical; - const char *version; - const char *age_groups; - struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_bool ("critical", - &critical), - GNUNET_JSON_spec_string ("version", - &version), - GNUNET_JSON_spec_string ("age_groups", - &age_groups), - GNUNET_JSON_spec_end () - }; - - if (GNUNET_OK != - GNUNET_JSON_parse (age_restriction, - spec, - NULL, NULL)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + struct TALER_MasterSignatureP extensions_sig = {0}; + json_t *extensions = NULL; + struct GNUNET_JSON_Specification ext_spec[] = { + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_json ("extensions", + &extensions)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_fixed_auto ( + "extensions_sig", + &extensions_sig)), + GNUNET_JSON_spec_end () + }; - if (critical || // do we care? - 0 != strncmp (version, "1", 1) ) /* TODO: better compatibility check */ - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + /* 1. Search for extensions in the response to /keys */ + EXITIF (GNUNET_OK != + GNUNET_JSON_parse (resp_obj, + ext_spec, + NULL, NULL)); - if (GNUNET_OK != - TALER_parse_age_group_string (age_groups, - &key_data->age_mask)) - { - // TODO: print more specific error? - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + if (NULL != extensions) + { + /* 2. We have an extensions object. Verify its signature. */ + EXITIF (GNUNET_OK != + TALER_extensions_verify_json_config_signature ( + extensions, + &extensions_sig, + &key_data->master_pub)); + + /* 3. Parse and set the the configuration of the extensions accordingly */ + EXITIF (GNUNET_OK != + TALER_extensions_load_json_config (extensions)); } } -- cgit v1.2.3