From 4d98a1200a4dc03a89968212913dfd47bc1749a8 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 15 Mar 2015 18:27:32 +0100 Subject: [PATCH] refactor denomination key structs to allow proper signing / serialization with new variable-size RSA keys --- src/include/taler_signatures.h | 7 +++++-- src/mint/key_io.h | 9 ++++++++- src/mint/taler-mint-httpd_keystate.c | 14 ++++++++------ src/mint/taler-mint-keyup.c | 4 +++- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/include/taler_signatures.h b/src/include/taler_signatures.h index ac8f78a85..b91639321 100644 --- a/src/include/taler_signatures.h +++ b/src/include/taler_signatures.h @@ -442,8 +442,11 @@ struct TALER_MINT_DenomKeyIssue */ struct TALER_AmountNBO fee_refresh; - // FIXME: does not work like this: - struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub; + /** + * Hash code of the denomination public key. + */ + struct GNUNET_HashCode denom_hash; + }; GNUNET_NETWORK_STRUCT_END diff --git a/src/mint/key_io.h b/src/mint/key_io.h index 2f3f5fead..b204629a2 100644 --- a/src/mint/key_io.h +++ b/src/mint/key_io.h @@ -60,6 +60,7 @@ struct TALER_MINT_SignKeyIssuePriv struct TALER_MINT_SignKeyIssue issue; }; + GNUNET_NETWORK_STRUCT_END @@ -77,7 +78,13 @@ struct TALER_MINT_DenomKeyIssuePriv struct GNUNET_CRYPTO_rsa_PrivateKey *denom_priv; /** - * Public information about a denomination key. + * Decoded denomination public key (the hash of it is in + * @e issue, but we sometimes need the full public key as well). + */ + struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub; + + /** + * Signed public information about a denomination key. */ struct TALER_MINT_DenomKeyIssue issue; }; diff --git a/src/mint/taler-mint-httpd_keystate.c b/src/mint/taler-mint-httpd_keystate.c index 405b4bec6..bf802f5b5 100644 --- a/src/mint/taler-mint-httpd_keystate.c +++ b/src/mint/taler-mint-httpd_keystate.c @@ -106,11 +106,13 @@ static int reload_pipe[2]; * Convert the public part of a denomination key issue to a JSON * object. * + * @param pk public key of the denomination key * @param dki the denomination key issue * @return a JSON object describing the denomination key isue (public part) */ static json_t * -denom_key_issue_to_json (const struct TALER_MINT_DenomKeyIssue *dki) +denom_key_issue_to_json (struct GNUNET_CRYPTO_rsa_PublicKey *pk, + const struct TALER_MINT_DenomKeyIssue *dki) { return json_pack ("{s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o}", @@ -124,7 +126,7 @@ denom_key_issue_to_json (const struct TALER_MINT_DenomKeyIssue *dki) "stamp_expire_deposit", TALER_JSON_from_abs (GNUNET_TIME_absolute_ntoh (dki->expire_spend)), "denom_pub", - TALER_JSON_from_rsa_public_key (dki->denom_pub), + TALER_JSON_from_rsa_public_key (pk), "value", TALER_JSON_from_amount (TALER_amount_ntoh (dki->value)), "fee_withdraw", @@ -202,9 +204,8 @@ reload_keys_denom_iter (void *cls, return GNUNET_OK; } - GNUNET_CRYPTO_hash (&dki->issue.denom_pub, - sizeof (struct GNUNET_CRYPTO_EddsaPublicKey), - &denom_key_hash); + GNUNET_CRYPTO_rsa_public_key_hash (dki->denom_pub, + &denom_key_hash); d2 = GNUNET_memdup (dki, sizeof (struct TALER_MINT_DenomKeyIssuePriv)); res = GNUNET_CONTAINER_multihashmap_put (ctx->denomkey_map, @@ -220,7 +221,8 @@ reload_keys_denom_iter (void *cls, return GNUNET_OK; } json_array_append_new (ctx->denom_keys_array, - denom_key_issue_to_json (&dki->issue)); + denom_key_issue_to_json (dki->denom_pub, + &dki->issue)); return GNUNET_OK; } diff --git a/src/mint/taler-mint-keyup.c b/src/mint/taler-mint-keyup.c index c4e153476..c5358b6cf 100644 --- a/src/mint/taler-mint-keyup.c +++ b/src/mint/taler-mint-keyup.c @@ -442,7 +442,9 @@ create_denomkey_issue (struct CoinTypeParams *params, struct TALER_MINT_DenomKeyIssuePriv *dki) { GNUNET_assert (NULL != (dki->denom_priv = GNUNET_CRYPTO_rsa_private_key_create (RSA_KEYSIZE))); - dki->issue.denom_pub = GNUNET_CRYPTO_rsa_private_key_get_public (dki->denom_priv); + dki->denom_pub = GNUNET_CRYPTO_rsa_private_key_get_public (dki->denom_priv); + GNUNET_CRYPTO_rsa_public_key_hash (dki->denom_pub, + &dki->issue.denom_hash); dki->issue.master = *master_pub; dki->issue.start = GNUNET_TIME_absolute_hton (params->anchor); dki->issue.expire_withdraw =