From 8921862c25692fee473842cf06eca103f3f60aed Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 25 Aug 2024 22:39:00 +0200 Subject: normalize paytos when using them in auditor --- src/auditor/generate-auditor-basedb.conf | 21 +---- src/auditor/taler-helper-auditor-wire-credit.c | 50 ++++++----- src/auditor/taler-helper-auditor-wire-debit.c | 119 ++++++++++++++----------- src/bank-lib/bank_api_credit.c | 10 +-- src/bank-lib/bank_api_debit.c | 10 +-- 5 files changed, 108 insertions(+), 102 deletions(-) diff --git a/src/auditor/generate-auditor-basedb.conf b/src/auditor/generate-auditor-basedb.conf index cbd8b1cd4..36de9d244 100644 --- a/src/auditor/generate-auditor-basedb.conf +++ b/src/auditor/generate-auditor-basedb.conf @@ -47,7 +47,7 @@ IDLE_RESERVE_EXPIRATION_TIME = 4 weeks LEGAL_RESERVE_EXPIRATION_TIME = 4 weeks [exchange-account-1] -PAYTO_URI = payto://iban/SANDBOXX/DE989651?receiver-name=Exchange+Company +PAYTO_URI = payto://iban/DE989651?receiver-name=Exchange+Company ENABLE_DEBIT = YES ENABLE_CREDIT = YES @@ -57,25 +57,6 @@ WIRE_GATEWAY_AUTH_METHOD = basic USERNAME = exchange PASSWORD = x -[exchange-account-2] -PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2" -ENABLE_DEBIT = YES -ENABLE_CREDIT = YES - -[exchange-accountcredentials-2] -WIRE_GATEWAY_AUTH_METHOD = basic -USERNAME = exchange -PASSWORD = x -WIRE_GATEWAY_URL = "http://localhost:8082/accounts/exchange/taler-wire-gateway/" - -[admin-accountcredentials-2] -WIRE_GATEWAY_AUTH_METHOD = basic -# For now, fakebank still checks against the exchange account... -USERNAME = exchange -PASSWORD = x -WIRE_GATEWAY_URL = "http://localhost:8082/accounts/exchange/taler-wire-gateway/" - - [merchant] FORCE_AUDIT = YES SERVE = TCP diff --git a/src/auditor/taler-helper-auditor-wire-credit.c b/src/auditor/taler-helper-auditor-wire-credit.c index e733e3e02..d2e598f4a 100644 --- a/src/auditor/taler-helper-auditor-wire-credit.c +++ b/src/auditor/taler-helper-auditor-wire-credit.c @@ -469,7 +469,9 @@ reserve_in_cb (void *cls, struct WireAccount *wa = cls; struct ReserveInInfo *rii; size_t slen; + char *snp; + snp = TALER_payto_normalize (sender_account_details); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Analyzing exchange wire IN (%llu) at %s of %s with reserve_pub %s\n", (unsigned long long) rowid, @@ -479,7 +481,7 @@ reserve_in_cb (void *cls, TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_wire_in), &TALER_ARL_USE_AB (total_wire_in), credit); - slen = strlen (sender_account_details) + 1; + slen = strlen (snp) + 1; rii = GNUNET_malloc (sizeof (struct ReserveInInfo) + slen); rii->rowid = rowid; rii->credit_details.type = TALER_BANK_CT_RESERVE; @@ -488,8 +490,9 @@ reserve_in_cb (void *cls, rii->credit_details.details.reserve.reserve_pub = *reserve_pub; rii->credit_details.debit_account_uri = (const char *) &rii[1]; GNUNET_memcpy (&rii[1], - sender_account_details, + snp, slen); + GNUNET_free (snp); GNUNET_CRYPTO_hash (&wire_reference, sizeof (uint64_t), &rii->row_off_hash); @@ -736,28 +739,35 @@ analyze_credit ( } } - if (0 != strcasecmp (credit_details->debit_account_uri, - rii->credit_details.debit_account_uri)) { - struct TALER_AUDITORDB_MisattributionInInconsistency mii = { - .reserve_pub = rii->credit_details.details.reserve.reserve_pub, - .amount = rii->credit_details.amount, - .bank_row = credit_details->serial_id - }; - enum GNUNET_DB_QueryStatus qs; + char *np; - qs = TALER_ARL_adb->insert_misattribution_in_inconsistency ( - TALER_ARL_adb->cls, - &mii); - if (qs <= 0) + np = TALER_payto_normalize (credit_details->debit_account_uri); + if (0 != strcasecmp (np, + rii->credit_details.debit_account_uri)) { - global_qs = qs; - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); - return false; + struct TALER_AUDITORDB_MisattributionInInconsistency mii = { + .reserve_pub = rii->credit_details.details.reserve.reserve_pub, + .amount = rii->credit_details.amount, + .bank_row = credit_details->serial_id + }; + enum GNUNET_DB_QueryStatus qs; + + qs = TALER_ARL_adb->insert_misattribution_in_inconsistency ( + TALER_ARL_adb->cls, + &mii); + if (qs <= 0) + { + global_qs = qs; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + GNUNET_free (np); + return false; + } + TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_misattribution_in), + &TALER_ARL_USE_AB (total_misattribution_in), + &rii->credit_details.amount); } - TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_misattribution_in), - &TALER_ARL_USE_AB (total_misattribution_in), - &rii->credit_details.amount); + GNUNET_free (np); } if (GNUNET_TIME_timestamp_cmp (credit_details->execution_date, !=, diff --git a/src/auditor/taler-helper-auditor-wire-debit.c b/src/auditor/taler-helper-auditor-wire-debit.c index de4b71dac..894464586 100644 --- a/src/auditor/taler-helper-auditor-wire-debit.c +++ b/src/auditor/taler-helper-auditor-wire-debit.c @@ -908,33 +908,40 @@ check_profit_drain (struct ReserveOutInfo *roi) return GNUNET_NO; } GNUNET_free (account_section); - if (0 != - strcasecmp (payto_uri, - roi->details.credit_account_uri)) + { - struct TALER_AUDITORDB_WireOutInconsistency woi = { - .wire_out_row_id = serial, - .destination_account = (char *) roi->details.credit_account_uri, - .diagnostic = "profit drain wired to invalid account", - .expected = roi->details.amount, - .claimed = zero, - }; + char *np = TALER_payto_normalize (payto_uri); - qs = TALER_ARL_adb->insert_wire_out_inconsistency ( - TALER_ARL_adb->cls, - &woi); - if (qs < 0) + if (0 != + strcasecmp (np, + roi->details.credit_account_uri)) { - global_qs = qs; - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + struct TALER_AUDITORDB_WireOutInconsistency woi = { + .wire_out_row_id = serial, + .destination_account = (char *) roi->details.credit_account_uri, + .diagnostic = "profit drain wired to invalid account", + .expected = roi->details.amount, + .claimed = zero, + }; + + GNUNET_free (np); + qs = TALER_ARL_adb->insert_wire_out_inconsistency ( + TALER_ARL_adb->cls, + &woi); + if (qs < 0) + { + global_qs = qs; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + GNUNET_free (payto_uri); + return GNUNET_SYSERR; + } + TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_bad_amount_out_plus), + &TALER_ARL_USE_AB (total_bad_amount_out_plus), + &amount); GNUNET_free (payto_uri); - return GNUNET_SYSERR; + return GNUNET_YES; /* justified, kind-of */ } - TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_bad_amount_out_plus), - &TALER_ARL_USE_AB (total_bad_amount_out_plus), - &amount); - GNUNET_free (payto_uri); - return GNUNET_YES; /* justified, kind-of */ + GNUNET_free (np); } GNUNET_free (payto_uri); if (0 != @@ -1122,37 +1129,43 @@ wire_out_cb ( amount); return GNUNET_OK; } - if (0 != strcasecmp (payto_uri, - roi->details.credit_account_uri)) { - /* Destination bank account is wrong in actual wire transfer, so - we should count the wire transfer as entirely spurious, and - additionally consider the justified wire transfer as missing. */ - struct TALER_AUDITORDB_WireOutInconsistency woi = { - .wire_out_row_id = rowid, - .destination_account = (char *) payto_uri, - .diagnostic = "receiver account mismatch", - .expected = *amount, - .claimed = zero, - }; - enum GNUNET_DB_QueryStatus qs; + char *np = TALER_payto_normalize (payto_uri); - qs = TALER_ARL_adb->insert_wire_out_inconsistency ( - TALER_ARL_adb->cls, - &woi); - if (qs < 0) + if (0 != strcasecmp (np, + roi->details.credit_account_uri)) { - global_qs = qs; - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); - return GNUNET_SYSERR; + /* Destination bank account is wrong in actual wire transfer, so + we should count the wire transfer as entirely spurious, and + additionally consider the justified wire transfer as missing. */ + struct TALER_AUDITORDB_WireOutInconsistency woi = { + .wire_out_row_id = rowid, + .destination_account = (char *) payto_uri, + .diagnostic = "receiver account mismatch", + .expected = *amount, + .claimed = zero, + }; + enum GNUNET_DB_QueryStatus qs; + + GNUNET_free (np); + qs = TALER_ARL_adb->insert_wire_out_inconsistency ( + TALER_ARL_adb->cls, + &woi); + if (qs < 0) + { + global_qs = qs; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return GNUNET_SYSERR; + } + TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_bad_amount_out_plus), + &TALER_ARL_USE_AB (total_bad_amount_out_plus), + &roi->details.amount); + TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_bad_amount_out_minus), + &TALER_ARL_USE_AB (total_bad_amount_out_minus), + amount); + return GNUNET_OK; } - TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_bad_amount_out_plus), - &TALER_ARL_USE_AB (total_bad_amount_out_plus), - &roi->details.amount); - TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_bad_amount_out_minus), - &TALER_ARL_USE_AB (total_bad_amount_out_minus), - amount); - return GNUNET_OK; + GNUNET_free (np); } if (0 != TALER_amount_cmp (&roi->details.amount, amount)) @@ -1354,6 +1367,7 @@ history_debit_cb ( { const struct TALER_BANK_DebitDetails *dd = &dhr->details.ok.details[i]; + char *np = TALER_payto_normalize (dd->credit_account_uri); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Analyzing bank DEBIT #%llu at %s of %s with WTID %s\n", @@ -1362,7 +1376,7 @@ history_debit_cb ( TALER_amount2s (&dd->amount), TALER_B2S (&dd->wtid)); wa->wire_off_out = dd->serial_id + 1; - slen = strlen (dd->credit_account_uri) + 1; + slen = strlen (np) + 1; roi = GNUNET_malloc (sizeof (struct ReserveOutInfo) + slen); GNUNET_CRYPTO_hash (&dd->wtid, @@ -1372,8 +1386,9 @@ history_debit_cb ( roi->details.credit_account_uri = (const char *) &roi[1]; GNUNET_memcpy (&roi[1], - dd->credit_account_uri, + np, slen); + GNUNET_free (np); if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (out_map, &roi->subject_hash, @@ -1532,7 +1547,7 @@ reserve_closed_cb ( TALER_ARL_USE_PP (wire_reserve_close_id) = GNUNET_MAX (TALER_ARL_USE_PP (wire_reserve_close_id), rowid + 1); - rc->receiver_account = GNUNET_strdup (receiver_account); + rc->receiver_account = TALER_payto_normalize (receiver_account); rc->wtid = *wtid; rc->execution_date = execution_date; rc->rowid = rowid; diff --git a/src/bank-lib/bank_api_credit.c b/src/bank-lib/bank_api_credit.c index 29becbfa9..dc92b064a 100644 --- a/src/bank-lib/bank_api_credit.c +++ b/src/bank-lib/bank_api_credit.c @@ -86,8 +86,8 @@ parse_account_history (struct TALER_BANK_CreditHistoryHandle *hh, struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_array_const ("incoming_transactions", &history_array), - GNUNET_JSON_spec_string ("credit_account", - &chr.details.ok.credit_account_uri), + TALER_JSON_spec_payto_uri ("credit_account", + &chr.details.ok.credit_account_uri), GNUNET_JSON_spec_end () }; @@ -118,8 +118,8 @@ parse_account_history (struct TALER_BANK_CreditHistoryHandle *hh, &td->execution_date), GNUNET_JSON_spec_uint64 ("row_id", &td->serial_id), - GNUNET_JSON_spec_string ("debit_account", - &td->debit_account_uri), + TALER_JSON_spec_payto_uri ("debit_account", + &td->debit_account_uri), GNUNET_JSON_spec_end () }; json_t *transaction = json_array_get (history_array, @@ -178,7 +178,7 @@ parse_account_history (struct TALER_BANK_CreditHistoryHandle *hh, type)) { struct GNUNET_JSON_Specification wad_spec[] = { - GNUNET_JSON_spec_string ("origin_exchange_url", + TALER_JSON_spec_web_url ("origin_exchange_url", &td->details.wad.origin_exchange_url), GNUNET_JSON_spec_fixed_auto ("wad_id", &td->details.wad.wad_id), diff --git a/src/bank-lib/bank_api_debit.c b/src/bank-lib/bank_api_debit.c index 58dc0a736..62bf66c0f 100644 --- a/src/bank-lib/bank_api_debit.c +++ b/src/bank-lib/bank_api_debit.c @@ -86,8 +86,8 @@ parse_account_history (struct TALER_BANK_DebitHistoryHandle *hh, struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_array_const ("outgoing_transactions", &history_array), - GNUNET_JSON_spec_string ("debit_account", - &dhr.details.ok.debit_account_uri), + TALER_JSON_spec_payto_uri ("debit_account", + &dhr.details.ok.debit_account_uri), GNUNET_JSON_spec_end () }; @@ -117,9 +117,9 @@ parse_account_history (struct TALER_BANK_DebitHistoryHandle *hh, &td->serial_id), GNUNET_JSON_spec_fixed_auto ("wtid", &td->wtid), - GNUNET_JSON_spec_string ("credit_account", - &td->credit_account_uri), - GNUNET_JSON_spec_string ("exchange_base_url", + TALER_JSON_spec_payto_uri ("credit_account", + &td->credit_account_uri), + TALER_JSON_spec_web_url ("exchange_base_url", &td->exchange_base_url), GNUNET_JSON_spec_end () }; -- cgit v1.2.3