summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorLucien Heuzeveldt <lucienclaude.heuzeveldt@students.bfh.ch>2022-01-08 20:41:01 +0100
committerGian Demarmels <gian@demarmels.org>2022-02-04 15:35:31 +0100
commit9074e66ebc8b73ecc98500f32af52088fd7f0722 (patch)
treee5e270bea1e2b3de44e915b428df01866a93203e /src/lib
parent4c7aa097840eb3254a6823177abcc90fa7ccf0d0 (diff)
downloadexchange-9074e66ebc8b73ecc98500f32af52088fd7f0722.tar.gz
exchange-9074e66ebc8b73ecc98500f32af52088fd7f0722.tar.bz2
exchange-9074e66ebc8b73ecc98500f32af52088fd7f0722.zip
implement withdraw (nonce reuse check missing)
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/exchange_api_withdraw.c88
-rw-r--r--src/lib/exchange_api_withdraw2.c74
2 files changed, 119 insertions, 43 deletions
diff --git a/src/lib/exchange_api_withdraw.c b/src/lib/exchange_api_withdraw.c
index 91838d4ce..2c57797fd 100644
--- a/src/lib/exchange_api_withdraw.c
+++ b/src/lib/exchange_api_withdraw.c
@@ -59,11 +59,21 @@ struct TALER_EXCHANGE_WithdrawHandle
void *cb_cls;
/**
+ * Reserve private key.
+ */
+ const struct TALER_ReservePrivateKeyP *reserve_priv;
+
+ /**
* Secrets of the planchet.
*/
struct TALER_PlanchetSecretsP ps;
/**
+ * Details of the planchet.
+ */
+ struct TALER_PlanchetDetail pd;
+
+ /**
* Denomination key we are withdrawing.
*/
struct TALER_EXCHANGE_DenomPublicKey pk;
@@ -162,24 +172,44 @@ withdraw_cs_stage_two_callback (void *cls,
const struct TALER_EXCHANGE_CsRResponse *csrr)
{
struct TALER_EXCHANGE_WithdrawHandle *wh = cls;
- // TODO: this should only be set for non-OK cases
- struct TALER_EXCHANGE_WithdrawResponse wr = {
- .hr = csrr->hr
- };
- // switch (csrr->hr.http_status)
- // {
- // case MHD_HTTP_OK:
- // // TODO: implement rest of withdraw
- // break;
- // default:
- // break;
- // }
+ wh->csrh = NULL;
- // TODO: this should only be called for non-OK cases
- wh->cb (wh->cb_cls,
- &wr);
- TALER_EXCHANGE_withdraw_cancel (wh);
+ GNUNET_assert (TALER_DENOMINATION_CS == wh->pk.key.cipher);
+
+ switch (csrr->hr.http_status)
+ {
+ case MHD_HTTP_OK:
+ wh->ps.cs_r_pub = csrr->details.success.r_pubs;
+ TALER_blinding_secret_create (&wh->ps.blinding_key,
+ wh->pk.key.cipher,
+ &wh->ps.coin_priv,
+ &wh->ps.cs_r_pub);
+ if (GNUNET_OK !=
+ TALER_planchet_prepare (&wh->pk.key,
+ &wh->ps,
+ &wh->c_hash,
+ &wh->pd))
+ {
+ GNUNET_break (0);
+ GNUNET_free (wh);
+ }
+ wh->wh2 = TALER_EXCHANGE_withdraw2 (wh->exchange,
+ &wh->pd,
+ wh->reserve_priv,
+ &handle_reserve_withdraw_finished,
+ wh);
+ break;
+ default:
+ // the CSR request went wrong -> serve response to the callback
+ struct TALER_EXCHANGE_WithdrawResponse wr = {
+ .hr = csrr->hr
+ };
+ wh->cb (wh->cb_cls,
+ &wr);
+ TALER_EXCHANGE_withdraw_cancel (wh);
+ break;
+ }
}
@@ -210,16 +240,19 @@ TALER_EXCHANGE_withdraw (
TALER_EXCHANGE_WithdrawCallback res_cb,
void *res_cb_cls)
{
- struct TALER_PlanchetDetail pd;
struct TALER_EXCHANGE_WithdrawHandle *wh;
wh = GNUNET_new (struct TALER_EXCHANGE_WithdrawHandle);
wh->exchange = exchange;
wh->cb = res_cb;
wh->cb_cls = res_cb_cls;
- wh->pk = *pk;
+ wh->reserve_priv = reserve_priv;
wh->ps = *ps;
+ wh->pk = *pk;
wh->csrh = NULL;
+
+ TALER_denom_pub_deep_copy (&wh->pk.key,
+ &pk->key);
switch (pk->key.cipher)
{
case TALER_DENOMINATION_RSA:
@@ -227,27 +260,28 @@ TALER_EXCHANGE_withdraw (
TALER_planchet_prepare (&pk->key,
ps,
&wh->c_hash,
- &pd))
+ &wh->pd))
{
GNUNET_break (0);
GNUNET_free (wh);
return NULL;
}
- TALER_denom_pub_deep_copy (&wh->pk.key,
- &pk->key);
wh->wh2 = TALER_EXCHANGE_withdraw2 (exchange,
- &pd,
- reserve_priv,
+ &wh->pd,
+ wh->reserve_priv,
&handle_reserve_withdraw_finished,
wh);
- GNUNET_free (pd.blinded_planchet.details.rsa_blinded_planchet.blinded_msg);
+ GNUNET_free (
+ wh->pd.blinded_planchet.details.rsa_blinded_planchet.blinded_msg);
return wh;
case TALER_DENOMINATION_CS:
- struct TALER_WithdrawNonce nonce;
- TALER_cs_withdraw_nonce_derive (&ps->coin_priv, &nonce);
+ TALER_cs_withdraw_nonce_derive (&ps->coin_priv,
+ &wh->pd.blinded_planchet.details.
+ cs_blinded_planchet.nonce);
wh->csrh = TALER_EXCHANGE_csr (exchange,
pk,
- &nonce,
+ &wh->pd.blinded_planchet.details.
+ cs_blinded_planchet.nonce,
&withdraw_cs_stage_two_callback,
wh);
return wh;
diff --git a/src/lib/exchange_api_withdraw2.c b/src/lib/exchange_api_withdraw2.c
index c8eb31822..cb767e434 100644
--- a/src/lib/exchange_api_withdraw2.c
+++ b/src/lib/exchange_api_withdraw2.c
@@ -437,11 +437,26 @@ TALER_EXCHANGE_withdraw2 (
TALER_amount_hton (&req.amount_with_fee,
&wh->requested_amount);
- 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);
+ switch (dk->key.cipher)
+ {
+ 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;
+ }
GNUNET_CRYPTO_eddsa_sign (&reserve_priv->eddsa_priv,
&req,
&reserve_sig.eddsa_signature);
@@ -449,17 +464,44 @@ TALER_EXCHANGE_withdraw2 (
{
json_t *withdraw_obj;
-
- 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));
+ 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;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Attempting to withdraw from reserve %s\n",
TALER_B2S (&wh->reserve_pub));