first steps adding extension data structures

This commit is contained in:
Özgür Kesim 2021-12-13 11:52:08 +01:00
parent 96304043fb
commit fe18b02ab6
Signed by: oec
GPG Key ID: 3D76A56D79EDD9D7
5 changed files with 125 additions and 67 deletions

View File

@ -750,7 +750,7 @@ load_age_mask (const char*section_name)
struct TALER_AgeMask age_mask = {0}; struct TALER_AgeMask age_mask = {0};
/* FIXME-oec: get age_mask from database, not from config */ /* FIXME-oec: get age_mask from database, not from config */
if (TALER_EXTENSION_OK != TALER_get_age_mask (TEH_cfg, &age_mask)) if (TALER_Extension_OK != TALER_get_age_mask (TEH_cfg, &age_mask))
{ {
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
TALER_EXTENSION_SECTION_AGE_RESTRICTION, TALER_EXTENSION_SECTION_AGE_RESTRICTION,
@ -761,6 +761,9 @@ load_age_mask (const char*section_name)
if (age_mask.mask == 0) 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; return null_mask;
} }

View File

@ -2619,8 +2619,9 @@ TALER_EXCHANGE_post_management_keys_cancel (
*/ */
struct TALER_EXCHANGE_ManagementPostExtensionsData struct TALER_EXCHANGE_ManagementPostExtensionsData
{ {
struct TALER_Extension *extensions;
/* FIXME-oec: define data structure */ struct TALER_MasterSignatureP *extension_sigs;
uint32_t num_extensions;
}; };
/** /**

View File

@ -26,17 +26,63 @@
#define TALER_EXTENSION_SECTION_PREFIX "exchange-extension-" #define TALER_EXTENSION_SECTION_PREFIX "exchange-extension-"
enum TALER_EXTENSION_ReturnValue enum TALER_Extension_ReturnValue
{ {
TALER_EXTENSION_OK = 0, TALER_Extension_OK = 0,
TALER_EXTENSION_ERROR_PARSING = 1, TALER_Extension_ERROR_PARSING = 1,
TALER_EXTENSION_ERROR_INVALID = 2, TALER_Extension_ERROR_INVALID = 2,
TALER_EXTENSION_ERROR_SYS = 3 TALER_Extension_ERROR_SYS = 3
};
enum TALER_Extension_Type
{
TALER_Extension_Peer2Peer = 0,
TALER_Extension_AgeRestriction = 1
};
struct TALER_Extension
{
enum TALER_Extension_Type type;
char *name;
bool critical;
void *config;
size_t config_size;
};
struct TALER_Peer2Peer_Config
{
// FIXME
};
/**
* g_TALER_Extensions_by_Type is the global manifest with the list supported
* extensions, sorted by TALER_Extension_Type.
*
* TODO: Mutex?
*
**/
struct TALER_Extension g_TALER_Extensions_by_Type[] = {
[TALER_Extension_Peer2Peer] = {
.type = TALER_Extension_Peer2Peer,
.name = "peer2peer",
.critical = false,
.config_size = sizeof(struct TALER_Peer2Peer_Config),
},
[TALER_Extension_AgeRestriction] = {
.type = TALER_Extension_AgeRestriction,
.name = "age_restriction",
.critical = false,
.config_size = sizeof(struct TALER_AgeMask),
},
}; };
/* /*
* TALER Age Restriction Extensions * TALER Peer2Peer Extension
*/
/*
* TALER Age Restriction Extension
*/ */
#define TALER_EXTENSION_SECTION_AGE_RESTRICTION (TALER_EXTENSION_SECTION_PREFIX \ #define TALER_EXTENSION_SECTION_AGE_RESTRICTION (TALER_EXTENSION_SECTION_PREFIX \
@ -55,7 +101,7 @@ enum TALER_EXTENSION_ReturnValue
* @param[out] mask Mask representation for age restriction. * @param[out] mask Mask representation for age restriction.
* @return Error, if age groups were invalid, OK otherwise. * @return Error, if age groups were invalid, OK otherwise.
*/ */
enum TALER_EXTENSION_ReturnValue enum TALER_Extension_ReturnValue
TALER_parse_age_group_string (char *groups, TALER_parse_age_group_string (char *groups,
struct TALER_AgeMask *mask); struct TALER_AgeMask *mask);
@ -66,8 +112,7 @@ TALER_parse_age_group_string (char *groups,
* @return Error if extension for age restriction was set but age groups were * @return Error if extension for age restriction was set but age groups were
* invalid, OK otherwise. * invalid, OK otherwise.
*/ */
enum TALER_EXTENSION_ReturnValue enum TALER_Extension_ReturnValue
TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg, TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg,
struct TALER_AgeMask *mask); struct TALER_AgeMask *mask);
#endif #endif

View File

