diff options
Diffstat (limited to 'src/lib/exchange_api_link.c')
-rw-r--r-- | src/lib/exchange_api_link.c | 122 |
1 files changed, 46 insertions, 76 deletions
diff --git a/src/lib/exchange_api_link.c b/src/lib/exchange_api_link.c index 9e8625ed5..4b1adc723 100644 --- a/src/lib/exchange_api_link.c +++ b/src/lib/exchange_api_link.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2015-2021 Taler Systems SA + Copyright (C) 2015-2023 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 @@ -37,11 +37,6 @@ struct TALER_EXCHANGE_LinkHandle { /** - * The connection to exchange this request handle will use - */ - struct TALER_EXCHANGE_Handle *exchange; - - /** * The url for this request. */ char *url; @@ -94,9 +89,9 @@ parse_link_coin (const struct TALER_EXCHANGE_LinkHandle *lh, struct TALER_BlindedDenominationSignature bsig; struct TALER_DenominationPublicKey rpub; struct TALER_CoinSpendSignatureP link_sig; - union TALER_DenominationBlindingKeyP bks; + union GNUNET_CRYPTO_BlindingSecretP bks; struct TALER_ExchangeWithdrawValues alg_values; - struct TALER_CsNonce nonce; + union GNUNET_CRYPTO_BlindSessionNonce nonce; bool no_nonce; uint32_t coin_idx; struct GNUNET_JSON_Specification spec[] = { @@ -119,6 +114,7 @@ parse_link_coin (const struct TALER_EXCHANGE_LinkHandle *lh, struct TALER_TransferSecretP secret; struct TALER_PlanchetDetail pd; struct TALER_CoinPubHashP c_hash; + struct TALER_AgeCommitmentHash *pah = NULL; /* parse reply */ if (GNUNET_OK != @@ -142,49 +138,43 @@ parse_link_coin (const struct TALER_EXCHANGE_LinkHandle *lh, &alg_values, &bks); - lci->age_commitment_proof = NULL; - lci->h_age_commitment = NULL; + lci->has_age_commitment = false; /* Derive the age commitment and calculate the hash */ if (NULL != lh->age_commitment_proof) { - lci->age_commitment_proof = GNUNET_new (struct TALER_AgeCommitmentProof); - lci->h_age_commitment = GNUNET_new (struct TALER_AgeCommitmentHash); GNUNET_assert (GNUNET_OK == TALER_age_commitment_derive ( lh->age_commitment_proof, &secret.key, - lci->age_commitment_proof)); + &lci->age_commitment_proof)); TALER_age_commitment_hash ( - &(lci->age_commitment_proof->commitment), - lci->h_age_commitment); + &lci->age_commitment_proof.commitment, + &lci->h_age_commitment); + + lci->has_age_commitment = true; + pah = &lci->h_age_commitment; } if (GNUNET_OK != - TALER_planchet_prepare (&rpub, - &alg_values, - &bks, - &lci->coin_priv, - lci->h_age_commitment, - &c_hash, - &pd)) + TALER_planchet_prepare ( + &rpub, + &alg_values, + &bks, + no_nonce + ? NULL + : &nonce, + &lci->coin_priv, + pah, + &c_hash, + &pd)) { GNUNET_break (0); GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } - if (TALER_DENOMINATION_CS == alg_values.cipher) - { - if (no_nonce) - { - GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); - return GNUNET_SYSERR; - } - pd.blinded_planchet.details.cs_blinded_planchet.nonce = nonce; - } /* extract coin and signature */ if (GNUNET_OK != TALER_denom_sig_unblind (&lci->sig, @@ -224,8 +214,8 @@ parse_link_coin (const struct TALER_EXCHANGE_LinkHandle *lh, } /* clean up */ - TALER_denom_pub_deep_copy (&lci->pub, - &rpub); + TALER_denom_pub_copy (&lci->pub, + &rpub); GNUNET_JSON_parse_free (spec); return GNUNET_OK; } @@ -270,9 +260,10 @@ parse_link_ok (struct TALER_EXCHANGE_LinkHandle *lh, whilst 'i' and 'session' track the 2d array. */// for (session = 0; session<json_array_size (json); session++) { - json_t *jsona; + const json_t *jsona; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("new_coins", &jsona), + GNUNET_JSON_spec_array_const ("new_coins", + &jsona), GNUNET_JSON_spec_end () }; @@ -285,16 +276,8 @@ parse_link_ok (struct TALER_EXCHANGE_LinkHandle *lh, GNUNET_break_op (0); return GNUNET_SYSERR; } - if (! json_is_array (jsona)) - { - GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); - return GNUNET_SYSERR; - } - /* count all coins over all sessions */ num_coins += json_array_size (jsona); - GNUNET_JSON_parse_free (spec); } /* Now that we know how big the 1d array is, allocate and fill it. */ @@ -307,11 +290,11 @@ parse_link_ok (struct TALER_EXCHANGE_LinkHandle *lh, off_coin = 0; for (session = 0; session<json_array_size (json); session++) { - json_t *jsona; + const json_t *jsona; struct TALER_TransferPublicKeyP trans_pub; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("new_coins", - &jsona), + GNUNET_JSON_spec_array_const ("new_coins", + &jsona), GNUNET_JSON_spec_fixed_auto ("transfer_pub", &trans_pub), GNUNET_JSON_spec_end () @@ -326,12 +309,6 @@ parse_link_ok (struct TALER_EXCHANGE_LinkHandle *lh, GNUNET_break_op (0); return GNUNET_SYSERR; } - if (! json_is_array (jsona)) - { - GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); - return GNUNET_SYSERR; - } /* decode all coins */ for (i = 0; i<json_array_size (jsona); i++) @@ -357,16 +334,14 @@ parse_link_ok (struct TALER_EXCHANGE_LinkHandle *lh, { GNUNET_break_op (0); ret = GNUNET_SYSERR; - GNUNET_JSON_parse_free (spec); break; } - GNUNET_JSON_parse_free (spec); } /* end of for (session) */ if (off_coin == num_coins) { - lr.details.success.num_coins = num_coins; - lr.details.success.coins = lcis; + lr.details.ok.num_coins = num_coins; + lr.details.ok.coins = lcis; lh->link_cb (lh->link_cb_cls, &lr); lh->link_cb = NULL; @@ -384,6 +359,8 @@ parse_link_ok (struct TALER_EXCHANGE_LinkHandle *lh, { TALER_denom_sig_free (&lcis[i].sig); TALER_denom_pub_free (&lcis[i].pub); + if (lcis[i].has_age_commitment) + TALER_age_commitment_proof_free (&lcis[i].age_commitment_proof); } } return ret; @@ -466,26 +443,19 @@ handle_link_finished (void *cls, struct TALER_EXCHANGE_LinkHandle * -TALER_EXCHANGE_link (struct TALER_EXCHANGE_Handle *exchange, - const struct TALER_CoinSpendPrivateKeyP *coin_priv, - const struct - TALER_AgeCommitmentProof *age_commitment_proof, - TALER_EXCHANGE_LinkCallback link_cb, - void *link_cb_cls) +TALER_EXCHANGE_link ( + struct GNUNET_CURL_Context *ctx, + const char *url, + const struct TALER_CoinSpendPrivateKeyP *coin_priv, + const struct TALER_AgeCommitmentProof *age_commitment_proof, + TALER_EXCHANGE_LinkCallback link_cb, + void *link_cb_cls) { struct TALER_EXCHANGE_LinkHandle *lh; CURL *eh; - struct GNUNET_CURL_Context *ctx; struct TALER_CoinSpendPublicKeyP coin_pub; char arg_str[sizeof (struct TALER_CoinSpendPublicKeyP) * 2 + 32]; - if (GNUNET_YES != - TEAH_handle_is_ready (exchange)) - { - GNUNET_break (0); - return NULL; - } - GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv, &coin_pub.eddsa_pub); { @@ -500,17 +470,17 @@ TALER_EXCHANGE_link (struct TALER_EXCHANGE_Handle *exchange, *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/coins/%s/link", + "coins/%s/link", pub_str); } lh = GNUNET_new (struct TALER_EXCHANGE_LinkHandle); - lh->exchange = exchange; lh->link_cb = link_cb; lh->link_cb_cls = link_cb_cls; lh->coin_priv = *coin_priv; lh->age_commitment_proof = age_commitment_proof; - lh->url = TEAH_path_to_url (exchange, - arg_str); + lh->url = TALER_url_join (url, + arg_str, + NULL); if (NULL == lh->url) { GNUNET_free (lh); @@ -524,7 +494,6 @@ TALER_EXCHANGE_link (struct TALER_EXCHANGE_Handle *exchange, GNUNET_free (lh); return NULL; } - ctx = TEAH_handle_to_context (exchange); lh->job = GNUNET_CURL_job_add_with_ct_json (ctx, eh, &handle_link_finished, @@ -541,6 +510,7 @@ TALER_EXCHANGE_link_cancel (struct TALER_EXCHANGE_LinkHandle *lh) GNUNET_CURL_job_cancel (lh->job); lh->job = NULL; } + GNUNET_free (lh->url); GNUNET_free (lh); } |