From d833966d521e9b836c8c854595671197c64c24f6 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 4 Feb 2022 22:02:48 +0100 Subject: -API work --- src/lib/exchange_api_refreshes_reveal.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'src/lib/exchange_api_refreshes_reveal.c') diff --git a/src/lib/exchange_api_refreshes_reveal.c b/src/lib/exchange_api_refreshes_reveal.c index 82f92322..85d20e55 100644 --- a/src/lib/exchange_api_refreshes_reveal.c +++ b/src/lib/exchange_api_refreshes_reveal.c @@ -73,7 +73,7 @@ struct TALER_EXCHANGE_RefreshesRevealHandle /** * Actual information about the melt operation. */ - struct MeltData *md; + struct MeltData md; /** * The index selected by the exchange in cut-and-choose to not be revealed. @@ -298,7 +298,8 @@ handle_refresh_reveal_finished (void *cls, struct TALER_EXCHANGE_RefreshesRevealHandle * TALER_EXCHANGE_refreshes_reveal ( struct TALER_EXCHANGE_Handle *exchange, - const json_t *refresh_data, + const struct TALER_PlanchetSecretsP *ps, + const struct TALER_EXCHANGE_RefreshData *rd, uint32_t noreveal_index, TALER_EXCHANGE_RefreshesRevealCallback reveal_cb, void *reveal_cb_cls) @@ -311,7 +312,7 @@ TALER_EXCHANGE_refreshes_reveal ( json_t *link_sigs; CURL *eh; struct GNUNET_CURL_Context *ctx; - struct MeltData *md; + struct MeltData md; struct TALER_TransferPublicKeyP transfer_pub; char arg_str[sizeof (struct TALER_RefreshCommitmentP) * 2 + 32]; @@ -330,9 +331,10 @@ TALER_EXCHANGE_refreshes_reveal ( GNUNET_break (0); return NULL; } - md = TALER_EXCHANGE_deserialize_melt_data_ (refresh_data, - exchange->key_data.currency); - if (NULL == md) + if (GNUNET_OK != + TALER_EXCHANGE_get_melt_data (ps, + rd, + &md)) { GNUNET_break (0); return NULL; @@ -340,21 +342,21 @@ TALER_EXCHANGE_refreshes_reveal ( /* now transfer_pub */ GNUNET_CRYPTO_ecdhe_key_get_public ( - &md->melted_coin.transfer_priv[noreveal_index].ecdhe_priv, + &md.melted_coin.transfer_priv[noreveal_index].ecdhe_priv, &transfer_pub.ecdhe_pub); /* now new_denoms */ GNUNET_assert (NULL != (new_denoms_h = json_array ())); GNUNET_assert (NULL != (coin_evs = json_array ())); GNUNET_assert (NULL != (link_sigs = json_array ())); - for (unsigned int i = 0; inum_fresh_coins; i++) + for (unsigned int i = 0; ifresh_pks[i], + TALER_denom_pub_hash (&md.fresh_pks[i], &denom_hash); GNUNET_assert (0 == json_array_append_new (new_denoms_h, @@ -364,9 +366,9 @@ TALER_EXCHANGE_refreshes_reveal ( // TODO: implement cipher handling alg_values.cipher = TALER_DENOMINATION_RSA; if (GNUNET_OK != - TALER_planchet_prepare (&md->fresh_pks[i], + TALER_planchet_prepare (&md.fresh_pks[i], &alg_values, - &md->fresh_coins[noreveal_index][i], + &md.fresh_coins[noreveal_index][i], &c_hash, &pd)) { @@ -374,6 +376,7 @@ TALER_EXCHANGE_refreshes_reveal ( GNUNET_break (0); json_decref (new_denoms_h); json_decref (coin_evs); + TALER_EXCHANGE_free_melt_data_ (&md); return NULL; } GNUNET_assert (0 == @@ -394,7 +397,7 @@ TALER_EXCHANGE_refreshes_reveal ( blinded_msg, pd.blinded_planchet.details.rsa_blinded_planchet. blinded_msg_size, - &md->melted_coin.coin_priv, + &md.melted_coin.coin_priv, &link_sig); GNUNET_assert (0 == json_array_append_new ( @@ -417,7 +420,7 @@ TALER_EXCHANGE_refreshes_reveal ( GNUNET_assert (0 == json_array_append_new (transfer_privs, GNUNET_JSON_from_data_auto ( - &md->melted_coin.transfer_priv[j]))); + &md.melted_coin.transfer_priv[j]))); } /* build main JSON request */ @@ -436,7 +439,7 @@ TALER_EXCHANGE_refreshes_reveal ( char pub_str[sizeof (struct TALER_RefreshCommitmentP) * 2]; char *end; - end = GNUNET_STRINGS_data_to_string (&md->rc, + end = GNUNET_STRINGS_data_to_string (&md.rc, sizeof (struct TALER_RefreshCommitmentP), pub_str, @@ -459,6 +462,7 @@ TALER_EXCHANGE_refreshes_reveal ( if (NULL == rrh->url) { json_decref (reveal_obj); + TALER_EXCHANGE_free_melt_data_ (&md); GNUNET_free (rrh); return NULL; } @@ -473,6 +477,7 @@ TALER_EXCHANGE_refreshes_reveal ( if (NULL != eh) curl_easy_cleanup (eh); json_decref (reveal_obj); + TALER_EXCHANGE_free_melt_data_ (&md); GNUNET_free (rrh->url); GNUNET_free (rrh); return NULL; -- cgit v1.2.3 From cfc6c3fcd04e9bed639816828d05e8645d80860f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 4 Feb 2022 23:09:19 +0100 Subject: make API actually workable: --- src/include/taler_exchange_service.h | 11 +++++++++-- src/lib/exchange_api_melt.c | 2 +- src/lib/exchange_api_refreshes_reveal.c | 20 ++++++++++++++------ 3 files changed, 24 insertions(+), 9 deletions(-) (limited to 'src/lib/exchange_api_refreshes_reveal.c') diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h index ba80da3e..8fe1bf7d 100644 --- a/src/include/taler_exchange_service.h +++ b/src/include/taler_exchange_service.h @@ -1609,6 +1609,8 @@ struct TALER_EXCHANGE_MeltHandle; * * @param cls closure * @param hr HTTP response data + * @param num_coins number of fresh coins to be created, length of the @a exchange_vals array, 0 if the operation failed + * @param alg_values array @a num_coins of exchange values contributed to the refresh operation * @param noreveal_index choice by the exchange in the cut-and-choose protocol, * UINT32_MAX on error * @param sign_key exchange key used to sign @a full_response, or NULL @@ -1617,6 +1619,8 @@ typedef void (*TALER_EXCHANGE_MeltCallback) ( void *cls, const struct TALER_EXCHANGE_HttpResponse *hr, + unsigned int num_coins, + const struct TALER_ExchangeWithdrawValues *alg_values, uint32_t noreveal_index, const struct TALER_ExchangePublicKeyP *sign_key); @@ -1670,7 +1674,7 @@ TALER_EXCHANGE_melt_cancel (struct TALER_EXCHANGE_MeltHandle *mh); * * @param cls closure * @param hr HTTP response data - * @param num_coins number of fresh coins created, length of the @a exchange_vals, @a sigs and @a coin_privs arrays, 0 if the operation failed + * @param num_coins number of fresh coins created, length of the @a sigs and @a coin_privs arrays, 0 if the operation failed * @param exchange_vals array of contributions from the exchange on the refreshes * @param coin_privs array of @a num_coins private keys for the coins that were created, NULL on error * @param sigs array of signature over @a num_coins coins, NULL on error @@ -1681,7 +1685,6 @@ typedef void const struct TALER_EXCHANGE_HttpResponse *hr, unsigned int num_coins, const struct TALER_CoinSpendPrivateKeyP *coin_privs, - const struct TALER_ExchangeWithdrawValues *exchange_vals, const struct TALER_DenominationSignature *sigs); @@ -1703,6 +1706,8 @@ struct TALER_EXCHANGE_RefreshesRevealHandle; * @param exchange the exchange handle; the exchange must be ready to operate * @param ps the fresh secret that defines the refresh operation * @param rd the refresh data that characterizes the refresh operation + * @param num_coins number of fresh coins to be created, length of the @a exchange_vals array, must match value in @a rd + * @param alg_values array @a num_coins of exchange values contributed to the refresh operation * @param noreveal_index response from the exchange to the * #TALER_EXCHANGE_melt() invocation * @param reveal_cb the callback to call with the final result of the @@ -1716,6 +1721,8 @@ TALER_EXCHANGE_refreshes_reveal ( struct TALER_EXCHANGE_Handle *exchange, const struct TALER_PlanchetSecretsP *ps, const struct TALER_EXCHANGE_RefreshData *rd, + unsigned int num_coins, + const struct TALER_ExchangeWithdrawValues *alg_values, uint32_t noreveal_index, TALER_EXCHANGE_RefreshesRevealCallback reveal_cb, void *reveal_cb_cls); diff --git a/src/lib/exchange_api_melt.c b/src/lib/exchange_api_melt.c index 204e5254..b93d255e 100644 --- a/src/lib/exchange_api_melt.c +++ b/src/lib/exchange_api_melt.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2015-2021 Taler Systems SA + Copyright (C) 2015-2022 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 diff --git a/src/lib/exchange_api_refreshes_reveal.c b/src/lib/exchange_api_refreshes_reveal.c index 85d20e55..a233df4b 100644 --- a/src/lib/exchange_api_refreshes_reveal.c +++ b/src/lib/exchange_api_refreshes_reveal.c @@ -95,12 +95,14 @@ struct TALER_EXCHANGE_RefreshesRevealHandle * * @param rrh operation handle * @param json reply from the exchange - * @param[out] sigs array of length `num_fresh_coins`, initialized to contain RSA signatures + * @param[out] sigs array of length `num_fresh_coins`, initialized to contain the coin private keys + * @param[out] sigs array of length `num_fresh_coins`, initialized to contain signatures * @return #GNUNET_OK on success, #GNUNET_SYSERR on errors */ static enum GNUNET_GenericReturnValue refresh_reveal_ok (struct TALER_EXCHANGE_RefreshesRevealHandle *rrh, const json_t *json, + struct TALER_CoinSpendPrivateKeyP *coin_privs, struct TALER_DenominationSignature *sigs) { json_t *jsona; @@ -165,6 +167,7 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshesRevealHandle *rrh, /* needed to verify the signature, and we didn't store it earlier, hence recomputing it here... */ + coin_privs[i] = fc->coin_priv; GNUNET_CRYPTO_eddsa_key_get_public (&fc->coin_priv.eddsa_priv, &coin_pub.eddsa_pub); /* FIXME-Oec: Age commitment hash. */ @@ -223,13 +226,15 @@ handle_refresh_reveal_finished (void *cls, case MHD_HTTP_OK: { struct TALER_DenominationSignature sigs[rrh->md->num_fresh_coins]; - int ret; + struct TALER_CoinSpendPrivateKeyP coin_privs[rrh->md->num_fresh_coins]; + enum GNUNET_GenericReturnValue ret; memset (sigs, 0, sizeof (sigs)); ret = refresh_reveal_ok (rrh, j, + coin_privs, sigs); if (GNUNET_OK != ret) { @@ -241,7 +246,7 @@ handle_refresh_reveal_finished (void *cls, rrh->reveal_cb (rrh->reveal_cb_cls, &hr, rrh->md->num_fresh_coins, - rrh->md->fresh_coins[rrh->noreveal_index], + coin_privs, sigs); rrh->reveal_cb = NULL; } @@ -300,6 +305,8 @@ TALER_EXCHANGE_refreshes_reveal ( struct TALER_EXCHANGE_Handle *exchange, const struct TALER_PlanchetSecretsP *ps, const struct TALER_EXCHANGE_RefreshData *rd, + unsigned int num_coins, + const struct TALER_ExchangeWithdrawValues *alg_values, uint32_t noreveal_index, TALER_EXCHANGE_RefreshesRevealCallback reveal_cb, void *reveal_cb_cls) @@ -363,11 +370,9 @@ TALER_EXCHANGE_refreshes_reveal ( GNUNET_JSON_from_data_auto ( &denom_hash))); - // TODO: implement cipher handling - alg_values.cipher = TALER_DENOMINATION_RSA; if (GNUNET_OK != TALER_planchet_prepare (&md.fresh_pks[i], - &alg_values, + &rrh->exchange_vals[i], &md.fresh_coins[noreveal_index][i], &c_hash, &pd)) @@ -452,6 +457,8 @@ TALER_EXCHANGE_refreshes_reveal ( } /* finally, we can actually issue the request */ rrh = GNUNET_new (struct TALER_EXCHANGE_RefreshesRevealHandle); + rrh->exchange_vals = GNUNET_new_array (struct TALER_ExchangeWithdrawValues, + md.num_fresh_coins); rrh->exchange = exchange; rrh->noreveal_index = noreveal_index; rrh->reveal_cb = reveal_cb; @@ -505,6 +512,7 @@ TALER_EXCHANGE_refreshes_reveal_cancel ( GNUNET_free (rrh->url); TALER_curl_easy_post_finished (&rrh->ctx); TALER_EXCHANGE_free_melt_data_ (rrh->md); /* does not free 'md' itself */ + GNUNET_free (rrh->exchange_vals); GNUNET_free (rrh->md); GNUNET_free (rrh); } -- cgit v1.2.3 From d81a6c7cf22fecb03ea7857b2c6bc2156b2a2ebc Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 5 Feb 2022 00:12:58 +0100 Subject: -work on reveal --- src/lib/exchange_api_refreshes_reveal.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/lib/exchange_api_refreshes_reveal.c') diff --git a/src/lib/exchange_api_refreshes_reveal.c b/src/lib/exchange_api_refreshes_reveal.c index a233df4b..7536c6de 100644 --- a/src/lib/exchange_api_refreshes_reveal.c +++ b/src/lib/exchange_api_refreshes_reveal.c @@ -323,6 +323,7 @@ TALER_EXCHANGE_refreshes_reveal ( struct TALER_TransferPublicKeyP transfer_pub; char arg_str[sizeof (struct TALER_RefreshCommitmentP) * 2 + 32]; + GNUNET_assert (num_coins == rd->fresh_pks_len); if (noreveal_index >= TALER_CNC_KAPPA) { /* We check this here, as it would be really bad to below just @@ -339,9 +340,10 @@ TALER_EXCHANGE_refreshes_reveal ( return NULL; } if (GNUNET_OK != - TALER_EXCHANGE_get_melt_data (ps, - rd, - &md)) + TALER_EXCHANGE_get_melt_data_ (ps, + rd, + alg_values, + &md)) { GNUNET_break (0); return NULL; @@ -457,8 +459,6 @@ TALER_EXCHANGE_refreshes_reveal ( } /* finally, we can actually issue the request */ rrh = GNUNET_new (struct TALER_EXCHANGE_RefreshesRevealHandle); - rrh->exchange_vals = GNUNET_new_array (struct TALER_ExchangeWithdrawValues, - md.num_fresh_coins); rrh->exchange = exchange; rrh->noreveal_index = noreveal_index; rrh->reveal_cb = reveal_cb; @@ -511,9 +511,8 @@ TALER_EXCHANGE_refreshes_reveal_cancel ( } GNUNET_free (rrh->url); TALER_curl_easy_post_finished (&rrh->ctx); - TALER_EXCHANGE_free_melt_data_ (rrh->md); /* does not free 'md' itself */ + TALER_EXCHANGE_free_melt_data_ (&rrh->md); GNUNET_free (rrh->exchange_vals); - GNUNET_free (rrh->md); GNUNET_free (rrh); } -- cgit v1.2.3 From aea7fc36c3da02d550367c41ae7dd758daf698f4 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 5 Feb 2022 00:13:51 +0100 Subject: -style fix --- src/lib/exchange_api_refreshes_reveal.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/lib/exchange_api_refreshes_reveal.c') diff --git a/src/lib/exchange_api_refreshes_reveal.c b/src/lib/exchange_api_refreshes_reveal.c index 7536c6de..cdfb5140 100644 --- a/src/lib/exchange_api_refreshes_reveal.c +++ b/src/lib/exchange_api_refreshes_reveal.c @@ -447,8 +447,7 @@ TALER_EXCHANGE_refreshes_reveal ( char *end; end = GNUNET_STRINGS_data_to_string (&md.rc, - sizeof (struct - TALER_RefreshCommitmentP), + sizeof (md.rc), pub_str, sizeof (pub_str)); *end = '\0'; -- cgit v1.2.3