diff options
Diffstat (limited to 'src/merchant-tools')
-rw-r--r-- | src/merchant-tools/.gitignore | 5 | ||||
-rw-r--r-- | src/merchant-tools/Makefile.am | 21 | ||||
-rw-r--r-- | src/merchant-tools/benchmark-common.conf | 88 | ||||
-rw-r--r-- | src/merchant-tools/benchmark-cs.conf | 16 | ||||
-rw-r--r-- | src/merchant-tools/benchmark-rsa.conf | 16 | ||||
-rw-r--r-- | src/merchant-tools/coins-cs.conf | 58 | ||||
-rw-r--r-- | src/merchant-tools/coins-rsa.conf | 63 | ||||
-rw-r--r-- | src/merchant-tools/exchange_benchmark_home/taler/exchange/offline-keys/master.priv | 1 | ||||
-rw-r--r-- | src/merchant-tools/taler-merchant-benchmark.c | 696 | ||||
-rw-r--r-- | src/merchant-tools/taler-merchant-passwd.c | 197 | ||||
-rw-r--r-- | src/merchant-tools/taler-merchant-setup-reserve.c | 91 |
11 files changed, 874 insertions, 378 deletions
diff --git a/src/merchant-tools/.gitignore b/src/merchant-tools/.gitignore new file mode 100644 index 00000000..93285154 --- /dev/null +++ b/src/merchant-tools/.gitignore @@ -0,0 +1,5 @@ +*.edited +exchange_benchmark_home/taler/exchange-offline/ +exchange_benchmark_home/taler/exchange-secmod-cs/ +exchange_benchmark_home/taler/exchange-secmod-eddsa/ +exchange_benchmark_home/taler/exchange-secmod-rsa/ diff --git a/src/merchant-tools/Makefile.am b/src/merchant-tools/Makefile.am index 987a0897..21ddb89a 100644 --- a/src/merchant-tools/Makefile.am +++ b/src/merchant-tools/Makefile.am @@ -7,9 +7,16 @@ if USE_COVERAGE endif bin_PROGRAMS = \ - taler-merchant-benchmark \ taler-merchant-dbinit \ - taler-merchant-setup-reserve + taler-merchant-passwd \ + taler-merchant-benchmark + +EXTRA_DIST = \ + benchmark-common.conf \ + benchmark-cs.conf \ + benchmark-rsa.conf \ + coins-cs.conf \ + coins-rsa.conf taler_merchant_benchmark_SOURCES = \ taler-merchant-benchmark.c @@ -40,12 +47,12 @@ taler_merchant_dbinit_LDADD = \ -lgnunetutil \ $(XLIB) -taler_merchant_setup_reserve_SOURCES = \ - taler-merchant-setup-reserve.c -taler_merchant_setup_reserve_LDADD = \ +taler_merchant_passwd_SOURCES = \ + taler-merchant-passwd.c +taler_merchant_passwd_LDADD = \ $(LIBGCRYPT_LIBS) \ - $(top_builddir)/src/lib/libtalermerchant.la \ + $(top_builddir)/src/backenddb/libtalermerchantdb.la \ -ltalerutil \ - -lgnunetcurl \ + -ltalerpq \ -lgnunetutil \ $(XLIB) diff --git a/src/merchant-tools/benchmark-common.conf b/src/merchant-tools/benchmark-common.conf new file mode 100644 index 00000000..1f54127f --- /dev/null +++ b/src/merchant-tools/benchmark-common.conf @@ -0,0 +1,88 @@ +# This file is in the public domain. +[paths] +TALER_TEST_HOME=exchange_benchmark_home/ + +[taler] +CURRENCY=EUR +CURRENCY_ROUND_UNIT=EUR:0.01 + +[merchant-benchmark] +MERCHANT_URL = "http://localhost:9966/" + +[exchange] +AML_THRESHOLD=EUR:99999999 +SIGNKEY_LEGAL_DURATION=2 years +PORT=8081 +MASTER_PUBLIC_KEY=MN7KME8DKVVXFSX7H2VTG7YGRFWFJV37KHJG7FEBFKMEDP73V3VG +DB=postgres +BASE_URL="http://localhost:8081/" +# AGGREGATOR_SHARD_SIZE=67108864 +WIREWATCH_IDLE_SLEEP_INTERVAL=5 ms + +[exchangedb-postgres] +CONFIG="postgres:///talercheck" + +[exchange-offline] +MASTER_PRIV_FILE=${TALER_DATA_HOME}/exchange/offline-keys/master.priv + +[taler-exchange-secmod-rsa] +LOOKAHEAD_SIGN="1 d" + +[taler-exchange-secmod-cs] +LOOKAHEAD_SIGN="1 d" + +[taler-exchange-secmod-eddsa] +DURATION="2 d" +LOOKAHEAD_SIGN="1 d" + +# account-2 is suitable for fakebank +[exchange-account-1] +PAYTO_URI = "payto://x-taler-bank/localhost/42?receiver-name=42" +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES + +[exchange-accountcredentials-1] +WIRE_GATEWAY_AUTH_METHOD = none +WIRE_GATEWAY_URL = "http://localhost:8082/accounts/42/taler-wire-gateway/" + +# account-2 is suitable for libeufin +[exchange-account-2] +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES +PAYTO_URI = payto://iban/SANDBOXX/DE033310?receiver-name=Exchange+Company + +[exchange-accountcredentials-2] +WIRE_GATEWAY_AUTH_METHOD = basic +USERNAME = exchange +PASSWORD = x +WIRE_GATEWAY_URL = "http://localhost:8082/accounts/exchange/taler-wire-gateway/" + + +# Trust local exchange for "EUR" currency +[merchant-exchange-benchmark] +EXCHANGE_BASE_URL = http://localhost:8081/ +MASTER_KEY=MN7KME8DKVVXFSX7H2VTG7YGRFWFJV37KHJG7FEBFKMEDP73V3VG +CURRENCY = EUR + + +[merchantdb-postgres] +CONFIG="postgres:///talercheck" + +[auditordb-postgres] +CONFIG="postgres:///talercheck" + +[syncdb-postgres] +CONFIG="postgres:///talercheck" + +[bank] +HTTP_PORT=8082 +SERVE=http + +[libeufin-nexus] +DB_CONNECTION="postgresql:///talercheck" + +[libeufin-sandbox] +DB_CONNECTION="postgresql:///talercheck" + +[auditor] +BASE_URL="http://localhost:8083/" diff --git a/src/merchant-tools/benchmark-cs.conf b/src/merchant-tools/benchmark-cs.conf new file mode 100644 index 00000000..7f660ad3 --- /dev/null +++ b/src/merchant-tools/benchmark-cs.conf @@ -0,0 +1,16 @@ +# This file is in the public domain. +@INLINE@ benchmark-common.conf +@INLINE@ coins-cs.conf + +[exchange-account-test] +# What is the bank account (with the "Taler Bank" demo system)? Must end with "/". +PAYTO_URI = "payto://x-taler-bank/localhost/Exchange" +# Authentication information for basic authentication +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES + +[exchange-accountcredentials-test] +WIRE_GATEWAY_URL = http://localhost:8082/accounts/Exchange/taler-wire-gateway/ +WIRE_GATEWAY_AUTH_METHOD = "basic" +USERNAME = Exchange +PASSWORD = x diff --git a/src/merchant-tools/benchmark-rsa.conf b/src/merchant-tools/benchmark-rsa.conf new file mode 100644 index 00000000..a6c1512e --- /dev/null +++ b/src/merchant-tools/benchmark-rsa.conf @@ -0,0 +1,16 @@ +# This file is in the public domain. +@INLINE@ benchmark-common.conf +@INLINE@ coins-rsa.conf + +[exchange-account-test] +# What is the bank account (with the "Taler Bank" demo system)? Must end with "/". +PAYTO_URI = "payto://x-taler-bank/localhost/Exchange" +# Authentication information for basic authentication +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES + +[exchange-accountcredentials-test] +WIRE_GATEWAY_URL = http://localhost:8082/accounts/Exchange/taler-wire-gateway/ +WIRE_GATEWAY_AUTH_METHOD = "basic" +USERNAME = Exchange +PASSWORD = x diff --git a/src/merchant-tools/coins-cs.conf b/src/merchant-tools/coins-cs.conf new file mode 100644 index 00000000..c4b5a45c --- /dev/null +++ b/src/merchant-tools/coins-cs.conf @@ -0,0 +1,58 @@ +# This file is in the public domain. +# +# Sections starting with "coin_" specify which denominations +# the exchange should support (and their respective fee structure) +[coin_eur_ct_1] +value = EUR:0.01 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.00 +fee_deposit = EUR:0.00 +fee_refresh = EUR:0.01 +fee_refund = EUR:0.01 +CIPHER = CS + +[coin_eur_ct_10] +value = EUR:0.10 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +CIPHER = CS + +[coin_eur_1] +value = EUR:1 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +CIPHER = CS + +[coin_eur_5] +value = EUR:5 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +CIPHER = CS + +[coin_eur_10] +value = EUR:10 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +CIPHER = CS diff --git a/src/merchant-tools/coins-rsa.conf b/src/merchant-tools/coins-rsa.conf new file mode 100644 index 00000000..42eb8acf --- /dev/null +++ b/src/merchant-tools/coins-rsa.conf @@ -0,0 +1,63 @@ +# This file is in the public domain. +# +# Sections starting with "coin_" specify which denominations +# the exchange should support (and their respective fee structure) +[coin_eur_ct_1] +value = EUR:0.01 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.00 +fee_deposit = EUR:0.00 +fee_refresh = EUR:0.01 +fee_refund = EUR:0.01 +CIPHER = RSA +rsa_keysize = 2048 + +[coin_eur_ct_10] +value = EUR:0.10 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +CIPHER = RSA +rsa_keysize = 2048 + +[coin_eur_1] +value = EUR:1 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +CIPHER = RSA +rsa_keysize = 2048 + +[coin_eur_5] +value = EUR:5 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +CIPHER = RSA +rsa_keysize = 2048 + +[coin_eur_10] +value = EUR:10 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +CIPHER = RSA +rsa_keysize = 2048 diff --git a/src/merchant-tools/exchange_benchmark_home/taler/exchange/offline-keys/master.priv b/src/merchant-tools/exchange_benchmark_home/taler/exchange/offline-keys/master.priv new file mode 100644 index 00000000..b10ea6f6 --- /dev/null +++ b/src/merchant-tools/exchange_benchmark_home/taler/exchange/offline-keys/master.priv @@ -0,0 +1 @@ +-ڟ|Fl#L ruMo|,p]
\ No newline at end of file diff --git a/src/merchant-tools/taler-merchant-benchmark.c b/src/merchant-tools/taler-merchant-benchmark.c index d60cfeed..238b9f03 100644 --- a/src/merchant-tools/taler-merchant-benchmark.c +++ b/src/merchant-tools/taler-merchant-benchmark.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2014--2020 Taler Systems SA + (C) 2014--2023 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 @@ -16,7 +16,6 @@ along with TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ - /** * @file taler-merchant-benchmark.c * @brief benchmark the backend to evaluate performance @@ -25,18 +24,9 @@ */ #include "platform.h" #include <taler/taler_util.h> -#include <taler/taler_signatures.h> -#include <taler/taler_exchange_service.h> -#include <taler/taler_json_lib.h> -#include <gnunet/gnunet_util_lib.h> -#include <microhttpd.h> -#include <taler/taler_bank_service.h> -#include <taler/taler_fakebank_lib.h> #include <taler/taler_testing_lib.h> -#include <taler/taler_error_codes.h> #include "taler_merchant_testing_lib.h" -#define PAYTO_I1 "payto://x-taler-bank/localhost/42" /** * Maximum length of an amount (value plus currency string) needed by the test. @@ -51,22 +41,6 @@ #define MAX_ORDER_LEN (MAX_AMOUNT_LEN * 4 + 2048) -/* Error codes. */ -enum PaymentGeneratorError -{ - PG_SUCCESS = 0, - PG_NO_SUBCOMMAND, - PG_BAD_OPTIONS, - PG_BAD_CONFIG_FILE, - PG_FAILED_CFG_CURRENCY, - PG_FAILED_TO_PREPARE_MERCHANT, - PG_FAILED_TO_PREPARE_BANK, - PG_FAILED_TO_LAUNCH_MERCHANT, - PG_FAILED_TO_LAUNCH_BANK, - PG_RUNTIME_FAILURE -}; - - /** * ID to use for the 'alternative' instance. */ @@ -108,21 +82,11 @@ static unsigned int twocoins_number = 1; static unsigned int payments_number = 1; /** - * How many /tracks operation we want to perform. - */ -static unsigned int tracks_number = 1; - -/** * Config filename to give to commands (like wirewatch). */ static char *cfg_filename; /** - * Bank configuration. - */ -static struct TALER_TESTING_BankConfiguration bc; - -/** * Merchant base URL. */ static char *merchant_url; @@ -132,6 +96,22 @@ static char *merchant_url; */ static char *currency; +/** + * Set to 1 if `-f` command line option given. + */ +static int use_fakebank; + +/** + * Configuration section with details about the exchange + * bank account to use. + */ +static char *exchange_bank_section; + +/** + * Credentials to use for the benchmark. + */ +static struct TALER_TESTING_Credentials cred; + /** * Actual commands collection. @@ -186,106 +166,79 @@ run (void *cls, sizeof (CURRENCY_0_01), "%s:0.01", currency); - - if (NULL != apikey) - { - char *hdr; - - GNUNET_asprintf (&hdr, - "%s: %s", - MHD_HTTP_HEADER_AUTHORIZATION, - apikey); - GNUNET_assert (GNUNET_OK == - GNUNET_CURL_append_header (is->ctx, - hdr)); - GNUNET_free (hdr); - } - if (ordinary) { struct TALER_TESTING_Command ordinary_commands[] = { - TALER_TESTING_cmd_merchant_post_instances ("instance-create-default", - merchant_url, - "default", - PAYTO_I1, - currency, - MHD_HTTP_NO_CONTENT), - TALER_TESTING_cmd_admin_add_incoming ("create-reserve-1", - CURRENCY_10_02, - &bc.exchange_auth, - bc.user43_payto), - TALER_TESTING_cmd_exec_wirewatch ("wirewatch-1", - cfg_filename), - TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1", - "create-reserve-1", - CURRENCY_5, - 0, - MHD_HTTP_OK), - TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-2", - "create-reserve-1", - CURRENCY_5, - 0, - MHD_HTTP_OK), - TALER_TESTING_cmd_merchant_post_orders ("create-proposal-1", - merchant_url, - MHD_HTTP_OK, - NULL, /* random order ID please */ - GNUNET_TIME_UNIT_ZERO_TS, - GNUNET_TIME_UNIT_FOREVER_TS, - CURRENCY_5), - TALER_TESTING_cmd_merchant_pay_order ("deposit-simple", - merchant_url, - MHD_HTTP_OK, - "create-proposal-1", - "withdraw-coin-1", - CURRENCY_5, - CURRENCY_4_99, - NULL), - TALER_TESTING_cmd_rewind_ip ("rewind-payments", - "create-reserve-1", - payments_number), - /* Next proposal-pay cycle will be used by /track CMDs - * and so it will not have to be looped over, only /track - * CMDs will have to. */ - TALER_TESTING_cmd_merchant_post_orders ("create-proposal-2", - merchant_url, - MHD_HTTP_OK, - NULL, /* random order ID */ - GNUNET_TIME_UNIT_ZERO_TS, - GNUNET_TIME_UNIT_FOREVER_TS, - CURRENCY_5), - TALER_TESTING_cmd_merchant_pay_order ("deposit-simple-2", - merchant_url, - MHD_HTTP_OK, - "create-proposal-2", - "withdraw-coin-2", - CURRENCY_5, - CURRENCY_4_99, - NULL), - /* /track/transaction over deposit-simple-2 */ - - TALER_TESTING_cmd_exec_aggregator ("aggregate-1", - cfg_filename), - TALER_TESTING_cmd_exec_transfer ("transfer-1", - cfg_filename), - TALER_TESTING_cmd_merchant_post_transfer ( - "post-transfer-1", - &bc.exchange_auth, - bc.exchange_auth.wire_gateway_url, + TALER_TESTING_cmd_get_exchange ( + "get-exchange", + cred.cfg, + NULL, + true, + true), + TALER_TESTING_cmd_set_authorization ( + "set-auth-valid", + apikey), + TALER_TESTING_cmd_merchant_post_instances ( + "instance-create-default", + merchant_url, + "default", + MHD_HTTP_NO_CONTENT), + TALER_TESTING_cmd_merchant_post_account ( + "instance-create-default-account", + merchant_url, + cred.user42_payto, + NULL, NULL, + MHD_HTTP_OK), + TALER_TESTING_cmd_admin_add_incoming ( + "create-reserve-1", + CURRENCY_10_02, + &cred.ba, + cred.user43_payto), + TALER_TESTING_cmd_exec_wirewatch2 ( + "wirewatch-1", + cfg_filename, + exchange_bank_section), + TALER_TESTING_cmd_withdraw_amount ( + "withdraw-coin-1", + "create-reserve-1", + CURRENCY_5, + 0, + MHD_HTTP_OK), + TALER_TESTING_cmd_withdraw_amount ( + "withdraw-coin-2", + "create-reserve-1", + CURRENCY_5, + 0, + MHD_HTTP_OK), + TALER_TESTING_cmd_merchant_post_orders ( + "create-proposal-1", + cred.cfg, + merchant_url, + MHD_HTTP_OK, + NULL, /* random order ID please */ + GNUNET_TIME_UNIT_ZERO_TS, + GNUNET_TIME_UNIT_FOREVER_TS, + CURRENCY_5), + TALER_TESTING_cmd_merchant_pay_order ( + "deposit-simple", merchant_url, - CURRENCY_4_98, MHD_HTTP_OK, - "deposit-simple-2", + "create-proposal-1", + "withdraw-coin-1", + CURRENCY_5, + CURRENCY_4_99, NULL), - TALER_TESTING_cmd_merchant_get_transfers ("track-transfer-1", - merchant_url, - bc.user42_payto, - MHD_HTTP_OK, - "post-transfer-1", - NULL), - TALER_TESTING_cmd_rewind_ip ("rewind-tracks", - "track-transfer-1", - tracks_number), + TALER_TESTING_cmd_rewind_ip ( + "rewind-payments", + "create-reserve-1", + payments_number), + TALER_TESTING_cmd_exec_aggregator ( + "aggregate-1x", + cfg_filename), + TALER_TESTING_cmd_exec_transfer ( + "transfer-1", + cfg_filename), + TALER_TESTING_cmd_end () }; @@ -297,85 +250,123 @@ run (void *cls, if (corner) /* should never be 'false' here */ { struct TALER_TESTING_Command corner_commands[] = { - TALER_TESTING_cmd_merchant_post_instances ("instance-create-default", - merchant_url, - "default", - PAYTO_I1, - currency, - MHD_HTTP_NO_CONTENT), - TALER_TESTING_cmd_merchant_post_instances ("instance-create-alt", - merchant_url, - alt_instance_id, - PAYTO_I1, - currency, - MHD_HTTP_NO_CONTENT), - TALER_TESTING_cmd_admin_add_incoming ("create-reserve-1", - CURRENCY_5_01, - &bc.exchange_auth, - bc.user43_payto), - TALER_TESTING_cmd_exec_wirewatch ("wirewatch-1", - cfg_filename), - TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1", - "create-reserve-1", - CURRENCY_5, - 0, - MHD_HTTP_OK), - TALER_TESTING_cmd_merchant_post_orders ("create-unaggregated-proposal", - alt_instance_url, - MHD_HTTP_OK, - NULL, /* use random order ID */ - GNUNET_TIME_UNIT_ZERO_TS, - GNUNET_TIME_UNIT_FOREVER_TS, - CURRENCY_5), - TALER_TESTING_cmd_merchant_pay_order ("deposit-unaggregated", - alt_instance_url, - MHD_HTTP_OK, - "create-unaggregated-proposal", - "withdraw-coin-1", - CURRENCY_5, - CURRENCY_4_99, - NULL), - TALER_TESTING_cmd_rewind_ip ("rewind-unaggregated", - "create-reserve-1", - unaggregated_number), - TALER_TESTING_cmd_admin_add_incoming ("create-reserve-2", - CURRENCY_10_02, - &bc.exchange_auth, - bc.user43_payto), - TALER_TESTING_cmd_exec_wirewatch ("wirewatch-2", - cfg_filename), - TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-2", - "create-reserve-2", - CURRENCY_5, - 0, - MHD_HTTP_OK), - TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-3", - "create-reserve-2", - CURRENCY_5, - 0, - MHD_HTTP_OK), - TALER_TESTING_cmd_merchant_post_orders ("create-twocoins-proposal", - merchant_url, - MHD_HTTP_OK, - NULL, /* use random order ID */ - GNUNET_TIME_UNIT_ZERO_TS, - GNUNET_TIME_UNIT_FOREVER_TS, - CURRENCY_10), - TALER_TESTING_cmd_merchant_pay_order ("deposit-twocoins", - merchant_url, - MHD_HTTP_OK, - "create-twocoins-proposal", - "withdraw-coin-2;withdraw-coin-3", - CURRENCY_10, - CURRENCY_9_98, - NULL), - TALER_TESTING_cmd_exec_aggregator ("aggregate-twocoins", - cfg_filename), - TALER_TESTING_cmd_exec_transfer ("transfer-twocoins", - cfg_filename), - TALER_TESTING_cmd_rewind_ip ("rewind-twocoins", - "create-reserve-2", - twocoins_number), + TALER_TESTING_cmd_get_exchange ( + "get-exchange", + cred.cfg, + NULL, + true, + true), + TALER_TESTING_cmd_set_authorization ( + "set-auth-valid", + apikey), + TALER_TESTING_cmd_merchant_post_instances ( + "instance-create-default", + merchant_url, + "default", + MHD_HTTP_NO_CONTENT), + TALER_TESTING_cmd_merchant_post_account ( + "instance-create-default-account", + merchant_url, + cred.user42_payto, + NULL, NULL, + MHD_HTTP_OK), + TALER_TESTING_cmd_merchant_post_instances ( + "instance-create-alt", + merchant_url, + alt_instance_id, + MHD_HTTP_NO_CONTENT), + TALER_TESTING_cmd_merchant_post_account ( + "instance-create-alt-account", + alt_instance_url, + cred.user42_payto, + NULL, NULL, + MHD_HTTP_OK), + TALER_TESTING_cmd_admin_add_incoming ( + "create-reserve-1", + CURRENCY_5_01, + &cred.ba, + cred.user43_payto), + TALER_TESTING_cmd_exec_wirewatch2 ( + "wirewatch-1", + cfg_filename, + exchange_bank_section), + TALER_TESTING_cmd_withdraw_amount ( + "withdraw-coin-1", + "create-reserve-1", + CURRENCY_5, + 0, + MHD_HTTP_OK), + TALER_TESTING_cmd_merchant_post_orders ( + "create-unaggregated-proposal", + cred.cfg, + alt_instance_url, + MHD_HTTP_OK, + NULL, /* use random order ID */ + GNUNET_TIME_UNIT_ZERO_TS, + GNUNET_TIME_UNIT_FOREVER_TS, + CURRENCY_5), + TALER_TESTING_cmd_merchant_pay_order ( + "deposit-unaggregated", + alt_instance_url, + MHD_HTTP_OK, + "create-unaggregated-proposal", + "withdraw-coin-1", + CURRENCY_5, + CURRENCY_4_99, + NULL), + TALER_TESTING_cmd_rewind_ip ( + "rewind-unaggregated", + "create-reserve-1", + unaggregated_number), + TALER_TESTING_cmd_admin_add_incoming ( + "create-reserve-2", + CURRENCY_10_02, + &cred.ba, + cred.user43_payto), + TALER_TESTING_cmd_exec_wirewatch2 ( + "wirewatch-2", + cfg_filename, + exchange_bank_section), + TALER_TESTING_cmd_withdraw_amount ( + "withdraw-coin-2", + "create-reserve-2", + CURRENCY_5, + 0, + MHD_HTTP_OK), + TALER_TESTING_cmd_withdraw_amount ( + "withdraw-coin-3", + "create-reserve-2", + CURRENCY_5, + 0, + MHD_HTTP_OK), + TALER_TESTING_cmd_merchant_post_orders ( + "create-twocoins-proposal", + cred.cfg, + merchant_url, + MHD_HTTP_OK, + NULL, /* use random order ID */ + GNUNET_TIME_UNIT_ZERO_TS, + GNUNET_TIME_UNIT_FOREVER_TS, + CURRENCY_10), + TALER_TESTING_cmd_merchant_pay_order ( + "deposit-twocoins", + merchant_url, + MHD_HTTP_OK, + "create-twocoins-proposal", + "withdraw-coin-2;withdraw-coin-3", + CURRENCY_10, + CURRENCY_9_98, + NULL), + TALER_TESTING_cmd_exec_aggregator ( + "aggregate-twocoins", + cfg_filename), + TALER_TESTING_cmd_exec_transfer ( + "transfer-twocoins", + cfg_filename), + TALER_TESTING_cmd_rewind_ip ( + "rewind-twocoins", + "create-reserve-2", + twocoins_number), TALER_TESTING_cmd_end () }; @@ -387,21 +378,6 @@ run (void *cls, /** - * Send SIGTERM and wait for process termination. - * - * @param process process to terminate. - */ -static void -terminate_process (struct GNUNET_OS_Process *process) -{ - GNUNET_OS_process_kill (process, - SIGTERM); - GNUNET_OS_process_wait (process); - GNUNET_OS_process_destroy (process); -} - - -/** * The main function of the serve tool * * @param argc number of arguments from the command line @@ -415,86 +391,110 @@ main (int argc, char *loglev = NULL; char *logfile = NULL; char *exchange_account = NULL; - struct GNUNET_OS_Process *bankd; - struct GNUNET_OS_Process *merchantd; struct GNUNET_GETOPT_CommandLineOption *options; struct GNUNET_GETOPT_CommandLineOption root_options[] = { GNUNET_GETOPT_option_cfgfile (&cfg_filename), + GNUNET_GETOPT_option_string ( + 'u', + "exchange-account-section", + "SECTION", + "use exchange bank account configuration from the given SECTION", + &exchange_bank_section), + GNUNET_GETOPT_option_flag ( + 'f', + "fakebank", + "use fakebank for the banking system", + &use_fakebank), GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION), - GNUNET_GETOPT_option_help ("Runs benchmark logic against merchant backend. " - "Must be used with either 'ordinary' or 'corner' sub-commands."), - GNUNET_GETOPT_option_string ('l', - "logfile", - "LF", - "will log to file LF", - &logfile), + GNUNET_GETOPT_option_help ( + "Runs benchmark logic against merchant backend. " + "Must be used with either 'ordinary' or 'corner' sub-commands."), + GNUNET_GETOPT_option_string ( + 'l', + "logfile", + "LF", + "will log to file LF", + &logfile), GNUNET_GETOPT_option_loglevel (&loglev), GNUNET_GETOPT_OPTION_END }; struct GNUNET_GETOPT_CommandLineOption corner_options[] = { - GNUNET_GETOPT_option_string ('l', - "logfile", - "LF", - "will log to file LF", - &logfile), - GNUNET_GETOPT_option_loglevel (&loglev), + GNUNET_GETOPT_option_string ( + 'a', + "apikey", + "APIKEY", + "HTTP 'Authorization' header to send to the merchant", + &apikey), GNUNET_GETOPT_option_cfgfile (&cfg_filename), + GNUNET_GETOPT_option_flag ( + 'f', + "fakebank", + "use fakebank for the banking system", + &use_fakebank), GNUNET_GETOPT_option_help ("Populate databases with corner case payments"), - GNUNET_GETOPT_option_uint ('u', - "unaggregated-number", - "UN", - "will generate UN unaggregated payments, defaults to 1", - &unaggregated_number), - GNUNET_GETOPT_option_uint ('t', - "two-coins", - "TC", - "will perform TC 2-coins payments, defaults to 1", - &twocoins_number), - GNUNET_GETOPT_option_mandatory ( - GNUNET_GETOPT_option_string ('e', - "exchange-account", - "SECTION", - "configuration section specifying the exchange account to use, mandatory", - &exchange_account)), - GNUNET_GETOPT_option_string ('a', - "apikey", - "APIKEY", - "HTTP 'Authorization' header to send to the merchant", - &apikey), + GNUNET_GETOPT_option_string ( + 'l', + "logfile", + "LF", + "will log to file LF", + &logfile), + GNUNET_GETOPT_option_loglevel (&loglev), + GNUNET_GETOPT_option_uint ( + 't', + "two-coins", + "TC", + "will perform TC 2-coins payments, defaults to 1", + &twocoins_number), + GNUNET_GETOPT_option_uint ( + 'U', + "unaggregated-number", + "UN", + "will generate UN unaggregated payments, defaults to 1", + &unaggregated_number), + GNUNET_GETOPT_option_string ( + 'u', + "exchange-account-section", + "SECTION", + "use exchange bank account configuration from the given SECTION", + &exchange_bank_section), GNUNET_GETOPT_OPTION_END }; struct GNUNET_GETOPT_CommandLineOption ordinary_options[] = { - GNUNET_GETOPT_option_string ('l', - "logfile", - "LF", - "will log to file LF", - &logfile), - GNUNET_GETOPT_option_loglevel (&loglev), + GNUNET_GETOPT_option_string ( + 'a', + "apikey", + "APIKEY", + "HTTP 'Authorization' header to send to the merchant", + &apikey), GNUNET_GETOPT_option_cfgfile (&cfg_filename), - GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION), - GNUNET_GETOPT_option_help ("Generate Taler ordinary payments" - " to populate the databases"), GNUNET_GETOPT_option_mandatory ( - GNUNET_GETOPT_option_string ('e', - "exchange-account", - "SECTION", - "configuration section specifying the exchange account to use, mandatory", - &exchange_account)), - GNUNET_GETOPT_option_uint ('p', - "payments-number", - "PN", - "will generate PN payments, defaults to 1", - &payments_number), - GNUNET_GETOPT_option_string ('a', - "apikey", - "APIKEY", - "HTTP 'Authorization' header to send to the merchant", - &apikey), - GNUNET_GETOPT_option_uint ('t', - "tracks-number", - "TN", - "will perform TN /track operations, defaults to 1", - &tracks_number), + GNUNET_GETOPT_option_string ( + 'e', + "exchange-account", + "SECTION", + "configuration section specifying the exchange account to use, mandatory", + &exchange_account)), + GNUNET_GETOPT_option_flag ( + 'f', + "fakebank", + "use fakebank for the banking system", + &use_fakebank), + GNUNET_GETOPT_option_help ( + "Generate Taler ordinary payments" + " to populate the databases"), + GNUNET_GETOPT_option_string ( + 'l', + "logfile", + "LF", + "will log to file LF", + &logfile), + GNUNET_GETOPT_option_loglevel (&loglev), + GNUNET_GETOPT_option_uint ( + 'p', + "payments-number", + "PN", + "will generate PN payments, defaults to 1", + &payments_number), GNUNET_GETOPT_option_version (PACKAGE_VERSION "-" VCS_VERSION), GNUNET_GETOPT_OPTION_END }; @@ -517,19 +517,26 @@ main (int argc, } { - int result; + enum GNUNET_GenericReturnValue result; result = GNUNET_GETOPT_run ("taler-merchant-benchmark", options, argc, argv); - if (GNUNET_SYSERR == result) + switch (result) { - return PG_BAD_OPTIONS; + case GNUNET_SYSERR: + return EXIT_INVALIDARGUMENT; + case GNUNET_NO: + return EXIT_SUCCESS; + case GNUNET_OK: + break; } - if (0 == result) - return PG_SUCCESS; } + if (NULL == exchange_bank_section) + exchange_bank_section = "exchange-account-1"; + if (NULL == loglev) + loglev = "INFO"; GNUNET_log_setup ("taler-merchant-benchmark", loglev, logfile); @@ -537,7 +544,7 @@ main (int argc, (! corner) ) { TALER_LOG_ERROR ("Please use 'ordinary' or 'corner' subcommands.\n"); - return PG_NO_SUBCOMMAND; + return EXIT_INVALIDARGUMENT; } if (NULL == cfg_filename) cfg_filename = (char *) default_config_file; @@ -551,7 +558,7 @@ main (int argc, cfg_filename)) { TALER_LOG_ERROR ("Could not parse configuration\n"); - return PG_BAD_CONFIG_FILE; + return EXIT_NOTCONFIGURED; } if (GNUNET_OK != TALER_config_get_currency (cfg, @@ -559,56 +566,59 @@ main (int argc, { TALER_LOG_ERROR ("Failed to read currency from configuration\n"); GNUNET_CONFIGURATION_destroy (cfg); - return PG_FAILED_CFG_CURRENCY; + return EXIT_NOTCONFIGURED; + } + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + "merchant-benchmark", + "MERCHANT_URL", + &merchant_url)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "merchant-benchmark", + "MERCHANT_URL"); + GNUNET_CONFIGURATION_destroy (cfg); + return EXIT_NOTCONFIGURED; + } + if ( (0 == strlen (merchant_url)) || + (merchant_url[strlen (merchant_url) - 1] != '/') ) + { + GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, + "merchant-benchmark", + "MERCHANT_URL", + "Not a valid URL"); + GNUNET_CONFIGURATION_destroy (cfg); + return EXIT_NOTCONFIGURED; + } + + if (GNUNET_OK != + TALER_TESTING_get_credentials ( + cfg_filename, + exchange_bank_section, + use_fakebank + ? TALER_TESTING_BS_FAKEBANK + : TALER_TESTING_BS_IBAN, + &cred)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Required bank credentials not given in configuration\n"); + GNUNET_free (cfg_filename); + return EXIT_NOTCONFIGURED; } + GNUNET_CONFIGURATION_destroy (cfg); } - /* prepare merchant and bank */ - merchant_url = TALER_TESTING_prepare_merchant (cfg_filename); - if (NULL == merchant_url) - { - TALER_LOG_ERROR ("Failed to prepare for the merchant\n"); - return PG_FAILED_TO_PREPARE_MERCHANT; - } - GNUNET_assert (0 < strlen (merchant_url)); - GNUNET_assert (merchant_url[strlen (merchant_url) - 1] == '/'); - GNUNET_assert (0 < GNUNET_asprintf (&alt_instance_url, - "%sinstances/%s/", - merchant_url, - alt_instance_id)); - if (GNUNET_OK != - TALER_TESTING_prepare_bank (cfg_filename, - GNUNET_NO, - exchange_account, - &bc)) - { - TALER_LOG_ERROR ("Failed to prepare for the bank\n"); - return PG_FAILED_TO_PREPARE_BANK; - } - /* launch merchant and bank */ - if (NULL == (merchantd = TALER_TESTING_run_merchant (cfg_filename, - merchant_url))) + GNUNET_asprintf (&alt_instance_url, + "%sinstances/%s/", + merchant_url, + alt_instance_id); { - TALER_LOG_ERROR ("Failed to launch the merchant\n"); - return PG_FAILED_TO_LAUNCH_MERCHANT; - } - if (NULL == (bankd = TALER_TESTING_run_bank (cfg_filename, - bc.exchange_auth.wire_gateway_url))) - { - TALER_LOG_ERROR ("Failed to run the bank\n"); - terminate_process (merchantd); - return PG_FAILED_TO_LAUNCH_BANK; - } + enum GNUNET_GenericReturnValue result; - /* launch exchange and run benchmark */ - { - int result; - - result = TALER_TESTING_setup_with_exchange (&run, - NULL, - cfg_filename); - terminate_process (merchantd); - terminate_process (bankd); - return (GNUNET_OK == result) ? 0 : PG_RUNTIME_FAILURE; + result = TALER_TESTING_loop (&run, + NULL); + return (GNUNET_OK == result) + ? 0 + : EXIT_FAILURE; } } diff --git a/src/merchant-tools/taler-merchant-passwd.c b/src/merchant-tools/taler-merchant-passwd.c new file mode 100644 index 00000000..bcb856e5 --- /dev/null +++ b/src/merchant-tools/taler-merchant-passwd.c @@ -0,0 +1,197 @@ +/* + This file is part of TALER + Copyright (C) 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 + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ +/** + * @file merchant-tools/taler-merchant-passwd.c + * @brief Reset access tokens for instances. + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_util.h> +#include <taler/taler_dbevents.h> +#include <gnunet/gnunet_util_lib.h> +#include "taler_merchantdb_lib.h" +#include "taler_merchantdb_lib.h" + +/** + * Instance to set password for. + */ +static char *instance; + +/** + * Return value from main(). + */ +static int global_ret; + +/** + * Main function that will be run. + * + * @param cls closure + * @param args remaining command-line arguments + * @param cfgfile name of the configuration file used (for saving, can be NULL!) + * @param config configuration + */ +static void +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *config) +{ + struct TALER_MERCHANTDB_Plugin *plugin; + struct GNUNET_CONFIGURATION_Handle *cfg; + const char *pw = args[0]; + struct TALER_MERCHANTDB_InstanceAuthSettings ias; + enum GNUNET_DB_QueryStatus qs; + + if (NULL == pw) + pw = getenv ("TALER_MERCHANT_PASSWORD"); + if (NULL == pw) + { + fprintf (stderr, + "New password not specified (pass on command-line or via TALER_MERCHANT_PASSWORD)\n"); + global_ret = -1; + return; + } + if (0 != strncmp (pw, + RFC_8959_PREFIX, + strlen (RFC_8959_PREFIX))) + { + fprintf (stderr, + "Invalid password specified, does not begin with `%s'\n", + RFC_8959_PREFIX); + global_ret = 1; + return; + } + if (NULL == instance) + instance = GNUNET_strdup ("default"); + cfg = GNUNET_CONFIGURATION_dup (config); + if (NULL == + (plugin = TALER_MERCHANTDB_plugin_load (cfg))) + { + fprintf (stderr, + "Failed to initialize database plugin.\n"); + global_ret = 1; + GNUNET_CONFIGURATION_destroy (cfg); + return; + } + + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, + &ias.auth_salt, + sizeof (ias.auth_salt)); + GNUNET_assert (GNUNET_YES == + GNUNET_CRYPTO_kdf (&ias.auth_hash, + sizeof (ias.auth_hash), + &ias.auth_salt, + sizeof (ias.auth_salt), + pw, + strlen (pw), + "merchant-instance-auth", + strlen ("merchant-instance-auth"), + NULL, + 0)); + if (GNUNET_OK != + plugin->connect (plugin->cls)) + { + fprintf (stderr, + "Failed to connect to database\n"); + global_ret = 1; + TALER_MERCHANTDB_plugin_unload (plugin); + GNUNET_CONFIGURATION_destroy (cfg); + return; + } + qs = plugin->update_instance_auth (plugin->cls, + instance, + &ias); + switch (qs) + { + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + { + struct GNUNET_DB_EventHeaderP es = { + .size = ntohs (sizeof (es)), + .type = ntohs (TALER_DBEVENT_MERCHANT_INSTANCE_SETTINGS) + }; + + plugin->event_notify (plugin->cls, + &es, + instance, + strlen (instance) + 1); + } + break; + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + fprintf (stderr, + "Instance `%s' unknown, cannot reset token\n", + instance); + global_ret = 2; + break; + case GNUNET_DB_STATUS_SOFT_ERROR: + case GNUNET_DB_STATUS_HARD_ERROR: + fprintf (stderr, + "Internal database error.\n"); + global_ret = 3; + break; + } + TALER_MERCHANTDB_plugin_unload (plugin); + GNUNET_CONFIGURATION_destroy (cfg); +} + + +/** + * The main function of the database initialization tool. + * Used to initialize the Taler Exchange's database. + * + * @param argc number of arguments from the command line + * @param argv command line arguments + * @return 0 ok, 1 on error + */ +int +main (int argc, + char *const *argv) +{ + struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_option_string ('i', + "instance", + "ID", + "which instance to reset the password of", + &instance), + + GNUNET_GETOPT_option_version (PACKAGE_VERSION "-" VCS_VERSION), + GNUNET_GETOPT_OPTION_END + }; + enum GNUNET_GenericReturnValue ret; + + /* force linker to link against libtalerutil; if we do + not do this, the linker may "optimize" libtalerutil + away and skip #TALER_OS_init(), which we do need */ + (void) TALER_project_data_default (); + if (GNUNET_OK != + GNUNET_STRINGS_get_utf8_args (argc, argv, + &argc, &argv)) + return 4; + ret = GNUNET_PROGRAM_run ( + argc, argv, + "taler-merchant-passwd", + gettext_noop ("Reset instance password"), + options, + &run, NULL); + GNUNET_free_nz ((void *) argv); + if (GNUNET_SYSERR == ret) + return 3; + if (GNUNET_NO == ret) + return 0; + return global_ret; +} + + +/* end of taler-merchant-passwd.c */ diff --git a/src/merchant-tools/taler-merchant-setup-reserve.c b/src/merchant-tools/taler-merchant-setup-reserve.c index 1ed50530..46888171 100644 --- a/src/merchant-tools/taler-merchant-setup-reserve.c +++ b/src/merchant-tools/taler-merchant-setup-reserve.c @@ -156,46 +156,81 @@ do_request (void *cls); * POST /reserves request to a merchant * * @param cls closure - * @param hr HTTP response details - * @param reserve_pub public key of the created reserve, NULL on error - * @param payto_uri where to make the payment to for filling the reserve, NULL on error + * @param prr response details */ static void result_cb (void *cls, - const struct TALER_MERCHANT_HttpResponse *hr, - const struct TALER_ReservePublicKeyP *reserve_pub, - const char *payto_uri) + const struct TALER_MERCHANT_PostReservesResponse *prr) { (void) cls; prh = NULL; - switch (hr->http_status) + switch (prr->hr.http_status) { case MHD_HTTP_OK: { - char res_str[sizeof (*reserve_pub) * 2 + 1]; + char res_str[sizeof (prr->details.ok.reserve_pub) * 2 + 1]; - GNUNET_STRINGS_data_to_string (reserve_pub, - sizeof (*reserve_pub), + GNUNET_STRINGS_data_to_string (&prr->details.ok.reserve_pub, + sizeof (prr->details.ok.reserve_pub), res_str, sizeof (res_str)); - if (NULL != strchr (payto_uri, '?')) - fprintf (stdout, - "%s&message=%s\n", - payto_uri, - res_str); - else - fprintf (stdout, - "%s?message=%s\n", - payto_uri, - res_str); + for (unsigned int i = 0; i<prr->details.ok.accounts_len; i++) + { + const struct TALER_EXCHANGE_WireAccount *wa + = &prr->details.ok.accounts[i]; + const char *payto_uri = wa->payto_uri; + bool skip = false; + + for (unsigned int j = 0; j<wa->credit_restrictions_length; j++) + if (TALER_EXCHANGE_AR_DENY == + wa->credit_restrictions[j].type) + skip = true; + if (skip) + continue; + if (NULL != strchr (payto_uri, '?')) + fprintf (stdout, + "%s&message=%s\n", + payto_uri, + res_str); + else + fprintf (stdout, + "%s?message=%s\n", + payto_uri, + res_str); + if (NULL != wa->conversion_url) + fprintf (stdout, + "\tConversion needed: %s\n", + wa->conversion_url); + for (unsigned int j = 0; j<wa->credit_restrictions_length; j++) + { + const struct TALER_EXCHANGE_AccountRestriction *cr + = &wa->credit_restrictions[j]; + + switch (cr->type) + { + case TALER_EXCHANGE_AR_INVALID: + GNUNET_assert (0); + break; + case TALER_EXCHANGE_AR_DENY: + GNUNET_assert (0); + break; + case TALER_EXCHANGE_AR_REGEX: + fprintf (stdout, + "\tCredit restriction: %s (%s)\n", + cr->details.regex.human_hint, + cr->details.regex.posix_egrep); + break; + } + } + } } break; case MHD_HTTP_CONFLICT: fprintf (stderr, "Conflict trying to setup reserve: %u/%d\nHint: %s\n", - hr->http_status, - (int) hr->ec, - hr->hint); + prr->hr.http_status, + (int) prr->hr.ec, + prr->hr.hint); global_ret = 1; break; case MHD_HTTP_INTERNAL_SERVER_ERROR: @@ -212,16 +247,16 @@ result_cb (void *cls, } GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Merchant failed too often (%u/%d), giving up\n", - hr->http_status, - hr->ec); + prr->hr.http_status, + prr->hr.ec); global_ret = 1; break; default: fprintf (stderr, "Unexpected backend failure: %u/%d\nHint: %s\n", - hr->http_status, - (int) hr->ec, - hr->hint); + prr->hr.http_status, + (int) prr->hr.ec, + prr->hr.hint); global_ret = 1; break; } |