From 720783b66a08a14624f30e8063daf64d25ce3e4c Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 22 Jun 2023 22:05:34 +0200 Subject: -more exchange API atomization --- src/include/taler_exchange_service.h | 46 +++++++++++++++++----------- src/lib/exchange_api_kyc_proof.c | 35 ++++++++------------- src/lib/exchange_api_kyc_wallet.c | 25 ++++++--------- src/lib/exchange_api_link.c | 19 ++++-------- src/lib/exchange_api_reserves_attest.c | 26 +++++----------- src/testing/testing_api_cmd_kyc_proof.c | 25 +++++++++------ src/testing/testing_api_cmd_kyc_wallet_get.c | 25 +++++++++------ src/testing/testing_api_cmd_refresh.c | 23 ++++++++------ src/testing/testing_api_cmd_reserve_attest.c | 25 +++++++++------ 9 files changed, 123 insertions(+), 126 deletions(-) (limited to 'src') diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h index 32617ba0f..065c2dcde 100644 --- a/src/include/taler_exchange_service.h +++ b/src/include/taler_exchange_service.h @@ -3286,7 +3286,8 @@ typedef void * This API is typically not used by anyone, it is more a threat against those * trying to receive a funds transfer by abusing the refresh protocol. * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param ctx CURL context + * @param url exchange base URL * @param coin_priv private key to request link data for * @param age_commitment_proof age commitment to the corresponding coin, might be NULL * @param link_cb the callback to call with the useful result of the @@ -3296,7 +3297,8 @@ typedef void */ struct TALER_EXCHANGE_LinkHandle * TALER_EXCHANGE_link ( - struct TALER_EXCHANGE_Handle *exchange, + 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, @@ -4025,7 +4027,8 @@ struct TALER_EXCHANGE_KycProofHandle; /** * Run interaction with exchange to provide proof of KYC status. * - * @param eh exchange handle to use + * @param ctx CURL context + * @param url exchange base URL * @param h_payto hash of payto URI identifying the target account * @param logic name of the KYC logic to run * @param args additional args to pass, can be NULL @@ -4035,12 +4038,14 @@ struct TALER_EXCHANGE_KycProofHandle; * @return NULL on error */ struct TALER_EXCHANGE_KycProofHandle * -TALER_EXCHANGE_kyc_proof (struct TALER_EXCHANGE_Handle *eh, - const struct TALER_PaytoHashP *h_payto, - const char *logic, - const char *args, - TALER_EXCHANGE_KycProofCallback cb, - void *cb_cls); +TALER_EXCHANGE_kyc_proof ( + struct GNUNET_CURL_Context *ctx, + const char *url, + const struct TALER_PaytoHashP *h_payto, + const char *logic, + const char *args, + TALER_EXCHANGE_KycProofCallback cb, + void *cb_cls); /** @@ -4118,7 +4123,8 @@ typedef void * Run interaction with exchange to find out the wallet's KYC * identifier. * - * @param eh exchange handle to use + * @param ctx CURL context + * @param url exchange base URL * @param reserve_priv wallet private key to check * @param balance balance (or balance threshold) crossed by the wallet * @param cb function to call with the result @@ -4126,11 +4132,13 @@ typedef void * @return NULL on error */ struct TALER_EXCHANGE_KycWalletHandle * -TALER_EXCHANGE_kyc_wallet (struct TALER_EXCHANGE_Handle *eh, - const struct TALER_ReservePrivateKeyP *reserve_priv, - const struct TALER_Amount *balance, - TALER_EXCHANGE_KycWalletCallback cb, - void *cb_cls); +TALER_EXCHANGE_kyc_wallet ( + struct GNUNET_CURL_Context *ctx, + const char *url, + const struct TALER_ReservePrivateKeyP *reserve_priv, + const struct TALER_Amount *balance, + TALER_EXCHANGE_KycWalletCallback cb, + void *cb_cls); /** @@ -6250,7 +6258,7 @@ struct TALER_EXCHANGE_PurseCreateMergeResponse union { /** - * Detailed returned on #MHD_HTTP_OK. + * Details returned on #MHD_HTTP_OK. */ struct { @@ -6746,7 +6754,8 @@ typedef void /** * Submit a request to attest attributes about the owner of a reserve. * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param ctx CURL context + * @param url exchange base URL * @param reserve_priv private key of the reserve to attest * @param attributes_length length of the @a attributes array * @param attributes array of names of attributes to get attestations for @@ -6757,7 +6766,8 @@ typedef void */ struct TALER_EXCHANGE_ReservesAttestHandle * TALER_EXCHANGE_reserves_attest ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, const struct TALER_ReservePrivateKeyP *reserve_priv, unsigned int attributes_length, const char *const*attributes, diff --git a/src/lib/exchange_api_kyc_proof.c b/src/lib/exchange_api_kyc_proof.c index 1298df4fd..e7cc9c4cf 100644 --- a/src/lib/exchange_api_kyc_proof.c +++ b/src/lib/exchange_api_kyc_proof.c @@ -36,11 +36,6 @@ struct TALER_EXCHANGE_KycProofHandle { - /** - * The connection to exchange this request handle will use - */ - struct TALER_EXCHANGE_Handle *exchange; - /** * The url for this request. */ @@ -140,27 +135,22 @@ handle_kyc_proof_finished (void *cls, struct TALER_EXCHANGE_KycProofHandle * -TALER_EXCHANGE_kyc_proof (struct TALER_EXCHANGE_Handle *exchange, - const struct TALER_PaytoHashP *h_payto, - const char *logic, - const char *args, - TALER_EXCHANGE_KycProofCallback cb, - void *cb_cls) +TALER_EXCHANGE_kyc_proof ( + struct GNUNET_CURL_Context *ctx, + const char *url, + const struct TALER_PaytoHashP *h_payto, + const char *logic, + const char *args, + TALER_EXCHANGE_KycProofCallback cb, + void *cb_cls) { struct TALER_EXCHANGE_KycProofHandle *kph; - struct GNUNET_CURL_Context *ctx; char *arg_str; if (NULL == args) args = ""; else GNUNET_assert (args[0] == '&'); - if (GNUNET_YES != - TEAH_handle_is_ready (exchange)) - { - GNUNET_break (0); - return NULL; - } { char hstr[sizeof (struct TALER_PaytoHashP) * 2]; char *end; @@ -171,17 +161,17 @@ TALER_EXCHANGE_kyc_proof (struct TALER_EXCHANGE_Handle *exchange, sizeof (hstr)); *end = '\0'; GNUNET_asprintf (&arg_str, - "/kyc-proof/%s?state=%s%s", + "kyc-proof/%s?state=%s%s", logic, hstr, args); } kph = GNUNET_new (struct TALER_EXCHANGE_KycProofHandle); - kph->exchange = exchange; kph->cb = cb; kph->cb_cls = cb_cls; - kph->url = TEAH_path_to_url (exchange, - arg_str); + kph->url = TALER_url_join (url, + arg_str, + NULL); GNUNET_free (arg_str); if (NULL == kph->url) { @@ -202,7 +192,6 @@ TALER_EXCHANGE_kyc_proof (struct TALER_EXCHANGE_Handle *exchange, curl_easy_setopt (kph->eh, CURLOPT_FOLLOWLOCATION, 0L)); - ctx = TEAH_handle_to_context (exchange); kph->job = GNUNET_CURL_job_add_raw (ctx, kph->eh, NULL, diff --git a/src/lib/exchange_api_kyc_wallet.c b/src/lib/exchange_api_kyc_wallet.c index 56794b94e..7197694ae 100644 --- a/src/lib/exchange_api_kyc_wallet.c +++ b/src/lib/exchange_api_kyc_wallet.c @@ -42,11 +42,6 @@ struct TALER_EXCHANGE_KycWalletHandle */ struct TALER_CURL_PostContext ctx; - /** - * The connection to exchange this request handle will use - */ - struct TALER_EXCHANGE_Handle *exchange; - /** * The url for this request. */ @@ -154,16 +149,17 @@ handle_kyc_wallet_finished (void *cls, struct TALER_EXCHANGE_KycWalletHandle * -TALER_EXCHANGE_kyc_wallet (struct TALER_EXCHANGE_Handle *exchange, - const struct TALER_ReservePrivateKeyP *reserve_priv, - const struct TALER_Amount *balance, - TALER_EXCHANGE_KycWalletCallback cb, - void *cb_cls) +TALER_EXCHANGE_kyc_wallet ( + struct GNUNET_CURL_Context *ctx, + const char *url, + const struct TALER_ReservePrivateKeyP *reserve_priv, + const struct TALER_Amount *balance, + TALER_EXCHANGE_KycWalletCallback cb, + void *cb_cls) { struct TALER_EXCHANGE_KycWalletHandle *kwh; CURL *eh; json_t *req; - struct GNUNET_CURL_Context *ctx; struct TALER_ReservePublicKeyP reserve_pub; struct TALER_ReserveSignatureP reserve_sig; @@ -181,18 +177,17 @@ TALER_EXCHANGE_kyc_wallet (struct TALER_EXCHANGE_Handle *exchange, &reserve_sig)); GNUNET_assert (NULL != req); kwh = GNUNET_new (struct TALER_EXCHANGE_KycWalletHandle); - kwh->exchange = exchange; kwh->cb = cb; kwh->cb_cls = cb_cls; - kwh->url = TEAH_path_to_url (exchange, - "/kyc-wallet"); + kwh->url = TALER_url_join (url, + "kyc-wallet", + NULL); if (NULL == kwh->url) { json_decref (req); GNUNET_free (kwh); return NULL; } - ctx = TEAH_handle_to_context (exchange); eh = TALER_EXCHANGE_curl_easy_get_ (kwh->url); if ( (NULL == eh) || (GNUNET_OK != diff --git a/src/lib/exchange_api_link.c b/src/lib/exchange_api_link.c index cc65b0dd3..04beeb296 100644 --- a/src/lib/exchange_api_link.c +++ b/src/lib/exchange_api_link.c @@ -447,7 +447,8 @@ handle_link_finished (void *cls, struct TALER_EXCHANGE_LinkHandle * TALER_EXCHANGE_link ( - struct TALER_EXCHANGE_Handle *exchange, + 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, @@ -455,17 +456,9 @@ TALER_EXCHANGE_link ( { 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); { @@ -480,7 +473,7 @@ TALER_EXCHANGE_link ( *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/coins/%s/link", + "coins/%s/link", pub_str); } lh = GNUNET_new (struct TALER_EXCHANGE_LinkHandle); @@ -488,8 +481,9 @@ TALER_EXCHANGE_link ( 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); @@ -503,7 +497,6 @@ TALER_EXCHANGE_link ( 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, diff --git a/src/lib/exchange_api_reserves_attest.c b/src/lib/exchange_api_reserves_attest.c index 82d5785b7..ea9ec8426 100644 --- a/src/lib/exchange_api_reserves_attest.c +++ b/src/lib/exchange_api_reserves_attest.c @@ -38,11 +38,6 @@ struct TALER_EXCHANGE_ReservesAttestHandle { - /** - * The connection to exchange this request handle will use - */ - struct TALER_EXCHANGE_Handle *exchange; - /** * The url for this request. */ @@ -131,6 +126,8 @@ handle_reserves_attest_ok (struct TALER_EXCHANGE_ReservesAttestHandle *rsh, GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } + /* FIXME: validate exchange_pub is actually + a good exchange signing key */ rsh->cb (rsh->cb_cls, &rs); rsh->cb = NULL; @@ -228,7 +225,8 @@ handle_reserves_attest_finished (void *cls, struct TALER_EXCHANGE_ReservesAttestHandle * TALER_EXCHANGE_reserves_attest ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, const struct TALER_ReservePrivateKeyP *reserve_priv, unsigned int attributes_length, const char *const*attributes, @@ -236,7 +234,6 @@ TALER_EXCHANGE_reserves_attest ( void *cb_cls) { struct TALER_EXCHANGE_ReservesAttestHandle *rsh; - struct GNUNET_CURL_Context *ctx; CURL *eh; char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 32]; struct TALER_ReserveSignatureP reserve_sig; @@ -248,12 +245,6 @@ TALER_EXCHANGE_reserves_attest ( GNUNET_break (0); return NULL; } - if (GNUNET_YES != - TEAH_handle_is_ready (exchange)) - { - GNUNET_break (0); - return NULL; - } details = json_array (); GNUNET_assert (NULL != details); for (unsigned int i = 0; iexchange = exchange; rsh->cb = cb; rsh->cb_cls = cb_cls; GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv, @@ -280,11 +270,12 @@ TALER_EXCHANGE_reserves_attest ( *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/reserves-attest/%s", + "reserves-attest/%s", pub_str); } - rsh->url = TEAH_path_to_url (exchange, - arg_str); + rsh->url = TALER_url_join (url, + arg_str, + NULL); if (NULL == rsh->url) { json_decref (details); @@ -328,7 +319,6 @@ TALER_EXCHANGE_reserves_attest ( } json_decref (attest_obj); } - ctx = TEAH_handle_to_context (exchange); rsh->job = GNUNET_CURL_job_add2 (ctx, eh, rsh->post_ctx.headers, diff --git a/src/testing/testing_api_cmd_kyc_proof.c b/src/testing/testing_api_cmd_kyc_proof.c index 291378d97..c0fe7495a 100644 --- a/src/testing/testing_api_cmd_kyc_proof.c +++ b/src/testing/testing_api_cmd_kyc_proof.c @@ -127,13 +127,16 @@ proof_kyc_run (void *cls, const struct TALER_TESTING_Command *res_cmd; const struct TALER_PaytoHashP *h_payto; char *uargs; - struct TALER_EXCHANGE_Handle *exchange - = TALER_TESTING_get_exchange (is); + const char *exchange_url; (void) cmd; - if (NULL == exchange) - return; kps->is = is; + exchange_url = TALER_TESTING_get_exchange_url (is); + if (NULL == exchange_url) + { + GNUNET_break (0); + return; + } res_cmd = TALER_TESTING_interpreter_lookup_command ( kps->is, kps->payment_target_reference); @@ -157,12 +160,14 @@ proof_kyc_run (void *cls, GNUNET_asprintf (&uargs, "&code=%s", kps->code); - kps->kph = TALER_EXCHANGE_kyc_proof (exchange, - h_payto, - kps->logic, - uargs, - &proof_kyc_cb, - kps); + kps->kph = TALER_EXCHANGE_kyc_proof ( + TALER_TESTING_interpreter_get_context (is), + exchange_url, + h_payto, + kps->logic, + uargs, + &proof_kyc_cb, + kps); GNUNET_free (uargs); GNUNET_assert (NULL != kps->kph); } diff --git a/src/testing/testing_api_cmd_kyc_wallet_get.c b/src/testing/testing_api_cmd_kyc_wallet_get.c index 5f6eaeb4c..fa6edab20 100644 --- a/src/testing/testing_api_cmd_kyc_wallet_get.c +++ b/src/testing/testing_api_cmd_kyc_wallet_get.c @@ -147,13 +147,16 @@ wallet_kyc_run (void *cls, struct TALER_TESTING_Interpreter *is) { struct KycWalletGetState *kwg = cls; - struct TALER_EXCHANGE_Handle *exchange - = TALER_TESTING_get_exchange (is); + const char *exchange_url; kwg->cmd = cmd; - if (NULL == exchange) - return; kwg->is = is; + exchange_url = TALER_TESTING_get_exchange_url (is); + if (NULL == exchange_url) + { + GNUNET_break (0); + return; + } if (NULL != kwg->reserve_reference) { const struct TALER_TESTING_Command *res_cmd; @@ -185,13 +188,15 @@ wallet_kyc_run (void *cls, GNUNET_CRYPTO_eddsa_key_get_public (&kwg->reserve_priv.eddsa_priv, &kwg->reserve_pub.eddsa_pub); kwg->reserve_payto_uri - = TALER_reserve_make_payto (TALER_EXCHANGE_get_base_url (exchange), + = TALER_reserve_make_payto (exchange_url, &kwg->reserve_pub); - kwg->kwh = TALER_EXCHANGE_kyc_wallet (exchange, - &kwg->reserve_priv, - &kwg->balance, - &wallet_kyc_cb, - kwg); + kwg->kwh = TALER_EXCHANGE_kyc_wallet ( + TALER_TESTING_interpreter_get_context (is), + exchange_url, + &kwg->reserve_priv, + &kwg->balance, + &wallet_kyc_cb, + kwg); GNUNET_assert (NULL != kwg->kwh); } diff --git a/src/testing/testing_api_cmd_refresh.c b/src/testing/testing_api_cmd_refresh.c index a15e8dbc6..3b420ac66 100644 --- a/src/testing/testing_api_cmd_refresh.c +++ b/src/testing/testing_api_cmd_refresh.c @@ -783,13 +783,16 @@ refresh_link_run (void *cls, const struct TALER_TESTING_Command *reveal_cmd; const struct TALER_TESTING_Command *melt_cmd; const struct TALER_TESTING_Command *coin_cmd; - struct TALER_EXCHANGE_Handle *exchange - = TALER_TESTING_get_exchange (is); + const char *exchange_url; rls->cmd = cmd; - if (NULL == exchange) - return; rls->is = is; + exchange_url = TALER_TESTING_get_exchange_url (is); + if (NULL == exchange_url) + { + GNUNET_break (0); + return; + } reveal_cmd = TALER_TESTING_interpreter_lookup_command (rls->is, rls->reveal_reference); if (NULL == reveal_cmd) @@ -832,11 +835,13 @@ refresh_link_run (void *cls, } /* finally, use private key from withdraw sign command */ - rls->rlh = TALER_EXCHANGE_link (exchange, - coin_priv, - rms->refresh_data.melt_age_commitment_proof, - &link_cb, - rls); + rls->rlh = TALER_EXCHANGE_link ( + TALER_TESTING_interpreter_get_context (is), + exchange_url, + coin_priv, + rms->refresh_data.melt_age_commitment_proof, + &link_cb, + rls); if (NULL == rls->rlh) { diff --git a/src/testing/testing_api_cmd_reserve_attest.c b/src/testing/testing_api_cmd_reserve_attest.c index 77166d2b5..64b15a10d 100644 --- a/src/testing/testing_api_cmd_reserve_attest.c +++ b/src/testing/testing_api_cmd_reserve_attest.c @@ -152,12 +152,15 @@ attest_run (void *cls, { struct AttestState *ss = cls; const struct TALER_TESTING_Command *create_reserve; - struct TALER_EXCHANGE_Handle *exchange - = TALER_TESTING_get_exchange (is); + const char *exchange_url; - if (NULL == exchange) - return; ss->is = is; + exchange_url = TALER_TESTING_get_exchange_url (is); + if (NULL == exchange_url) + { + GNUNET_break (0); + return; + } create_reserve = TALER_TESTING_interpreter_lookup_command (is, ss->reserve_reference); @@ -179,12 +182,14 @@ attest_run (void *cls, } GNUNET_CRYPTO_eddsa_key_get_public (&ss->reserve_priv->eddsa_priv, &ss->reserve_pub.eddsa_pub); - ss->rsh = TALER_EXCHANGE_reserves_attest (exchange, - ss->reserve_priv, - ss->attrs_len, - ss->attrs, - &reserve_attest_cb, - ss); + ss->rsh = TALER_EXCHANGE_reserves_attest ( + TALER_TESTING_interpreter_get_context (is), + exchange_url, + ss->reserve_priv, + ss->attrs_len, + ss->attrs, + &reserve_attest_cb, + ss); } -- cgit v1.2.3