diff options
25 files changed, 446 insertions, 427 deletions
| diff --git a/src/auditor/generate-auditor-basedb.conf b/src/auditor/generate-auditor-basedb.conf index 21e40c32..337f9413 100644 --- a/src/auditor/generate-auditor-basedb.conf +++ b/src/auditor/generate-auditor-basedb.conf @@ -73,6 +73,8 @@ CURRENCY_ROUND_UNIT = TESTKUDOS:0.01  PAYTO_URI = payto://x-taler-bank/localhost/Exchange  enable_debit = yes  enable_credit = yes + +[exchange-accountcredentials-1]  WIRE_GATEWAY_URL = "http://localhost:8082/taler-wire-gateway/Exchange/"  WIRE_GATEWAY_AUTH_METHOD = basic  USERNAME = Exchange diff --git a/src/auditor/taler-helper-auditor-wire.c b/src/auditor/taler-helper-auditor-wire.c index c0b25eed..8dded816 100644 --- a/src/auditor/taler-helper-auditor-wire.c +++ b/src/auditor/taler-helper-auditor-wire.c @@ -68,14 +68,9 @@ struct WireAccount    struct WireAccount *prev;    /** -   * Authentication data for the account. +   * Account details.     */ -  struct TALER_BANK_AuthenticationData auth; - -  /** -   * Name of the section that configures this account. -   */ -  char *section_name; +  const struct TALER_EXCHANGEDB_AccountInfo *ai;    /**     * Active wire request for the transaction history. @@ -108,16 +103,6 @@ struct WireAccount    uint64_t out_wire_off;    /** -   * We should check for inbound transactions to this account. -   */ -  int watch_credit; - -  /** -   * We should check for outbound transactions from this account. -   */ -  int watch_debit; - -  /**     * Return value when we got this account's progress point.     */    enum GNUNET_DB_QueryStatus qsx; @@ -573,8 +558,6 @@ do_shutdown (void *cls)      GNUNET_CONTAINER_DLL_remove (wa_head,                                   wa_tail,                                   wa); -    TALER_BANK_auth_free (&wa->auth); -    GNUNET_free (wa->section_name);      GNUNET_free (wa);    }    if (NULL != ctx) @@ -587,6 +570,8 @@ do_shutdown (void *cls)      GNUNET_CURL_gnunet_rc_destroy (rc);      rc = NULL;    } +  TALER_EXCHANGEDB_unload_accounts (); +  TALER_ARL_cfg = NULL;  } @@ -688,28 +673,28 @@ commit (enum GNUNET_DB_QueryStatus qs)         NULL != wa;         wa = wa->next)    { -    GNUNET_assert (0 == -                   json_array_append_new ( -                     report_account_progress, -                     GNUNET_JSON_PACK ( -                       GNUNET_JSON_pack_string ("account", -                                                wa->section_name), -                       GNUNET_JSON_pack_uint64 ("start_reserve_in", -                                                wa->start_pp. -                                                last_reserve_in_serial_id), -                       GNUNET_JSON_pack_uint64 ("end_reserve_in", -                                                wa->pp.last_reserve_in_serial_id), -                       GNUNET_JSON_pack_uint64 ("start_wire_out", -                                                wa->start_pp. -                                                last_wire_out_serial_id), -                       GNUNET_JSON_pack_uint64 ("end_wire_out", -                                                wa->pp.last_wire_out_serial_id)))); +    GNUNET_assert ( +      0 == +      json_array_append_new ( +        report_account_progress, +        GNUNET_JSON_PACK ( +          GNUNET_JSON_pack_string ("account", +                                   wa->ai->section_name), +          GNUNET_JSON_pack_uint64 ("start_reserve_in", +                                   wa->start_pp.last_reserve_in_serial_id), +          GNUNET_JSON_pack_uint64 ("end_reserve_in", +                                   wa->pp.last_reserve_in_serial_id), +          GNUNET_JSON_pack_uint64 ("start_wire_out", +                                   wa->start_pp. +                                   last_wire_out_serial_id), +          GNUNET_JSON_pack_uint64 ("end_wire_out", +                                   wa->pp.last_wire_out_serial_id))));      if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == wa->qsx)        qs = TALER_ARL_adb->update_wire_auditor_account_progress (          TALER_ARL_adb->cls,          TALER_ARL_asession,          &TALER_ARL_master_pub, -        wa->section_name, +        wa->ai->section_name,          &wa->pp,          wa->in_wire_off,          wa->out_wire_off); @@ -718,7 +703,7 @@ commit (enum GNUNET_DB_QueryStatus qs)          TALER_ARL_adb->cls,          TALER_ARL_asession,          &TALER_ARL_master_pub, -        wa->section_name, +        wa->ai->section_name,          &wa->pp,          wa->in_wire_off,          wa->out_wire_off); @@ -893,7 +878,7 @@ check_for_required_transfers (void)    if (0 > qs)    {      GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); -    global_ret = 1; +    global_ret = EXIT_FAILURE;      GNUNET_SCHEDULER_shutdown ();      return;    } @@ -1016,7 +1001,7 @@ wire_out_cb (void *cls,                          GNUNET_JSON_pack_string ("diagnostic",                                                   "wire transfer not made (yet?)"),                          GNUNET_JSON_pack_string ("account_section", -                                                 wa->section_name))); +                                                 wa->ai->section_name)));      TALER_ARL_amount_add (&total_bad_amount_out_minus,                            &total_bad_amount_out_minus,                            amount); @@ -1050,7 +1035,7 @@ wire_out_cb (void *cls,                            GNUNET_JSON_pack_string ("target",                                                     payto_uri),                            GNUNET_JSON_pack_string ("account_section", -                                                   wa->section_name))); +                                                   wa->ai->section_name)));        TALER_ARL_amount_add (&total_bad_amount_out_plus,                              &total_bad_amount_out_plus,                              &roi->details.amount); @@ -1072,7 +1057,7 @@ wire_out_cb (void *cls,                                                     roi->details.                                                     credit_account_url),                            GNUNET_JSON_pack_string ("account_section", -                                                   wa->section_name))); +                                                   wa->ai->section_name)));        TALER_ARL_amount_add (&total_bad_amount_out_minus,                              &total_bad_amount_out_minus,                              amount); @@ -1099,7 +1084,7 @@ wire_out_cb (void *cls,                          GNUNET_JSON_pack_string ("diagnostic",                                                   "wire amount does not match"),                          GNUNET_JSON_pack_string ("account_section", -                                                 wa->section_name))); +                                                 wa->ai->section_name)));      if (0 < TALER_amount_cmp (amount,                                &roi->details.amount))      { @@ -1156,9 +1141,9 @@ struct CheckMatchContext    const struct ReserveOutInfo *roi;    /** -   * Set to #GNUNET_YES if we found a match. +   * Set to true if we found a match.     */ -  int found; +  bool found;  }; @@ -1188,7 +1173,7 @@ check_rc_matches (void *cls,                             rc->rowid,                             rc->execution_date,                             ctx->roi->details.execution_date); -    ctx->found = GNUNET_YES; +    ctx->found = true;      free_rc (NULL,               key,               rc); @@ -1218,7 +1203,7 @@ complain_out_not_found (void *cls,    struct GNUNET_HashCode rkey;    struct CheckMatchContext ctx = {      .roi = roi, -    .found = GNUNET_NO +    .found = false    };    (void) key; @@ -1229,7 +1214,7 @@ complain_out_not_found (void *cls,                                                &rkey,                                                &check_rc_matches,                                                &ctx); -  if (GNUNET_YES == ctx.found) +  if (ctx.found)      return GNUNET_OK;    TALER_ARL_report (report_wire_out_inconsistencies,                      GNUNET_JSON_PACK ( @@ -1245,7 +1230,7 @@ complain_out_not_found (void *cls,                                                        roi->details.                                                        execution_date),                        GNUNET_JSON_pack_string ("account_section", -                                               wa->section_name), +                                               wa->ai->section_name),                        GNUNET_JSON_pack_string ("diagnostic",                                                 "justification for wire transfer not found")));    TALER_ARL_amount_add (&total_bad_amount_out_plus, @@ -1279,18 +1264,18 @@ check_exchange_wire_out (struct WireAccount *wa)    GNUNET_log (GNUNET_ERROR_TYPE_INFO,                "Analyzing exchange's wire OUT table for account `%s'\n", -              wa->section_name); +              wa->ai->section_name);    qs = TALER_ARL_edb->select_wire_out_above_serial_id_by_account (      TALER_ARL_edb->cls,      TALER_ARL_esession, -    wa->section_name, +    wa->ai->section_name,      wa->pp.last_wire_out_serial_id,      &wire_out_cb,      wa);    if (0 > qs)    {      GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); -    global_ret = 1; +    global_ret = EXIT_FAILURE;      GNUNET_SCHEDULER_shutdown ();      return;    } @@ -1338,11 +1323,11 @@ history_debit_cb (void *cls,      {        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,                    "Error fetching debit history of account %s: %u/%u!\n", -                  wa->section_name, +                  wa->ai->section_name,                    http_status_code,                    (unsigned int) ec);        commit (GNUNET_DB_STATUS_HARD_ERROR); -      global_ret = 1; +      global_ret = EXIT_FAILURE;        GNUNET_SCHEDULER_shutdown ();        return GNUNET_SYSERR;      } @@ -1412,7 +1397,7 @@ process_debits (void *cls)    /* skip accounts where DEBIT is not enabled */    while ( (NULL != wa) && -          (GNUNET_NO == wa->watch_debit) ) +          (GNUNET_NO == wa->ai->debit_enabled) )      wa = wa->next;    if (NULL == wa)    { @@ -1423,10 +1408,10 @@ process_debits (void *cls)    }    GNUNET_log (GNUNET_ERROR_TYPE_INFO,                "Checking bank DEBIT records of account `%s'\n", -              wa->section_name); +              wa->ai->section_name);    GNUNET_assert (NULL == wa->dhh);    wa->dhh = TALER_BANK_debit_history (ctx, -                                      &wa->auth, +                                      wa->ai->auth,                                        wa->out_wire_off,                                        INT64_MAX,                                        &history_debit_cb, @@ -1435,9 +1420,9 @@ process_debits (void *cls)    {      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,                  "Failed to obtain bank transaction history for `%s'\n", -                wa->section_name); +                wa->ai->section_name);      commit (GNUNET_DB_STATUS_HARD_ERROR); -    global_ret = 1; +    global_ret = EXIT_FAILURE;      GNUNET_SCHEDULER_shutdown ();      return;    } @@ -1577,7 +1562,7 @@ complain_in_not_found (void *cls,                                                        rii->details.                                                        execution_date),                        GNUNET_JSON_pack_string ("account", -                                               wa->section_name), +                                               wa->ai->section_name),                        GNUNET_JSON_pack_string ("diagnostic",                                                 "incoming wire transfer claimed by exchange not found")));    TALER_ARL_amount_add (&total_bad_amount_in_minus, @@ -1629,19 +1614,19 @@ history_credit_cb (void *cls,      if (TALER_EC_NONE != ec)      {        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, -                  "Error fetching credit history of account %s: %u/%u!\n", -                  wa->section_name, +                  "Error fetching credit history of account %s: %u/%s!\n", +                  wa->ai->section_name,                    http_status, -                  (unsigned int) ec); +                  TALER_ErrorCode_get_hint (ec));        commit (GNUNET_DB_STATUS_HARD_ERROR); -      global_ret = 1; +      global_ret = EXIT_FAILURE;        GNUNET_SCHEDULER_shutdown ();        return GNUNET_SYSERR;      }      /* end of operation */      GNUNET_log (GNUNET_ERROR_TYPE_INFO,                  "Reconciling CREDIT processing of account `%s'\n", -                wa->section_name); +                wa->ai->section_name);      GNUNET_CONTAINER_multihashmap_iterate (in_map,                                             &complain_in_not_found,                                             wa); @@ -1825,7 +1810,7 @@ process_credits (void *cls)    /* skip accounts where CREDIT is not enabled */    while ( (NULL != wa) && -          (GNUNET_NO == wa->watch_credit) ) +          (GNUNET_NO == wa->ai->credit_enabled) )      wa = wa->next;    if (NULL == wa)    { @@ -1835,27 +1820,27 @@ process_credits (void *cls)    }    GNUNET_log (GNUNET_ERROR_TYPE_INFO,                "Analyzing exchange's wire IN table for account `%s'\n", -              wa->section_name); +              wa->ai->section_name);    qs = TALER_ARL_edb->select_reserves_in_above_serial_id_by_account (      TALER_ARL_edb->cls,      TALER_ARL_esession, -    wa->section_name, +    wa->ai->section_name,      wa->pp.last_reserve_in_serial_id,      &reserve_in_cb,      wa);    if (0 > qs)    {      GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); -    global_ret = 1; +    global_ret = EXIT_FAILURE;      GNUNET_SCHEDULER_shutdown ();      return;    }    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,                "Starting bank CREDIT history of account `%s'\n", -              wa->section_name); +              wa->ai->section_name);    wa->chh = TALER_BANK_credit_history (ctx, -                                       &wa->auth, +                                       wa->ai->auth,                                         wa->in_wire_off,                                         INT64_MAX,                                         &history_credit_cb, @@ -1865,7 +1850,7 @@ process_credits (void *cls)      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,                  "Failed to obtain bank transaction history\n");      commit (GNUNET_DB_STATUS_HARD_ERROR); -    global_ret = 1; +    global_ret = EXIT_FAILURE;      GNUNET_SCHEDULER_shutdown ();      return;    } @@ -2005,7 +1990,7 @@ begin_transaction (void)        TALER_ARL_adb->cls,        TALER_ARL_asession,        &TALER_ARL_master_pub, -      wa->section_name, +      wa->ai->section_name,        &wa->pp,        &wa->in_wire_off,        &wa->out_wire_off); @@ -2074,31 +2059,14 @@ process_account_cb (void *cls,    struct WireAccount *wa;    (void) cls; -  if ( (GNUNET_NO == ai->debit_enabled) && -       (GNUNET_NO == ai->credit_enabled) ) +  if ( (! ai->debit_enabled) && +       (! ai->credit_enabled) )      return; /* not an active exchange account */    GNUNET_log (GNUNET_ERROR_TYPE_INFO,                "Found exchange account `%s'\n",                ai->section_name);    wa = GNUNET_new (struct WireAccount); -  wa->section_name = GNUNET_strdup (ai->section_name); -  wa->watch_debit = ai->debit_enabled; -  wa->watch_credit = ai->credit_enabled; -  if (GNUNET_OK != -      TALER_BANK_auth_parse_cfg (TALER_ARL_cfg, -                                 ai->section_name, -                                 &wa->auth)) -  { -    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, -                "Failed to access bank account `%s'\n", -                wa->section_name); -    GNUNET_break (0); -    GNUNET_free (wa->section_name); -    GNUNET_free (wa); -    global_ret = 1; -    GNUNET_SCHEDULER_shutdown (); -    return; -  } +  wa->ai = ai;    GNUNET_CONTAINER_DLL_insert (wa_head,                                 wa_tail,                                 wa); @@ -2127,7 +2095,7 @@ run (void *cls,    if (GNUNET_OK !=        TALER_ARL_init (c))    { -    global_ret = 1; +    global_ret = EXIT_FAILURE;      return;    }    if (GNUNET_OK != @@ -2136,7 +2104,7 @@ run (void *cls,                                 "TINY_AMOUNT",                                 &tiny_amount))    { -    global_ret = 1; +    global_ret = EXIT_NOTCONFIGURED;      return;    }    GNUNET_SCHEDULER_add_shutdown (&do_shutdown, @@ -2147,6 +2115,7 @@ run (void *cls,    if (NULL == ctx)    {      GNUNET_break (0); +    global_ret = EXIT_FAILURE;      return;    }    reserve_closures = GNUNET_CONTAINER_multihashmap_create (1024, @@ -2198,13 +2167,24 @@ run (void *cls,    GNUNET_assert (GNUNET_OK ==                   TALER_amount_set_zero (TALER_ARL_currency,                                          &zero)); -  TALER_EXCHANGEDB_find_accounts (TALER_ARL_cfg, -                                  &process_account_cb, +  if (GNUNET_OK != +      TALER_EXCHANGEDB_load_accounts (TALER_ARL_cfg, +                                      TALER_EXCHANGEDB_ALO_DEBIT +                                      | TALER_EXCHANGEDB_ALO_CREDIT +                                      | TALER_EXCHANGEDB_ALO_AUTHDATA)) +  { +    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, +                "No bank accounts configured\n"); +    global_ret = EXIT_NOTCONFIGURED; +    GNUNET_SCHEDULER_shutdown (); +  } +  TALER_EXCHANGEDB_find_accounts (&process_account_cb,                                    NULL);    if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=        begin_transaction ())    { -    global_ret = 1; +    GNUNET_break (0); +    global_ret = EXIT_FAILURE;      GNUNET_SCHEDULER_shutdown ();    }  } @@ -2246,7 +2226,7 @@ main (int argc,    if (GNUNET_OK !=        GNUNET_STRINGS_get_utf8_args (argc, argv,                                      &argc, &argv)) -    return 4; +    return EXIT_INVALIDARGUMENT;    ret = GNUNET_PROGRAM_run (      argc,      argv, @@ -2258,9 +2238,9 @@ main (int argc,      NULL);    GNUNET_free_nz ((void *) argv);    if (GNUNET_SYSERR == ret) -    return 3; +    return EXIT_INVALIDARGUMENT;    if (GNUNET_NO == ret) -    return 0; +    return EXIT_SUCCESS;    return global_ret;  } diff --git a/src/auditor/test-auditor.conf b/src/auditor/test-auditor.conf index 2089b156..da440c60 100644 --- a/src/auditor/test-auditor.conf +++ b/src/auditor/test-auditor.conf @@ -7,6 +7,8 @@ BASE_URL = http://localhost:8083/  PAYTO_URI = payto://x-taler-bank/localhost/Exchange  enable_debit = yes  enable_credit = yes + +[exchange-accountcredentials-1]  WIRE_GATEWAY_URL = "http://localhost:8082/taler-wire-gateway/Exchange/"  WIRE_GATEWAY_AUTH_METHOD = basic  USERNAME = Exchange diff --git a/src/benchmark/bank-benchmark.conf b/src/benchmark/bank-benchmark.conf index 1b2eccaf..1942d551 100644 --- a/src/benchmark/bank-benchmark.conf +++ b/src/benchmark/bank-benchmark.conf @@ -56,6 +56,10 @@ USER_PAYTO_URI = payto://x-taler-bank/localhost:8082/42  [exchange-account-2]  # What is the payto://-URL of the exchange (to generate wire response)  PAYTO_URI = "payto://x-taler-bank/localhost:8082/Exchange" +enable_debit = YES +enable_credit = YES + +[exchange-accountcredentials-2]  # What is the bank account (with the "Taler Bank" demo system)? Must end with "/".  WIRE_GATEWAY_URL = http://localhost:8082/Exchange/  # Authentication information for basic authentication @@ -63,8 +67,6 @@ WIRE_GATEWAY_AUTH_METHOD = "basic"  username = Exchange  password = x -enable_debit = YES -enable_credit = YES diff --git a/src/benchmark/benchmark.conf b/src/benchmark/benchmark.conf index a5fe4340..3a11b73e 100644 --- a/src/benchmark/benchmark.conf +++ b/src/benchmark/benchmark.conf @@ -56,6 +56,10 @@ USER_PAYTO_URI = payto://x-taler-bank/localhost:8082/42  [exchange-account-2]  # What is the payto://-URL of the exchange (to generate wire response)  PAYTO_URI = "payto://x-taler-bank/localhost:8082/Exchange" +enable_debit = YES +enable_credit = YES + +[exchange-accountcredentials-2]  # What is the bank account (with the "Taler Bank" demo system)? Must end with "/".  WIRE_GATEWAY_URL = http://localhost:8082/taler-wire-gateway/Exchange/  # Authentication information for basic authentication @@ -63,8 +67,6 @@ WIRE_GATEWAY_AUTH_METHOD = "basic"  username = Exchange  password = x -enable_debit = YES -enable_credit = YES diff --git a/src/exchange/taler-exchange-aggregator.c b/src/exchange/taler-exchange-aggregator.c index 75de467d..a2ea65c3 100644 --- a/src/exchange/taler-exchange-aggregator.c +++ b/src/exchange/taler-exchange-aggregator.c @@ -1,6 +1,6 @@  /*    This file is part of TALER -  Copyright (C) 2016-2020 Taler Systems SA +  Copyright (C) 2016-2021 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 @@ -87,7 +87,7 @@ struct AggregationUnit     * Exchange wire account to be used for the preparation and     * eventual execution of the aggregate wire transfer.     */ -  struct TALER_EXCHANGEDB_WireAccount *wa; +  const struct TALER_EXCHANGEDB_AccountInfo *wa;    /**     * Database session for all of our transactions. @@ -262,7 +262,8 @@ parse_wirewatch_config (void)      return GNUNET_SYSERR;    }    if (GNUNET_OK != -      TALER_EXCHANGEDB_load_accounts (cfg)) +      TALER_EXCHANGEDB_load_accounts (cfg, +                                      TALER_EXCHANGEDB_ALO_DEBIT))    {      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,                  "No wire accounts configured for debit!\n"); diff --git a/src/exchange/taler-exchange-closer.c b/src/exchange/taler-exchange-closer.c index 0cd288b4..d14bedac 100644 --- a/src/exchange/taler-exchange-closer.c +++ b/src/exchange/taler-exchange-closer.c @@ -158,7 +158,8 @@ parse_wirewatch_config (void)      return GNUNET_SYSERR;    }    if (GNUNET_OK != -      TALER_EXCHANGEDB_load_accounts (cfg)) +      TALER_EXCHANGEDB_load_accounts (cfg, +                                      TALER_EXCHANGEDB_ALO_DEBIT))    {      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,                  "No wire accounts configured for debit!\n"); @@ -236,7 +237,7 @@ expired_reserve_cb (void *cls,    struct TALER_Amount closing_fee;    int ret;    enum GNUNET_DB_QueryStatus qs; -  struct TALER_EXCHANGEDB_WireAccount *wa; +  const struct TALER_EXCHANGEDB_AccountInfo *wa;    /* NOTE: potential optimization: use custom SQL API to not       fetch this: */ diff --git a/src/exchange/taler-exchange-transfer.c b/src/exchange/taler-exchange-transfer.c index a416eb15..a242547b 100644 --- a/src/exchange/taler-exchange-transfer.c +++ b/src/exchange/taler-exchange-transfer.c @@ -50,7 +50,7 @@ struct WirePrepareData    /**     * Wire account used for this preparation.     */ -  struct TALER_EXCHANGEDB_WireAccount *wa; +  const struct TALER_EXCHANGEDB_AccountInfo *wa;    /**     * Row ID of the transfer. @@ -179,7 +179,9 @@ parse_wirewatch_config (void)      return GNUNET_SYSERR;    }    if (GNUNET_OK != -      TALER_EXCHANGEDB_load_accounts (cfg)) +      TALER_EXCHANGEDB_load_accounts (cfg, +                                      TALER_EXCHANGEDB_ALO_DEBIT +                                      | TALER_EXCHANGEDB_ALO_AUTHDATA))    {      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,                  "No wire accounts configured for debit!\n"); @@ -353,7 +355,7 @@ wire_prepare_cb (void *cls,                   const char *buf,                   size_t buf_size)  { -  struct TALER_EXCHANGEDB_WireAccount *wa; +  const struct TALER_EXCHANGEDB_AccountInfo *wa;    (void) cls;    if ( (NULL == wire_method) || @@ -382,7 +384,7 @@ wire_prepare_cb (void *cls,    }    wa = wpd->wa;    wpd->eh = TALER_BANK_transfer (ctx, -                                 &wa->auth, +                                 wa->auth,                                   buf,                                   buf_size,                                   &wire_confirm_cb, diff --git a/src/exchange/taler-exchange-wirewatch.c b/src/exchange/taler-exchange-wirewatch.c index eeb1af48..6e40fc00 100644 --- a/src/exchange/taler-exchange-wirewatch.c +++ b/src/exchange/taler-exchange-wirewatch.c @@ -52,9 +52,9 @@ struct WireAccount    struct WireAccount *prev;    /** -   * Name of the section that configures this account. +   * Information about this account.     */ -  char *section_name; +  const struct TALER_EXCHANGEDB_AccountInfo *ai;    /**     * Database session we are using for the current transaction. @@ -67,11 +67,6 @@ struct WireAccount    struct TALER_BANK_CreditHistoryHandle *hh;    /** -   * Authentication data. -   */ -  struct TALER_BANK_AuthenticationData auth; - -  /**     * Until when is processing this wire plugin delayed?     */    struct GNUNET_TIME_Absolute delayed_until; @@ -233,8 +228,6 @@ shutdown_task (void *cls)        GNUNET_CONTAINER_DLL_remove (wa_head,                                     wa_tail,                                     wa); -      TALER_BANK_auth_free (&wa->auth); -      GNUNET_free (wa->section_name);        GNUNET_free (wa->job_name);        GNUNET_free (wa);      } @@ -258,6 +251,8 @@ shutdown_task (void *cls)    }    TALER_EXCHANGEDB_plugin_unload (db_plugin);    db_plugin = NULL; +  TALER_EXCHANGEDB_unload_accounts (); +  cfg = NULL;  } @@ -275,21 +270,10 @@ add_account_cb (void *cls,    struct WireAccount *wa;    (void) cls; -  if (GNUNET_YES != ai->credit_enabled) +  if (! ai->credit_enabled)      return; /* not enabled for us, skip */    wa = GNUNET_new (struct WireAccount); -  if (GNUNET_OK != -      TALER_BANK_auth_parse_cfg (cfg, -                                 ai->section_name, -                                 &wa->auth)) -  { -    GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, -                "Failed to load account `%s'\n", -                ai->section_name); -    GNUNET_free (wa); -    return; -  } -  wa->section_name = GNUNET_strdup (ai->section_name); +  wa->ai = ai;    GNUNET_asprintf (&wa->job_name,                     "wirewatch-%s",                     ai->section_name); @@ -325,20 +309,24 @@ exchange_serve_process_config (void)    if (NULL ==        (db_plugin = TALER_EXCHANGEDB_plugin_load (cfg)))    { -    fprintf (stderr, -             "Failed to initialize DB subsystem\n"); +    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, +                "Failed to initialize DB subsystem\n");      return GNUNET_SYSERR;    } -  TALER_EXCHANGEDB_find_accounts (cfg, -                                  &add_account_cb, -                                  NULL); -  if (NULL == wa_head) +  if (GNUNET_OK != +      TALER_EXCHANGEDB_load_accounts (cfg, +                                      TALER_EXCHANGEDB_ALO_CREDIT +                                      | TALER_EXCHANGEDB_ALO_AUTHDATA))    { -    fprintf (stderr, -             "No wire accounts configured for credit!\n"); +    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, +                "No wire accounts configured for credit!\n");      TALER_EXCHANGEDB_plugin_unload (db_plugin); +    db_plugin = NULL;      return GNUNET_SYSERR;    } +  TALER_EXCHANGEDB_find_accounts (&add_account_cb, +                                  NULL); +  GNUNET_assert (NULL != wa_head);    return GNUNET_OK;  } @@ -558,7 +546,7 @@ history_cb (void *cls,                                        &details->amount,                                        details->execution_date,                                        details->debit_account_url, -                                      wa->section_name, +                                      wa->ai->section_name,                                        serial_id);    switch (qs)    { @@ -683,7 +671,7 @@ find_transfers (void *cls)    GNUNET_assert (NULL == wa_pos->hh);    wa_pos->latest_row_off = wa_pos->batch_start;    wa_pos->hh = TALER_BANK_credit_history (ctx, -                                          &wa_pos->auth, +                                          wa_pos->ai->auth,                                            wa_pos->batch_start,                                            limit,                                            &history_cb, diff --git a/src/exchange/test_taler_exchange_httpd.conf b/src/exchange/test_taler_exchange_httpd.conf index 1c2372d8..2adee505 100644 --- a/src/exchange/test_taler_exchange_httpd.conf +++ b/src/exchange/test_taler_exchange_httpd.conf @@ -62,6 +62,8 @@ CONFIG = "postgres:///talercheck"  PAYTO_URI = "payto://x-taler-bank/localhost:8082/3"  ENABLE_DEBIT = YES  ENABLE_CREDIT = YES + +[exchange-accountcredentials-1]  WIRE_GATEWAY_AUTH_METHOD = basic  USERNAME = Exchange  PASSWORD = x diff --git a/src/exchange/test_taler_exchange_unix.conf b/src/exchange/test_taler_exchange_unix.conf index b795794d..b9387f60 100644 --- a/src/exchange/test_taler_exchange_unix.conf +++ b/src/exchange/test_taler_exchange_unix.conf @@ -64,6 +64,8 @@ CONFIG = "postgres:///talercheck"  PAYTO_URI = "payto://x-taler-bank/localhost:8082/3"  ENABLE_DEBIT = YES  ENABLE_CREDIT = YES + +[exchange-accountcredentials-1]  TALER_BANK_AUTH_METHOD = NONE diff --git a/src/exchangedb/exchangedb_accounts.c b/src/exchangedb/exchangedb_accounts.c index e5683983..54204eaa 100644 --- a/src/exchangedb/exchangedb_accounts.c +++ b/src/exchangedb/exchangedb_accounts.c @@ -1,6 +1,6 @@  /*    This file is part of TALER -  Copyright (C) 2018 Taler Systems SA +  Copyright (C) 2018-2021 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 @@ -23,150 +23,76 @@  /** - * Head of list of wire accounts of the exchange. - */ -static struct TALER_EXCHANGEDB_WireAccount *wa_head; - -/** - * Tail of list of wire accounts of the exchange. + * Information we keep for each supported account of the exchange.   */ -static struct TALER_EXCHANGEDB_WireAccount *wa_tail; +struct WireAccount +{ +  /** +   * Accounts are kept in a DLL. +   */ +  struct WireAccount *next; +  /** +   * Plugins are kept in a DLL. +   */ +  struct WireAccount *prev; -/** - * Closure of #check_for_account. - */ -struct FindAccountContext -{    /** -   * Configuration we are using. +   * Externally visible account information.     */ -  const struct GNUNET_CONFIGURATION_Handle *cfg; +  struct TALER_EXCHANGEDB_AccountInfo ai;    /** -   * Callback to invoke. +   * Authentication data. Only parsed if +   * #TALER_EXCHANGEDB_ALO_AUTHDATA was set.     */ -  TALER_EXCHANGEDB_AccountCallback cb; +  struct TALER_BANK_AuthenticationData auth;    /** -   * Closure for @e cb. +   * Name of the section that configures this account.     */ -  void *cb_cls; +  char *section_name;    /** -   * Set to #GNUNET_SYSERR if the configuration is invalid. +   * Name of the wire method underlying the account.     */ -  int res; +  char *method; +  };  /** - * Check if @a section begins with "exchange-account-", and if so if the - * "PAYTO_URI" is given. If not, a warning is printed, otherwise we also check - * if "ENABLE_CREDIT" or "ENABLE_DEBIT" options are set to "YES" and then call - * the callback in @a cls with all of the information gathered. - * - * @param cls our `struct FindAccountContext` - * @param section name of a section in the configuration + * Head of list of wire accounts of the exchange.   */ -static void -check_for_account (void *cls, -                   const char *section) -{ -  struct FindAccountContext *ctx = cls; -  char *method; -  char *payto_uri; - -  if (0 != strncasecmp (section, -                        "exchange-account-", -                        strlen ("exchange-account-"))) -    return; -  if (GNUNET_OK != -      GNUNET_CONFIGURATION_get_value_string (ctx->cfg, -                                             section, -                                             "PAYTO_URI", -                                             &payto_uri)) -  { -    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, -                               section, -                               "PAYTO_URI"); -    ctx->res = GNUNET_SYSERR; -    return; -  } -  method = TALER_payto_get_method (payto_uri); -  if (NULL == method) -  { -    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, -                "payto URI in config ([%s]/PAYTO_URI) malformed\n", -                section); -    ctx->res = GNUNET_SYSERR; -    GNUNET_free (payto_uri); -    return; -  } -  { -    struct TALER_EXCHANGEDB_AccountInfo ai = { -      .section_name = section, -      .method = method, -      .debit_enabled = (GNUNET_YES == -                        GNUNET_CONFIGURATION_get_value_yesno ( -                          ctx->cfg, -                          section, -                          "ENABLE_DEBIT")), -      .credit_enabled = (GNUNET_YES == -                         GNUNET_CONFIGURATION_get_value_yesno (ctx->cfg, -                                                               section, -                                                               "ENABLE_CREDIT")) -    }; - -    ctx->cb (ctx->cb_cls, -             &ai); -  } -  GNUNET_free (payto_uri); -  GNUNET_free (method); -} - +static struct WireAccount *wa_head;  /** - * Parse the configuration to find account information. - * - * @param cfg configuration to use - * @param cb callback to invoke - * @param cb_cls closure for @a cb - * @return #GNUNET_OK if the configuration seems valid, #GNUNET_SYSERR if not + * Tail of list of wire accounts of the exchange.   */ -int -TALER_EXCHANGEDB_find_accounts (const struct GNUNET_CONFIGURATION_Handle *cfg, -                                TALER_EXCHANGEDB_AccountCallback cb, +static struct WireAccount *wa_tail; + + +void +TALER_EXCHANGEDB_find_accounts (TALER_EXCHANGEDB_AccountCallback cb,                                  void *cb_cls)  { -  struct FindAccountContext ctx = { -    .cfg = cfg, -    .cb = cb, -    .cb_cls = cb_cls, -    .res = GNUNET_OK -  }; - -  GNUNET_CONFIGURATION_iterate_sections (cfg, -                                         &check_for_account, -                                         &ctx); -  return ctx.res; +  for (struct WireAccount *wa = wa_head; +       NULL != wa; +       wa = wa->next) +    cb (cb_cls, +        &wa->ai);  } -/** - * Find the wire plugin for the given payto:// URL - * - * @param method wire method we need an account for - * @return NULL on error - */ -struct TALER_EXCHANGEDB_WireAccount * +const struct TALER_EXCHANGEDB_AccountInfo *  TALER_EXCHANGEDB_find_account_by_method (const char *method)  { -  for (struct TALER_EXCHANGEDB_WireAccount *wa = wa_head; NULL != wa; wa = -         wa->next) +  for (struct WireAccount *wa = wa_head; +       NULL != wa; +       wa = wa->next)      if (0 == strcmp (method,                       wa->method)) -      return wa; +      return &wa->ai;    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,                "No wire account known for method `%s'\n",                method); @@ -174,17 +100,11 @@ TALER_EXCHANGEDB_find_account_by_method (const char *method)  } -/** - * Find the wire plugin for the given payto:// URL - * - * @param url wire address we need an account for - * @return NULL on error - */ -struct TALER_EXCHANGEDB_WireAccount * +const struct TALER_EXCHANGEDB_AccountInfo *  TALER_EXCHANGEDB_find_account_by_payto_uri (const char *url)  {    char *method; -  struct TALER_EXCHANGEDB_WireAccount *wa; +  const struct TALER_EXCHANGEDB_AccountInfo *ai;    method = TALER_payto_get_method (url);    if (NULL == method) @@ -194,107 +114,177 @@ TALER_EXCHANGEDB_find_account_by_payto_uri (const char *url)                  url);      return NULL;    } -  wa = TALER_EXCHANGEDB_find_account_by_method (method); +  ai = TALER_EXCHANGEDB_find_account_by_method (method);    GNUNET_free (method); -  return wa; +  return ai;  }  /** + * Closure for #add_account_cb(). + */ +struct LoaderContext +{ +  /** +   * Configuration to use. +   */ +  const struct GNUNET_CONFIGURATION_Handle *cfg; + +  /** +   * true if we are to load the authentication data +   * for the access to the bank account. +   */ +  bool load_auth_data; + +  /** +   * Load accounts enabled for CREDIT. +   */ +  bool credit; + +  /** +   * Load accounts enabled for DEBIT. +   */ +  bool debit; + +  /** +   * Loader status (set by callback). +   */ +  enum GNUNET_GenericReturnValue res; +}; + + +/**   * Function called with information about a wire account.  Adds   * the account to our list.   * - * @param cls closure, a `struct GNUNET_CONFIGURATION_Handle` + * @param cls closure, a `struct LoaderContext`   * @param ai account information   */  static void  add_account_cb (void *cls, -                const struct TALER_EXCHANGEDB_AccountInfo *ai) +                const char *section)  { -  const struct GNUNET_CONFIGURATION_Handle *cfg = cls; -  struct TALER_EXCHANGEDB_WireAccount *wa; +  struct LoaderContext *lc = cls; +  const struct GNUNET_CONFIGURATION_Handle *cfg = lc->cfg; +  struct WireAccount *wa;    char *payto_uri; +  char *method; +  bool debit; +  bool credit; -  (void) cls; -  if (GNUNET_YES != ai->debit_enabled) +  if (0 != strncasecmp (section, +                        "exchange-account-", +                        strlen ("exchange-account-"))) +    return; + +  debit = (GNUNET_YES == +           GNUNET_CONFIGURATION_get_value_yesno (lc->cfg, +                                                 section, +                                                 "ENABLE_DEBIT")); +  credit = (GNUNET_YES == +            GNUNET_CONFIGURATION_get_value_yesno (lc->cfg, +                                                  section, +                                                  "ENABLE_CREDIT")); +  if (! ( ( (debit) && +            (lc->debit) ) || +          ( (credit) && +            (lc->credit) ) ) )      return; /* not enabled for us, skip */ -  wa = GNUNET_new (struct TALER_EXCHANGEDB_WireAccount);    if (GNUNET_OK !=        GNUNET_CONFIGURATION_get_value_string (cfg, -                                             ai->section_name, +                                             section,                                               "PAYTO_URI",                                               &payto_uri))    { -    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, -                               ai->section_name, +    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, +                               section,                                 "PAYTO_URI"); -    GNUNET_free (wa); +    lc->res = GNUNET_SYSERR;      return;    } -  wa->method = TALER_payto_get_method (payto_uri); -  if (NULL == wa->method) +  method = TALER_payto_get_method (payto_uri); +  GNUNET_free (payto_uri); +  if (NULL == method)    { -    GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, -                               ai->section_name, -                               "PAYTO_URI", -                               "could not obtain wire method from URI"); -    GNUNET_free (wa); +    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, +                "payto URI in config ([%s]/PAYTO_URI) malformed\n", +                section); +    lc->res = GNUNET_SYSERR;      return;    } -  GNUNET_free (payto_uri); -  if (GNUNET_OK != -      TALER_BANK_auth_parse_cfg (cfg, -                                 ai->section_name, -                                 &wa->auth)) +  wa = GNUNET_new (struct WireAccount); +  wa->section_name = GNUNET_strdup (section); +  wa->method = method; +  wa->ai.debit_enabled = debit; +  wa->ai.credit_enabled = credit; +  wa->ai.auth = NULL; +  wa->ai.section_name = wa->section_name; +  wa->ai.method = wa->method; +  if (lc->load_auth_data)    { -    GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, -                "Failed to load exchange account `%s'\n", -                ai->section_name); -    GNUNET_free (wa->method); -    GNUNET_free (wa); -    return; +    char *csn; + +    GNUNET_asprintf (&csn, +                     "exchange-accountcredentials-%s", +                     §ion[strlen ("exchange-account-")]); +    if (GNUNET_OK != +        TALER_BANK_auth_parse_cfg (cfg, +                                   csn, +                                   &wa->auth)) +    { +      GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, +                  "Failed to load exchange account credentials from section `%s'\n", +                  csn); +      GNUNET_free (csn); +      GNUNET_free (wa->section_name); +      GNUNET_free (wa->method); +      GNUNET_free (wa); +      return; +    } +    wa->ai.auth = &wa->auth; +    GNUNET_free (csn);    } -  wa->section_name = GNUNET_strdup (ai->section_name);    GNUNET_CONTAINER_DLL_insert (wa_head,                                 wa_tail,                                 wa);  } -/** - * Load account information opf the exchange from - * @a cfg. - * - * @param cfg configuration to load from - * @return #GNUNET_OK on success, #GNUNET_NO if no accounts are configured - */ -int -TALER_EXCHANGEDB_load_accounts (const struct GNUNET_CONFIGURATION_Handle *cfg) +enum GNUNET_GenericReturnValue +TALER_EXCHANGEDB_load_accounts ( +  const struct GNUNET_CONFIGURATION_Handle *cfg, +  enum TALER_EXCHANGEDB_AccountLoaderOptions options)  { -  TALER_EXCHANGEDB_find_accounts (cfg, -                                  &add_account_cb, -                                  (void *) cfg); +  struct LoaderContext lc = { +    .cfg = cfg, +    .debit = 0 != (options & TALER_EXCHANGEDB_ALO_DEBIT), +    .credit = 0 != (options & TALER_EXCHANGEDB_ALO_CREDIT), +    .load_auth_data = 0 != (options & TALER_EXCHANGEDB_ALO_AUTHDATA), +  }; + +  GNUNET_CONFIGURATION_iterate_sections (cfg, +                                         &add_account_cb, +                                         &lc); +  if (GNUNET_SYSERR == lc.res) +    return GNUNET_SYSERR;    if (NULL == wa_head)      return GNUNET_NO;    return GNUNET_OK;  } -/** - * Free resources allocated by - * #TALER_EXCHANGEDB_load_accounts(). - */  void  TALER_EXCHANGEDB_unload_accounts (void)  { -  struct TALER_EXCHANGEDB_WireAccount *wa; +  struct WireAccount *wa;    while (NULL != (wa = wa_head))    {      GNUNET_CONTAINER_DLL_remove (wa_head,                                   wa_tail,                                   wa); -    TALER_BANK_auth_free (&wa->auth); +    if (NULL != wa->ai.auth) +      TALER_BANK_auth_free (&wa->auth);      GNUNET_free (wa->section_name);      GNUNET_free (wa->method);      GNUNET_free (wa); diff --git a/src/include/taler_exchangedb_lib.h b/src/include/taler_exchangedb_lib.h index c850c691..7f466728 100644 --- a/src/include/taler_exchangedb_lib.h +++ b/src/include/taler_exchangedb_lib.h @@ -53,6 +53,12 @@ TALER_EXCHANGEDB_plugin_unload (struct TALER_EXCHANGEDB_Plugin *plugin);  struct TALER_EXCHANGEDB_AccountInfo  {    /** +   * Authentication data. Only parsed if +   * #TALER_EXCHANGEDB_ALO_AUTHDATA was set. +   */ +  const struct TALER_BANK_AuthenticationData *auth; + +  /**     * Section in the configuration file that specifies the     * account. Must start with "exchange-account-".     */ @@ -64,47 +70,22 @@ struct TALER_EXCHANGEDB_AccountInfo    const char *method;    /** -   * #GNUNET_YES if this account is enabed to be debited +   * true if this account is enabed to be debited     * by the taler-exchange-aggregator.     */ -  int debit_enabled; +  bool debit_enabled;    /** -   * #GNUNET_YES if this account is enabed to be credited by wallets +   * true if this account is enabed to be credited by wallets     * and needs to be watched by the taler-exchange-wirewatch.     * Also, the account will only be included in /wire if credit     * is enabled.     */ -  int credit_enabled; +  bool credit_enabled;  };  /** - * Function called with information about a wire account. - * - * @param cls closure - * @param ai account information - */ -typedef void -(*TALER_EXCHANGEDB_AccountCallback)( -  void *cls, -  const struct TALER_EXCHANGEDB_AccountInfo *ai); - -/** - * Parse the configuration to find account information. - * - * @param cfg configuration to use - * @param cb callback to invoke - * @param cb_cls closure for @a cb - * @return #GNUNET_OK if the configuration seems valid, #GNUNET_SYSERR if not - */ -int -TALER_EXCHANGEDB_find_accounts (const struct GNUNET_CONFIGURATION_Handle *cfg, -                                TALER_EXCHANGEDB_AccountCallback cb, -                                void *cb_cls); - - -/**   * Calculate the total value of all transactions performed.   * Stores @a off plus the cost of all transactions in @a tl   * in @a ret. @@ -121,39 +102,28 @@ TALER_EXCHANGEDB_calculate_transaction_list_totals (    struct TALER_Amount *ret); -/* ***************** convenience functions ******** */ -  /** - * Information we keep for each supported account of the exchange. + * Function called with information about a wire account. + * + * @param cls closure + * @param ai account information   */ -struct TALER_EXCHANGEDB_WireAccount -{ -  /** -   * Accounts are kept in a DLL. -   */ -  struct TALER_EXCHANGEDB_WireAccount *next; - -  /** -   * Plugins are kept in a DLL. -   */ -  struct TALER_EXCHANGEDB_WireAccount *prev; - -  /** -   * Authentication data. -   */ -  struct TALER_BANK_AuthenticationData auth; - -  /** -   * Name of the section that configures this account. -   */ -  char *section_name; +typedef void +(*TALER_EXCHANGEDB_AccountCallback)( +  void *cls, +  const struct TALER_EXCHANGEDB_AccountInfo *ai); -  /** -   * Name of the wire method underlying the account. -   */ -  char *method; -}; +/** + * Return information about all accounts that + * were loaded by #TALER_EXCHANGEDB_load_accounts(). + * + * @param cb callback to invoke + * @param cb_cls closure for @a cb + */ +void +TALER_EXCHANGEDB_find_accounts (TALER_EXCHANGEDB_AccountCallback cb, +                                void *cb_cls);  /** @@ -164,7 +134,7 @@ struct TALER_EXCHANGEDB_WireAccount   * @param method wire method we need an account for   * @return NULL on error   */ -struct TALER_EXCHANGEDB_WireAccount * +const struct TALER_EXCHANGEDB_AccountInfo *  TALER_EXCHANGEDB_find_account_by_method (const char *method); @@ -176,19 +146,48 @@ TALER_EXCHANGEDB_find_account_by_method (const char *method);   * @param url wire address we need an account for   * @return NULL on error   */ -struct TALER_EXCHANGEDB_WireAccount * +const struct TALER_EXCHANGEDB_AccountInfo *  TALER_EXCHANGEDB_find_account_by_payto_uri (const char *url);  /** + * Options for #TALER_EXCHANGEDB_load_accounts() + */ +enum TALER_EXCHANGEDB_AccountLoaderOptions +{ +  TALER_EXCHANGEDB_ALO_NONE = 0, + +  /** +   * Load accounts enabled for DEBITs. +   */ +  TALER_EXCHANGEDB_ALO_DEBIT = 1, + +  /** +   * Load accounts enabled for CREDITs. +   */ +  TALER_EXCHANGEDB_ALO_CREDIT = 2, + +  /** +   * Load authentication data from the +   * "taler-accountcredentials-" section +   * to access the account at the bank. +   */ +  TALER_EXCHANGEDB_ALO_AUTHDATA = 4 +}; + + +/**   * Load account information opf the exchange from   * @a cfg.   *   * @param cfg configuration to load from + * @param options loader options   * @return #GNUNET_OK on success, #GNUNET_NO if no accounts are configured   */ -int -TALER_EXCHANGEDB_load_accounts (const struct GNUNET_CONFIGURATION_Handle *cfg); +enum GNUNET_GenericReturnValue +TALER_EXCHANGEDB_load_accounts ( +  const struct GNUNET_CONFIGURATION_Handle *cfg, +  enum TALER_EXCHANGEDB_AccountLoaderOptions options);  /** diff --git a/src/testing/test-taler-exchange-aggregator-postgres.conf b/src/testing/test-taler-exchange-aggregator-postgres.conf index 2c03c5db..7f277629 100644 --- a/src/testing/test-taler-exchange-aggregator-postgres.conf +++ b/src/testing/test-taler-exchange-aggregator-postgres.conf @@ -70,13 +70,15 @@ LEGAL_RESERVE_EXPIRATION_TIME = 7 years  # What is the account URL?  PAYTO_URI = "payto://x-taler-bank/localhost/2" +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES + +[exchange-accountcredentials-1]  WIRE_GATEWAY_URL = "http://localhost:8082/2/"  WIRE_GATEWAY_AUTH_METHOD = basic  USERNAME = Exchange  PASSWORD = x -ENABLE_DEBIT = YES -ENABLE_CREDIT = YES -TALER_BANK_AUTH_METHOD = NONE +  [bank]  HTTP_PORT = 8082 diff --git a/src/testing/test-taler-exchange-wirewatch-postgres.conf b/src/testing/test-taler-exchange-wirewatch-postgres.conf index 6a963989..d42f9d44 100644 --- a/src/testing/test-taler-exchange-wirewatch-postgres.conf +++ b/src/testing/test-taler-exchange-wirewatch-postgres.conf @@ -56,17 +56,16 @@ BASE_URL = "http://localhost:8083/"  PORT = 8083  [exchange-account-1] -  # What is the account URL?  PAYTO_URI = "payto://x-taler-bank/localhost/2" +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES + +[exchange-accountcredentials-1]  WIRE_GATEWAY_URL = "http://localhost:8082/2/"  WIRE_GATEWAY_AUTH_METHOD = basic  USERNAME = Exchange  PASSWORD = x -PLUGIN = "taler_bank" -ENABLE_DEBIT = YES -ENABLE_CREDIT = YES -TALER_BANK_AUTH_METHOD = NONE  [bank]  HTTP_PORT = 8082 diff --git a/src/testing/test_auditor_api.conf b/src/testing/test_auditor_api.conf index 4140aeb4..03a5e245 100644 --- a/src/testing/test_auditor_api.conf +++ b/src/testing/test_auditor_api.conf @@ -57,6 +57,8 @@ CONFIG = "postgres:///talercheck"  [exchange-account-1]  # What is the URL of our account?  PAYTO_URI = "payto://x-taler-bank/localhost/42" + +[exchange-accountcredentials-1]  WIRE_GATEWAY_URL = "http://localhost:8082/42/"  [bank] @@ -66,17 +68,18 @@ HTTP_PORT = 8082  [exchange-account-2]  # What is the bank account (with the "Taler Bank" demo system)? -WIRE_GATEWAY_URL = "http://localhost:8082/2/"  PAYTO_URI = "payto://x-taler-bank/localhost/2" +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES  # Authentication information for basic authentication +[exchange-accountcredentials-2] +WIRE_GATEWAY_URL = "http://localhost:8082/2/"  WIRE_GATEWAY_AUTH_METHOD = "basic"  USERNAME = user  PASSWORD = pass -ENABLE_DEBIT = YES -ENABLE_CREDIT = YES  # Sections starting with "coin_" specify which denominations diff --git a/src/testing/test_bank_api.c b/src/testing/test_bank_api.c index 68c12aff..e5a12589 100644 --- a/src/testing/test_bank_api.c +++ b/src/testing/test_bank_api.c @@ -216,10 +216,11 @@ main (int argc,      TALER_LOG_DEBUG ("Running with Nexus.\n");      with_libeufin = GNUNET_YES;      cfgfile = CONFIG_FILE_NEXUS; -    if (GNUNET_OK != TALER_TESTING_prepare_nexus (CONFIG_FILE_NEXUS, -                                                  GNUNET_YES, -                                                  "exchange-account-2", -                                                  &bc)) +    if (GNUNET_OK != +        TALER_TESTING_prepare_nexus (CONFIG_FILE_NEXUS, +                                     GNUNET_YES, +                                     "exchange-account-2", +                                     &bc))      {        GNUNET_break (0);        return 77; diff --git a/src/testing/test_bank_api_fakebank.conf b/src/testing/test_bank_api_fakebank.conf index 78f9ecbd..b9742398 100644 --- a/src/testing/test_bank_api_fakebank.conf +++ b/src/testing/test_bank_api_fakebank.conf @@ -5,6 +5,8 @@ currency = KUDOS  [exchange-account-2]  PAYTO_URI = payto://x-taler-bank/localhost/2 + +[exchange-accountcredentials-2]  WIRE_GATEWAY_URL = "http://localhost:8081/2/"  WIRE_GATEWAY_AUTH_METHOD = basic  USERNAME = Exchange diff --git a/src/testing/test_bank_api_nexus.conf b/src/testing/test_bank_api_nexus.conf index e9a64e2a..c514170e 100644 --- a/src/testing/test_bank_api_nexus.conf +++ b/src/testing/test_bank_api_nexus.conf @@ -5,7 +5,8 @@ currency = KUDOS  [exchange-account-2]  PAYTO_URI = payto://iban/BIC/ES9121000418450200051332?receiver-name=Exchange -METHOD = iban + +[exchange-accountcredentials-2]  WIRE_GATEWAY_URL = http://localhost:5001/facades/my-facade/taler/  WIRE_GATEWAY_AUTH_METHOD = basic  # the exchange authenticates as the 'admin' user, diff --git a/src/testing/test_bank_api_pybank.conf b/src/testing/test_bank_api_pybank.conf index 93169d2f..6603ba8a 100644 --- a/src/testing/test_bank_api_pybank.conf +++ b/src/testing/test_bank_api_pybank.conf @@ -5,7 +5,8 @@ currency = KUDOS  [exchange-account-2]  PAYTO_URI = payto://x-taler-bank/localhost/Exchange -METHOD = x-taler-bank + +[exchange-accountcredentials-2]  WIRE_GATEWAY_URL = "http://localhost:8081/taler-wire-gateway/Exchange/"  WIRE_GATEWAY_AUTH_METHOD = basic  USERNAME = Exchange diff --git a/src/testing/test_bank_api_pybank_twisted.conf b/src/testing/test_bank_api_pybank_twisted.conf index 3a7b08c9..d89cf046 100644 --- a/src/testing/test_bank_api_pybank_twisted.conf +++ b/src/testing/test_bank_api_pybank_twisted.conf @@ -18,31 +18,26 @@ UNIXPATH = /tmp/taler-service-twister.sock  UNIX_MATCH_UID = NO  UNIX_MATCH_GID = YES -  [auditor]  BASE_URL = "http://localhost:8083/"  [taler]  currency = KUDOS -  [bank]  serve = http  http_port = 8081  database = postgres:///talercheck -  [exchange-account-1]  PAYTO_URI = payto://x-taler-bank/localhost/1  [exchange-account-2]  PAYTO_URI = payto://x-taler-bank/localhost/Exchange + +[exchange-accountcredentials-2]  WIRE_GATEWAY_URL = "http://localhost:8888/taler-wire-gateway/Exchange/"  WIRE_GATEWAY_AUTH_METHOD = basic  USERNAME = Exchange  PASSWORD = x - - -[bank] -HTTP_PORT = 8081 diff --git a/src/testing/test_exchange_api.conf b/src/testing/test_exchange_api.conf index 8c883c49..a1b74365 100644 --- a/src/testing/test_exchange_api.conf +++ b/src/testing/test_exchange_api.conf @@ -57,18 +57,22 @@ CONFIG = "postgres:///talercheck"  [exchange-account-1]  # What is the URL of our account?  PAYTO_URI = "payto://x-taler-bank/localhost/42" -WIRE_GATEWAY_URL = "http://localhost:9081/42/"  # ENABLE_CREDIT = YES +[exchange-accountcredentials-1] +WIRE_GATEWAY_URL = "http://localhost:9081/42/" +  [exchange-account-2]  # What is the bank account (with the "Taler Bank" demo system)?  PAYTO_URI = "payto://x-taler-bank/localhost/2" +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES + +[exchange-accountcredentials-2]  WIRE_GATEWAY_AUTH_METHOD = basic  USERNAME = Exchange  PASSWORD = x  WIRE_GATEWAY_URL = "http://localhost:9081/2/" -ENABLE_DEBIT = YES -ENABLE_CREDIT = YES  [bank]  HTTP_PORT = 9081 diff --git a/src/testing/test_exchange_api_keys_cherry_picking.conf b/src/testing/test_exchange_api_keys_cherry_picking.conf index e7a56f3c..d7dd9535 100644 --- a/src/testing/test_exchange_api_keys_cherry_picking.conf +++ b/src/testing/test_exchange_api_keys_cherry_picking.conf @@ -57,18 +57,22 @@ CONFIG = "postgres:///talercheck"  [exchange-account-1]  PAYTO_URI = payto://x-taler-bank/localhost/42 + +[exchange-accountcredentials-1]  WIRE_GATEWAY_URL = "http://localhost:9082/42/"  [exchange-account-2]  PAYTO_URI = payto://x-taler-bank/localhost/2 +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES + +[exchange-accountcredentials-2]  WIRE_GATEWAY_URL = "http://localhost:9082/2/"  # Authentication information for basic authentication  TALER_BANK_AUTH_METHOD = "basic"  USERNAME = user  PASSWORD = pass -ENABLE_DEBIT = YES -ENABLE_CREDIT = YES  [bank]  HTTP_PORT=8082 diff --git a/src/testing/test_exchange_api_twisted.conf b/src/testing/test_exchange_api_twisted.conf index 2d4fc517..a41cfd43 100644 --- a/src/testing/test_exchange_api_twisted.conf +++ b/src/testing/test_exchange_api_twisted.conf @@ -49,17 +49,21 @@ CONFIG = "postgres:///talercheck"  [exchange-account-1]  # What is the URL of our account?  PAYTO_URI = "payto://x-taler-bank/localhost/42" + +[exchange-accountcredentials-1]  WIRE_GATEWAY_URL = "http://localhost:9081/42/"  WIRE_GATEWAY_AUTH_METHOD = NONE  [exchange-account-2]  PAYTO_URI = payto://x-taler-bank/localhost/2 +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES + +[exchange-accountcredentials-2]  WIRE_GATEWAY_URL = "http://localhost:8082/2/"  WIRE_GATEWAY_AUTH_METHOD = BASIC  USERNAME = user  PASSWORD = pass -ENABLE_DEBIT = YES -ENABLE_CREDIT = YES  [bank]  HTTP_PORT = 8082 diff --git a/src/testing/testing_api_helpers_bank.c b/src/testing/testing_api_helpers_bank.c index a82bcbfe..d7cce01b 100644 --- a/src/testing/testing_api_helpers_bank.c +++ b/src/testing/testing_api_helpers_bank.c @@ -292,10 +292,14 @@ TALER_TESTING_prepare_nexus (const char *config_filename,    char *database = NULL; // silence compiler    char *exchange_payto_uri; +  GNUNET_assert (0 == +                 strncasecmp (config_section, +                              "exchange-account-", +                              strlen ("exchange-account-")));    cfg = GNUNET_CONFIGURATION_create (); -    if (GNUNET_OK != -      GNUNET_CONFIGURATION_load (cfg, config_filename)) +      GNUNET_CONFIGURATION_load (cfg, +                                 config_filename))    {      GNUNET_CONFIGURATION_destroy (cfg);      GNUNET_break (0); @@ -357,14 +361,25 @@ TALER_TESTING_prepare_nexus (const char *config_filename,      }    } -  if (GNUNET_OK != -      TALER_BANK_auth_parse_cfg (cfg, -                                 config_section, -                                 &bc->exchange_auth))    { -    GNUNET_break (0); -    GNUNET_CONFIGURATION_destroy (cfg); -    return GNUNET_SYSERR; +    char *csn; + +    GNUNET_asprintf (&csn, +                     "exchange-accountcredentials-%s", +                     &config_section[strlen ("exchange-account-")]); + + +    if (GNUNET_OK != +        TALER_BANK_auth_parse_cfg (cfg, +                                   csn, +                                   &bc->exchange_auth)) +    { +      GNUNET_break (0); +      GNUNET_CONFIGURATION_destroy (cfg); +      GNUNET_free (csn); +      return GNUNET_SYSERR; +    } +    GNUNET_free (csn);    }    GNUNET_CONFIGURATION_destroy (cfg);    bc->exchange_payto = exchange_payto_uri; @@ -400,10 +415,15 @@ TALER_TESTING_prepare_bank (const char *config_filename,    char *database;    char *exchange_payto_uri; +  GNUNET_assert (0 == +                 strncasecmp (config_section, +                              "exchange-account-", +                              strlen ("exchange-account-")));    cfg = GNUNET_CONFIGURATION_create ();    if (GNUNET_OK != -      GNUNET_CONFIGURATION_load (cfg, config_filename)) +      GNUNET_CONFIGURATION_load (cfg, +                                 config_filename))    {      GNUNET_CONFIGURATION_destroy (cfg);      GNUNET_break (0); @@ -522,14 +542,24 @@ TALER_TESTING_prepare_bank (const char *config_filename,      }      GNUNET_OS_process_destroy (dbreset_proc);    } -  if (GNUNET_OK != -      TALER_BANK_auth_parse_cfg (cfg, -                                 config_section, -                                 &bc->exchange_auth))    { -    GNUNET_break (0); -    GNUNET_CONFIGURATION_destroy (cfg); -    return GNUNET_SYSERR; +    char *csn; + +    GNUNET_asprintf (&csn, +                     "exchange-accountcredentials-%s", +                     &config_section[strlen ("exchange-account-")]); + +    if (GNUNET_OK != +        TALER_BANK_auth_parse_cfg (cfg, +                                   csn, +                                   &bc->exchange_auth)) +    { +      GNUNET_break (0); +      GNUNET_free (csn); +      GNUNET_CONFIGURATION_destroy (cfg); +      return GNUNET_SYSERR; +    } +    GNUNET_free (csn);    }    GNUNET_CONFIGURATION_destroy (cfg);    bc->exchange_payto = exchange_payto_uri; | 
