diff options
author | Özgür Kesim <oec-taler@kesim.org> | 2021-11-10 17:25:11 +0100 |
---|---|---|
committer | Özgür Kesim <oec-taler@kesim.org> | 2021-11-10 17:27:49 +0100 |
commit | 7c510388b9d789c35fc05bead7677b3de52a318e (patch) | |
tree | 43750109ca78184551dff403c881aa7e205152f9 /src/util | |
parent | 77bab625607514a628dfda101e55c7d57f6b623d (diff) | |
download | exchange-7c510388b9d789c35fc05bead7677b3de52a318e.tar.xz |
age restriction progress 2/n
Signed-off-by: Özgür Kesim <oec-taler@kesim.org>
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/Makefile.am | 1 | ||||
-rw-r--r-- | src/util/crypto.c | 1 | ||||
-rw-r--r-- | src/util/crypto_helper_denom.c | 21 | ||||
-rw-r--r-- | src/util/denom.c | 8 | ||||
-rw-r--r-- | src/util/extension_age_restriction.c | 49 | ||||
-rw-r--r-- | src/util/taler-exchange-secmod-rsa.c | 3 |
6 files changed, 77 insertions, 6 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 556c3b6f3..3c9a72646 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -71,6 +71,7 @@ libtalerutil_la_SOURCES = \ crypto_wire.c \ denom.c \ exchange_signatures.c \ + extension_age_restriction.c \ getopt.c \ lang.c \ iban.c \ diff --git a/src/util/crypto.c b/src/util/crypto.c index 2c81554b9..67cf14b42 100644 --- a/src/util/crypto.c +++ b/src/util/crypto.c @@ -320,6 +320,7 @@ void TALER_coin_pub_hash (const struct TALER_CoinSpendPublicKeyP *coin_pub, struct TALER_CoinPubHash *coin_h) { + // FIXME-Oec: hash over age-restriction, too GNUNET_CRYPTO_hash (&coin_pub->eddsa_pub, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), &coin_h->hash); diff --git a/src/util/crypto_helper_denom.c b/src/util/crypto_helper_denom.c index 4dfd32fbd..e1cd2b6ba 100644 --- a/src/util/crypto_helper_denom.c +++ b/src/util/crypto_helper_denom.c @@ -20,6 +20,7 @@ */ #include "platform.h" #include "taler_util.h" +#include "taler_extensions.h" #include "taler_signatures.h" #include "taler-exchange-secmod-rsa.h" #include <poll.h> @@ -62,6 +63,11 @@ struct TALER_CRYPTO_DenominationHelper * Have we ever been sync'ed? */ bool synced; + + /** + * Age Mask that applies to this denomination. + */ + struct TALER_AgeMask age_mask; }; @@ -273,6 +279,19 @@ TALER_CRYPTO_helper_denom_connect ( TALER_CRYPTO_helper_denom_disconnect (dh); return NULL; } + + /* Extract the age groups from the config, if the extension has been set, + * and serialize them into the age mask */ + if (GNUNET_OK != + TALER_get_age_mask (cfg, &dh->age_mask)) + { + GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, + "extensions", /* FIXME: right section etc? */ + "age-restriction", + "invalid age groups"); + TALER_CRYPTO_helper_denom_disconnect (dh); + return NULL; + } } TALER_CRYPTO_helper_denom_poll (dh); return dh; @@ -320,7 +339,7 @@ handle_mt_avail (struct TALER_CRYPTO_DenominationHelper *dh, struct TALER_DenominationHash h_denom_pub; denom_pub.cipher = TALER_DENOMINATION_RSA; - denom_pub.age_mask = 0; // FIXME-Oec! + denom_pub.age_mask = dh->age_mask; denom_pub.details.rsa_public_key = GNUNET_CRYPTO_rsa_public_key_decode (buf, ntohs (kan->pub_size)); diff --git a/src/util/denom.c b/src/util/denom.c index cdcfc5c3a..a5305343b 100644 --- a/src/util/denom.c +++ b/src/util/denom.c @@ -161,7 +161,7 @@ TALER_denom_pub_hash (const struct TALER_DenominationPublicKey *denom_pub, struct TALER_DenominationHash *denom_hash) { uint32_t opt[2] = { - htonl (denom_pub->age_mask), + htonl (denom_pub->age_mask.mask), htonl ((uint32_t) denom_pub->cipher) }; @@ -197,7 +197,7 @@ TALER_denom_pub_hash (const struct TALER_DenominationPublicKey *denom_pub, void TALER_denom_priv_to_pub (const struct TALER_DenominationPrivateKey *denom_priv, - uint32_t age_mask, + const struct TALER_AgeMask age_mask, struct TALER_DenominationPublicKey *denom_pub) { switch (denom_priv->cipher) @@ -446,8 +446,8 @@ TALER_denom_pub_cmp (const struct TALER_DenominationPublicKey *denom1, { if (denom1->cipher != denom2->cipher) return (denom1->cipher > denom2->cipher) ? 1 : -1; - if (denom1->age_mask != denom2->age_mask) - return (denom1->age_mask > denom2->age_mask) ? 1 : -1; + if (denom1->age_mask.mask != denom2->age_mask.mask) + return (denom1->age_mask.mask > denom2->age_mask.mask) ? 1 : -1; switch (denom1->cipher) { case TALER_DENOMINATION_INVALID: diff --git a/src/util/extension_age_restriction.c b/src/util/extension_age_restriction.c new file mode 100644 index 000000000..64ecaa31e --- /dev/null +++ b/src/util/extension_age_restriction.c @@ -0,0 +1,49 @@ +/* + This file is part of TALER + Copyright (C) 2014-2020 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ +/** + * @file extension_age_restriction.c + * @brief Utility functions regarding age restriction + * @author Özgür Kesim + */ +#include "platform.h" +#include "taler_util.h" + + +/** + * + * @param cfg + * @param[out] mask for age restriction + * @return Error if extension for age restriction was set but age groups were + * invalid, OK otherwise. + */ +enum GNUNET_GenericReturnValue +TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg, struct + TALER_AgeMask *mask) +{ + /* FIXME-Oec: + * + * - Detect if age restriction is enabled in config + * - if not, return 0 mask + * - else, parse age group and serialize into mask + * - return Error on + * + * */ + mask->mask = 0; + return GNUNET_OK; +} + + +/* end of extension_age_restriction.c */ diff --git a/src/util/taler-exchange-secmod-rsa.c b/src/util/taler-exchange-secmod-rsa.c index 1248b126d..e996f14ee 100644 --- a/src/util/taler-exchange-secmod-rsa.c +++ b/src/util/taler-exchange-secmod-rsa.c @@ -1422,9 +1422,10 @@ parse_key (struct Denomination *denom, struct TALER_DenominationPublicKey pub; struct DenominationKey *dk; struct DenominationKey *before; + struct TALER_AgeMask age_mask = { .mask = 0 }; /* FIXME-Oec */ TALER_denom_priv_to_pub (&priv, - 0 /* FIXME-Oec */, + age_mask, &pub); dk = GNUNET_new (struct DenominationKey); dk->denom_priv = priv; |