diff options
author | Christian Blättler <blatc2@bfh.ch> | 2024-04-21 12:32:48 +0200 |
---|---|---|
committer | Christian Blättler <blatc2@bfh.ch> | 2024-04-21 12:32:48 +0200 |
commit | f81ee7ff118bd3c2da5ca21fd6707ba7751832e6 (patch) | |
tree | a0b44dbff857ac92793af8a2495c033d4a12afb2 | |
parent | 75588f40ec9140ceb74b80e31fbf830f5341fde7 (diff) | |
download | exchange-f81ee7ff118bd3c2da5ca21fd6707ba7751832e6.tar.xz |
add token issue sig helper
-rw-r--r-- | src/include/taler_crypto_lib.h | 10 | ||||
-rw-r--r-- | src/include/taler_json_lib.h | 12 | ||||
-rw-r--r-- | src/json/json_helper.c | 129 | ||||
-rw-r--r-- | src/util/Makefile.am | 1 | ||||
-rw-r--r-- | src/util/tokens.c | 33 |
5 files changed, 184 insertions, 1 deletions
diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h index bd7164ca5..429cf1cc0 100644 --- a/src/include/taler_crypto_lib.h +++ b/src/include/taler_crypto_lib.h @@ -5961,7 +5961,7 @@ struct TALER_TokenUseSignature */ struct TALER_TokenIssueSignature { - struct GNUNET_CRYPTO_UnblindedSignature signature; + struct GNUNET_CRYPTO_UnblindedSignature *signature; }; /** @@ -5972,4 +5972,12 @@ struct TALER_TokenIssueBlindSignature struct GNUNET_CRYPTO_BlindedSignature signature; }; +/** + * Free internals of @a issue_sig, but not @a issue_sig itself. + * + * @param[in] issue_sig signature to free + */ +void +TALER_token_issue_sig_free (struct TALER_TokenIssueSignature *issue_sig); + #endif diff --git a/src/include/taler_json_lib.h b/src/include/taler_json_lib.h index 98e565f0c..dad493cb6 100644 --- a/src/include/taler_json_lib.h +++ b/src/include/taler_json_lib.h @@ -588,6 +588,18 @@ TALER_JSON_spec_i18n_str (const char *name, /** + * Generate line in parser specification for a + * token issue signature. + * + * @param field name of the field + * @param[out] sig the signature to initialize + * @return corresponding field spec + */ +struct GNUNET_JSON_Specification +TALER_JSON_spec_token_issue_sig (const char *field, + struct TALER_TokenIssueSignature *sig); + +/** * Hash a JSON for binary signing. * * See https://tools.ietf.org/html/draft-rundgren-json-canonicalization-scheme-15 diff --git a/src/json/json_helper.c b/src/json/json_helper.c index 0a533610b..f58d5fa5c 100644 --- a/src/json/json_helper.c +++ b/src/json/json_helper.c @@ -533,6 +533,135 @@ TALER_JSON_spec_age_commitment (const char *name, /** + * Parse given JSON object to token issue signature. + * TODO: Exctract common between this and parse_denom_sig function to a helper. + * + * @param cls closure, NULL + * @param root the json object representing data + * @param[out] spec where to write the data + * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error + */ +static enum GNUNET_GenericReturnValue +parse_token_issue_sig (void *cls, + json_t *root, + struct GNUNET_JSON_Specification *spec) +{ + struct TALER_TokenIssueSignature *issue_sig = spec->ptr; + struct GNUNET_CRYPTO_UnblindedSignature *unblinded_sig; + const char *cipher; + struct GNUNET_JSON_Specification dspec[] = { + GNUNET_JSON_spec_string ("cipher", + &cipher), + GNUNET_JSON_spec_end () + }; + const char *emsg; + unsigned int eline; + + (void) cls; + if (GNUNET_OK != + GNUNET_JSON_parse (root, + dspec, + &emsg, + &eline)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + unblinded_sig = GNUNET_new (struct GNUNET_CRYPTO_UnblindedSignature); + unblinded_sig->cipher = string_to_cipher (cipher); + unblinded_sig->rc = 1; + switch (unblinded_sig->cipher) + { + case GNUNET_CRYPTO_BSA_INVALID: + break; + case GNUNET_CRYPTO_BSA_RSA: + { + struct GNUNET_JSON_Specification ispec[] = { + GNUNET_JSON_spec_rsa_signature ( + "rsa_signature", + &unblinded_sig->details.rsa_signature), + GNUNET_JSON_spec_end () + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (root, + ispec, + &emsg, + &eline)) + { + GNUNET_break_op (0); + GNUNET_free (unblinded_sig); + return GNUNET_SYSERR; + } + issue_sig->signature = unblinded_sig; + return GNUNET_OK; + } + case GNUNET_CRYPTO_BSA_CS: + { + struct GNUNET_JSON_Specification ispec[] = { + GNUNET_JSON_spec_fixed_auto ("cs_signature_r", + &unblinded_sig->details.cs_signature. + r_point), + GNUNET_JSON_spec_fixed_auto ("cs_signature_s", + &unblinded_sig->details.cs_signature. + s_scalar), + GNUNET_JSON_spec_end () + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (root, + ispec, + &emsg, + &eline)) + { + GNUNET_break_op (0); + GNUNET_free (unblinded_sig); + return GNUNET_SYSERR; + } + issue_sig->signature = unblinded_sig; + return GNUNET_OK; + } + } + GNUNET_break_op (0); + GNUNET_free (unblinded_sig); + return GNUNET_SYSERR; +} + + +/** + * Cleanup data left from parsing token issue signature. + * + * @param cls closure, NULL + * @param[out] spec where to free the data + */ +static void +clean_token_issue_sig (void *cls, + struct GNUNET_JSON_Specification *spec) +{ + struct TALER_TokenIssueSignature *issue_sig = spec->ptr; + + (void) cls; + TALER_token_issue_sig_free (issue_sig); +} + + +struct GNUNET_JSON_Specification +TALER_JSON_spec_token_issue_sig (const char *field, + struct TALER_TokenIssueSignature *sig) +{ + struct GNUNET_JSON_Specification ret = { + .parser = &parse_token_issue_sig, + .cleaner = &clean_token_issue_sig, + .field = field, + .ptr = sig + }; + + sig->signature = NULL; + return ret; +} + + +/** * Parse given JSON object to denomination public key. * * @param cls closure, NULL diff --git a/src/util/Makefile.am b/src/util/Makefile.am index d2504588b..897a821b1 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -102,6 +102,7 @@ libtalerutil_la_SOURCES = \ payto.c \ secmod_signatures.c \ taler_error_codes.c \ + tokens.c \ url.c \ util.c \ wallet_signatures.c \ diff --git a/src/util/tokens.c b/src/util/tokens.c new file mode 100644 index 000000000..61fe40501 --- /dev/null +++ b/src/util/tokens.c @@ -0,0 +1,33 @@ +/* + This file is part of TALER + Copyright (C) 2024 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 tokens.c + * @brief token family utility functions + * @author Christian Blättler + */ +#include "platform.h" +#include "taler_util.h" + + +void +TALER_token_issue_sig_free (struct TALER_TokenIssueSignature *issue_sig) +{ + if (NULL != issue_sig->signature) + { + GNUNET_CRYPTO_unblinded_sig_decref (issue_sig->signature); + issue_sig->signature = NULL; + } +} |