@ -22,6 +22,7 @@
#include "platform.h" #include "platform.h"
#include "taler_json_lib.h" #include "taler_json_lib.h"
#include <gnunet/gnunet_curl_lib.h> #include <gnunet/gnunet_curl_lib.h>
#include "taler_extensions.h"
#include "taler_exchange_service.h" #include "taler_exchange_service.h"
#include "taler_signatures.h" #include "taler_signatures.h"
#include "taler_curl_lib.h" #include "taler_curl_lib.h"
@ -131,11 +132,9 @@ TALER_EXCHANGE_management_post_extensions (
struct TALER_EXCHANGE_ManagementPostExtensionsHandle *ph; struct TALER_EXCHANGE_ManagementPostExtensionsHandle *ph;
// FIXME-oec: TODO! // FIXME-oec: TODO!
CURL *eh = NULL; CURL *eh = NULL;
/*
json_t *body; json_t *body;
json_t *denom_sigs; json_t *extensions = NULL;
json_t *signkey_sigs; json_t *extension_sigs = NULL;
*/
ph = GNUNET_new (struct TALER_EXCHANGE_ManagementPostExtensionsHandle); ph = GNUNET_new (struct TALER_EXCHANGE_ManagementPostExtensionsHandle);
ph->cb = cb; ph->cb = cb;
@ -151,44 +150,57 @@ TALER_EXCHANGE_management_post_extensions (
GNUNET_free (ph); GNUNET_free (ph);
return NULL; return NULL;
} }
/* extensions = json_array ();
denom_sigs = json_array (); GNUNET_assert (NULL != extensions);
GNUNET_assert (NULL != denom_sigs); for (unsigned int i = 0; i<pkd->num_extensions; i++)
for (unsigned int i = 0; i<pkd->num_denom_sigs; i++)
{ {
const struct TALER_EXCHANGE_DenominationKeySignature *dks json_t *config;
= &pkd->denom_sigs[i]; const struct TALER_Extension *ext
= &pkd->extensions[i];
GNUNET_assert (0 == switch (ext->type)
json_array_append_new ( {
denom_sigs, // TODO: case TALER_Extension_Peer2Peer
GNUNET_JSON_PACK ( case TALER_Extension_AgeRestriction:
GNUNET_JSON_pack_data_auto ("h_denom_pub", struct TALER_AgeMask *mask = (struct TALER_AgeMask *) (&ext->config);
&dks->h_denom_pub), config = GNUNET_JSON_PACK (GNUNET_JSON_pack_data_auto ("mask",
GNUNET_JSON_pack_data_auto ("master_sig", &mask->mask));
&dks->master_sig)))); GNUNET_assert (NULL != config);
break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Extension not supported.\n");
} }
signkey_sigs = json_array ();
GNUNET_assert (NULL != signkey_sigs);
for (unsigned int i = 0; i<pkd->num_sign_sigs; i++)
{
const struct TALER_EXCHANGE_SigningKeySignature *sks
= &pkd->sign_sigs[i];
GNUNET_assert (0 == GNUNET_assert (0 ==
json_array_append_new ( json_array_append_new (
signkey_sigs, extensions,
GNUNET_JSON_PACK ( GNUNET_JSON_PACK (
GNUNET_JSON_pack_data_auto ("exchange_pub", GNUNET_JSON_pack_data_auto ("extension",
&sks->exchange_pub), &ext->name),
GNUNET_JSON_pack_data_auto ("master_sig", GNUNET_JSON_pack_data_auto ("config",
&sks->master_sig)))); config)
)));
}
extension_sigs = json_array ();
GNUNET_assert (NULL != extension_sigs);
for (unsigned int i = 0; i<pkd->num_extensions; i++)
{
const struct TALER_MasterSignatureP *sks
= &pkd->extension_sigs[i];
GNUNET_assert (0 ==
json_array_append_new (
extension_sigs,
GNUNET_JSON_PACK (
GNUNET_JSON_pack_data_auto ("extension_sig",
&sks->eddsa_signature))));
} }
body = GNUNET_JSON_PACK ( body = GNUNET_JSON_PACK (
GNUNET_JSON_pack_array_steal ("denom_sigs", GNUNET_JSON_pack_array_steal ("extensions",
denom_sigs), extensions),
GNUNET_JSON_pack_array_steal ("signkey_sigs", GNUNET_JSON_pack_array_steal ("extension_sigs",
signkey_sigs)); extension_sigs));
eh = curl_easy_init (); eh = curl_easy_init ();
GNUNET_assert (NULL != eh); GNUNET_assert (NULL != eh);
if (GNUNET_OK != if (GNUNET_OK !=
@ -209,7 +221,6 @@ TALER_EXCHANGE_management_post_extensions (
GNUNET_assert (CURLE_OK == curl_easy_setopt (eh, GNUNET_assert (CURLE_OK == curl_easy_setopt (eh,
CURLOPT_URL, CURLOPT_URL,
ph->url)); ph->url));
*/
ph->job = GNUNET_CURL_job_add2 (ctx, ph->job = GNUNET_CURL_job_add2 (ctx,
eh, eh,
ph->post_ctx.headers, ph->post_ctx.headers,
@ -228,7 +239,6 @@ void
TALER_EXCHANGE_post_management_extensions_cancel ( TALER_EXCHANGE_post_management_extensions_cancel (
struct TALER_EXCHANGE_ManagementPostExtensionsHandle *ph) struct TALER_EXCHANGE_ManagementPostExtensionsHandle *ph)
{ {
/* FIXME-oec: TODO
if (NULL != ph->job) if (NULL != ph->job)
{ {
GNUNET_CURL_job_cancel (ph->job); GNUNET_CURL_job_cancel (ph->job);
@ -237,5 +247,4 @@ TALER_EXCHANGE_post_management_extensions_cancel (
TALER_curl_easy_post_finished (&ph->post_ctx); TALER_curl_easy_post_finished (&ph->post_ctx);
GNUNET_free (ph->url); GNUNET_free (ph->url);
GNUNET_free (ph); GNUNET_free (ph);
*/
} }

View File

@ -31,12 +31,12 @@
* @return Error if extension for age restriction was set, but age groups were * @return Error if extension for age restriction was set, but age groups were
* invalid, OK otherwise. * invalid, OK otherwise.
*/ */
enum TALER_EXTENSION_ReturnValue enum TALER_Extension_ReturnValue
TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg, TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg,
struct TALER_AgeMask *mask) struct TALER_AgeMask *mask)
{ {
char *groups; char *groups;
enum TALER_EXTENSION_ReturnValue ret = TALER_EXTENSION_ERROR_SYS; enum TALER_Extension_ReturnValue ret = TALER_Extension_ERROR_SYS;
if ((GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, if ((GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg,
TALER_EXTENSION_SECTION_AGE_RESTRICTION, TALER_EXTENSION_SECTION_AGE_RESTRICTION,
@ -47,7 +47,7 @@ TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg,
{ {
/* Age restriction is not enabled */ /* Age restriction is not enabled */
mask->mask = 0; mask->mask = 0;
return TALER_EXTENSION_OK; return TALER_Extension_OK;
} }
/* Age restriction is enabled, extract age groups */ /* Age restriction is enabled, extract age groups */
@ -57,13 +57,13 @@ TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg,
&groups)) &groups))
{ {
/* FIXME: log error? */ /* FIXME: log error? */
return TALER_EXTENSION_ERROR_SYS; return TALER_Extension_ERROR_SYS;
} }
if (groups == NULL) if (groups == NULL)
{ {
/* No groups defined in config, return default_age_mask */ /* No groups defined in config, return default_age_mask */
mask->mask = TALER_EXTENSION_DEFAULT_AGE_MASK; mask->mask = TALER_EXTENSION_DEFAULT_AGE_MASK;
return TALER_EXTENSION_OK; return TALER_Extension_OK;
} }
ret = TALER_parse_age_group_string (groups, mask); ret = TALER_parse_age_group_string (groups, mask);
@ -80,11 +80,11 @@ TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg,
* @param[out] mask Bit representation of the age groups. * @param[out] mask Bit representation of the age groups.
* @return Error if string was invalid, OK otherwise. * @return Error if string was invalid, OK otherwise.
*/ */
enum TALER_EXTENSION_ReturnValue enum TALER_Extension_ReturnValue
TALER_parse_age_group_string (char *groups, TALER_parse_age_group_string (char *groups,
struct TALER_AgeMask *mask) struct TALER_AgeMask *mask)
{ {
enum TALER_EXTENSION_ReturnValue ret = TALER_EXTENSION_ERROR_SYS; enum TALER_Extension_ReturnValue ret = TALER_Extension_ERROR_SYS;
char *pos; char *pos;
unsigned int prev = 0; unsigned int prev = 0;
unsigned int val; unsigned int val;
@ -105,14 +105,14 @@ TALER_parse_age_group_string (char *groups,
{ {
/* Invalid input */ /* Invalid input */
mask->mask = 0; mask->mask = 0;
ret = TALER_EXTENSION_ERROR_PARSING; ret = TALER_Extension_ERROR_PARSING;
break; break;
} }
else if ((0 >= val) || (32 <= val) || (prev >= val)) else if ((0 >= val) || (32 <= val) || (prev >= val))
{ {
/* Invalid value */ /* Invalid value */
mask->mask = 0; mask->mask = 0;
ret = TALER_EXTENSION_ERROR_INVALID; ret = TALER_Extension_ERROR_INVALID;
break; break;
} }
@ -123,7 +123,7 @@ TALER_parse_age_group_string (char *groups,
{ {
/* We reached the end. Mark zeroth age-group and exit. */ /* We reached the end. Mark zeroth age-group and exit. */
mask->mask |= 1; mask->mask |= 1;
ret = TALER_EXTENSION_OK; ret = TALER_Extension_OK;
break; break;
} }