From 8d85c8b5b6c514ce093d856a2e4b931b4108ece5 Mon Sep 17 00:00:00 2001 From: Lucien Heuzeveldt Date: Sun, 16 Jan 2022 17:02:15 +0100 Subject: implement feedback --- src/lib/exchange_api_link.c | 10 +++--- src/lib/exchange_api_refresh_common.c | 5 ++- src/lib/exchange_api_refreshes_reveal.c | 12 +++++-- src/lib/exchange_api_withdraw.c | 14 ++++---- src/lib/exchange_api_withdraw2.c | 63 +++++---------------------------- 5 files changed, 35 insertions(+), 69 deletions(-) (limited to 'src/lib') diff --git a/src/lib/exchange_api_link.c b/src/lib/exchange_api_link.c index f2ef26d1a..78f8804a1 100644 --- a/src/lib/exchange_api_link.c +++ b/src/lib/exchange_api_link.c @@ -135,6 +135,7 @@ parse_link_coin (const struct TALER_EXCHANGE_LinkHandle *lh, *coin_priv = fc.coin_priv; /* verify link_sig */ { + struct TALER_ExchangeWithdrawValues alg_values; struct TALER_PlanchetDetail pd; struct TALER_CoinPubHash c_hash; struct TALER_CoinSpendPublicKeyP old_coin_pub; @@ -142,9 +143,11 @@ parse_link_coin (const struct TALER_EXCHANGE_LinkHandle *lh, GNUNET_CRYPTO_eddsa_key_get_public (&lh->coin_priv.eddsa_priv, &old_coin_pub.eddsa_pub); + // TODO: implement cipher handling + alg_values.cipher = TALER_DENOMINATION_RSA; if (GNUNET_OK != TALER_planchet_prepare (&rpub, - NULL, /* not needed in RSA*/ + &alg_values, &fc, &c_hash, &pd)) @@ -169,12 +172,11 @@ parse_link_coin (const struct TALER_EXCHANGE_LinkHandle *lh, &link_sig)) { GNUNET_break_op (0); - GNUNET_free ( - pd.blinded_planchet.details.rsa_blinded_planchet.blinded_msg); + TALER_blinded_planchet_free (&pd.blinded_planchet); GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } - GNUNET_free (pd.blinded_planchet.details.rsa_blinded_planchet.blinded_msg); + TALER_blinded_planchet_free (&pd.blinded_planchet); } /* clean up */ diff --git a/src/lib/exchange_api_refresh_common.c b/src/lib/exchange_api_refresh_common.c index 171b9adb1..65c7d6ba4 100644 --- a/src/lib/exchange_api_refresh_common.c +++ b/src/lib/exchange_api_refresh_common.c @@ -424,15 +424,18 @@ TALER_EXCHANGE_refresh_prepare ( { struct TALER_PlanchetSecretsP *fc = &md.fresh_coins[i][j]; struct TALER_RefreshCoinData *rcd = &rce[i].new_coins[j]; + struct TALER_ExchangeWithdrawValues alg_values; struct TALER_PlanchetDetail pd; struct TALER_CoinPubHash c_hash; TALER_planchet_setup_refresh (&trans_sec[i], j, fc); + // TODO: implement cipher handling + alg_values.cipher = TALER_DENOMINATION_RSA; if (GNUNET_OK != TALER_planchet_prepare (&md.fresh_pks[j], - NULL, /* not needed in RSA*/ + &alg_values, fc, &c_hash, &pd)) diff --git a/src/lib/exchange_api_refreshes_reveal.c b/src/lib/exchange_api_refreshes_reveal.c index 42e0cc328..82f92322a 100644 --- a/src/lib/exchange_api_refreshes_reveal.c +++ b/src/lib/exchange_api_refreshes_reveal.c @@ -138,6 +138,7 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshesRevealHandle *rrh, struct TALER_DenominationPublicKey *pk; json_t *jsonai; struct TALER_BlindedDenominationSignature blind_sig; + struct TALER_ExchangeWithdrawValues alg_values; struct TALER_CoinSpendPublicKeyP coin_pub; struct TALER_CoinPubHash coin_hash; struct GNUNET_JSON_Specification spec[] = { @@ -170,12 +171,14 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshesRevealHandle *rrh, TALER_coin_pub_hash (&coin_pub, NULL, /* FIXME-Oec */ &coin_hash); + // TODO: implement cipher handling + alg_values.cipher = TALER_DENOMINATION_RSA; if (GNUNET_OK != TALER_planchet_to_coin (pk, &blind_sig, fc, &coin_hash, - NULL, /* Not needed in RSA case */ + &alg_values, &coin)) { GNUNET_break_op (0); @@ -347,6 +350,7 @@ TALER_EXCHANGE_refreshes_reveal ( for (unsigned int i = 0; inum_fresh_coins; i++) { struct TALER_DenominationHash denom_hash; + struct TALER_ExchangeWithdrawValues alg_values; struct TALER_PlanchetDetail pd; struct TALER_CoinPubHash c_hash; @@ -357,9 +361,11 @@ 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], - NULL, /* not needed in RSA*/ + &alg_values, &md->fresh_coins[noreveal_index][i], &c_hash, &pd)) @@ -395,7 +401,7 @@ TALER_EXCHANGE_refreshes_reveal ( link_sigs, GNUNET_JSON_from_data_auto (&link_sig))); } - GNUNET_free (pd.blinded_planchet.details.rsa_blinded_planchet.blinded_msg); + TALER_blinded_planchet_free (&pd.blinded_planchet); } /* build array of transfer private keys */ diff --git a/src/lib/exchange_api_withdraw.c b/src/lib/exchange_api_withdraw.c index 5102b35a3..204c72359 100644 --- a/src/lib/exchange_api_withdraw.c +++ b/src/lib/exchange_api_withdraw.c @@ -186,10 +186,8 @@ withdraw_cs_stage_two_callback (void *cls, switch (csrr->hr.http_status) { case MHD_HTTP_OK: - wh->alg_values.cipher = TALER_DENOMINATION_CS; wh->alg_values.details.cs_values.r_pub = csrr->details.success.r_pubs; TALER_planchet_blinding_secret_create (&wh->ps, - wh->pk.key.cipher, &wh->alg_values); if (GNUNET_OK != TALER_planchet_prepare (&wh->pk.key, @@ -244,6 +242,7 @@ TALER_EXCHANGE_withdraw ( const struct TALER_EXCHANGE_DenomPublicKey *pk, const struct TALER_ReservePrivateKeyP *reserve_priv, struct TALER_PlanchetSecretsP *ps, + struct TALER_ExchangeWithdrawValues *alg_values, TALER_EXCHANGE_WithdrawCallback res_cb, void *res_cb_cls) { @@ -255,6 +254,7 @@ TALER_EXCHANGE_withdraw ( wh->cb_cls = res_cb_cls; wh->reserve_priv = reserve_priv; wh->ps = *ps; + wh->alg_values = *alg_values, wh->pk = *pk; wh->csrh = NULL; @@ -265,7 +265,7 @@ TALER_EXCHANGE_withdraw ( case TALER_DENOMINATION_RSA: if (GNUNET_OK != TALER_planchet_prepare (&pk->key, - NULL, /* not needed in RSA*/ + &wh->alg_values, ps, &wh->c_hash, &wh->pd)) @@ -279,9 +279,7 @@ TALER_EXCHANGE_withdraw ( wh->reserve_priv, &handle_reserve_withdraw_finished, wh); - GNUNET_free ( - wh->pd.blinded_planchet.details.rsa_blinded_planchet.blinded_msg); - return wh; + break; case TALER_DENOMINATION_CS: TALER_cs_withdraw_nonce_derive (&ps->coin_priv, &wh->pd.blinded_planchet.details. @@ -292,12 +290,14 @@ TALER_EXCHANGE_withdraw ( cs_blinded_planchet.nonce, &withdraw_cs_stage_two_callback, wh); - return wh; + break; default: GNUNET_break (0); GNUNET_free (wh); return NULL; } + TALER_blinded_planchet_free (&wh->pd.blinded_planchet); + return wh; } diff --git a/src/lib/exchange_api_withdraw2.c b/src/lib/exchange_api_withdraw2.c index cb767e434..6db0815c6 100644 --- a/src/lib/exchange_api_withdraw2.c +++ b/src/lib/exchange_api_withdraw2.c @@ -437,22 +437,9 @@ TALER_EXCHANGE_withdraw2 ( TALER_amount_hton (&req.amount_with_fee, &wh->requested_amount); - switch (dk->key.cipher) + if (GNUNET_OK != TALER_coin_ev_hash (&pd->blinded_planchet, + &req.h_coin_envelope)) { - case TALER_DENOMINATION_RSA: - TALER_coin_ev_hash ( - pd->blinded_planchet.details.rsa_blinded_planchet.blinded_msg, - pd->blinded_planchet.details.rsa_blinded_planchet. - blinded_msg_size, - &req.h_coin_envelope); - break; - case TALER_DENOMINATION_CS: - TALER_coin_ev_hash ( - &pd->blinded_planchet.details.cs_blinded_planchet, - sizeof (pd->blinded_planchet.details.cs_blinded_planchet), - &req.h_coin_envelope); - break; - default: GNUNET_break (0); GNUNET_free (wh); return NULL; @@ -463,45 +450,13 @@ TALER_EXCHANGE_withdraw2 ( } { - json_t *withdraw_obj; - switch (dk->key.cipher) - { - case TALER_DENOMINATION_RSA: - withdraw_obj = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_data_auto ("denom_pub_hash", - &pd->denom_pub_hash), - GNUNET_JSON_pack_data_varsize ("coin_ev", - pd->blinded_planchet.details. - rsa_blinded_planchet.blinded_msg, - pd->blinded_planchet.details. - rsa_blinded_planchet.blinded_msg_size), - GNUNET_JSON_pack_data_auto ("reserve_sig", - &reserve_sig)); - break; - case TALER_DENOMINATION_CS: - json_t *coin_ev_object = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_data_auto ("nonce", - &pd->blinded_planchet.details. - cs_blinded_planchet.nonce), - GNUNET_JSON_pack_data_auto ("c0", - &pd->blinded_planchet.details. - cs_blinded_planchet.c[0]), - GNUNET_JSON_pack_data_auto ("c1", - &pd->blinded_planchet.details. - cs_blinded_planchet.c[1])); - withdraw_obj = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_data_auto ("denom_pub_hash", - &pd->denom_pub_hash), - GNUNET_JSON_pack_object_steal ("coin_ev", - coin_ev_object), - GNUNET_JSON_pack_data_auto ("reserve_sig", - &reserve_sig)); - break; - default: - GNUNET_break (0); - GNUNET_free (wh); - return NULL; - } + json_t *withdraw_obj = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_data_auto ("denom_pub_hash", + &pd->denom_pub_hash), + TALER_JSON_pack_blinded_planchet ("coin_ev", + &pd->blinded_planchet), + GNUNET_JSON_pack_data_auto ("reserve_sig", + &reserve_sig)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Attempting to withdraw from reserve %s\n", TALER_B2S (&wh->reserve_pub)); -- cgit v1.2.3