diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-11-01 10:04:48 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-11-05 10:37:37 +0100 |
commit | a88d2a91a39c431c3d23c6c338e9a10a39380508 (patch) | |
tree | 8b2f03948955c8583da896ae45cac136239a756a | |
parent | 80340f545076f5d09321a9140aef9d5afdce0346 (diff) |
-work on exchange
-rw-r--r-- | src/exchange/taler-exchange-httpd_common_kyc.h | 3 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_reserves_attest.c | 14 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_reserves_close.c | 44 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_reserves_get_attest.c | 12 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_reserves_history.c | 10 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_reserves_purse.c | 42 | ||||
-rw-r--r-- | src/exchangedb/pg_iterate_reserve_close_info.c | 8 | ||||
-rw-r--r-- | src/exchangedb/pg_iterate_reserve_close_info.h | 2 | ||||
-rw-r--r-- | src/include/taler_exchangedb_plugin.h | 2 |
9 files changed, 76 insertions, 61 deletions
diff --git a/src/exchange/taler-exchange-httpd_common_kyc.h b/src/exchange/taler-exchange-httpd_common_kyc.h index 2c9e9bcff..9e2cd2288 100644 --- a/src/exchange/taler-exchange-httpd_common_kyc.h +++ b/src/exchange/taler-exchange-httpd_common_kyc.h @@ -299,6 +299,9 @@ typedef void struct TEH_LegitimizationCheckHandle; +/* FIXME: add another variation of this API with a + NormalizedPayto payto_uri, as we currently 'fake' + a full payto in 3 places related to wallets! */ /** * Do legitimization check. * diff --git a/src/exchange/taler-exchange-httpd_reserves_attest.c b/src/exchange/taler-exchange-httpd_reserves_attest.c index b3ae4828a..2ae16439e 100644 --- a/src/exchange/taler-exchange-httpd_reserves_attest.c +++ b/src/exchange/taler-exchange-httpd_reserves_attest.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2022 Taler Systems SA + Copyright (C) 2014-2022, 2024 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -53,7 +53,7 @@ struct ReserveAttestContext /** * Hash of the payto URI of this reserve. */ - struct TALER_PaytoHashP h_payto; + struct TALER_NormalizedPaytoHashP h_payto; /** * Timestamp of the request. @@ -165,7 +165,7 @@ reply_reserve_attest_success (struct MHD_Connection *connection, */ static void kyc_process_cb (void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, const char *provider_name, struct GNUNET_TIME_Timestamp collection_time, struct GNUNET_TIME_Timestamp expiration_time, @@ -355,13 +355,13 @@ TEH_handler_reserves_attest (struct TEH_RequestContext *rc, } { - char *payto_uri; + struct TALER_NormalizedPayto payto_uri; payto_uri = TALER_reserve_make_payto (TEH_base_url, &rsc.reserve_pub); - TALER_payto_hash (payto_uri, - &rsc.h_payto); - GNUNET_free (payto_uri); + TALER_normalized_payto_hash (payto_uri, + &rsc.h_payto); + GNUNET_free (payto_uri.normalized_payto); } if (GNUNET_OK != diff --git a/src/exchange/taler-exchange-httpd_reserves_close.c b/src/exchange/taler-exchange-httpd_reserves_close.c index 711129927..db3b9e851 100644 --- a/src/exchange/taler-exchange-httpd_reserves_close.c +++ b/src/exchange/taler-exchange-httpd_reserves_close.c @@ -70,7 +70,7 @@ struct ReserveCloseContext /** * Where to wire the funds, may be NULL. */ - const char *payto_uri; + struct TALER_FullPayto payto_uri; /** * Response to return. Note that the response must @@ -108,7 +108,7 @@ struct ReserveCloseContext /** * Hash of the @e payto_uri, if given (otherwise zero). */ - struct TALER_PaytoHashP h_payto; + struct TALER_FullPaytoHashP h_payto; /** * KYC status for the request. @@ -118,7 +118,7 @@ struct ReserveCloseContext /** * Hash of the payto-URI that was used for the KYC decision. */ - struct TALER_PaytoHashP kyc_payto; + struct TALER_NormalizedPaytoHashP kyc_payto; /** * Query status from the amount_it() helper function. @@ -280,7 +280,9 @@ reserve_close_transaction ( { struct ReserveCloseContext *rcc = cls; enum GNUNET_DB_QueryStatus qs; - char *payto_uri = NULL; + struct TALER_FullPayto payto_uri = { + .full_payto = NULL + }; const struct TALER_WireFeeSet *wf; qs = TEH_plugin->select_reserve_close_info ( @@ -313,8 +315,8 @@ reserve_close_transaction ( break; } - if ( (NULL == rcc->payto_uri) && - (NULL == payto_uri) ) + if ( (NULL == rcc->payto_uri.full_payto) && + (NULL == payto_uri.full_payto) ) { *mhd_ret = TALER_MHD_reply_with_error ( @@ -326,17 +328,17 @@ reserve_close_transaction ( } if ( (! rcc->resumed) && - (NULL != rcc->payto_uri) && - ( (NULL == payto_uri) || - (0 != strcmp (payto_uri, - rcc->payto_uri)) ) ) + (NULL != rcc->payto_uri.full_payto) && + ( (NULL == payto_uri.full_payto) || + (0 != TALER_full_payto_cmp (payto_uri, + rcc->payto_uri)) ) ) { /* KYC check may be needed: we're not returning the money to the account that funded the reserve in the first place. */ - TALER_payto_hash (rcc->payto_uri, - &rcc->kyc_payto); + TALER_full_payto_normalize_and_hash (rcc->payto_uri, + &rcc->kyc_payto); rcc->lch = TEH_legitimization_check ( &rcc->rc->async_scope_id, TALER_KYCLOGIC_KYC_TRIGGER_RESERVE_CLOSE, @@ -356,13 +358,13 @@ reserve_close_transaction ( return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; } rcc->kyc.ok = true; - if (NULL == rcc->payto_uri) + if (NULL == rcc->payto_uri.full_payto) rcc->payto_uri = payto_uri; { char *method; - method = TALER_payto_get_method (rcc->payto_uri); + method = TALER_payto_get_method (rcc->payto_uri.full_payto); wf = TEH_wire_fees_by_time (rcc->timestamp, method); if (NULL == wf) @@ -401,8 +403,8 @@ reserve_close_transaction ( rcc->timestamp, &rcc->balance, &wf->closing); - GNUNET_free (payto_uri); - rcc->payto_uri = NULL; + GNUNET_free (payto_uri.full_payto); + rcc->payto_uri.full_payto = NULL; if (GNUNET_DB_STATUS_HARD_ERROR == qs) { GNUNET_break (0); @@ -465,8 +467,8 @@ TEH_handler_reserves_close ( GNUNET_JSON_spec_timestamp ("request_timestamp", &rcc->timestamp), GNUNET_JSON_spec_mark_optional ( - TALER_JSON_spec_payto_uri ("payto_uri", - &rcc->payto_uri), + TALER_JSON_spec_full_payto_uri ("payto_uri", + &rcc->payto_uri), NULL), GNUNET_JSON_spec_fixed_auto ("reserve_sig", &rcc->reserve_sig), @@ -510,9 +512,9 @@ TEH_handler_reserves_close ( } } - if (NULL != rcc->payto_uri) - TALER_payto_hash (rcc->payto_uri, - &rcc->h_payto); + if (NULL != rcc->payto_uri.full_payto) + TALER_full_payto_hash (rcc->payto_uri, + &rcc->h_payto); if (GNUNET_OK != TALER_wallet_reserve_close_verify ( rcc->timestamp, diff --git a/src/exchange/taler-exchange-httpd_reserves_get_attest.c b/src/exchange/taler-exchange-httpd_reserves_get_attest.c index c3cb7bc16..aba74220b 100644 --- a/src/exchange/taler-exchange-httpd_reserves_get_attest.c +++ b/src/exchange/taler-exchange-httpd_reserves_get_attest.c @@ -43,7 +43,7 @@ struct ReserveAttestContext /** * Hash of the payto URI of this reserve. */ - struct TALER_PaytoHashP h_payto; + struct TALER_NormalizedPaytoHashP h_payto; /** * Available attributes. @@ -67,7 +67,7 @@ struct ReserveAttestContext */ static void kyc_process_cb (void *cls, - const struct TALER_PaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, const char *provider_name, struct GNUNET_TIME_Timestamp collection_time, struct GNUNET_TIME_Timestamp expiration_time, @@ -135,14 +135,14 @@ TEH_handler_reserves_get_attest ( args[0]); } { - char *payto_uri; + struct TALER_NormalizedPayto payto_uri; payto_uri = TALER_reserve_make_payto (TEH_base_url, &rsc.reserve_pub); - TALER_payto_hash (payto_uri, - &rsc.h_payto); - GNUNET_free (payto_uri); + TALER_normalized_payto_hash (payto_uri, + &rsc.h_payto); + GNUNET_free (payto_uri.normalized_payto); } { enum GNUNET_DB_QueryStatus qs; diff --git a/src/exchange/taler-exchange-httpd_reserves_history.c b/src/exchange/taler-exchange-httpd_reserves_history.c index 24f836cdd..f74f41592 100644 --- a/src/exchange/taler-exchange-httpd_reserves_history.c +++ b/src/exchange/taler-exchange-httpd_reserves_history.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2023 Taler Systems SA + Copyright (C) 2014-2024 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -63,8 +63,8 @@ compile_reserve_history ( "CREDIT"), GNUNET_JSON_pack_timestamp ("timestamp", bank->execution_date), - GNUNET_JSON_pack_string ("sender_account_url", - bank->sender_account_details), + TALER_JSON_pack_full_payto ("sender_account_url", + bank->sender_account_details), GNUNET_JSON_pack_uint64 ("wire_reference", bank->wire_reference), TALER_JSON_pack_amount ("amount", @@ -178,8 +178,8 @@ compile_reserve_history ( GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("type", "CLOSING"), - GNUNET_JSON_pack_string ("receiver_account_details", - closing->receiver_account_details), + TALER_JSON_pack_full_payto ("receiver_account_details", + closing->receiver_account_details), GNUNET_JSON_pack_data_auto ("wtid", &closing->wtid), GNUNET_JSON_pack_data_auto ("exchange_pub", diff --git a/src/exchange/taler-exchange-httpd_reserves_purse.c b/src/exchange/taler-exchange-httpd_reserves_purse.c index 26425448b..56207ef8c 100644 --- a/src/exchange/taler-exchange-httpd_reserves_purse.c +++ b/src/exchange/taler-exchange-httpd_reserves_purse.c @@ -73,7 +73,7 @@ struct ReservePurseContext /** * Payto URI for the reserve. */ - char *payto_uri; + struct TALER_NormalizedPayto payto_uri; /** * Public key of the account (reserve) we are creating a purse for. @@ -133,7 +133,7 @@ struct ReservePurseContext /** * Hash of the @e payto_uri. */ - struct TALER_PaytoHashP h_payto; + struct TALER_NormalizedPaytoHashP h_payto; /** * KYC status of the operation. @@ -580,7 +580,7 @@ rpc_cleaner (struct TEH_RequestContext *rc) rpc->lch = NULL; } GNUNET_free (rpc->econtract.econtract); - GNUNET_free (rpc->payto_uri); + GNUNET_free (rpc->payto_uri.normalized_payto); GNUNET_free (rpc); } @@ -663,8 +663,8 @@ TEH_handler_reserves_purse ( rpc->payto_uri = TALER_reserve_make_payto (TEH_base_url, &rpc->account_pub.reserve_pub); - TALER_payto_hash (rpc->payto_uri, - &rpc->h_payto); + TALER_normalized_payto_hash (rpc->payto_uri, + &rpc->h_payto); TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++; @@ -682,8 +682,7 @@ TEH_handler_reserves_purse ( connection, MHD_HTTP_FORBIDDEN, TALER_EC_EXCHANGE_RESERVES_PURSE_MERGE_SIGNATURE_INVALID, - rpc->payto_uri); - GNUNET_free (rpc->payto_uri); + rpc->payto_uri.normalized_payto); return ret; } GNUNET_assert (GNUNET_OK == @@ -816,17 +815,24 @@ TEH_handler_reserves_purse ( TALER_EC_EXCHANGE_PURSE_ECONTRACT_SIGNATURE_INVALID, NULL); } - - rpc->lch = TEH_legitimization_check ( - &rpc->rc->async_scope_id, - TALER_KYCLOGIC_KYC_TRIGGER_P2P_RECEIVE, - rpc->payto_uri, - &rpc->h_payto, - &rpc->account_pub, - &amount_iterator, - rpc, - &reserve_purse_legi_cb, - rpc); + { + struct TALER_FullPayto fake_full_payto; + + GNUNET_asprintf (&fake_full_payto.full_payto, + "%s?receiver-name=wallet", + rpc->payto_uri.normalized_payto); + rpc->lch = TEH_legitimization_check ( + &rpc->rc->async_scope_id, + TALER_KYCLOGIC_KYC_TRIGGER_P2P_RECEIVE, + fake_full_payto, + &rpc->h_payto, + &rpc->account_pub, + &amount_iterator, + rpc, + &reserve_purse_legi_cb, + rpc); + GNUNET_free (fake_full_payto.full_payto); + } GNUNET_assert (NULL != rpc->lch); MHD_suspend_connection (rc->connection); GNUNET_CONTAINER_DLL_insert (rpc_head, diff --git a/src/exchangedb/pg_iterate_reserve_close_info.c b/src/exchangedb/pg_iterate_reserve_close_info.c index 4b57041fd..2584014ce 100644 --- a/src/exchangedb/pg_iterate_reserve_close_info.c +++ b/src/exchangedb/pg_iterate_reserve_close_info.c @@ -93,7 +93,7 @@ iterate_reserve_close_info_cb (void *cls, enum GNUNET_DB_QueryStatus TEH_PG_iterate_reserve_close_info ( void *cls, - const struct TALER_FullPaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, struct GNUNET_TIME_Absolute time_limit, TALER_EXCHANGEDB_KycAmountCallback kac, void *kac_cls) @@ -116,7 +116,11 @@ TEH_PG_iterate_reserve_close_info ( " amount" ",execution_date" " FROM reserves_close" - " WHERE wire_target_h_payto=$1" + " WHERE wire_target_h_payto IN (" + " SELECT wire_target_h_payto" + " FROM wire_targets" + " WHERE h_normalized_payto=$1" + " )" " AND execution_date >= $2" " ORDER BY execution_date DESC"); return GNUNET_PQ_eval_prepared_multi_select ( diff --git a/src/exchangedb/pg_iterate_reserve_close_info.h b/src/exchangedb/pg_iterate_reserve_close_info.h index a06002bdc..55cd5f487 100644 --- a/src/exchangedb/pg_iterate_reserve_close_info.h +++ b/src/exchangedb/pg_iterate_reserve_close_info.h @@ -40,7 +40,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_iterate_reserve_close_info ( void *cls, - const struct TALER_FullPaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, struct GNUNET_TIME_Absolute time_limit, TALER_EXCHANGEDB_KycAmountCallback kac, void *kac_cls); diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index cb27c4f71..faeaf7615 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -5232,7 +5232,7 @@ struct TALER_EXCHANGEDB_Plugin enum GNUNET_DB_QueryStatus (*iterate_reserve_close_info)( void *cls, - const struct TALER_FullPaytoHashP *h_payto, + const struct TALER_NormalizedPaytoHashP *h_payto, struct GNUNET_TIME_Absolute time_limit, TALER_EXCHANGEDB_KycAmountCallback kac, void *kac_cls); |