summaryrefslogtreecommitdiff
path: root/src/lib/exchange_api_batch_withdraw.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/exchange_api_batch_withdraw.c')
-rw-r--r--src/lib/exchange_api_batch_withdraw.c192
1 files changed, 109 insertions, 83 deletions
diff --git a/src/lib/exchange_api_batch_withdraw.c b/src/lib/exchange_api_batch_withdraw.c
index 4e0d6abcf..a1b21f347 100644
--- a/src/lib/exchange_api_batch_withdraw.c
+++ b/src/lib/exchange_api_batch_withdraw.c
@@ -54,9 +54,14 @@ struct CoinData
const struct TALER_AgeCommitmentHash *ach;
/**
- * blinding secret
+ * blinding secret
*/
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
+
+ /**
+ * Session nonce.
+ */
+ union GNUNET_CRYPTO_BlindSessionNonce nonce;
/**
* Private key of the coin we are withdrawing.
@@ -69,7 +74,7 @@ struct CoinData
struct TALER_PlanchetDetail pd;
/**
- * Values of the @cipher selected
+ * Values of the cipher selected
*/
struct TALER_ExchangeWithdrawValues alg_values;
@@ -79,7 +84,7 @@ struct CoinData
struct TALER_CoinPubHashP c_hash;
/**
- * Handler for the CS R request (only used for TALER_DENOMINATION_CS denominations)
+ * Handler for the CS R request (only used for GNUNET_CRYPTO_BSA_CS denominations)
*/
struct TALER_EXCHANGE_CsRWithdrawHandle *csrh;
@@ -97,9 +102,19 @@ struct TALER_EXCHANGE_BatchWithdrawHandle
{
/**
- * The connection to exchange this request handle will use
+ * The curl context to use
+ */
+ struct GNUNET_CURL_Context *curl_ctx;
+
+ /**
+ * The base URL to the exchange
+ */
+ const char *exchange_url;
+
+ /**
+ * The /keys information from the exchange
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ const struct TALER_EXCHANGE_Keys *keys;
/**
* Handle for the actual (internal) batch withdraw operation.
@@ -144,37 +159,34 @@ struct TALER_EXCHANGE_BatchWithdrawHandle
* HTTP /reserves/$RESERVE_PUB/batch-withdraw request.
*
* @param cls the `struct TALER_EXCHANGE_BatchWithdrawHandle`
- * @param hr HTTP response data
- * @param blind_sigs array of blind signatures over the coins, NULL on error
- * @param blind_sigs_length length of the @a blind_sigs array
+ * @param bw2r response data
*/
static void
handle_reserve_batch_withdraw_finished (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_BlindedDenominationSignature *blind_sigs,
- unsigned int blind_sigs_length)
+ const struct TALER_EXCHANGE_BatchWithdraw2Response *bw2r)
{
struct TALER_EXCHANGE_BatchWithdrawHandle *wh = cls;
struct TALER_EXCHANGE_BatchWithdrawResponse wr = {
- .hr = *hr
+ .hr = bw2r->hr
};
- struct TALER_EXCHANGE_PrivateCoinDetails coins[wh->num_coins];
+ struct TALER_EXCHANGE_PrivateCoinDetails coins[GNUNET_NZL (wh->num_coins)];
wh->wh2 = NULL;
memset (coins,
0,
sizeof (coins));
- if (blind_sigs_length != wh->num_coins)
- {
- GNUNET_break_op (0);
- wr.hr.http_status = 0;
- wr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- }
- switch (hr->http_status)
+ switch (bw2r->hr.http_status)
{
case MHD_HTTP_OK:
{
+ if (bw2r->details.ok.blind_sigs_length != wh->num_coins)
+ {
+ GNUNET_break_op (0);
+ wr.hr.http_status = 0;
+ wr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ break;
+ }
for (unsigned int i = 0; i<wh->num_coins; i++)
{
struct CoinData *cd = &wh->coins[i];
@@ -183,7 +195,7 @@ handle_reserve_batch_withdraw_finished (
if (GNUNET_OK !=
TALER_planchet_to_coin (&cd->pk.key,
- &blind_sigs[i],
+ &bw2r->details.ok.blind_sigs[i],
&cd->bks,
&cd->priv,
cd->ach,
@@ -200,20 +212,24 @@ handle_reserve_batch_withdraw_finished (
coin->sig = fc.sig;
coin->exchange_vals = cd->alg_values;
}
- wr.details.success.coins = coins;
- wr.details.success.num_coins = wh->num_coins;
+ wr.details.ok.coins = coins;
+ wr.details.ok.num_coins = wh->num_coins;
break;
}
case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
{
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_uint64 ("payment_target_uuid",
- &wr.details.accepted.payment_target_uuid),
+ GNUNET_JSON_spec_fixed_auto (
+ "h_payto",
+ &wr.details.unavailable_for_legal_reasons.h_payto),
+ GNUNET_JSON_spec_uint64 (
+ "requirement_row",
+ &wr.details.unavailable_for_legal_reasons.requirement_row),
GNUNET_JSON_spec_end ()
};
if (GNUNET_OK !=
- GNUNET_JSON_parse (hr->reply,
+ GNUNET_JSON_parse (bw2r->hr.reply,
spec,
NULL, NULL))
{
@@ -254,10 +270,12 @@ phase_two (struct TALER_EXCHANGE_BatchWithdrawHandle *wh)
pds[i] = cd->pd;
}
wh->wh2 = TALER_EXCHANGE_batch_withdraw2 (
- wh->exchange,
+ wh->curl_ctx,
+ wh->exchange_url,
+ wh->keys,
wh->reserve_priv,
- pds,
wh->num_coins,
+ pds,
&handle_reserve_batch_withdraw_finished,
wh);
}
@@ -281,30 +299,38 @@ withdraw_cs_stage_two_callback (
};
cd->csrh = NULL;
- GNUNET_assert (TALER_DENOMINATION_CS == cd->pk.key.cipher);
+ GNUNET_assert (GNUNET_CRYPTO_BSA_CS ==
+ cd->pk.key.bsign_pub_key->cipher);
switch (csrr->hr.http_status)
{
case MHD_HTTP_OK:
- cd->alg_values = csrr->details.success.alg_values;
+ GNUNET_assert (NULL ==
+ cd->alg_values.blinding_inputs);
+ TALER_denom_ewv_copy (&cd->alg_values,
+ &csrr->details.ok.alg_values);
TALER_planchet_setup_coin_priv (&cd->ps,
&cd->alg_values,
&cd->priv);
TALER_planchet_blinding_secret_create (&cd->ps,
&cd->alg_values,
&cd->bks);
- /* This initializes the 2nd half of the
- wh->pd.blinded_planchet! */
if (GNUNET_OK !=
TALER_planchet_prepare (&cd->pk.key,
&cd->alg_values,
&cd->bks,
+ &cd->nonce,
&cd->priv,
cd->ach,
&cd->c_hash,
&cd->pd))
{
GNUNET_break (0);
+ wr.hr.http_status = 0;
+ wr.hr.ec = TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR;
+ wh->cb (wh->cb_cls,
+ &wr);
TALER_EXCHANGE_batch_withdraw_cancel (wh);
+ return;
}
wh->cs_pending--;
if (0 == wh->cs_pending)
@@ -321,17 +347,21 @@ withdraw_cs_stage_two_callback (
struct TALER_EXCHANGE_BatchWithdrawHandle *
TALER_EXCHANGE_batch_withdraw (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *curl_ctx,
+ const char *exchange_url,
+ const struct TALER_EXCHANGE_Keys *keys,
const struct TALER_ReservePrivateKeyP *reserve_priv,
- const struct TALER_EXCHANGE_WithdrawCoinInput *wcis,
unsigned int wci_length,
+ const struct TALER_EXCHANGE_WithdrawCoinInput wcis[static wci_length],
TALER_EXCHANGE_BatchWithdrawCallback res_cb,
void *res_cb_cls)
{
struct TALER_EXCHANGE_BatchWithdrawHandle *wh;
wh = GNUNET_new (struct TALER_EXCHANGE_BatchWithdrawHandle);
- wh->exchange = exchange;
+ wh->curl_ctx = curl_ctx;
+ wh->exchange_url = exchange_url;
+ wh->keys = keys;
wh->cb = res_cb;
wh->cb_cls = res_cb_cls;
wh->reserve_priv = reserve_priv;
@@ -347,58 +377,53 @@ TALER_EXCHANGE_batch_withdraw (
cd->ps = *wci->ps;
cd->ach = wci->ach;
cd->pk = *wci->pk;
- TALER_denom_pub_deep_copy (&cd->pk.key,
- &wci->pk->key);
- switch (wci->pk->key.cipher)
+ TALER_denom_pub_copy (&cd->pk.key,
+ &wci->pk->key);
+ switch (wci->pk->key.bsign_pub_key->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
+ TALER_denom_ewv_copy (&cd->alg_values,
+ TALER_denom_ewv_rsa_singleton ());
+ TALER_planchet_setup_coin_priv (&cd->ps,
+ &cd->alg_values,
+ &cd->priv);
+ TALER_planchet_blinding_secret_create (&cd->ps,
+ &cd->alg_values,
+ &cd->bks);
+ if (GNUNET_OK !=
+ TALER_planchet_prepare (&cd->pk.key,
+ &cd->alg_values,
+ &cd->bks,
+ NULL,
+ &cd->priv,
+ cd->ach,
+ &cd->c_hash,
+ &cd->pd))
{
- cd->alg_values.cipher = TALER_DENOMINATION_RSA;
- TALER_planchet_setup_coin_priv (&cd->ps,
- &cd->alg_values,
- &cd->priv);
- TALER_planchet_blinding_secret_create (&cd->ps,
- &cd->alg_values,
- &cd->bks);
- if (GNUNET_OK !=
- TALER_planchet_prepare (&cd->pk.key,
- &cd->alg_values,
- &cd->bks,
- &cd->priv,
- cd->ach,
- &cd->c_hash,
- &cd->pd))
- {
- GNUNET_break (0);
- TALER_EXCHANGE_batch_withdraw_cancel (wh);
- return NULL;
- }
- break;
+ GNUNET_break (0);
+ TALER_EXCHANGE_batch_withdraw_cancel (wh);
+ return NULL;
}
- case TALER_DENOMINATION_CS:
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
+ TALER_cs_withdraw_nonce_derive (
+ &cd->ps,
+ &cd->nonce.cs_nonce);
+ cd->csrh = TALER_EXCHANGE_csr_withdraw (
+ curl_ctx,
+ exchange_url,
+ &cd->pk,
+ &cd->nonce.cs_nonce,
+ &withdraw_cs_stage_two_callback,
+ cd);
+ if (NULL == cd->csrh)
{
- TALER_cs_withdraw_nonce_derive (
- &cd->ps,
- &cd->pd.blinded_planchet.details.cs_blinded_planchet.nonce);
- /* Note that we only initialize the first half
- of the blinded_planchet here; the other part
- will be done after the /csr-withdraw request! */
- cd->pd.blinded_planchet.cipher = TALER_DENOMINATION_CS;
- cd->csrh = TALER_EXCHANGE_csr_withdraw (
- exchange,
- &cd->pk,
- &cd->pd.blinded_planchet.details.cs_blinded_planchet.nonce,
- &withdraw_cs_stage_two_callback,
- cd);
- if (NULL == cd->csrh)
- {
- GNUNET_break (0);
- TALER_EXCHANGE_batch_withdraw_cancel (wh);
- return NULL;
- }
- wh->cs_pending++;
- break;
+ GNUNET_break (0);
+ TALER_EXCHANGE_batch_withdraw_cancel (wh);
+ return NULL;
}
+ wh->cs_pending++;
+ break;
default:
GNUNET_break (0);
TALER_EXCHANGE_batch_withdraw_cancel (wh);
@@ -424,6 +449,7 @@ TALER_EXCHANGE_batch_withdraw_cancel (
TALER_EXCHANGE_csr_withdraw_cancel (cd->csrh);
cd->csrh = NULL;
}
+ TALER_denom_ewv_free (&cd->alg_values);
TALER_blinded_planchet_free (&cd->pd.blinded_planchet);
TALER_denom_pub_free (&cd->pk.key);
}