taler-exchange-manual.rst (71944B)
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 three 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 the age-restriction documentation below for 757 details. Age restriction is a protocol feature; it no longer uses the 758 retired generic extension mechanism described by DD06. 759 This option is optional and defaults to ``NO``. 760 761 See :doc:`manpages/taler-exchange.conf.5` for information on *duration* values 762 (i.e. ``DURATION_WITHDRAW`` and ``DURATION_SPEND`` above, 763 and ``OVERLAP_DURATION`` and ``DURATION`` below). 764 Additionally, there are two global configuration options of note: 765 766 - ``[taler-exchange-secmod-rsa/OVERLAP_DURATION]``: What is the overlap of the 767 withdrawal timespan for denomination keys? The value given here must 768 be smaller than any of the ``DURATION_WITHDRAW`` values for any of the coins. 769 770 - ``[taler-exchange-secmod-rsa/LOOKAHEAD_SIGN]``: For how far into the future 771 should denomination keys be pre-generated? This allows the exchange and 772 auditor operators to download, offline-sign, and upload denomination key 773 signatures for denomination keys that will be used in the future by the 774 exchange. 775 776 .. index:: maintenance 777 .. note:: 778 We recommend setting the ``LOOKAHEAD_SIGN`` value to at least one year and 779 then to perform the offline-signing procedure at least once every 6 months 780 to ensure that there is sufficient time for wallets to learn the new keys 781 and to avoid unavailability in case this critical maintenance procedure is 782 delayed. 783 784 .. note:: 785 It is crucial that the configuration provided in these sections is identical (!) 786 for the exchange and the crypto helpers. We recommend pointing both users 787 to the same configuration file! 788 789 The ``taler-harness`` has a helper command that generates a 790 reasonable denomination structure. 791 792 .. code-block:: shell-session 793 794 [root@exchange-online]# taler-harness deployment gen-coin-config \ 795 --min-amount EUR:0.01 \ 796 --max-amount EUR:100 \ 797 > /etc/taler-exchange/conf.d/exchange-coins.conf 798 799 You can manually review and edit the generated configuration file. The main 800 change that is possibly required is updating the various fees. Note that you 801 MUST NOT edit a coin configuration section after the initial setup. If you 802 must ``change`` the values, you must instead create a new section with a 803 different unique name (still with the ``coin_`` prefix) and comment out or 804 remove the existing section. Do take care to not introduce the name of the 805 disabled section again in the future. 806 807 808 .. _Sign-keys: 809 810 Sign keys 811 --------- 812 813 There are three global configuration options of note for sign keys: 814 815 - ``[taler-exchange-secmod-eddsa/DURATION]``: How long are sign keys 816 used to sign messages? After this time interval expires, a fresh 817 sign key will be used (key rotation). We recommend using 818 a ``DURATION`` of a few weeks to a few months for sign keys. 819 820 - ``[taler-exchange-secmod-eddsa/OVERLAP_DURATION]``: What is the overlap of the 821 timespan for sign keys? We recommend a few minutes or hours. Must 822 be smaller than ``DURATION``. 823 824 - ``[taler-exchange-secmod-eddsa/LOOKAHEAD_SIGN]``: For how far into the future 825 should sign keys be pre-generated? This allows the exchange and 826 auditor operators to download, offline-sign, and upload sign key 827 signatures for sign keys that will be used in the future by the exchange. 828 829 .. note:: 830 We recommend setting the ``LOOKAHEAD_SIGN`` value to at least one year and 831 then to perform the offline-signing procedure at least once every 6 months 832 to ensure that there is sufficient time for wallets to learn the new keys 833 and to avoid unavailability in case this critical maintenance procedure is 834 delayed. 835 836 837 .. _OfflineConfiguration: 838 839 Setting up the offline signing key 840 ---------------------------------- 841 842 Before launching an exchange, the offline signing (master) key must be 843 generated and set in the configuration. The offline signing keys of the 844 exchange should be stored on a different machine. The responsibilities of 845 this offline signing machine are: 846 847 * Generation of the exchange's offline master signing key. 848 * Secure storage of the exchange's offline master signing key. 849 * Generation of certificates (signed with the offline master signing key) that will be imported by the exchange. 850 * Revocation of keys when the online system was compromised or is being terminated 851 852 853 Configuration file options related to the master key are: 854 855 - ``[exchange-offline/MASTER_PRIV_FILE]``: Path to the exchange’s master 856 private file. Only needs to be provided on the offline system where the 857 ``taler-exchange-offline`` command is used. The default value is usually 858 fine and does not require adjustment. 859 860 - ``[exchange/MASTER_PUBLIC_KEY]``: Must specify the exchange’s master public 861 key. Needed for the exchange to verify information signed by the offline 862 system. This value must almost always be set explicitly by hand. 863 864 865 866 .. code-block:: shell-session 867 868 [root@exchange-offline]# taler-exchange-offline setup 869 < ... prints the exchange master public key > 870 871 The public key printed as the output of this command must be put into the 872 configuration of the online machine: 873 874 .. code-block:: ini 875 :caption: /etc/taler-exchange/conf.d/exchange-business.conf 876 877 [exchange] 878 MASTER_PUBLIC_KEY = YE6Q6TR1ED... 879 880 # ... rest of file ... 881 882 883 Wire Gateway Setup 884 ================== 885 886 The :ref:`Taler Wire Gateway <taler-wire-gateway-http-api>` is an API that 887 connects the Taler exchange to the underlying core banking system. There are 888 several implementations of wire gateways: 889 890 * `Project deploymerization <https://git.taler.net/taler/depolymerization/files.html>`_ implements a wire gateway on top of Bitcoin or Ethereum 891 * The :ref:`libeufin-bank <libeufin-bank>` provides a wire gateway interface on top of a regional currency bank 892 * The **taler-fakebank-run** command is an in-memory bank simulator with a wire gateway interface for testing 893 894 .. 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! 895 896 Before continuing, you need to decide which wire gateway you want to use, 897 and install and configure it on your system. Afterwards, you need to 898 have two key pieces of information from that setup: 899 900 * The username and password to access the exchange's account in the system. 901 * The ``payto://`` URI of that account (see `RFC 8905 <https://www.rfc-editor.org/rfc/rfc8905>`_). 902 903 If you use the libeufin-bank, you need to set a special configuration option 904 because the taler-exchange-wire-gateway-client does not yet support token 905 authentication: 906 907 .. code-block:: ini 908 :caption: /etc/libeufin/libeufin-bank.conf 909 910 [libeufin-bank] 911 PWD_AUTH_COMPAT = YES 912 913 .. FIXME: Remove the text above once #9703 is fixed. 914 915 .. _exchange-bank-account-configuration: 916 917 Exchange Bank Account Configuration 918 ----------------------------------- 919 920 An exchange must be configured with the right settings to access its bank 921 account via a :ref:`Taler wire gateway <taler-wire-gateway-http-api>`. An 922 exchange can be configured to use multiple bank accounts by using multiple 923 wire gateways. Typically only one wire gateway is used. 924 925 To configure a bank account in Taler, we need to furnish two pieces of 926 information: 927 928 - The ``payto://`` URI of the bank account, which uniquely identifies the 929 account. Examples for such URIs include 930 ``payto://iban/CH9300762011623852957`` for a bank account with 931 an IBAN or 932 ``payto://x-taler-bank/localhost:8080/2`` for the 2nd bank account at 933 the Taler bank demonstrator running at ``localhost`` on port 8080. 934 The first part of the URI following ``payto://`` (``iban`` or 935 ``x-taler-bank``) is called the wire method. 936 937 - The ``taler-exchange-wirewatch`` and ``taler-exchange-transfer`` 938 tools needs to be provided resources for authentication 939 to the respective banking service. The format in which the 940 authentication information is currently a username and password 941 for HTTP basic authentication. 942 943 944 Each Taler wire gateway is configured in a configuration section that follows 945 the pattern ``exchange-account-$id``, where ``$id`` is an internal identifier 946 for the bank account accessed by the exchange. The basic information for an 947 account should be put in ``/etc/taler-exchange/conf.d/exchange-business.conf``. The 948 secret credentials to access the Taler Wire Gateway API should be put into a 949 corresponding ``exchange-accountcredentials-$id`` section in 950 ``/etc/taler-exchange/secrets/exchange-accountcredentials.conf``. The latter file 951 should be only readable for the ``taler-exchange-wire`` user. Only the 952 ``taler-exchange-wirewatch`` and ``taler-exchange-transfer`` services should 953 run as the ``taler-exchange-wire`` user. Other exchange processes do not need 954 to have access to the account credentials. 955 956 You can configure multiple accounts for an exchange by creating sections 957 starting with ``exchange-account-`` for the section name. You must specify 958 ``ENABLE_``-settings for each account whether it should be used, and for what 959 (incoming or outgoing wire transfers): 960 961 .. code-block:: ini 962 :caption: /etc/taler-exchange/conf.d/exchange-business.conf 963 964 [exchange-account-1] 965 # Account identifier in the form of an RFC-8905 payto:// URI. 966 # For SEPA, looks like payto://iban/$IBAN?receiver-name=$NAME 967 # Make sure to URL-encode spaces in $NAME! 968 # 969 # With x-taler-bank (for Fakebank) 970 # PAYTO_URI = "payto://x-taler-bank/bank.demo.taler.net/Exchange?receiver-name=exop" 971 # 972 # Example using IBAN (for use with LibEuFin) 973 PAYTO_URI = "payto://iban/CH9300762011623852957?receiver=name=exop" 974 975 # Use for exchange-aggregator (outgoing transfers) 976 ENABLE_DEBIT = YES 977 # Use for exchange-wirewatch (and listed in /wire) 978 ENABLE_CREDIT = YES 979 980 @inline-secret@ exchange-accountcredentials-1 ../secrets/exchange-accountcredentials.secret.conf 981 982 983 .. code-block:: ini 984 :caption: /etc/taler-exchange/secrets/exchange-accountcredentials.secret.conf 985 986 [exchange-accountcredentials-1] 987 988 # LibEuFin expects basic auth. 989 WIRE_GATEWAY_AUTH_METHOD = basic 990 991 # Username and password to access the Taler wire gateway. 992 USERNAME = ... 993 PASSWORD = ... 994 995 # URL for talking to the bank wire the wire API. 996 WIRE_GATEWAY_URL = https://bank.demo.taler.net/accounts/exchange/taler-wire-gateway/ 997 998 999 Such a wire gateway configuration can be tested with the following commands: 1000 1001 .. code-block:: shell-session 1002 1003 [root@exchange-online]# taler-exchange-wire-gateway-client \ 1004 --section exchange-accountcredentials-1 --debit-history 1005 [root@exchange-online]# taler-exchange-wire-gateway-client \ 1006 --section exchange-accountcredentials-1 --credit-history 1007 1008 On success, you will see some of your account's transaction history (or an 1009 empty history), while on failure you should see an error message. 1010 1011 1012 .. _Deployment: 1013 1014 Deployment 1015 ========== 1016 1017 This chapter describes how to deploy the exchange once the basic installation 1018 and configuration are completed. 1019 1020 .. _Serving: 1021 1022 Serving 1023 ------- 1024 1025 The exchange can serve HTTP over both TCP and UNIX domain socket. 1026 1027 The following options are to be configured in the section ``[exchange]``: 1028 1029 - ``SERVE``: Must be set to ``tcp`` to serve HTTP over TCP, or ``unix`` to serve 1030 HTTP over a UNIX domain socket. 1031 1032 - ``PORT``: Set to the TCP port to listen on if ``SERVE`` is ``tcp``. 1033 1034 - ``UNIXPATH``: Set to the UNIX domain socket path to listen on if ``SERVE`` is 1035 ``unix``. 1036 1037 - ``UNIXPATH_MODE``: Number giving the mode with the access permission mask 1038 for the ``UNIXPATH`` (i.e. 660 = ``rw-rw---``). Make sure to set it in such 1039 a way that your reverse proxy has permissions to access the UNIX domain 1040 socket. The default (660) assumes that the reverse proxy is a member of 1041 the group under which the exchange HTTP server is running. 1042 1043 .. _ReverseProxy: 1044 1045 Reverse Proxy Setup 1046 ------------------- 1047 1048 By default, the ``taler-exchange-httpd`` service listens for HTTP connections 1049 on a UNIX domain socket. To make the service publicly available, a reverse 1050 proxy such as nginx should be used. We strongly recommend to configure nginx 1051 to use TLS. 1052 1053 The public URL that the exchange will be served under should 1054 be put in ``/etc/taler-exchange/conf.d/exchange-business.conf`` configuration file. 1055 1056 .. code-block:: ini 1057 :caption: /etc/taler-exchange/conf.d/exchange-business.conf 1058 1059 [exchange] 1060 BASE_URL = https://example.com/ 1061 1062 # ... rest of file ... 1063 1064 The ``taler-exchange`` package ships with a sample configuration that can be 1065 enabled in nginx: 1066 1067 .. code-block:: shell-session 1068 1069 [root@exchange-online]# vim /etc/nginx/sites-available/taler-exchange 1070 < ... customize configuration ... > 1071 [root@exchange-online]# ln -s /etc/nginx/sites-available/taler-exchange \ 1072 /etc/nginx/sites-enabled/taler-exchange 1073 [root@exchange-online]# systemctl reload nginx 1074 1075 Note that the reverse proxy must set a HTTP ``X-Forwarded-Host`` header to 1076 refer to the hostname used by nginx and a HTTP ``X-Forwarded-Proto`` header to 1077 inform the exchange whether the external protocol was ``http`` or ``https``. 1078 Thus, depending on your setup, you will likely have to edit those parts of the 1079 provided ``taler-exchange`` configuration file. 1080 1081 With this last step, we are finally ready to launch the 1082 main exchange process. 1083 1084 .. _Launch: 1085 1086 Launching an exchange 1087 --------------------- 1088 1089 A running exchange requires starting the following processes: 1090 1091 - ``taler-exchange-secmod-rsa`` (as special user, sharing group with the HTTPD) 1092 - ``taler-exchange-secmod-cs`` (as special user, sharing group with the HTTPD) 1093 - ``taler-exchange-secmod-eddsa`` (as special user, sharing group with the HTTPD) 1094 - ``taler-exchange-httpd`` (needs database access) 1095 - ``taler-exchange-aggregator`` (only needs database access) 1096 - ``taler-exchange-closer`` (only needs database access) 1097 - ``taler-exchange-wirewatch`` (needs bank account read credentials and database access) 1098 - ``taler-exchange-transfer`` (needs credentials to initiate outgoing wire transfers and database access) 1099 1100 The crypto helpers (``secmod``) must be started before the ``taler-exchange-httpd`` and 1101 they should use the same configuration file. 1102 1103 For the most secure deployment, we recommend using separate users for each of 1104 these processes to minimize information disclosures should any of them be 1105 compromised. The helpers do not need access to the PostgreSQL database (and 1106 thus also should not have it). 1107 1108 The processes that require access to the bank account need to have a 1109 configuration file with the respective credentials in it. We recommend using a 1110 separate configuration at least for ``taler-exchange-transfer`` which is the 1111 *only* process that needs to know the credentials to execute outgoing wire 1112 transfers. 1113 1114 All of these processes should also be started via a hypervisor like 1115 ``systemd`` or ``gnunet-arm`` that automatically re-starts them should they 1116 have terminated unexpectedly. If the bank is down (say for maintenance), it is 1117 *possible* to halt the ``taler-exchange-wirewatch`` and/or 1118 ``taler-exchange-transfer`` processes (to avoid them making requests to the 1119 bank API that can only fail) without impacting other operations of the 1120 exchange. Naturally, incoming wire transfers will only be observed once 1121 ``taler-exchange-wirewatch`` is resumed, and merchants may complain if the 1122 disabled ``taler-exchange-transfer`` process causes payment deadlines to be 1123 missed. 1124 1125 .. note:: 1126 The ``taler-exchange-httpd`` does not ship with HTTPS enabled by default. 1127 In production, it should be run behind an HTTPS reverse proxy that performs 1128 TLS termination on the same system. Thus, it would typically be configured 1129 to listen on a UNIX domain socket. The ``/management`` and ``/auditors`` 1130 APIs do technically not have to be exposed on the Internet (only to the 1131 administrators running ``taler-exchange-offline``) and should be blocked 1132 by the reverse proxy for requests originating from outside of the bank. 1133 (However, this is not a strong security assumption: in principle having 1134 these endpoints available should do no harm. However, it increases the 1135 attack surface.) 1136 1137 1138 Given proper packaging, all of the above are realized via a simple systemd 1139 target. This enables the various processes of an exchange service to be 1140 started using a simple command: 1141 1142 .. code-block:: shell-session 1143 1144 [root@exchange-online]# systemctl start taler-exchange.target 1145 1146 .. note:: 1147 1148 At this point, the exchange service is not yet fully operational. 1149 1150 1151 To check whether the exchange is running correctly under the advertised 1152 base URL, run: 1153 1154 .. code-block:: shell-session 1155 1156 [root@exchange-online]# export BASE_URL=$(taler-exchange-config -s exchange -o base_url) 1157 [root@exchange-online]# wget ${BASE_URL}management/keys 1158 1159 The request might take some time to complete on slow machines, because 1160 a lot of key material will be generated. 1161 1162 1163 Offline Signing Setup, Key Maintenance and Tear-Down 1164 ==================================================== 1165 1166 The exchange HTTP service must be running before you can complete the 1167 following offline signing procedure. Note that when an exchange is running 1168 without offline keys its not fully operational. To make the exchange HTTP 1169 service fully operational, the following steps involving the offline signing 1170 machine must be completed: 1171 1172 1. The public keys of various online keys used by the exchange service are exported 1173 via a management HTTP API. 1174 2. The offline signing system validates this request and signs it. 1175 Additionally, the offline signing system signs policy messages 1176 to configure the exchange's bank accounts and associated fees. 1177 3. The messages generated by the offline signing system are uploaded 1178 via the management API of the exchange HTTP service. 1179 1180 A typical minimal setup would look something like this: 1181 1182 .. code-block:: shell-session 1183 1184 [anybody@exchange-online]# taler-exchange-offline \ 1185 download > sig-request.json 1186 1187 [root@exchange-offline]# taler-exchange-offline \ 1188 sign < sig-request.json > sig-response.json 1189 [root@exchange-offline]# taler-exchange-offline \ 1190 enable-account payto://iban/$IBAN?receiver-name=$NAME > acct-response.json 1191 [root@exchange-offline]# taler-exchange-offline \ 1192 wire-fee now iban EUR:0 EUR:0 > fee-response.json 1193 [root@exchange-offline]# taler-exchange-offline \ 1194 global-fee now EUR:0 EUR:0 EUR:0 4weeks 6a 4 > global-response.json 1195 1196 [anybody@exchange-online]# taler-exchange-offline upload < sig-response.json 1197 [anybody@exchange-online]# taler-exchange-offline upload < acct-response.json 1198 [anybody@exchange-online]# taler-exchange-offline upload < fee-response.json 1199 [anybody@exchange-online]# taler-exchange-offline upload < global-response.json 1200 1201 The following sections will discuss these steps in more depth. 1202 1203 .. _Keys-generation: 1204 1205 Signing the online signing keys 1206 ------------------------------- 1207 1208 To sign the online signing keys, first the *future* key material should be downloaded using: 1209 1210 .. code-block:: console 1211 1212 $ taler-exchange-offline download > future-keys.json 1213 1214 Afterwards, *future-keys.json* contains data about denomination and 1215 online signing keys that the exchange operator needs to sign with 1216 the offline tool. The file should be copied to the offline system. 1217 There, the operator should run: 1218 1219 .. code-block:: console 1220 1221 $ taler-exchange-offline show < future-keys.json 1222 1223 and verify that the output contains the fee structure and key lifetimes 1224 they expect to see. They should also note the public keys being shown 1225 and communicate those to the *auditors* over a secure channel. Once 1226 they are convinced the file is acceptable, they should run: 1227 1228 .. code-block:: console 1229 1230 $ taler-exchange-offline sign < future-keys.json > offline-sigs.json 1231 1232 The *offline-sigs.json* file must then be copied to an online system 1233 that is able to again communicate with the exchange. On that system, run: 1234 1235 .. code-block:: console 1236 1237 $ taler-exchange-offline upload < offline-sigs.json 1238 1239 to provision the signatures to the exchange. 1240 1241 The ``download sign upload`` sequence in the commands above has to be done 1242 periodically, as it signs the various online signing keys of the exchange 1243 which periodically expire. 1244 1245 1246 .. _exchange-account-signing: 1247 1248 Account signing 1249 --------------- 1250 1251 The ``enable-account`` step is important and must be used to sign the 1252 ``payto://`` URI in a way suitable to convince wallets that this is the 1253 correct address to wire funds to. Note that for each bank account, additional 1254 options **must** be set in the configuration file to tell the exchange how to 1255 access the bank account. The offline tool *only* configures the externally 1256 visible portions of the setup. The chapter on 1257 :ref:`bank account configuration <exchange-bank-account-configuration>` has 1258 further details. 1259 1260 taler-exchange-offline accepts additional options to configure the use of the 1261 account. For example, additional options can be used to add currency 1262 conversion or to restrict interactions to bank accounts from certain 1263 countries: 1264 1265 .. code-block:: console 1266 1267 $ taler-exchange-offline \ 1268 enable-account payto://iban/CH9300762011623852957 1269 conversion-url https://conversion.example.com/ 1270 1271 For details on optional ``enable-account`` arguments, 1272 see :doc:`manpages/taler-exchange-offline.1`. 1273 1274 .. _Wire-fee-structure: 1275 1276 Wire fee structure 1277 ------------------ 1278 1279 .. index:: wire fee 1280 .. index:: fee 1281 1282 For each wire method (“iban” or “x-taler-bank”) the 1283 exchange must know about applicable wire fees. This is also done 1284 using the ``taler-exchange-offline`` tool: 1285 1286 .. code-block:: console 1287 1288 $ taler-exchange-offline wire-fee 2040 iban EUR:0.05 EUR:0.10 1289 1290 The above sets the wire fees for wire transfers involving ``iban`` accounts 1291 (in Euros) in the year 2040 to 5 cents (wire fee) and 10 cents (closing fee). 1292 The tool only supports setting fees that apply for the entire calendar year. 1293 1294 We recommend provisioning an exchange with wire fees at least for the next two 1295 years. Note that once the fees have been set for a year, they cannot be 1296 changed (basically, by signing the fees the exchange makes a legally binding 1297 offer to the customers). 1298 1299 .. index:: maintenance 1300 .. note:: 1301 Provisioning future wire fees, like provisioning future denomination 1302 and signing keys, are key regular maintenance procedures for every 1303 exchange operator. We recommend setting automated reminders for 1304 this maintenance activity! 1305 1306 1307 .. _Auditor-configuration: 1308 1309 Auditor configuration 1310 --------------------- 1311 1312 At this point, the exchange will be able to use those keys, but wallets and 1313 merchants may not yet trust them! Thus, the next step is for an auditor to 1314 affirm that they are auditing this exchange. Before an auditor can do this, 1315 the exchange service must be informed about any auditor that is expected to 1316 provision it with auditor signatures. 1317 1318 This is also done using the ``taler-exchange-offline`` tool on the offline 1319 system. First, the auditor must be configured and provide the exchange 1320 operator with its public key (using ``taler-auditor-offline setup``) and the 1321 URL of its REST API. The exchange operator also needs a human-readable name 1322 that may be shown to users to identify the auditor. For more information on 1323 how to setup and operate an auditor, see 1324 :doc:`manpages/taler-auditor-offline.1` and :doc:`taler-auditor-manual`. 1325 1326 Given this information, the exchange operator can enable the auditor: 1327 1328 .. code-block:: console 1329 1330 $ taler-exchange-offline enable-auditor $PUB_KEY $REST_URL "$AUDITOR_NAME" > auditor.json 1331 1332 As before, the *auditor.json* file must then be copied from the offline system 1333 to a system connected to the exchange and there ``uploaded`` to the exchange using ``taler-exchange-offline upload``. 1334 1335 1336 .. _Revocations: 1337 1338 Revocations 1339 ----------- 1340 1341 When an exchange goes out of business or detects that the private key of 1342 a denomination key pair has been compromised, it may revoke some or all 1343 of its denomination keys. At this point, the hashes of the revoked keys 1344 must be returned as part of the ``/keys`` response under “recoup”. 1345 Wallets detect this, and then return unspent coins of the respective 1346 denomination key using the ``/recoup`` API. 1347 1348 To revoke a denomination key, you need to know the hash of the denomination 1349 public key, ``$HDP``. The ``$HDP`` value is usually included in the security 1350 report that is generated when a compromise is detected). Given this 1351 value, the key revocation can be approved on the offline system: 1352 1353 .. code-block:: console 1354 1355 $ taler-exchange-offline revoke-denominatin $HDP > revocation.json 1356 1357 The resulting *revocation.json* must be copied to a system connected to the 1358 exchange and uploaded to the exchange using the ``upload`` subcommand 1359 of ``taler-exchange-offline``. 1360 1361 .. note:: 1362 Denomination key revocations should only happen 1363 under highly unusual (“emergency”) conditions and not in normal 1364 operation. 1365 1366 1367 Setup Linting 1368 ============= 1369 1370 The ``taler-harness`` package comes with a tool that runs various 1371 checks on the current GNU Taler exchange deployment: 1372 1373 .. code-block:: shell-session 1374 1375 [root@exchange-online]# apt install taler-harness 1376 [root@exchange-online]# taler-harness deployment lint-exchange 1377 1378 You can optionally pass the ``--debug`` option to get more verbose output, and 1379 ``--continue`` to continue with further checks even though a previous one has 1380 failed. 1381 1382 1383 Testing and Troubleshooting 1384 =========================== 1385 1386 We recommend testing whether an exchange deployment is functional by using the 1387 Taler wallet command line interface. The tool can be used to withdraw and 1388 deposit electronic cash via the exchange without having to deploy and operate a 1389 separate merchant backend and storefront. 1390 1391 The following shell session illustrates how the wallet can be used to withdraw 1392 electronic cash from the exchange and subsequently spend it. For these steps, 1393 a merchant backend is not required, as the wallet acts as a merchant. 1394 1395 .. code-block:: shell-session 1396 1397 # This will now output a payto URI that money needs to be sent to in order to allow withdrawal 1398 # of taler coins. 1399 $ taler-wallet-cli advanced withdraw-manually --exchange $EXCHANGE_URL --amount EUR:10.50 1400 1401 1402 Show the status of the manual withdrawal operation. 1403 1404 .. code-block:: shell-session 1405 1406 $ taler-wallet-cli transactions 1407 1408 At this point, a bank transfer to the exchange's bank account 1409 needs to be made with the correct subject / remittance information 1410 as instructed by the wallet after the first step. With the 1411 above configuration, it should take about 5 minutes after the 1412 wire transfer for the incoming transfer to be observed by the 1413 Nexus. 1414 1415 Run the following command to check whether the exchange received 1416 an incoming bank transfer: 1417 1418 .. code-block:: shell-session 1419 1420 [root@exchange-online]# taler-exchange-wire-gateway-client \ 1421 --section exchange-accountcredentials-1 --credit-history 1422 1423 Once the transfer has been made, try completing the withdrawal 1424 using: 1425 1426 .. code-block:: shell-session 1427 1428 $ taler-wallet-cli run-pending 1429 1430 Afterwards, check the status of transactions and show the 1431 current wallet balance: 1432 1433 .. code-block:: shell-session 1434 1435 $ taler-wallet-cli transactions 1436 $ taler-wallet-cli balance 1437 1438 1439 Now, we can directly deposit coins via the exchange into a target 1440 account. (Usually, a payment is made via a merchant. The wallet 1441 provides this functionality for testing.) 1442 1443 .. code-block:: shell-session 1444 1445 $ taler-wallet-cli deposit create EUR:5 \ 1446 payto://iban/$IBAN?receiver-name=Name 1447 $ taler-wallet-cli run-pending 1448 1449 1450 Check if this transaction was successful (from the perspective 1451 of the wallet): 1452 1453 .. code-block:: shell-session 1454 1455 $ taler-wallet-cli transactions 1456 1457 If the transaction failed, fix any open issue(s) with the exchange and 1458 run the "run-pending" command. 1459 1460 The wallet can also track if the exchange wired the money to the merchant 1461 account. The "deposit group id" can be found in the output of the 1462 transactions list. 1463 1464 .. code-block:: shell-session 1465 1466 $ taler-wallet-cli deposit track $DEPOSIT_GROUP_ID 1467 1468 You can also check using the exchange-tools whether the exchange sent 1469 an outgoing transfer: 1470 1471 .. code-block:: shell-session 1472 1473 [root@exchange-online]# taler-exchange-wire-gateway-client \ 1474 --section exchange-accountcredentials-1 --debit-history 1475 1476 After enough time has passed, the money should arrive at the specified IBAN. 1477 1478 For more information on the taler-wallet-cli tool, see 1479 :doc:`manpages/taler-wallet-cli.1`. 1480 1481 taler-exchange-config 1482 --------------------- 1483 1484 .. _Using_taler_exchange_config: 1485 1486 .. index:: taler-exchange-config 1487 1488 .. include:: frags/using-taler-config.rst 1489 1490 1491 Private key storage 1492 ------------------- 1493 1494 Keeping the private keys the helpers create secret is paramount. If the 1495 private keys are lost, it is easy to provision fresh keys (with the help of 1496 the auditor). Thus, we recommend that the private keys of the crypto helpers 1497 are *not* backed up: in the rare event of a disk failure, they can be 1498 regenerated. However, we do recommend using RAID (1+1 or 1+1+1) for all 1499 disks of the system. 1500 1501 1502 .. _Internal-audit: 1503 1504 Internal audits 1505 --------------- 1506 1507 While an exchange should use an external auditor to attest to regulators that 1508 it is operating correctly, an exchange operator can also use the auditor's 1509 logic to perform internal checks. For this, an exchange operator can generally 1510 follow the auditor guide. However, instead of using ``taler-auditor-sync``, 1511 an internal audit can and likely should be performed either directly against 1512 the production exchange database or against a synchronous copy created using 1513 standard database replication techniques. After all, the exchange operator 1514 runs this for diagnostics and can generally trust its own database to maintain 1515 the database invariants. 1516 1517 Running the auditor against the original production database (without 1518 using ``taler-auditor-sync``) enables the auditing logic to perform a few 1519 additional checks that can detect inconsistencies. These checks are enabled 1520 by passing the **-i** option to the ``taler-auditor`` command. As always, 1521 the resulting report should be read carefully to see if there are any problems 1522 with the setup. 1523 1524 Reports are generally created incrementally, with ``taler-auditor`` reporting 1525 only incidents and balance changes that were not covered in previous reports. 1526 While it is possible to reset the auditor database and to restart the audit 1527 from the very beginning, this is generally not recommended as this may be too 1528 expensive. 1529 1530 1531 .. _Database-Scheme: 1532 1533 Database Scheme 1534 --------------- 1535 1536 The exchange database must be initialized using ``taler-exchange-dbinit``. 1537 This tool creates the tables required by the Taler exchange to operate. 1538 The tool also allows you to reset the Taler exchange database, which is 1539 useful for test cases but should never be used in production. Finally, 1540 ``taler-exchange-dbinit`` has a function to garbage collect a database, 1541 allowing administrators to purge records that are no longer required. 1542 1543 The database scheme used by the exchange looks as follows: 1544 1545 .. image:: images/exchange-db.png 1546 1547 The ``jmeasures`` JSON in the ``legitimization_measures`` 1548 table is of type `LegitimizationMeasures`: 1549 1550 .. ts:def:: LegitimizationMeasures 1551 1552 interface LegitimizationMeasures { 1553 1554 // Array of legitimization measures that 1555 // are to be applied. 1556 measures: MeasureInformation[]; 1557 1558 // True if the client is expected to eventually satisfy all requirements. 1559 // Default (if missing) is false. 1560 is_and_combinator?: boolean; 1561 1562 // True if the requested operation is categorically forbidden. 1563 // The measures array will be empty in this case. 1564 verboten: boolean; 1565 } 1566 1567 1568 .. _Database-upgrades: 1569 1570 Database upgrades 1571 ----------------- 1572 1573 Before installing a new exchange version, you should probably make a backup of 1574 the existing database and study the release notes on migration. In general, 1575 the way to migrate is to stop all existing Taler exchange processes and run: 1576 1577 .. code-block:: console 1578 1579 $ taler-exchange-dbinit 1580 1581 This will migrate the existing schema to the new schema. You also may need 1582 to grant Taler exchange processes the rights to the new tables (see last 1583 step of database setup). 1584 1585 .. note:: 1586 1587 The **taler-exchange-dbconfig** tool can be used to automate the database 1588 migration. In general, simply invoking it again should trigger the 1589 migration including **taler-exchange-dbinit** and setting the permissions. 1590 1591 1592 If you do not want to keep any data from the previous installation, the 1593 exchange database can be fully re-initialized using: 1594 1595 .. code-block:: console 1596 1597 $ taler-exchange-dbinit --reset 1598 1599 However, running this command will result in all data in the database 1600 being lost, which may result in significant financial liabilities as the 1601 exchange can then not detect double-spending. Hence this operation must 1602 not be performed in a production system. You still also need to then 1603 grant the permissions to the other exchange processes again. 1604 1605 .. _ExchangeBenchmarking: 1606 1607 Benchmarking 1608 ============ 1609 1610 This chapter describes how to run various benchmarks against a Taler exchange. 1611 These benchmark can be used to measure the performance of the exchange by 1612 running a (possibly large) number of simulated clients against one Taler 1613 deployment with a bank, exchange and (optionally) auditor. 1614 1615 Real benchmarks that are intended to demonstrate the scalability of GNU Taler 1616 should not use the tools presented in this section: they may be suitable for 1617 microbenchmarking and tuning, but the setup is inherently not optimized for 1618 performance or realism, both for the load generation and the server side. 1619 Thus, we do not recommend using these performance numbers to assess the 1620 scalability of GNU Taler. That said, the tools can be useful to help identify 1621 performance issues. 1622 1623 The ``taler-unified-setup.sh`` script can be used to launch all required 1624 services and clients. However, the resulting deployment is simplistic 1625 (everything on the local machine, one single-threaded process per service 1626 type) and not optimized for performance at all. However, this can still be 1627 useful to assess the performance impact of changes 1628 to the code or configuration. 1629 1630 The various configuration files used in the code snippets in this section can 1631 be found in the ``src/benchmark/`` directory of the exchange. These are 1632 generally intended as starting points. Note that the configuration files 1633 ending in ``.edited`` are created by ``taler-unified-setup.sh`` and contain 1634 some options that are determined at runtime by the setup logic provided by 1635 ``taler-unified-setup.sh``. 1636 1637 1638 .. _Benchmark-choose-bank: 1639 1640 Choosing a bank 1641 --------------- 1642 1643 For the bank, both a fakebank (``-f``) and libeufin-based (``-ns``) 1644 bank deployment are currently supported by all benchmark tools and 1645 configuration templates. 1646 1647 Fakebank is an ultra-fast in-memory implementation of the Taler bank API. It 1648 is suitable when the goal is to benchmark the core GNU Taler payment system 1649 and to ignore the real-time gross settlement (RTGS) system typically provided 1650 by an existing bank. When using the fakebank, ``taler-unified-setup.sh`` must 1651 be started with the ``-f`` option and be told to use the right exchange bank 1652 account from the configuration files via ``-u exchange-account-1``. 1653 1654 .. code-block:: console 1655 1656 $ dropdb talercheck; createdb talercheck 1657 $ taler-unified-setup.sh -emwt -c $CONF -f -u exchange-account-1 1658 1659 1660 libeufin is GNU Taler's adapter to the core banking system using the EBICS 1661 banking protocol standard. It uses a Postgres database to persist data and is 1662 thus much slower than fakebank. If your GNU Taler deployment uses libeufin in 1663 production, it likely makes sense to benchmark with libeufin. When using the 1664 fakebank, ``taler-unified-setup.sh`` must be started with the ``-ns`` options 1665 (starting libeufin-nexus and libeufin-bank) and be told to use the right 1666 exchange bank account from the configuration files via ``-u 1667 exchange-account-2``. Note that ``taler-unified-setup.sh`` currently cannot 1668 reset a libeufin database, and also will not run if the database is already 1669 initialized. Thus, you must re-create the database every time before 1670 running the command: 1671 1672 .. code-block:: console 1673 1674 $ dropdb talercheck; createdb talercheck 1675 $ taler-unified-setup.sh -emwt -c $CONF -ns -u exchange-account-2 1676 1677 1678 taler-bank-benchmark 1679 -------------------- 1680 1681 This is the simplest benchmarking tool, simulating only the bank 1682 interaction. 1683 1684 .. code-block:: console 1685 1686 $ CONF="benchmark-cs.conf" 1687 $ # or with libeufin 1688 $ dropdb talercheck; createdb talercheck 1689 $ taler-unified-setup.sh -emwt -c "$CONF" -f -u exchange-account-1 1690 $ # Once <<READY>>, in another shell (remember to set $CONF): 1691 $ time taler-bank-benchmark -c "$CONF" -r 40 -p 4 -P4 -u exchange-account-1 -f 1692 $ # or with libeufin 1693 $ dropdb talercheck; createdb talercheck 1694 $ taler-unified-setup.sh -emwt -c "$CONF" -ns -u exchange-account-2 1695 $ # Once <<READY>>, in another shell (remember to set $CONF): 1696 $ time taler-bank-benchmark -c "$CONF" -r 40 -p 1 -P1 -u exchange-account-2 1697 1698 For each *parallel* (``-p``) client, a number of *reserves* (``-r``) is first 1699 established by **transferring** money from a "user" account (42) to the 1700 Exchange's account with the respective reserve public key as wire subject. 1701 Processing is then handled by *parallel* (``-P``) service workers. 1702 1703 1704 taler-exchange-benchmark 1705 ------------------------ 1706 1707 This benchmarking tool simulates a number of clients withdrawing, 1708 depositing and refreshing coins. Operations that are not covered by the 1709 ``taler-exchange-benchmark`` tool today include closing reserves, refunds, 1710 recoups and P2P payments. 1711 1712 .. code-block:: console 1713 1714 $ CONF="benchmark-cs.conf" # -rsa also makes sense 1715 $ # With fakebank 1716 $ dropdb talercheck; createdb talercheck 1717 $ taler-unified-setup.sh -aemwt -c "$CONF" -f -u exchange-account-1 1718 $ # Once <<READY>>, in another shell (remember to set $CONF): 1719 $ taler-exchange-benchmark -c "$CONF".edited -u exchange-account-1 -n 1 -p1 -r 5 -f 1720 $ # 1721 $ # With libeufin 1722 $ dropdb talercheck; createdb talercheck 1723 $ taler-unified-setup.sh -aemwt -c "$CONF" -ns -u exchange-account-2 1724 $ # Once <<READY>>, in another shell (remember to set $CONF): 1725 $ taler-exchange-benchmark -c "$CONF".edited -u exchange-account-2 -L WARNING -n 1 -p1 -r 5 1726 1727 For each *parallel* (``-p``) client, a number of *reserves* (``-r``) is first 1728 established by **transferring** money from a "user" account (42) to the 1729 Exchange's account with the respective reserve public key as wire subject. 1730 Next, the client will **withdraw** a *number of coins* (``-n``) from the 1731 reserve and **deposit** them. Additionally, a *fraction* (``-R``) of the dirty 1732 coins will then be subject to **refreshing**. For some deposits, the auditor 1733 will receive **deposit confirmations**. 1734 1735 The output of ``taler-exchange-benchmark`` will include for each parallel 1736 client the total time spent in each of the major operations, possible 1737 repetitions (i.e. if the operation failed the first time), total execution 1738 time (operating system and user space) and other details. 1739 1740 1741 taler-aggregator-benchmark 1742 -------------------------- 1743 1744 This is another simple benchmark tool that merely prepares an exchange 1745 database to run a stand-alone benchmark of the ``taler-exchange-aggregator`` 1746 tool. After preparing a database and running the tool, you can then 1747 run one or more ``taler-exchange-aggregator`` processes and measure how 1748 quickly they perform the aggregation work. 1749 1750 .. code-block:: console 1751 1752 $ CONF=benchmark-rsa.conf 1753 $ taler-exchange-dbinit -c "$CONF" --reset 1754 $ ./taler-aggregator-benchmark -c "$CONF" -m 500 -r 10 -d 100 1755 $ time taler-exchange-aggregator -c "$CONF" --test 1756 1757 This above commands will first create 100 deposits with 10 refunds into each 1758 of 500 merchant accounts using randomized time stamps. Afterwards, it will 1759 time a single aggregator process in ``--test`` mode (asking it to terminate 1760 as soon as there is no more pending work). 1761 1762 1763 FIXMEs 1764 ====== 1765 1766 * We should have some summary with the inventory of services that should be 1767 running. Systemd by default doesn't show this nicely. Maybe suggest running 1768 "systemd list-dependencies taler-exchange.target"? 1769 * What happens when the TWG doesn't like one particular outgoing transaction? 1770 How to recover from that as a sysadmin when it happens in practice?