taler-docs

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

taler-exchange-manual.rst (71929B)


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