From 3954fbe8c0bf1501c6067907c874127109a12457 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 22 Jun 2015 14:36:01 +0200 Subject: finishing implementation of #3516 --- src/mint-lib/mint_api_json.c | 40 ++++++++++++++++++++++++++++++++++------ src/mint-lib/mint_api_json.h | 11 +++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/mint-lib/mint_api_json.c b/src/mint-lib/mint_api_json.c index 81511c1c0..e2a73bdd4 100644 --- a/src/mint-lib/mint_api_json.c +++ b/src/mint-lib/mint_api_json.c @@ -202,12 +202,40 @@ parse_json (json_t *root, case MAJ_CMD_EDDSA_SIGNATURE: { - /* FIXME: parse the JSON signature - and the purpose, then check that the - signature is valid and the size field - is also correct; if all checks out, - return the purpose */ - GNUNET_break (0); // FIXME: implement! #3516 + struct TALER_CoinSpendSignatureP sig; + struct GNUNET_CRYPTO_EccSignaturePurpose *purpose; + size_t size; + struct MAJ_Specification sig_spec[] = { + MAJ_spec_fixed_auto ("eddsa_sig", &sig), + MAJ_spec_varsize ("eddsa_val", (void**) &purpose, &size), + MAJ_spec_end + }; + + if (GNUNET_OK != + MAJ_parse_json (pos, + sig_spec)) + { + GNUNET_break_op (0); + MAJ_parse_free (sig_spec); + return i; + } + if (size != ntohl (purpose->size)) + { + GNUNET_break_op (0); + MAJ_parse_free (sig_spec); + return i; + } + if (GNUNET_OK != + GNUNET_CRYPTO_eddsa_verify (ntohl (purpose->purpose), + purpose, + &sig.eddsa_signature, + spec[i].details.eddsa_signature.pub_key)) + { + GNUNET_break_op (0); + MAJ_parse_free (sig_spec); + return i; + } + *spec[i].details.eddsa_signature.purpose_p = purpose; } break; diff --git a/src/mint-lib/mint_api_json.h b/src/mint-lib/mint_api_json.h index 91679831d..ec3b63cbc 100644 --- a/src/mint-lib/mint_api_json.h +++ b/src/mint-lib/mint_api_json.h @@ -218,6 +218,17 @@ MAJ_parse_free (struct MAJ_Specification *spec); #define MAJ_spec_fixed_auto(name,obj) { .cmd = MAJ_CMD_BINARY_FIXED, .field = name, .details.fixed_data.dest = obj, .details.fixed_data.dest_size = sizeof (*obj) } +/** + * Variable size object (in network byte order, encoded using Crockford + * Base32hex encoding). + * + * @param name name of the JSON field + * @param obj_ptr pointer where to write the data (a `void **`) + * @param size where to store the number of bytes allocated for @a obj (of type `size_t *` + */ +#define MAJ_spec_varsize(name,obj,size) { .cmd = MAJ_CMD_BINARY_VARIABLE, .field = name, .details.variable_data.dest_p = obj, .details.variable_data.dest_size_p = size } + + /** * Absolute time. * -- cgit v1.2.3