taler-docs

Documentation for GNU Taler components, APIs and protocols
Log | Files | Refs | README | LICENSE

taler-exchange-manual.rst (71818B)


      1 ..
      2   This file is part of GNU TALER.
      3 
      4   Copyright (C) 2014-2024 Taler Systems SA
      5 
      6   TALER is free software; you can redistribute it and/or modify it under the
      7   terms of the GNU Affero General Public License as published by the Free Software
      8   Foundation; either version 3.0, or (at your option) any later version.
      9 
     10   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     11   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     12   A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
     13 
     14   You should have received a copy of the GNU Affero General Public License along with
     15   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     16 
     17   @author Christian Grothoff
     18   @author Florian Dold
     19 
     20 Exchange Operator Manual
     21 ########################
     22 
     23 Introduction
     24 ============
     25 
     26 About GNU Taler
     27 ---------------
     28 
     29 .. include:: frags/about-taler.rst
     30 
     31 
     32 About this manual
     33 -----------------
     34 
     35 This manual targets system administrators who want to install and
     36 operate a GNU Taler exchange.
     37 
     38 
     39 Organizational prerequisites
     40 ----------------------------
     41 
     42 Operating a GNU Taler exchange means that you are operating a payment service
     43 provider, which means that you will most likely need a bank license and/or
     44 follow applicable financial regulation. The :ref:`Exchange KYC/AML Operator
     45 Manual <KycOperatorManual>` goes into depth for how an exchange can be
     46 configured for compliance.  Exceptions to compliance rules may apply,
     47 especially if you are operating a regional currency or a payment system for an
     48 event with a closed user group.  If in doubt, please contact a competent
     49 lawyer in your country about the legality of operating a GNU Taler exchange.
     50 
     51 GNU Taler payment service providers generally need to ensure high availability
     52 and should have *really* good backups (synchronous replication, asynchronous
     53 remote replication, off-site backup, 24/7 monitoring, etc.).  This manual will
     54 not cover these aspects of operating a payment service provider.
     55 
     56 We will assume that you can operate a (sufficiently high-availability,
     57 high-assurance) PostgreSQL database. Furthermore, we expect some moderate
     58 familiarity with the compilation and installation of free software
     59 packages. You need to understand the cryptographic concepts of private and
     60 public keys and must be able to protect private keys stored in files on disk.
     61 
     62 .. include:: frags/db-stores-sensitive-data.rst
     63 
     64 
     65 Architecture overview
     66 ---------------------
     67 
     68 GNU Taler is a pure payment system, not a crypto-currency. As such, it
     69 operates in a traditional banking context. In particular, this means that
     70 payments can be executed in ordinary currencies such as USD or EUR.
     71 Furthermore, a typical merchant in Taler has a regular bank account, and would
     72 use it to receive funds via Taler.
     73 
     74 Consequently, a typical Taler exchange must interact with a bank. The bank of
     75 the exchange holds funds in an account where the balance is basically
     76 equivalent to the value of all coins in circulation. (Small mismatches arise
     77 whenever customers are about to withdraw coins and have already sent the funds
     78 into the bank account, or if merchants just deposited coins and are about to
     79 receive wire transfers for deposited coins, or due to fees charged by the
     80 exchange and the operator not yet having drained the fees from the account.)
     81 
     82 The exchange uses an intermediary system to talk to its bank.  This shifts the
     83 technical burden (XML-based communications, additional cryptography, and a
     84 vast variety of standards) for this interaction into another bank-specific
     85 subsystem.  Such intermediary system abstracts the native banking protocol by
     86 exposing the *Taler Wire Gateway API*; this way, the exchange can conduct its
     87 banking operations in a simplified and JSON-based style.
     88 
     89 When customers wire money to the exchange's bank account, the Taler Wire
     90 Gateway API must notify the exchange about the incoming wire transfers. The
     91 exchange then creates a *reserve* based on the subject of the wire
     92 transfer. The wallet which knows the secret key matching the wire transfer
     93 subject can then withdraw coins from the reserve, thereby draining it. The
     94 liability of the exchange against the reserve is thereby converted into a
     95 liability against digital coins issued by the exchange. When the customer
     96 later spends the coins at a merchant, and the merchant *deposits* the coins at
     97 the exchange, the exchange first *aggregates* the amount from multiple
     98 deposits from the same merchant and then instructs its bank to make a wire
     99 transfer to the merchant, thereby fulfilling its obligation and eliminating
    100 the liability. The exchange charges *fees* for some or all of its operations
    101 to cover costs and possibly make a profit.
    102 
    103 *Auditors* are third parties, for example financial regulators, that verify
    104 that the exchange operates correctly. The same software is also used to
    105 calculate the exchange’s profits, risk and liabilities by the accountants of
    106 the exchange.
    107 
    108 The Taler software stack for an exchange consists of the following
    109 components:
    110 
    111 -  **HTTP frontend**:
    112    The HTTP frontend interacts with Taler wallets and merchant backends.
    113    It is used to withdraw coins, deposit coins, refresh coins, issue
    114    refunds, map wire transfers to Taler transactions, inquire about the
    115    exchange’s bank account details, signing keys and fee structure. The
    116    binary is the ``taler-exchange-httpd``.
    117 
    118 -  **Crypto-Helpers**:
    119    The ``taler-exchange-secmod-rsa``, ``taler-exchange-secmod-cs`` and
    120    ``taler-exchange-secmod-eddsa``
    121    are three programs that are responsible for managing the exchange's
    122    online signing keys. They must run on the same machine as the
    123    ``taler-exchange-httpd`` as the HTTP frontend communicates with the
    124    crypto helpers using UNIX Domain Sockets.
    125 
    126 -  **Aggregator**:
    127    The aggregator combines multiple deposits made by the same merchant
    128    and (eventually) triggers wire transfers for the aggregate amount.
    129    The merchant can control how quickly wire transfers are made. The
    130    exchange may charge a fee per wire transfer to discourage
    131    excessively frequent transfers. The binary is the
    132    ``taler-exchange-aggregator``.
    133 
    134 -  **Closer**:
    135    The ``taler-exchange-closer`` tool check that reserves are properly
    136    closed. If a customer wires funds to an exchange and then fails
    137    to withdraw them, the closer will (eventually) trigger a wire
    138    transfer that sends the customer's funds back to the originating
    139    wire account.
    140 
    141 -  **Transfer**:
    142    The ``taler-exchange-transfer`` tool is responsible for actually
    143    executing the aggregated wire transfers. It is the only process
    144    that needs to have the credentials to execute outgoing wire
    145    transfers.  The tool uses the Taler Wire Gateway API to execute
    146    wire transfers.  This API is provided by the Taler Python Bank
    147    for stand-alone deployments (like those with ``KUDOS``) and
    148    by LibEuFin.  LibEuFin is an adapter which maps the Taler Wire
    149    REST API to traditional banking protocols like EBICS and FinTS.
    150 
    151 -  **Wirewatch**:
    152    The ``taler-exchange-wirewatch`` tool is responsible for observing
    153    incoming wire transfers to the exchange. It needs to have the
    154    credentials to obtain a list of incoming wire transfers.
    155    The tool also uses the Taler Wire Gateway API to observe such
    156    incoming transfers.  It is possible that observing incoming and
    157    making outgoing wire transfers is done via different bank accounts
    158    and/or credentials.
    159 
    160 -  **Wire adapter**:
    161    A wire adapter is a component that enables exchange to talk to a bank.
    162    Each wire adapter must implement the Taler Wire Gateway API.  Three
    163    wire adapters are currently provided:
    164 
    165    (1) The **libtalerfakebank** implements a bank with a wire adapter API
    166        inside of a testcase.  ``taler-fakebank-run`` is a stand-alone
    167        process using libtalerfakebank.  Note that this adapter is only
    168        useful for tests, as all transaction data is kept in memory.
    169        The binary is packaged in the ``libtalerexchange-dev`` package
    170        on Debian/Ubuntu and possibly other platforms as it is not intended
    171        for production.
    172    (2) For production, **libeufin**'s ``libeufin-nexus`` component
    173        implements a wire adapter towards the traditional SEPA banking
    174        system with IBAN accounts using the EBICS protocol.
    175    (3) **taler-magnet-bank** component
    176        implements a wire adapter towards the Magnet Bank API.
    177    (4) **taler-cyclos** component
    178        implements a wire adapter towards the Cyclos API.
    179    (5) **taler-wise** component
    180        implements a wire adapter towards the Wise API.
    181    (6) To use GNU Taler with blockchains, the **Depolymerization**
    182        component provides a wire gateway API that runs on top of
    183        blockchains like Bitcoin and Ethereum.
    184 
    185    The client-side wire adapter API is implemented in **libtalerbank** and
    186    is used by ``taler-exchange-transfer`` to execute wire transfers and by
    187    ``taler-exchange-wirewatch`` and the Taler auditor to query bank
    188    transaction histories.
    189 
    190 -  **DBMS**:
    191    The exchange requires a DBMS to store the transaction history for
    192    the Taler exchange and aggregator, and a (typically separate) DBMS
    193    for the Taler auditor. For now, the GNU Taler reference implementation
    194    only supports PostgreSQL, but the code could be easily extended to
    195    support another DBMS.
    196    .. index:: PostgreSQL
    197 
    198 -  **Auditor**:
    199    The auditor verifies that the transactions performed by the exchange
    200    were done properly. It checks the various signatures, totals up the
    201    amounts and alerts the operator to any inconsistencies. It also
    202    computes the expected bank balance, revenue and risk exposure of the
    203    exchange operator. The main binary is the ``taler-auditor``.
    204    Aside from the key setup procedures, the most critical setup for
    205    deploying an auditor is providing the auditor with an up-to-date
    206    copy of the exchange's database.
    207 
    208 
    209 .. _KeyTypes:
    210 
    211 Key Types
    212 ---------
    213 
    214 The exchange works with four types of keys:
    215 
    216 -  master key (kept offline, configured manually at merchants and wallets)
    217 
    218 -  online message signing keys (signs normal messages from the exchange)
    219 
    220 -  denomination keys (signs digital coins)
    221 
    222 -  security module keys (signs online message signing keys and denomination keys)
    223 
    224 Additionally, the exchange is sometimes concerned with the auditor's public
    225 key (to verify messages signed by auditors approved by the exchange operator)
    226 and the merchant's public key (to verify refunds are authorized by the
    227 merchant).
    228 
    229 Most of the keys are managed fully automatically or configured as part of the
    230 denomination configuration.  Some configuration settings must be manually
    231 set with regards to the exchange's master key.
    232 
    233 
    234 Offline keys
    235 ------------
    236 
    237 The exchange (and ideally also its auditor(s)) uses a long-term offline master
    238 siging key that identifies the operator and is used to authenticate critical
    239 information, such as the exchange's bank account and the actual keys the
    240 exchange uses online.
    241 
    242 Interactions with the offline system are performed using the
    243 ``taler-exchange-offline`` tool.  To use the offline system will require
    244 exchange operators to copy JSON files from or to the offline system (say using
    245 an USB stick).  The offline system does not need any significant amount of
    246 computing power, a Raspberry-Pi is perfectly sufficient and the form-factor
    247 might be good for safe-keeping! (You should keep a copy of the (encrypted)
    248 private offline key on more than one physical medium though.)
    249 
    250 Exchange operators are strongly advised to secure their private master key and
    251 any copies on encrypted, always-offline computers. Again, this manual assumes
    252 that you are familiar with good best practices in operational security,
    253 including securing key material.
    254 
    255 
    256 Online signing key security
    257 ---------------------------
    258 
    259 To provide an additional level of protection for the private *online* signing
    260 keys used by the exchange, the actual cryptographic signing operations are
    261 performed by three helper processes, ``taler-exchange-secmod-rsa``,
    262 ``taler-exchange-secmod-cs`` and ``taler-exchange-secmod-eddsa``.
    263 
    264 The current implementation does not yet support the use of a hardware security
    265 module (HSM).  If you have such a device with adequate functionality and are
    266 interested in Taler supporting it, please contact the developers for HSM
    267 integration support.
    268 
    269 
    270 Functionality
    271 ^^^^^^^^^^^^^
    272 
    273 The UNIX domain sockets of the *secmod* helpers have mode 0620 (u+rw, g+w).
    274 The exchange process MUST thus be in the same group as the crypto helper
    275 processes to enable access to the keys. No other users should be in that
    276 group!
    277 
    278 The two helper processes will create the required private keys, and allow
    279 anyone with access to the UNIX domain socket to sign arbitrary messages with
    280 the keys or to inform them about a key being revoked.  The helper processes
    281 are also responsible for deleting the private keys if their validity period
    282 expires or if they are informed about a key having been revoked.
    283 
    284 
    285 Security goals
    286 ^^^^^^^^^^^^^^
    287 
    288 From a security point of view, the helpers are designed to *only* make it
    289 harder for an attacker who took control of the HTTP daemon's account to
    290 extract the private keys, limiting the attacker's ability to create
    291 signatures to the duration of their control of that account.
    292 
    293 .. note::
    294    In the future, the helper processes should additionally provide a mechanism
    295    to track the total number of signatures they have made for the various keys.
    296 
    297 Setup
    298 ^^^^^
    299 
    300 The helper processes should be run under a user ID that is separate from that
    301 of the user running the main ``taler-exchange-httpd`` service.  To get any
    302 security benefit from this, it is important that helpers run under a different
    303 user ID than the main HTTP frontend. In fact, ideally, each helper should run
    304 under its own user ID.  The ``taler-exchange-httpd`` service will securely
    305 communicate with the helpers using UNIX domain sockets.
    306 
    307 Configuration
    308 ^^^^^^^^^^^^^
    309 
    310 The helpers and the exchange HTTP service need both access to the same
    311 configuration information.  Having divergent configurations may result in
    312 run-time failures.  It is recommended that the configuration file (``-c``
    313 option) is simply shared between all of the different processes, even though
    314 they run as different system users. The configuration does not contain any
    315 sensitive information.
    316 
    317 
    318 .. _ExchangeInstallation:
    319 
    320 Installation
    321 ============
    322 
    323 Before installing a Taler exchange, please make sure that your system does not
    324 have swap space enabled.  Swap space is a security risk that Taler does not
    325 try to mitigate against.
    326 
    327 We recommend the setup of offline signing keys to be done on a second machine that
    328 does not have Internet access.
    329 
    330 In this guide's shell-session fragments, the command prompt shows two pieces
    331 of information:
    332 
    333 * Who is performing the command
    334   (``$user`` vs ``root``, and ending character ``$`` vs ``#``).
    335 * Host where the command is supposed to be executed
    336   (``exchange-offline`` vs ``exchange-online``).
    337   It is possible to do the entire setup on one machine,
    338   but we do not recommend this for security reasons.
    339 
    340 Before you start
    341 ----------------
    342 
    343 To deploy this with a real bank, you need:
    344 
    345   * IBAN of the bank account to use
    346   * BIC of the bank
    347   * EBICS host, user and partner IDs
    348 
    349 Information to write down during the installation:
    350 
    351   * LibEuFin Nexus superuser password
    352   * Taler facade base URL
    353   * exchange Nexus username and password
    354 
    355 
    356 
    357 Installing from source
    358 ----------------------
    359 
    360 The following instructions will show how to install libgnunetutil and
    361 the GNU Taler exchange from source.
    362 
    363 The package sources can be find in our
    364 `download directory <http://ftpmirror.gnu.org/taler/>`__.
    365 
    366 .. include:: frags/semver.rst
    367 
    368 First, the following packages need to be installed before we can compile the
    369 backend:
    370 
    371 .. include:: frags/list-of-dependencies.rst
    372 
    373 .. include:: frags/installing-gnunet.rst
    374 
    375 .. include:: frags/install-before-check.rst
    376 
    377 There is no need to actually run a GNUnet peer to use the Taler merchant
    378 backend -- all the merchant needs from GNUnet is a number of headers and
    379 libraries!
    380 
    381 .. include:: frags/installing-taler-exchange.rst
    382 
    383 .. include:: frags/install-before-check.rst
    384 
    385 
    386 
    387 Installing the GNU Taler binary packages on Debian
    388 --------------------------------------------------
    389 
    390 .. include:: frags/installing-debian.rst
    391 
    392 To install the Taler exchange, you can now simply run:
    393 
    394 .. code-block:: shell-session
    395 
    396    [root@exchange-online]# apt install taler-exchange
    397 
    398 Note that the package does not perform any configuration work except for
    399 setting up the various users and the systemd service scripts. You still must
    400 configure at least the database, HTTP reverse proxy (typically with TLS
    401 certificates), denomination and fee structure, bank account, auditor(s),
    402 offline signing and the terms of service.
    403 
    404 On the offline system, you should run at least:
    405 
    406 .. code-block:: shell-session
    407 
    408    [root@exchange-offline]# apt install taler-exchange-offline
    409 
    410 
    411 Installing the GNU Taler binary packages on Ubuntu
    412 --------------------------------------------------
    413 
    414 .. include:: frags/installing-ubuntu.rst
    415 
    416 To install the Taler exchange, you can now simply run:
    417 
    418 .. code-block:: shell-session
    419 
    420    [root@exchange-online]# apt install taler-exchange
    421 
    422 Note that the package does not perform any configuration work except for
    423 setting up the various users and the systemd service scripts. You still must
    424 configure at least the database, HTTP reverse proxy (typically with TLS
    425 certificates), denomination and fee structure, bank account, auditor(s),
    426 offline signing and the terms of service.
    427 
    428 On the offline system, you should run at least:
    429 
    430 .. code-block:: shell-session
    431 
    432    [root@exchange-offline]# apt install taler-exchange-offline
    433 
    434 
    435 Services, users, groups and file system hierarchy
    436 -------------------------------------------------
    437 
    438 The *taler-exchange* package will create several system users
    439 to compartmentalize different parts of the system:
    440 
    441 * ``taler-exchange-httpd``: runs the HTTP daemon with the core business logic.
    442 * ``taler-exchange-secmod-rsa``: manages the RSA private online signing keys.
    443 * ``taler-exchange-secmod-cs``: manages the CS private online signing keys.
    444 * ``taler-exchange-secmod-eddsa``: manages the EdDSA private online signing keys.
    445 * ``taler-exchange-closer``: closes idle reserves by triggering wire transfers that refund the originator.
    446 * ``taler-exchange-aggregator``: aggregates deposits into larger wire transfer requests.
    447 * ``taler-exchange-transfer``: performs wire transfers with the bank (via LibEuFin/Nexus).
    448 * ``taler-exchange-wirewatch``: checks for incoming wire transfers with the bank (via LibEuFin/Nexus).
    449 * ``postgres``: runs the PostgreSQL database (from *postgresql* package).
    450 * ``www-data``: runs the frontend HTTPS service with the TLS keys (from *nginx* package).
    451 
    452 .. note::
    453 
    454    The *taler-merchant* package additionally creates a ``taler-merchant-httpd`` user
    455    to run the HTTP daemon with the merchant business logic.
    456 
    457 
    458 The exchange setup uses the following system groups:
    459 
    460 * ``taler-exchange-db``: group for all Taler users with direct database access, specifically taler-exchange-httpd, taler-exchange-wirewatch, taler-exchange-closer and taler-exchange-aggregator.
    461 * ``taler-exchange-secmod``: group for processes with access to online signing keys; this group must have four users: taler-exchange-secmod-rsa, taler-exchange-secmod-cs, taler-exchange-secmod-eddsa and taler-exchange-httpd.
    462 * ``taler-exchange-offline``: group for the access to the offline private key (only used on the offline host and not used on the online system).
    463 
    464 
    465 The package will deploy systemd service files in
    466 ``/usr/lib/systemd/system/`` for the various components:
    467 
    468 * ``taler-exchange-aggregator.service``: service that schedules wire transfers
    469   which combine multiple deposits to the same merchant.
    470 * ``taler-exchange-closer.service``: service that watches for reserves that have been abandoned and schedules wire transfers to send the money back to the originator.
    471 * ``taler-exchange-httpd.service``: main Taler exchange logic with the public REST API.
    472 * ``taler-exchange-httpd.socket``: systemd socket activation for the Taler exchange HTTP daemon.
    473 * ``taler-exchange-secmod-eddsa.service``: software security module for making EdDSA signatures.
    474 * ``taler-exchange-secmod-rsa.service``: software security module for making RSA signatures.
    475 * ``taler-exchange-secmod-cs.service``: software security module for making CS signatures.
    476 * ``taler-exchange-transfer.service``: service that triggers outgoing wire transfers (pays merchants).
    477 * ``taler-exchange-wirewatch.service``: service that watches for incoming wire transfers (first step of withdraw).
    478 * ``taler-exchange.target``: Main target for the Taler exchange to be operational.
    479 
    480 
    481 The deployment creates the following key locations in the system:
    482 
    483 * ``/etc/taler-exchange/``: configuration files.
    484 * ``/run/taler-exchange/``: contains the UNIX domain sockets for inter-process communication (IPC).
    485 * ``/var/lib/taler-exchange/``: serves as the $HOME for all Taler exchange users and contains sub-directories
    486   with the private keys; which keys are stored here depends on the host:
    487 
    488   * online system: exchange-secmod-eddsa, exchange-secmod-cs and exchange-secmod-rsa keys.
    489   * offline system: exchange-offline keys.
    490 
    491 
    492 Configuration Fundamentals
    493 ==========================
    494 
    495 This chapter provides fundamental details about the exchange configuration.
    496 
    497 The configuration for all Taler components uses a single configuration file
    498 as entry point: ``/etc/taler-exchange/taler-exchange.conf``.
    499 
    500 System defaults are automatically loaded from files in
    501 ``/usr/share/taler-exchange/config.d``.
    502 These default files should never be modified.
    503 
    504 The default configuration ``taler-exchange.conf`` configuration file
    505 also includes all configuration files in ``/etc/taler-exchange/conf.d``.
    506 The settings from files in
    507 ``conf.d`` are only relevant to particular components of an exchange, while
    508 ``taler-exchange.conf`` contains settings that affect all exchange components.
    509 
    510 
    511 The directory ``/etc/taler-exchange/secrets`` contains configuration file snippets with
    512 values that should only be readable to certain users.  They are included with the ``@inline-secret@``
    513 directive and should end with ``.secret.conf``.
    514 
    515 To view the entire configuration annotated with the source of each configuration option, you
    516 can use the ``taler-exchange-config`` helper:
    517 
    518 
    519 .. code-block:: shell-session
    520 
    521   [root@exchange-online]# taler-exchange-config --diagnostics
    522   < ... annotated, full configuration ... >
    523 
    524 .. warning::
    525 
    526   While ``taler-exchange-config`` also supports rewriting configuration files, we strongly
    527   recommend to edit configuration files manually, as ``taler-exchange-config`` does not
    528   preserve comments and, by default, rewrites ``/etc/taler-exchange/taler-exchange.conf``.
    529 
    530 
    531 .. include:: frags/configuration-format.rst
    532 
    533 
    534 Exchange Database Setup
    535 =======================
    536 
    537 The access credentials for the exchange's database are configured in
    538 ``/etc/taler-exchange/secrets/exchange-db.secret.conf``.
    539 Currently, only PostgreSQL is supported as a database backend.
    540 
    541 The following users must have access to the exchange database:
    542 
    543 * taler-exchange-httpd
    544 * taler-exchange-wire
    545 * taler-exchange-aggregator
    546 * taler-exchange-closer
    547 
    548 These users are all in the taler-exchange-db group, and the
    549 ``exchange-db.secret.conf`` should be only readable by users in
    550 this group.
    551 
    552 .. note::
    553 
    554    The **taler-exchange-dbconfig** tool can be used to automate the database
    555    setup. When using the Debian/Ubuntu packages, the users should already have
    556    been created, so you can just run the tool without any arguments and should
    557    have a working database configuration. The rest of this section only
    558    explains what the **taler-exchange-dbconfig** shell script fully automates.
    559 
    560 To create a database for the Taler exchange on the local system, run:
    561 
    562 .. code-block:: shell-session
    563 
    564   [root@exchange-online]# su - postgres
    565   [postgres@exchange-online]# createuser taler-exchange-httpd
    566   [postgres@exchange-online]# createuser taler-exchange-wire
    567   [postgres@exchange-online]# createuser taler-exchange-aggregator
    568   [postgres@exchange-online]# createuser taler-exchange-closer
    569   [postgres@exchange-online]# createdb -O taler-exchange-httpd taler-exchange
    570   [postgres@exchange-online]# exit
    571 
    572 This will create a ``taler-exchange`` database owned by the
    573 ``taler-exchange-httpd`` user.  We will use that user later to perform
    574 database maintenance operations.
    575 
    576 
    577 Assuming the above database setup, the database credentials to configure
    578 in the configuration file would simply be:
    579 
    580 .. code-block:: ini
    581   :caption: /etc/taler-exchange/secrets/exchange-db.secret.conf
    582 
    583   [exchange]
    584   DB = postgres
    585 
    586   [exchangedb-postgres]
    587   CONFIG=postgres:///taler-exchange
    588 
    589 
    590 If the database is run on a different host, please follow the instructions
    591 from the PostgreSQL manual for configuring remote access.
    592 
    593 After configuring the database credentials, the exchange database needs
    594 to be initialized with the following command:
    595 
    596 .. code-block:: shell-session
    597 
    598   [root@exchange-online]# sudo -u taler-exchange-httpd taler-exchange-dbinit
    599 
    600   ..note::
    601 
    602     To run this command, the user must have ``CREATE TABLE``, ``CREATE
    603     INDEX``, ``ALTER TABLE`` and (in the future possibly even) ``DROP TABLE``
    604     permissions.  Those permissions are only required for this step (which may
    605     have to be repeated when upgrading a deployment).  Afterwards, during
    606     normal operation, permissions to ``CREATE`` or ``ALTER`` tables are not
    607     required by any of the Taler exchange processes and thus should not be
    608     granted.  For more information, see
    609     :doc:`manpages/taler-exchange-dbinit.1`.
    610 
    611 Finally we need to grant the other accounts limited access:
    612 
    613 .. code-block:: shell-session
    614 
    615   [root@exchange-online]# sudo -u taler-exchange-httpd bash
    616   [taler-exchange-httpd@exchange-online]# echo 'GRANT SELECT,INSERT,UPDATE ON ALL TABLES IN SCHEMA exchange TO "taler-exchange-aggregator";' \
    617     | psql taler-exchange
    618   [taler-exchange-httpd@exchange-online]# echo 'GRANT SELECT,INSERT,UPDATE ON ALL TABLES IN SCHEMA exchange TO "taler-exchange-closer";' \
    619     | psql taler-exchange
    620   [taler-exchange-httpd@exchange-online]# echo 'GRANT SELECT,INSERT,UPDATE ON ALL TABLES IN SCHEMA exchange TO "taler-exchange-wire";' \
    621     | psql taler-exchange
    622   [taler-exchange-httpd@exchange-online]# echo 'GRANT USAGE ON ALL SEQUENCES IN SCHEMA exchange TO "taler-exchange-aggregator";' \
    623     | psql taler-exchange
    624   [taler-exchange-httpd@exchange-online]# echo 'GRANT USAGE ON ALL SEQUENCES IN SCHEMA exchange TO "taler-exchange-closer";' \
    625     | psql taler-exchange
    626   [taler-exchange-httpd@exchange-online]# echo 'GRANT USAGE ON ALL SEQUENCES IN SCHEMA exchange TO "taler-exchange-wire";' \
    627     | psql taler-exchange
    628   [taler-exchange-httpd@exchange-online]# exit
    629 
    630 .. note::
    631 
    632    The above instructions for changing database permissions only work *after*
    633    having initialized the database with ``taler-exchange-dbinit``, as
    634    the tables need to exist before permissions can be granted on them. The
    635    ``taler-exchange-dbinit`` tool cannot setup these permissions, as it
    636    does not know which users will be used for which processes.
    637 
    638 .. _Dataprotection:
    639 
    640 Data protection concept
    641 -----------------------
    642 
    643 The ``kyc-attributes`` table contains the most sensitive
    644 data, namely the KYC records of the recipients of payments.
    645 The data could include passports, business documentation
    646 and other sensitive information. At a high-level, it is
    647 stored in JSON format (key-value), compressed and then
    648 additionally encrypted using a secret key from the
    649 exchange configuration (the ``ATTRIBUTE_ENCRYPTION_KEY``).
    650 Thus, this data is protected even if the full database
    651 is leaked.
    652 
    653 The ``aml-history`` table stores the main information
    654 provided by AML officers. This may contain sensitive
    655 data about risk assessments on customers, exposed or
    656 secret limits imposed on individual accounts, and
    657 in general forms supplied by bank staff. AML decisions
    658 are also tracked in the ``legitimization-*`` tables,
    659 including the latest rules that apply to an account.
    660 
    661 The second most sensitive table is
    662 ``wire-targets``, as it contains the IBANs (and possibly
    663 other visible information from RFC 8905) of the bank
    664 accounts of the customers. Many other tables contain
    665 transaction data (incoming, outgoing, p2p transfers,
    666 etc) which are somewhat less sensitive. It should be
    667 noted that the actual contracts between customers and
    668 merchants are not available to the exchange operator;
    669 the ``contracts`` table only stores contracts for p2p
    670 transfers in an end-to-end encrypted format that the
    671 exchange itself can never decrypt.
    672 
    673 The database is periodically cleaned up via the
    674 ``taler-exchange-dbinit --gc`` command. It is
    675 currently hard-coded (!) to delete KYC/AML data
    676 of accounts that have been inactive for 10 years.
    677 
    678 Data on incoming wire transfers (reserves) is
    679 deleted after the ``LEGAL_RESERVE_EXPIRATION_TIME``
    680 is reached, as configured in the ``[exchangedb]``
    681 section. The default is set to 7 years.
    682 
    683 Payment data is deleted whenever the legal expiration date for the
    684 ``DURATION_LEGAL`` configured in the respective section ``coin`` is reached
    685 (typically also after 10 years).
    686 
    687 
    688 Basic Setup: Currency, Denominations and Keys
    689 =============================================
    690 
    691 A Taler exchange only supports a single currency.  The currency
    692 and the smallest currency unit supported by the bank system
    693 must be specified in ``/etc/taler-exchange/taler-exchange.conf``.
    694 
    695 .. code-block:: ini
    696   :caption: /etc/taler-exchange/taler-exchange.conf
    697 
    698    [exchange]
    699    CURRENCY = EUR
    700    CURRENCY_ROUND_UNIT = EUR:0.01
    701 
    702    # ... rest of file ...
    703 
    704 .. warning::
    705 
    706    When editing ``/etc/taler-exchange/taler-exchange.conf``, take care to not accidentally remove
    707    the ``@inline-matching@`` directive to include the configuration files in ``conf.d``.
    708 
    709  .. _Coins-denomination-keys:
    710 
    711 Coins (denomination keys)
    712 -------------------------
    713 
    714 Next, the electronic cash denominations that the exchange offers must be
    715 specified.
    716 
    717 Sections specifying denomination (coin) information start with ``coin_``.  By
    718 convention, the name continues with ``$CURRENCY_[$SUBUNIT]_$VALUE_$REVISION``,
    719 i.e. ``[coin_eur_ct_10_0]`` for a 10 cent piece. However, only the ``coin_``
    720 prefix is mandatory.  Once configured, these configuration values must not
    721 change.  The ``$REVISION`` part of the section name should be incremented if
    722 any of the coin attributes in the section changes.  Each ``coin_``-section
    723 must then have the following options:
    724 
    725 -  ``VALUE``: How much is the coin worth, the format is
    726    CURRENCY:VALUE.FRACTION. For example, a 10 cent piece is "EUR:0.10".
    727 
    728 -  ``DURATION_WITHDRAW``: How long can a coin of this type be withdrawn?
    729    This limits the losses incurred by the exchange when a denomination
    730    key is compromised.
    731 
    732 -  ``DURATION_SPEND``: How long is a coin of the given type valid? Smaller
    733    values result in lower storage costs for the exchange.
    734 
    735 -  ``DURATION_LEGAL``: How long is the coin of the given type legal?
    736 
    737 -  ``FEE_WITHDRAW``: What does it cost to withdraw this coin? Specified
    738    using the same format as value.
    739 
    740 -  ``FEE_DEPOSIT``: What does it cost to deposit this coin? Specified using
    741    the same format as value.
    742 
    743 -  ``FEE_REFRESH``: What does it cost to refresh this coin? Specified using
    744    the same format as value.
    745 
    746 -  ``FEE_REFUND``: What does it cost to refund this coin?
    747    Specified using the same format as value.
    748 
    749 -  ``CIPHER``: Which cipher to use for this coin? Must be either ``RSA`` or
    750    ``CS``.
    751 
    752 -  ``RSA_KEYSIZE``: How many bits should the RSA modulus (product of the two
    753    primes) have for this type of coin.
    754 
    755 - ``AGE_RESTRICTED``: Set to ``YES`` to make this a denomination with support
    756    for age restrictions. See age restriction extension below for details.
    757    This option is optional and defaults to ``NO``.
    758 
    759 See :doc:`manpages/taler-exchange.conf.5` for information on *duration* values
    760 (i.e. ``DURATION_WITHDRAW`` and ``DURATION_SPEND`` above,
    761 and ``OVERLAP_DURATION`` and ``DURATION`` below).
    762 Additionally, there are two global configuration options of note:
    763 
    764 -  ``[taler-exchange-secmod-rsa/OVERLAP_DURATION]``: What is the overlap of the
    765    withdrawal timespan for denomination keys?  The value given here must
    766    be smaller than any of the ``DURATION_WITHDRAW`` values for any of the coins.
    767 
    768 -  ``[taler-exchange-secmod-rsa/LOOKAHEAD_SIGN]``: For how far into the future
    769    should denomination keys be pre-generated?  This allows the exchange and
    770    auditor operators to download, offline-sign, and upload denomination key
    771    signatures for denomination keys that will be used in the future by the
    772    exchange.
    773 
    774 .. index:: maintenance
    775 .. note::
    776    We recommend setting the ``LOOKAHEAD_SIGN`` value to at least one year and
    777    then to perform the offline-signing procedure at least once every 6 months
    778    to ensure that there is sufficient time for wallets to learn the new keys
    779    and to avoid unavailability in case this critical maintenance procedure is
    780    delayed.
    781 
    782 .. note::
    783    It is crucial that the configuration provided in these sections is identical (!)
    784    for the exchange and the crypto helpers.  We recommend pointing both users
    785    to the same configuration file!
    786 
    787 The ``taler-harness`` has a helper command that generates a
    788 reasonable denomination structure.
    789 
    790 .. code-block:: shell-session
    791 
    792   [root@exchange-online]# taler-harness deployment gen-coin-config \
    793                             --min-amount EUR:0.01 \
    794                             --max-amount EUR:100 \
    795                             > /etc/taler-exchange/conf.d/exchange-coins.conf
    796 
    797 You can manually review and edit the generated configuration file. The main
    798 change that is possibly required is updating the various fees.  Note that you
    799 MUST NOT edit a coin configuration section after the initial setup. If you
    800 must ``change`` the values, you must instead create a new section with a
    801 different unique name (still with the ``coin_`` prefix) and comment out or
    802 remove the existing section.  Do take care to not introduce the name of the
    803 disabled section again in the future.
    804 
    805 
    806 .. _Sign-keys:
    807 
    808 Sign keys
    809 ---------
    810 
    811 There are three global configuration options of note for sign keys:
    812 
    813 -  ``[taler-exchange-secmod-eddsa/DURATION]``: How long are sign keys
    814    used to sign messages? After this time interval expires, a fresh
    815    sign key will be used (key rotation).  We recommend using
    816    a ``DURATION`` of a few weeks to a few months for sign keys.
    817 
    818 -  ``[taler-exchange-secmod-eddsa/OVERLAP_DURATION]``: What is the overlap of the
    819    timespan for sign keys?  We recommend a few minutes or hours.  Must
    820    be smaller than ``DURATION``.
    821 
    822 -  ``[taler-exchange-secmod-eddsa/LOOKAHEAD_SIGN]``: For how far into the future
    823    should sign keys be pre-generated?  This allows the exchange and
    824    auditor operators to download, offline-sign, and upload sign key
    825    signatures for sign keys that will be used in the future by the exchange.
    826 
    827 .. note::
    828    We recommend setting the ``LOOKAHEAD_SIGN`` value to at least one year and
    829    then to perform the offline-signing procedure at least once every 6 months
    830    to ensure that there is sufficient time for wallets to learn the new keys
    831    and to avoid unavailability in case this critical maintenance procedure is
    832    delayed.
    833 
    834 
    835 .. _OfflineConfiguration:
    836 
    837 Setting up the offline signing key
    838 ----------------------------------
    839 
    840 Before launching an exchange, the offline signing (master) key must be
    841 generated and set in the configuration.  The offline signing keys of the
    842 exchange should be stored on a different machine.  The responsibilities of
    843 this offline signing machine are:
    844 
    845 * Generation of the exchange's offline master signing key.
    846 * Secure storage of the exchange's offline master signing key.
    847 * Generation of certificates (signed with the offline master signing key) that will be imported by the exchange.
    848 * Revocation of keys when the online system was compromised or is being terminated
    849 
    850 
    851 Configuration file options related to the master key are:
    852 
    853 - ``[exchange-offline/MASTER_PRIV_FILE]``: Path to the exchange’s master
    854    private file.  Only needs to be provided on the offline system where the
    855    ``taler-exchange-offline`` command is used.  The default value is usually
    856    fine and does not require adjustment.
    857 
    858 - ``[exchange/MASTER_PUBLIC_KEY]``: Must specify the exchange’s master public
    859    key.  Needed for the exchange to verify information signed by the offline
    860    system.  This value must almost always be set explicitly by hand.
    861 
    862 
    863 
    864 .. code-block:: shell-session
    865 
    866   [root@exchange-offline]# taler-exchange-offline setup
    867   < ... prints the exchange master public key >
    868 
    869 The public key printed as the output of this command must be put into the
    870 configuration of the online machine:
    871 
    872 .. code-block:: ini
    873   :caption: /etc/taler-exchange/conf.d/exchange-business.conf
    874 
    875    [exchange]
    876    MASTER_PUBLIC_KEY = YE6Q6TR1ED...
    877 
    878    # ... rest of file ...
    879 
    880 
    881 Wire Gateway Setup
    882 ==================
    883 
    884 The :ref:`Taler Wire Gateway <taler-wire-gateway-http-api>` is an API that
    885 connects the Taler exchange to the underlying core banking system.  There are
    886 several implementations of wire gateways:
    887 
    888   * `Project deploymerization <https://git.taler.net/taler/depolymerization/files.html>`_ implements a wire gateway on top of Bitcoin or Ethereum
    889   * The :ref:`libeufin-bank <libeufin-bank>` provides a wire gateway interface on top of a regional currency bank
    890   * The **taler-fakebank-run** command is an in-memory bank simulator with a wire gateway interface for testing
    891 
    892 .. FIXME :ref:`libeufin-nexus <libeufin-nexus>` is an implementation of the Wire Gateway API for the EBICS protocol. Add to list above once nexus implements the TWG directly!
    893 
    894 Before continuing, you need to decide which wire gateway you want to use,
    895 and install and configure it on your system.  Afterwards, you need to
    896 have two key pieces of information from that setup:
    897 
    898   * The username and password to access the exchange's account in the system.
    899   * The ``payto://`` URI of that account (see `RFC 8905 <https://www.rfc-editor.org/rfc/rfc8905>`_).
    900 
    901 If you use the libeufin-bank, you need to set a special configuration option
    902 because the taler-exchange-wire-gateway-client does not yet support token
    903 authentication:
    904 
    905 .. code-block:: ini
    906   :caption: /etc/libeufin/libeufin-bank.conf
    907 
    908    [libeufin-bank]
    909    PWD_AUTH_COMPAT = YES
    910 
    911 .. FIXME: Remove the text above once #9703 is fixed.
    912 
    913 .. _exchange-bank-account-configuration:
    914 
    915 Exchange Bank Account Configuration
    916 -----------------------------------
    917 
    918 An exchange must be configured with the right settings to access its bank
    919 account via a :ref:`Taler wire gateway <taler-wire-gateway-http-api>`.  An
    920 exchange can be configured to use multiple bank accounts by using multiple
    921 wire gateways.  Typically only one wire gateway is used.
    922 
    923 To configure a bank account in Taler, we need to furnish two pieces of
    924 information:
    925 
    926 -  The ``payto://`` URI of the bank account, which uniquely identifies the
    927    account. Examples for such URIs include
    928    ``payto://iban/CH9300762011623852957`` for a bank account with
    929    an IBAN or
    930    ``payto://x-taler-bank/localhost:8080/2`` for the 2nd bank account at
    931    the Taler bank demonstrator running at ``localhost`` on port 8080.
    932    The first part of the URI following ``payto://`` (``iban`` or
    933    ``x-taler-bank``) is called the wire method.
    934 
    935 -  The ``taler-exchange-wirewatch`` and ``taler-exchange-transfer``
    936    tools needs to be provided resources for authentication
    937    to the respective banking service. The format in which the
    938    authentication information is currently a username and password
    939    for HTTP basic authentication.
    940 
    941 
    942 Each Taler wire gateway is configured in a configuration section that follows
    943 the pattern ``exchange-account-$id``, where ``$id`` is an internal identifier
    944 for the bank account accessed by the exchange.  The basic information for an
    945 account should be put in ``/etc/taler-exchange/conf.d/exchange-business.conf``.  The
    946 secret credentials to access the Taler Wire Gateway API should be put into a
    947 corresponding ``exchange-accountcredentials-$id`` section in
    948 ``/etc/taler-exchange/secrets/exchange-accountcredentials.conf``.  The latter file
    949 should be only readable for the ``taler-exchange-wire`` user.  Only the
    950 ``taler-exchange-wirewatch`` and ``taler-exchange-transfer`` services should
    951 run as the ``taler-exchange-wire`` user.  Other exchange processes do not need
    952 to have access to the account credentials.
    953 
    954 You can configure multiple accounts for an exchange by creating sections
    955 starting with ``exchange-account-`` for the section name. You must specify
    956 ``ENABLE_``-settings for each account whether it should be used, and for what
    957 (incoming or outgoing wire transfers):
    958 
    959 .. code-block:: ini
    960   :caption: /etc/taler-exchange/conf.d/exchange-business.conf
    961 
    962   [exchange-account-1]
    963   # Account identifier in the form of an RFC-8905 payto:// URI.
    964   # For SEPA, looks like payto://iban/$IBAN?receiver-name=$NAME
    965   # Make sure to URL-encode spaces in $NAME!
    966   #
    967   # With x-taler-bank (for Fakebank)
    968   # PAYTO_URI = "payto://x-taler-bank/bank.demo.taler.net/Exchange?receiver-name=exop"
    969   #
    970   # Example using IBAN (for use with LibEuFin)
    971   PAYTO_URI = "payto://iban/CH9300762011623852957?receiver=name=exop"
    972 
    973   # Use for exchange-aggregator (outgoing transfers)
    974   ENABLE_DEBIT = YES
    975   # Use for exchange-wirewatch (and listed in /wire)
    976   ENABLE_CREDIT = YES
    977 
    978   @inline-secret@ exchange-accountcredentials-1 ../secrets/exchange-accountcredentials.secret.conf
    979 
    980 
    981 .. code-block:: ini
    982   :caption: /etc/taler-exchange/secrets/exchange-accountcredentials.secret.conf
    983 
    984   [exchange-accountcredentials-1]
    985 
    986   # LibEuFin expects basic auth.
    987   WIRE_GATEWAY_AUTH_METHOD = basic
    988 
    989   # Username and password to access the Taler wire gateway.
    990   USERNAME = ...
    991   PASSWORD = ...
    992 
    993   # URL for talking to the bank wire the wire API.
    994   WIRE_GATEWAY_URL = https://bank.demo.taler.net/accounts/exchange/taler-wire-gateway/
    995 
    996 
    997 Such a wire gateway configuration can be tested with the following commands:
    998 
    999 .. code-block:: shell-session
   1000 
   1001    [root@exchange-online]# taler-exchange-wire-gateway-client \
   1002      --section exchange-accountcredentials-1 --debit-history
   1003    [root@exchange-online]# taler-exchange-wire-gateway-client \
   1004      --section exchange-accountcredentials-1 --credit-history
   1005 
   1006 On success, you will see some of your account's transaction history (or an
   1007 empty history), while on failure you should see an error message.
   1008 
   1009 
   1010 .. _Deployment:
   1011 
   1012 Deployment
   1013 ==========
   1014 
   1015 This chapter describes how to deploy the exchange once the basic installation
   1016 and configuration are completed.
   1017 
   1018 .. _Serving:
   1019 
   1020 Serving
   1021 -------
   1022 
   1023 The exchange can serve HTTP over both TCP and UNIX domain socket.
   1024 
   1025 The following options are to be configured in the section ``[exchange]``:
   1026 
   1027 -  ``SERVE``: Must be set to ``tcp`` to serve HTTP over TCP, or ``unix`` to serve
   1028    HTTP over a UNIX domain socket.
   1029 
   1030 -  ``PORT``: Set to the TCP port to listen on if ``SERVE`` is ``tcp``.
   1031 
   1032 -  ``UNIXPATH``: Set to the UNIX domain socket path to listen on if ``SERVE`` is
   1033    ``unix``.
   1034 
   1035 - ``UNIXPATH_MODE``: Number giving the mode with the access permission mask
   1036    for the ``UNIXPATH`` (i.e. 660 = ``rw-rw---``). Make sure to set it in such
   1037    a way that your reverse proxy has permissions to access the UNIX domain
   1038    socket.  The default (660) assumes that the reverse proxy is a member of
   1039    the group under which the exchange HTTP server is running.
   1040 
   1041 .. _ReverseProxy:
   1042 
   1043 Reverse Proxy Setup
   1044 -------------------
   1045 
   1046 By default, the ``taler-exchange-httpd`` service listens for HTTP connections
   1047 on a UNIX domain socket.  To make the service publicly available, a reverse
   1048 proxy such as nginx should be used.  We strongly recommend to configure nginx
   1049 to use TLS.
   1050 
   1051 The public URL that the exchange will be served under should
   1052 be put in ``/etc/taler-exchange/conf.d/exchange-business.conf`` configuration file.
   1053 
   1054 .. code-block:: ini
   1055   :caption: /etc/taler-exchange/conf.d/exchange-business.conf
   1056 
   1057    [exchange]
   1058    BASE_URL = https://example.com/
   1059 
   1060    # ... rest of file ...
   1061 
   1062 The ``taler-exchange`` package ships with a sample configuration that can be
   1063 enabled in nginx:
   1064 
   1065 .. code-block:: shell-session
   1066 
   1067   [root@exchange-online]# vim /etc/nginx/sites-available/taler-exchange
   1068   < ... customize configuration ... >
   1069   [root@exchange-online]# ln -s /etc/nginx/sites-available/taler-exchange \
   1070                                 /etc/nginx/sites-enabled/taler-exchange
   1071   [root@exchange-online]# systemctl reload nginx
   1072 
   1073 Note that the reverse proxy must set a HTTP ``X-Forwarded-Host`` header to
   1074 refer to the hostname used by nginx and a HTTP ``X-Forwarded-Proto`` header to
   1075 inform the exchange whether the external protocol was ``http`` or ``https``.
   1076 Thus, depending on your setup, you will likely have to edit those parts of the
   1077 provided ``taler-exchange`` configuration file.
   1078 
   1079 With this last step, we are finally ready to launch the
   1080 main exchange process.
   1081 
   1082 .. _Launch:
   1083 
   1084 Launching an exchange
   1085 ---------------------
   1086 
   1087 A running exchange requires starting the following processes:
   1088 
   1089 -   ``taler-exchange-secmod-rsa`` (as special user, sharing group with the HTTPD)
   1090 -   ``taler-exchange-secmod-cs`` (as special user, sharing group with the HTTPD)
   1091 -   ``taler-exchange-secmod-eddsa`` (as special user, sharing group with the HTTPD)
   1092 -   ``taler-exchange-httpd`` (needs database access)
   1093 -   ``taler-exchange-aggregator`` (only needs database access)
   1094 -   ``taler-exchange-closer`` (only needs database access)
   1095 -   ``taler-exchange-wirewatch`` (needs bank account read credentials and database access)
   1096 -   ``taler-exchange-transfer`` (needs credentials to initiate outgoing wire transfers and database access)
   1097 
   1098 The crypto helpers (``secmod``) must be started before the ``taler-exchange-httpd`` and
   1099 they should use the same configuration file.
   1100 
   1101 For the most secure deployment, we recommend using separate users for each of
   1102 these processes to minimize information disclosures should any of them be
   1103 compromised.  The helpers do not need access to the PostgreSQL database (and
   1104 thus also should not have it).
   1105 
   1106 The processes that require access to the bank account need to have a
   1107 configuration file with the respective credentials in it. We recommend using a
   1108 separate configuration at least for ``taler-exchange-transfer`` which is the
   1109 *only* process that needs to know the credentials to execute outgoing wire
   1110 transfers.
   1111 
   1112 All of these processes should also be started via a hypervisor like
   1113 ``systemd`` or ``gnunet-arm`` that automatically re-starts them should they
   1114 have terminated unexpectedly.  If the bank is down (say for maintenance), it is
   1115 *possible* to halt the ``taler-exchange-wirewatch`` and/or
   1116 ``taler-exchange-transfer`` processes (to avoid them making requests to the
   1117 bank API that can only fail) without impacting other operations of the
   1118 exchange. Naturally, incoming wire transfers will only be observed once
   1119 ``taler-exchange-wirewatch`` is resumed, and merchants may complain if the
   1120 disabled ``taler-exchange-transfer`` process causes payment deadlines to be
   1121 missed.
   1122 
   1123 .. note::
   1124    The ``taler-exchange-httpd`` does not ship with HTTPS enabled by default.
   1125    In production, it should be run behind an HTTPS reverse proxy that performs
   1126    TLS termination on the same system.  Thus, it would typically be configured
   1127    to listen on a UNIX domain socket.  The ``/management`` and ``/auditors``
   1128    APIs do technically not have to be exposed on the Internet (only to the
   1129    administrators running ``taler-exchange-offline``) and should be blocked
   1130    by the reverse proxy for requests originating from outside of the bank.
   1131    (However, this is not a strong security assumption: in principle having
   1132    these endpoints available should do no harm. However, it increases the
   1133    attack surface.)
   1134 
   1135 
   1136 Given proper packaging, all of the above are realized via a simple systemd
   1137 target. This enables the various processes of an exchange service to be
   1138 started using a simple command:
   1139 
   1140 .. code-block:: shell-session
   1141 
   1142   [root@exchange-online]# systemctl start taler-exchange.target
   1143 
   1144 .. note::
   1145 
   1146    At this point, the exchange service is not yet fully operational.
   1147 
   1148 
   1149 To check whether the exchange is running correctly under the advertised
   1150 base URL, run:
   1151 
   1152 .. code-block:: shell-session
   1153 
   1154   [root@exchange-online]# export BASE_URL=$(taler-exchange-config -s exchange -o base_url)
   1155   [root@exchange-online]# wget ${BASE_URL}management/keys
   1156 
   1157 The request might take some time to complete on slow machines, because
   1158 a lot of key material will be generated.
   1159 
   1160 
   1161 Offline Signing Setup, Key Maintenance and Tear-Down
   1162 ====================================================
   1163 
   1164 The exchange HTTP service must be running before you can complete the
   1165 following offline signing procedure. Note that when an exchange is running
   1166 without offline keys its not fully operational.  To make the exchange HTTP
   1167 service fully operational, the following steps involving the offline signing
   1168 machine must be completed:
   1169 
   1170   1. The public keys of various online keys used by the exchange service are exported
   1171      via a management HTTP API.
   1172   2. The offline signing system validates this request and signs it.
   1173      Additionally, the offline signing system signs policy messages
   1174      to configure the exchange's bank accounts and associated fees.
   1175   3. The messages generated by the offline signing system are uploaded
   1176      via the management API of the exchange HTTP service.
   1177 
   1178 A typical minimal setup would look something like this:
   1179 
   1180 .. code-block:: shell-session
   1181 
   1182   [anybody@exchange-online]# taler-exchange-offline \
   1183     download > sig-request.json
   1184 
   1185   [root@exchange-offline]# taler-exchange-offline \
   1186     sign < sig-request.json > sig-response.json
   1187   [root@exchange-offline]# taler-exchange-offline \
   1188     enable-account payto://iban/$IBAN?receiver-name=$NAME > acct-response.json
   1189   [root@exchange-offline]# taler-exchange-offline \
   1190     wire-fee now iban EUR:0 EUR:0 > fee-response.json
   1191   [root@exchange-offline]# taler-exchange-offline \
   1192     global-fee now EUR:0 EUR:0 EUR:0 4weeks 6a 4 > global-response.json
   1193 
   1194   [anybody@exchange-online]# taler-exchange-offline upload < sig-response.json
   1195   [anybody@exchange-online]# taler-exchange-offline upload < acct-response.json
   1196   [anybody@exchange-online]# taler-exchange-offline upload < fee-response.json
   1197   [anybody@exchange-online]# taler-exchange-offline upload < global-response.json
   1198 
   1199 The following sections will discuss these steps in more depth.
   1200 
   1201 .. _Keys-generation:
   1202 
   1203 Signing the online signing keys
   1204 -------------------------------
   1205 
   1206 To sign the online signing keys, first the *future* key material should be downloaded using:
   1207 
   1208 .. code-block:: console
   1209 
   1210    $ taler-exchange-offline download > future-keys.json
   1211 
   1212 Afterwards, *future-keys.json* contains data about denomination and
   1213 online signing keys that the exchange operator needs to sign with
   1214 the offline tool.  The file should be copied to the offline system.
   1215 There, the operator should run:
   1216 
   1217 .. code-block:: console
   1218 
   1219    $ taler-exchange-offline show < future-keys.json
   1220 
   1221 and verify that the output contains the fee structure and key lifetimes
   1222 they expect to see. They should also note the public keys being shown
   1223 and communicate those to the *auditors* over a secure channel.  Once
   1224 they are convinced the file is acceptable, they should run:
   1225 
   1226 .. code-block:: console
   1227 
   1228    $ taler-exchange-offline sign < future-keys.json > offline-sigs.json
   1229 
   1230 The *offline-sigs.json* file must then be copied to an online system
   1231 that is able to again communicate with the exchange. On that system, run:
   1232 
   1233 .. code-block:: console
   1234 
   1235    $ taler-exchange-offline upload < offline-sigs.json
   1236 
   1237 to provision the signatures to the exchange.
   1238 
   1239 The ``download sign upload`` sequence in the commands above has to be done
   1240 periodically, as it signs the various online signing keys of the exchange
   1241 which periodically expire.
   1242 
   1243 
   1244 .. _exchange-account-signing:
   1245 
   1246 Account signing
   1247 ---------------
   1248 
   1249 The ``enable-account`` step is important and must be used to sign the
   1250 ``payto://`` URI in a way suitable to convince wallets that this is the
   1251 correct address to wire funds to.  Note that for each bank account, additional
   1252 options **must** be set in the configuration file to tell the exchange how to
   1253 access the bank account. The offline tool *only* configures the externally
   1254 visible portions of the setup.  The chapter on `bank account configuration <_exchange-bank-account-configuration>`_ has further details.
   1255 
   1256 taler-exchange-offline accepts additional options to configure the use of the
   1257 account. For example, additional options can be used to add currency
   1258 conversion or to restrict interactions to bank accounts from certain
   1259 countries:
   1260 
   1261 .. code-block:: console
   1262 
   1263    $ taler-exchange-offline \
   1264        enable-account payto://iban/CH9300762011623852957
   1265          conversion-url https://conversion.example.com/
   1266 
   1267 For details on optional ``enable-account`` arguments,
   1268 see :doc:`manpages/taler-exchange-offline.1`.
   1269 
   1270 .. _Wire-fee-structure:
   1271 
   1272 Wire fee structure
   1273 ------------------
   1274 
   1275 .. index:: wire fee
   1276 .. index:: fee
   1277 
   1278 For each wire method (“iban” or “x-taler-bank”) the
   1279 exchange must know about applicable wire fees. This is also done
   1280 using the ``taler-exchange-offline`` tool:
   1281 
   1282 .. code-block:: console
   1283 
   1284    $ taler-exchange-offline wire-fee 2040 iban EUR:0.05 EUR:0.10
   1285 
   1286 The above sets the wire fees for wire transfers involving ``iban`` accounts
   1287 (in Euros) in the year 2040 to 5 cents (wire fee) and 10 cents (closing fee).
   1288 The tool only supports setting fees that apply for the entire calendar year.
   1289 
   1290 We recommend provisioning an exchange with wire fees at least for the next two
   1291 years.  Note that once the fees have been set for a year, they cannot be
   1292 changed (basically, by signing the fees the exchange makes a legally binding
   1293 offer to the customers).
   1294 
   1295 .. index:: maintenance
   1296 .. note::
   1297    Provisioning future wire fees, like provisioning future denomination
   1298    and signing keys, are key regular maintenance procedures for every
   1299    exchange operator.  We recommend setting automated reminders for
   1300    this maintenance activity!
   1301 
   1302 
   1303 .. _Auditor-configuration:
   1304 
   1305 Auditor configuration
   1306 ---------------------
   1307 
   1308 At this point, the exchange will be able to use those keys, but wallets and
   1309 merchants may not yet trust them!  Thus, the next step is for an auditor to
   1310 affirm that they are auditing this exchange.  Before an auditor can do this,
   1311 the exchange service must be informed about any auditor that is expected to
   1312 provision it with auditor signatures.
   1313 
   1314 This is also done using the ``taler-exchange-offline`` tool on the offline
   1315 system.  First, the auditor must be configured and provide the exchange
   1316 operator with its public key (using ``taler-auditor-offline setup``) and the
   1317 URL of its REST API.  The exchange operator also needs a human-readable name
   1318 that may be shown to users to identify the auditor.  For more information on
   1319 how to setup and operate an auditor, see
   1320 :doc:`manpages/taler-auditor-offline.1` and :doc:`taler-auditor-manual`.
   1321 
   1322 Given this information, the exchange operator can enable the auditor:
   1323 
   1324 .. code-block:: console
   1325 
   1326    $ taler-exchange-offline enable-auditor $PUB_KEY $REST_URL "$AUDITOR_NAME" > auditor.json
   1327 
   1328 As before, the *auditor.json* file must then be copied from the offline system
   1329 to a system connected to the exchange and there ``uploaded`` to the exchange using ``taler-exchange-offline upload``.
   1330 
   1331 
   1332 .. _Revocations:
   1333 
   1334 Revocations
   1335 -----------
   1336 
   1337 When an exchange goes out of business or detects that the private key of
   1338 a denomination key pair has been compromised, it may revoke some or all
   1339 of its denomination keys. At this point, the hashes of the revoked keys
   1340 must be returned as part of the ``/keys`` response under “recoup”.
   1341 Wallets detect this, and then return unspent coins of the respective
   1342 denomination key using the ``/recoup`` API.
   1343 
   1344 To revoke a denomination key, you need to know the hash of the denomination
   1345 public key, ``$HDP``.  The ``$HDP`` value is usually included in the security
   1346 report that is generated when a compromise is detected).  Given this
   1347 value, the key revocation can be approved on the offline system:
   1348 
   1349 .. code-block:: console
   1350 
   1351    $ taler-exchange-offline revoke-denominatin $HDP > revocation.json
   1352 
   1353 The resulting *revocation.json* must be copied to a system connected to the
   1354 exchange and uploaded to the exchange using the ``upload`` subcommand
   1355 of ``taler-exchange-offline``.
   1356 
   1357 .. note::
   1358    Denomination key revocations should only happen
   1359    under highly unusual (“emergency”) conditions and not in normal
   1360    operation.
   1361 
   1362 
   1363 Setup Linting
   1364 =============
   1365 
   1366 The ``taler-harness`` package comes with a tool that runs various
   1367 checks on the current GNU Taler exchange deployment:
   1368 
   1369 .. code-block:: shell-session
   1370 
   1371   [root@exchange-online]# apt install taler-harness
   1372   [root@exchange-online]# taler-harness deployment lint-exchange
   1373 
   1374 You can optionally pass the ``--debug`` option to get more verbose output, and
   1375 ``--continue`` to continue with further checks even though a previous one has
   1376 failed.
   1377 
   1378 
   1379 Testing and Troubleshooting
   1380 ===========================
   1381 
   1382 We recommend testing whether an exchange deployment is functional by using the
   1383 Taler wallet command line interface.  The tool can be used to withdraw and
   1384 deposit electronic cash via the exchange without having to deploy and operate a
   1385 separate merchant backend and storefront.
   1386 
   1387 The following shell session illustrates how the wallet can be used to withdraw
   1388 electronic cash from the exchange and subsequently spend it.  For these steps,
   1389 a merchant backend is not required, as the wallet acts as a merchant.
   1390 
   1391 .. code-block:: shell-session
   1392 
   1393   # This will now output a payto URI that money needs to be sent to in order to allow withdrawal
   1394   # of taler coins.
   1395   $ taler-wallet-cli advanced withdraw-manually --exchange $EXCHANGE_URL --amount EUR:10.50
   1396 
   1397 
   1398 Show the status of the manual withdrawal operation.
   1399 
   1400 .. code-block:: shell-session
   1401 
   1402   $ taler-wallet-cli transactions
   1403 
   1404 At this point, a bank transfer to the exchange's bank account
   1405 needs to be made with the correct subject / remittance information
   1406 as instructed by the wallet after the first step.  With the
   1407 above configuration, it should take about 5 minutes after the
   1408 wire transfer for the incoming transfer to be observed by the
   1409 Nexus.
   1410 
   1411 Run the following command to check whether the exchange received
   1412 an incoming bank transfer:
   1413 
   1414 .. code-block:: shell-session
   1415 
   1416   [root@exchange-online]# taler-exchange-wire-gateway-client \
   1417      --section exchange-accountcredentials-1 --credit-history
   1418 
   1419 Once the transfer has been made, try completing the withdrawal
   1420 using:
   1421 
   1422 .. code-block:: shell-session
   1423 
   1424   $ taler-wallet-cli run-pending
   1425 
   1426 Afterwards, check the status of transactions and show the
   1427 current wallet balance:
   1428 
   1429 .. code-block:: shell-session
   1430 
   1431   $ taler-wallet-cli transactions
   1432   $ taler-wallet-cli balance
   1433 
   1434 
   1435 Now, we can directly deposit coins via the exchange into a target
   1436 account.  (Usually, a payment is made via a merchant.  The wallet
   1437 provides this functionality for testing.)
   1438 
   1439 .. code-block:: shell-session
   1440 
   1441   $ taler-wallet-cli deposit create EUR:5 \
   1442     payto://iban/$IBAN?receiver-name=Name
   1443   $ taler-wallet-cli run-pending
   1444 
   1445 
   1446 Check if this transaction was successful (from the perspective
   1447 of the wallet):
   1448 
   1449 .. code-block:: shell-session
   1450 
   1451   $ taler-wallet-cli transactions
   1452 
   1453 If the transaction failed, fix any open issue(s) with the exchange and
   1454 run the "run-pending" command.
   1455 
   1456 The wallet can also track if the exchange wired the money to the merchant
   1457 account.  The "deposit group id" can be found in the output of the
   1458 transactions list.
   1459 
   1460 .. code-block:: shell-session
   1461 
   1462   $ taler-wallet-cli deposit track $DEPOSIT_GROUP_ID
   1463 
   1464 You can also check using the exchange-tools whether the exchange sent
   1465 an outgoing transfer:
   1466 
   1467 .. code-block:: shell-session
   1468 
   1469   [root@exchange-online]# taler-exchange-wire-gateway-client \
   1470     --section exchange-accountcredentials-1 --debit-history
   1471 
   1472 After enough time has passed, the money should arrive at the specified IBAN.
   1473 
   1474 For more information on the taler-wallet-cli tool, see
   1475 :doc:`manpages/taler-wallet-cli.1`.
   1476 
   1477 taler-exchange-config
   1478 ---------------------
   1479 
   1480 .. _Using_taler_exchange_config:
   1481 
   1482 .. index:: taler-exchange-config
   1483 
   1484 .. include:: frags/using-taler-config.rst
   1485 
   1486 
   1487 Private key storage
   1488 -------------------
   1489 
   1490 Keeping the private keys the helpers create secret is paramount. If the
   1491 private keys are lost, it is easy to provision fresh keys (with the help of
   1492 the auditor).  Thus, we recommend that the private keys of the crypto helpers
   1493 are *not* backed up: in the rare event of a disk failure, they can be
   1494 regenerated.  However, we do recommend using RAID (1+1 or 1+1+1) for all
   1495 disks of the system.
   1496 
   1497 
   1498 .. _Internal-audit:
   1499 
   1500 Internal audits
   1501 ---------------
   1502 
   1503 While an exchange should use an external auditor to attest to regulators that
   1504 it is operating correctly, an exchange operator can also use the auditor's
   1505 logic to perform internal checks.  For this, an exchange operator can generally
   1506 follow the auditor guide.  However, instead of using ``taler-auditor-sync``,
   1507 an internal audit can and likely should be performed either directly against
   1508 the production exchange database or against a synchronous copy created using
   1509 standard database replication techniques. After all, the exchange operator
   1510 runs this for diagnostics and can generally trust its own database to maintain
   1511 the database invariants.
   1512 
   1513 Running the auditor against the original production database (without
   1514 using ``taler-auditor-sync``) enables the auditing logic to perform a few
   1515 additional checks that can detect inconsistencies.  These checks are enabled
   1516 by passing the **-i** option to the ``taler-auditor`` command.  As always,
   1517 the resulting report should be read carefully to see if there are any problems
   1518 with the setup.
   1519 
   1520 Reports are generally created incrementally, with ``taler-auditor`` reporting
   1521 only incidents and balance changes that were not covered in previous reports.
   1522 While it is possible to reset the auditor database and to restart the audit
   1523 from the very beginning, this is generally not recommended as this may be too
   1524 expensive.
   1525 
   1526 
   1527 .. _Database-Scheme:
   1528 
   1529 Database Scheme
   1530 ---------------
   1531 
   1532 The exchange database must be initialized using ``taler-exchange-dbinit``.
   1533 This tool creates the tables required by the Taler exchange to operate.
   1534 The tool also allows you to reset the Taler exchange database, which is
   1535 useful for test cases but should never be used in production. Finally,
   1536 ``taler-exchange-dbinit`` has a function to garbage collect a database,
   1537 allowing administrators to purge records that are no longer required.
   1538 
   1539 The database scheme used by the exchange looks as follows:
   1540 
   1541 .. image:: images/exchange-db.png
   1542 
   1543 The ``jmeasures`` JSON in the ``legitimization_measures``
   1544 table is of type `LegitimizationMeasures`:
   1545 
   1546 .. ts:def:: LegitimizationMeasures
   1547 
   1548   interface LegitimizationMeasures {
   1549 
   1550     // Array of legitimization measures that
   1551     // are to be applied.
   1552     measures: MeasureInformation[];
   1553 
   1554     // True if the client is expected to eventually satisfy all requirements.
   1555     // Default (if missing) is false.
   1556     is_and_combinator?: boolean;
   1557 
   1558     // True if the requested operation is categorically forbidden.
   1559     // The measures array will be empty in this case.
   1560     verboten: boolean;
   1561   }
   1562 
   1563 
   1564 .. _Database-upgrades:
   1565 
   1566 Database upgrades
   1567 -----------------
   1568 
   1569 Before installing a new exchange version, you should probably make a backup of
   1570 the existing database and study the release notes on migration.  In general,
   1571 the way to migrate is to stop all existing Taler exchange processes and run:
   1572 
   1573 .. code-block:: console
   1574 
   1575    $ taler-exchange-dbinit
   1576 
   1577 This will migrate the existing schema to the new schema. You also may need
   1578 to grant Taler exchange processes the rights to the new tables (see last
   1579 step of database setup).
   1580 
   1581 .. note::
   1582 
   1583    The **taler-exchange-dbconfig** tool can be used to automate the database
   1584    migration. In general, simply invoking it again should trigger the
   1585    migration including **taler-exchange-dbinit** and setting the permissions.
   1586 
   1587 
   1588 If you do not want to keep any data from the previous installation, the
   1589 exchange database can be fully re-initialized using:
   1590 
   1591 .. code-block:: console
   1592 
   1593    $ taler-exchange-dbinit --reset
   1594 
   1595 However, running this command will result in all data in the database
   1596 being lost, which may result in significant financial liabilities as the
   1597 exchange can then not detect double-spending. Hence this operation must
   1598 not be performed in a production system. You still also need to then
   1599 grant the permissions to the other exchange processes again.
   1600 
   1601 .. _ExchangeBenchmarking:
   1602 
   1603 Benchmarking
   1604 ============
   1605 
   1606 This chapter describes how to run various benchmarks against a Taler exchange.
   1607 These benchmark can be used to measure the performance of the exchange by
   1608 running a (possibly large) number of simulated clients against one Taler
   1609 deployment with a bank, exchange and (optionally) auditor.
   1610 
   1611 Real benchmarks that are intended to demonstrate the scalability of GNU Taler
   1612 should not use the tools presented in this section: they may be suitable for
   1613 microbenchmarking and tuning, but the setup is inherently not optimized for
   1614 performance or realism, both for the load generation and the server side.
   1615 Thus, we do not recommend using these performance numbers to assess the
   1616 scalability of GNU Taler.  That said, the tools can be useful to help identify
   1617 performance issues.
   1618 
   1619 The ``taler-unified-setup.sh`` script can be used to launch all required
   1620 services and clients. However, the resulting deployment is simplistic
   1621 (everything on the local machine, one single-threaded process per service
   1622 type) and not optimized for performance at all. However, this can still be
   1623 useful to assess the performance impact of changes
   1624 to the code or configuration.
   1625 
   1626 The various configuration files used in the code snippets in this section can
   1627 be found in the ``src/benchmark/`` directory of the exchange. These are
   1628 generally intended as starting points.  Note that the configuration files
   1629 ending in ``.edited`` are created by ``taler-unified-setup.sh`` and contain
   1630 some options that are determined at runtime by the setup logic provided by
   1631 ``taler-unified-setup.sh``.
   1632 
   1633 
   1634 .. _Benchmark-choose-bank:
   1635 
   1636 Choosing a bank
   1637 ---------------
   1638 
   1639 For the bank, both a fakebank (``-f``) and libeufin-based (``-ns``)
   1640 bank deployment are currently supported by all benchmark tools and
   1641 configuration templates.
   1642 
   1643 Fakebank is an ultra-fast in-memory implementation of the Taler bank API. It
   1644 is suitable when the goal is to benchmark the core GNU Taler payment system
   1645 and to ignore the real-time gross settlement (RTGS) system typically provided
   1646 by an existing bank.  When using the fakebank, ``taler-unified-setup.sh`` must
   1647 be started with the ``-f`` option and be told to use the right exchange bank
   1648 account from the configuration files via ``-u exchange-account-1``.
   1649 
   1650 .. code-block:: console
   1651 
   1652     $ dropdb talercheck; createdb talercheck
   1653     $ taler-unified-setup.sh -emwt -c $CONF -f -u exchange-account-1
   1654 
   1655 
   1656 libeufin is GNU Taler's adapter to the core banking system using the EBICS
   1657 banking protocol standard.  It uses a Postgres database to persist data and is
   1658 thus much slower than fakebank.  If your GNU Taler deployment uses libeufin in
   1659 production, it likely makes sense to benchmark with libeufin.  When using the
   1660 fakebank, ``taler-unified-setup.sh`` must be started with the ``-ns`` options
   1661 (starting libeufin-nexus and libeufin-bank) and be told to use the right
   1662 exchange bank account from the configuration files via ``-u
   1663 exchange-account-2``.  Note that ``taler-unified-setup.sh`` currently cannot
   1664 reset a libeufin database, and also will not run if the database is already
   1665 initialized. Thus, you must re-create the database every time before
   1666 running the command:
   1667 
   1668 .. code-block:: console
   1669 
   1670     $ dropdb talercheck; createdb talercheck
   1671     $ taler-unified-setup.sh -emwt -c $CONF -ns -u exchange-account-2
   1672 
   1673 
   1674 taler-bank-benchmark
   1675 --------------------
   1676 
   1677 This is the simplest benchmarking tool, simulating only the bank
   1678 interaction.
   1679 
   1680 .. code-block:: console
   1681 
   1682     $ CONF="benchmark-cs.conf"
   1683     $ # or with libeufin
   1684     $ dropdb talercheck; createdb talercheck
   1685     $ taler-unified-setup.sh -emwt -c "$CONF" -f -u exchange-account-1
   1686     $ # Once <<READY>>, in another shell (remember to set $CONF):
   1687     $ time taler-bank-benchmark -c "$CONF" -r 40 -p 4 -P4 -u exchange-account-1 -f
   1688     $ # or with libeufin
   1689     $ dropdb talercheck; createdb talercheck
   1690     $ taler-unified-setup.sh -emwt -c "$CONF" -ns -u exchange-account-2
   1691     $ # Once <<READY>>, in another shell (remember to set $CONF):
   1692     $ time taler-bank-benchmark -c "$CONF" -r 40 -p 1 -P1 -u exchange-account-2
   1693 
   1694 For each *parallel* (``-p``) client, a number of *reserves* (``-r``) is first
   1695 established by **transferring** money from a "user" account (42) to the
   1696 Exchange's account with the respective reserve public key as wire subject.
   1697 Processing is then handled by *parallel* (``-P``) service workers.
   1698 
   1699 
   1700 taler-exchange-benchmark
   1701 ------------------------
   1702 
   1703 This benchmarking tool simulates a number of clients withdrawing,
   1704 depositing and refreshing coins.  Operations that are not covered by the
   1705 ``taler-exchange-benchmark`` tool today include closing reserves, refunds,
   1706 recoups and P2P payments.
   1707 
   1708 .. code-block:: console
   1709 
   1710     $ CONF="benchmark-cs.conf" # -rsa also makes sense
   1711     $ # With fakebank
   1712     $ dropdb talercheck; createdb talercheck
   1713     $ taler-unified-setup.sh -aemwt -c "$CONF" -f -u exchange-account-1
   1714     $ # Once <<READY>>, in another shell (remember to set $CONF):
   1715     $ taler-exchange-benchmark -c "$CONF".edited -u exchange-account-1 -n 1 -p1 -r 5 -f
   1716     $ #
   1717     $ # With libeufin
   1718     $ dropdb talercheck; createdb talercheck
   1719     $ taler-unified-setup.sh -aemwt -c "$CONF" -ns -u exchange-account-2
   1720     $ # Once <<READY>>, in another shell (remember to set $CONF):
   1721     $ taler-exchange-benchmark -c "$CONF".edited -u exchange-account-2 -L WARNING -n 1 -p1 -r 5
   1722 
   1723 For each *parallel* (``-p``) client, a number of *reserves* (``-r``) is first
   1724 established by **transferring** money from a "user" account (42) to the
   1725 Exchange's account with the respective reserve public key as wire subject.
   1726 Next, the client will **withdraw** a *number of coins* (``-n``) from the
   1727 reserve and **deposit** them. Additionally, a *fraction* (``-R``) of the dirty
   1728 coins will then be subject to **refreshing**.  For some deposits, the auditor
   1729 will receive **deposit confirmations**.
   1730 
   1731 The output of ``taler-exchange-benchmark`` will include for each parallel
   1732 client the total time spent in each of the major operations, possible
   1733 repetitions (i.e. if the operation failed the first time), total execution
   1734 time (operating system and user space) and other details.
   1735 
   1736 
   1737 taler-aggregator-benchmark
   1738 --------------------------
   1739 
   1740 This is another simple benchmark tool that merely prepares an exchange
   1741 database to run a stand-alone benchmark of the ``taler-exchange-aggregator``
   1742 tool.  After preparing a database and running the tool, you can then
   1743 run one or more ``taler-exchange-aggregator`` processes and measure how
   1744 quickly they perform the aggregation work.
   1745 
   1746 .. code-block:: console
   1747 
   1748     $ CONF=benchmark-rsa.conf
   1749     $ taler-exchange-dbinit -c "$CONF" --reset
   1750     $ ./taler-aggregator-benchmark -c "$CONF" -m 500 -r 10 -d 100
   1751     $ time taler-exchange-aggregator -c "$CONF" --test
   1752 
   1753 This above commands will first create 100 deposits with 10 refunds into each
   1754 of 500 merchant accounts using randomized time stamps.  Afterwards, it will
   1755 time a single aggregator process in ``--test`` mode (asking it to terminate
   1756 as soon as there is no more pending work).
   1757 
   1758 
   1759 FIXMEs
   1760 ======
   1761 
   1762 * We should have some summary with the inventory of services that should be
   1763   running.  Systemd by default doesn't show this nicely.  Maybe suggest running
   1764   "systemd list-dependencies taler-exchange.target"?
   1765 * What happens when the TWG doesn't like one particular outgoing transaction?
   1766   How to recover from that as a sysadmin when it happens in practice?