api-auditor.rst (23942B)
1 .. 2 This file is part of GNU TALER. 3 Copyright (C) 2018-2024 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Affero General Public License as published by the Free Software 7 Foundation; either version 3.0, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. 12 13 You should have received a copy of the GNU Affero General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 16 @author Christian Grothoff 17 18 =================== 19 Auditor RESTful API 20 =================== 21 22 The API specified here follows the :ref:`general conventions <http-common>` 23 for all details not specified in the individual requests. 24 The `glossary <https://docs.taler.net/taler-developer-manual.html#developer-glossary>`_ 25 defines all specific terms used in this section. 26 27 28 --------------- 29 Version History 30 --------------- 31 32 The current protocol version is **v2**. 33 34 * The auditor SPA is currently targeting protocol version **v1**. 35 36 **Version history:** 37 38 * ``v2``: Adds a few additional GET endpoints to expose more auditor data 39 40 **Upcoming versions:** 41 42 * none anticipated 43 44 **Ideas for future version:** 45 46 * ``vXXX``: marker for features not yet targeted for release 47 48 49 .. _authentication: 50 51 -------------- 52 Authentication 53 -------------- 54 55 Each auditor instance has separate authentication settings for the private API resources 56 of that instance. 57 58 Currently, the API supports two main authentication methods: 59 60 * ``external``: With this method, no checks are done by the auditor backend. 61 Instead, a reverse proxy / API gateway must do all authentication/authorization checks. 62 * ``token``: With this method, the client must provide a ``Authorization: Bearer $TOKEN`` 63 header, where ``$TOKEN`` is a secret authentication token configured for the instance which must begin with the RFC 8959 prefix. 64 65 .. _auditor-version: 66 67 ------------------------- 68 Obtaining Auditor Version 69 ------------------------- 70 71 This endpoint is used by merchants to obtain a list of all exchanges audited by 72 this auditor. This may be required for the merchant to perform the required 73 know-your-customer (KYC) registration before issuing contracts. 74 75 .. include:: auditor/get-config.rst 76 77 78 .. _deposit-confirmation: 79 80 --------------------- 81 Deposit Confirmations 82 --------------------- 83 84 Merchants should probabilistically submit some of the deposit 85 confirmations they receive from the exchange to auditors to ensure 86 that the exchange does not lie about recording deposit confirmations 87 with the exchange. Participating in this scheme ensures that in case 88 an exchange runs into financial trouble to pay its obligations, the 89 merchants that did participate in detecting the bad behavior can be 90 paid out first. 91 92 .. include:: auditor/put-deposit-confirmation.rst 93 94 95 .. _auditor-monitoring-spa-api: 96 97 -------------- 98 Monitoring API 99 -------------- 100 101 The following entries specify how to access the results of an audit. 102 103 For most endpoints, rows may be marked as 'suppressed' to not send them again 104 upon subsequent GET requests. To do this, a 105 :ts:type:`GenericAuditorMonitorPatchRequest` object is used in the respective 106 PATCH request. 107 108 **Details:** 109 110 .. ts:def:: GenericAuditorMonitorPatchRequest 111 112 interface GenericAuditorMonitorPatchRequest { 113 114 // If true, subsequent GET requests will not return this element by default 115 suppressed : boolean; 116 117 } 118 119 120 .. _fee-time-inconsistency-list: 121 122 Fee Time Inconsistencies 123 ------------------------ 124 125 This section highlights cases where validity periods associated with wire fees 126 the exchange may charge merchants are invalid. This usually means that the 127 validity periods given for the same type of fee are overlapping and it is thus 128 unclear which fee really applies. This is a sign of a serious 129 misconfiguration or data corruption as usually the exchange logic should 130 prevent such a fee configuration from being accepted. 131 132 .. include:: auditor/get-monitoring-fee-time-inconsistency.rst 133 134 .. include:: auditor/patch-monitoring-fee-time-inconsistency-SERIAL_ID.rst 135 136 .. _emergency-list: 137 138 Emergencies 139 ----------- 140 141 This endpoint is used to obtain a list of emergencies. 142 143 Emergencies are errors where the total value of coins deposited (of a 144 particular denomination) exceeds the total value that the exchange remembers 145 issuing. This usually means that the private keys of the exchange were 146 compromised (stolen or factored) and subsequently used to sign coins off the 147 books. If this happens, all coins of the respective denomination that the 148 exchange has redeemed so far may have been created by the attacker, and the 149 exchange would have to refund all of the outstanding coins from ordinary 150 users. Thus, the risk exposure is the amount of coins in circulation for a 151 particular denomination and the maximum loss for the exchange from this type 152 of compromise. 153 154 The difference between emergencies and emergencies by count is how the auditor 155 detected the problem: by comparing amounts, or by counting coins. 156 Theoretically, counting coins should always detect an issue first, but given 157 the importance of emergencies, the auditor checks both total amounts and total 158 numbers of coins (they may differ as coins may be partially deposited). 159 160 .. include:: auditor/get-monitoring-emergency.rst 161 162 .. include:: auditor/patch-monitoring-emergency-SERIAL_ID.rst 163 164 .. _emergency-by-count-list: 165 166 Emergencies By Count 167 -------------------- 168 169 This endpoint is used to obtain a list of emergencies by count. 170 171 Emergencies are errors where more coins were deposited than the 172 exchange remembers issuing. This usually means that the private keys 173 of the exchange were compromised (stolen or factored) and subsequently 174 used to sign coins off the books. If this happens, all coins of the 175 respective denomination that the exchange has redeemed so far may have 176 been created by the attacker, and the exchange would have to refund 177 all of the outstanding coins from ordinary users. Thus, the risk 178 exposure is the amount of coins in circulation for a particular 179 denomination and the maximum loss for the exchange from this type of 180 compromise. 181 182 Emergencies "by count" are cases where this type of money printing was 183 detected simply by counting the number of coins the exchange officially put 184 into circulation and comparing it to the number of coins that were redeemed. 185 If the number of redeemed coins is higher than the number of issued coins, the 186 auditor reports an emergency-by-count. 187 188 .. include:: auditor/get-monitoring-emergency-by-count.rst 189 190 .. include:: auditor/patch-monitoring-emergency-by-count-SERIAL_ID.rst 191 192 193 .. _row-inconsistency-list: 194 195 Row Inconsistencies 196 ------------------- 197 198 This section highlights inconsistencies in a specific row of a specific table 199 of the exchange. Row inconsistencies are reported from different sources, and 200 largely point to some kind of data corruption (or bug). Nothing is implied 201 about the seriousness of the inconsistency. Most inconsistencies are detected 202 if some signature fails to validate. The affected table is noted in the 203 'table' field. A description of the nature of the inconsistency is noted in 204 'diagnostic'. 205 206 .. include:: auditor/get-monitoring-row-inconsistency.rst 207 208 209 .. include:: auditor/patch-monitoring-row-inconsistency-SERIAL_ID.rst 210 211 .. _reserve-in-inconsistency-list: 212 213 Reserve In Inconsistencies 214 -------------------------- 215 216 This section lists cases where the exchange's and auditor's expectation of 217 amounts transferred into a reserve differs. Basically, the exchange database 218 states that a certain reserve was credited for a certain amount via a wire 219 transfer, but the auditor disagrees about this basic fact. This may result in 220 either a customer losing funds (by being issued less digital cash than they 221 should be) or the exchange losing funds (by issuing a customer more digital 222 cash than they should be). 223 224 .. include:: auditor/get-monitoring-reserve-in-inconsistency.rst 225 226 227 228 229 .. include:: auditor/patch-monitoring-reserve-in-inconsistency-SERIAL_ID.rst 230 231 232 .. _purse-not-closed-inconsistencies-list: 233 234 Purse Not Closed Inconsistencies 235 -------------------------------- 236 237 This section highlights cases, in which either payer or payee did not finish 238 their part of a P2P payment. This caused a purse --– which may contain some 239 money --- to reach its expiration date. However, the exchange failed to 240 properly expire the purse, which means the payer did not get their money back. 241 The cause is usually that the **taler-exchange-expire** helper is not running 242 properly. 243 244 245 .. include:: auditor/get-monitoring-purse-not-closed-inconsistencies.rst 246 247 248 .. include:: auditor/patch-monitoring-purse-not-closed-inconsistencies-SERIAL_ID.rst 249 250 251 Early Aggregations 252 ------------------ 253 254 .. _early-aggregation-list: 255 256 257 This endpoint returns cases in which wire transfers are encountered before their 258 justifications. This can be harmless, if the justifications appear shortly afterwards. 259 260 .. include:: auditor/get-monitoring-early-aggregation.rst 261 262 263 264 Pending Deposits 265 ---------------- 266 267 .. _pending-deposits-list: 268 269 This endpoint returns cases in which deposits are pending, that is an 270 expected wire transfer for a given deposit was not yet found even though 271 it is past the wire deadline. 272 This can be harmless, if the wire transfers appear shortly afterwards. 273 274 .. include:: auditor/get-monitoring-pending-deposits.rst 275 276 277 278 279 280 281 .. _reserve-not-closed-inconsistency-list: 282 283 Reserve Not Closed Inconsistencies 284 ---------------------------------- 285 286 This section highlights cases, in which reserves were not closed, despite being expired. 287 As a result, customers that wired funds to the exchange and then failed to withdraw them 288 are not getting their money back. The cause is usually that the **taler-exchange-closer** 289 process is not running properly. 290 291 .. include:: auditor/get-monitoring-reserve-not-closed-inconsistency.rst 292 293 294 295 296 .. include:: auditor/patch-monitoring-reserve-not-closed-inconsistency-SERIAL_ID.rst 297 298 299 300 301 .. _reserve-balance-insufficient-inconsistency-list: 302 303 Reserve Balance Insufficient Inconsistencies 304 -------------------------------------------- 305 306 This section highlights cases where more coins were withdrawn from a 307 reserve than the reserve contained funding for. This is a serious 308 compromise resulting in proportional financial losses to the exchange. 309 310 .. include:: auditor/get-monitoring-reserve-balance-insufficient-inconsistency.rst 311 312 313 314 315 316 .. include:: auditor/patch-monitoring-reserve-balance-insufficient-inconsistency-SERIAL_ID.rst 317 318 319 .. _invalid-signature-losses-list: 320 321 Invalid Signature Losses 322 ------------------------ 323 324 This section lists operations that the exchange performed, but for which the 325 signatures provided are invalid. Hence the operations are invalid and the 326 amount involved could be a loss for the exchange (as the involved parties 327 could successfully dispute the resulting transactions). 328 329 .. include:: auditor/get-monitoring-bad-sig-losses.rst 330 331 332 .. include:: auditor/patch-monitoring-bad-sig-losses-SERIAL_ID.rst 333 334 335 .. _coin-inconsistency-list: 336 337 Coin Inconsistencies 338 -------------------- 339 340 This section lists cases where the exchange made arithmetic errors found when 341 looking at the transaction history of a coin. The totals sum up the differences 342 in amounts that matter for profit/loss calculations of the exchange. When an 343 exchange merely shifted money from customers to merchants (or vice versa) without 344 any effects on its own balance, those entries are excluded from the total. 345 346 .. include:: auditor/get-monitoring-coin-inconsistency.rst 347 348 349 .. include:: auditor/patch-monitoring-coin-inconsistency-SERIAL_ID.rst 350 351 352 353 354 .. _denominations-without-signatures-list: 355 356 Denominations Without Signatures 357 -------------------------------- 358 359 This section highlights denomination keys that lack a proper 360 signature from the **taler-auditor-offline** tool. This may be 361 legitimate, say in case where the auditor's involvement in the 362 exchange business is ending and a new auditor is responsible for 363 future denominations. So this must be read with a keen eye on the 364 business situation. 365 366 .. include:: auditor/get-monitoring-denominations-without-sigs.rst 367 368 369 370 .. include:: auditor/patch-monitoring-denominations-without-sigs-SERIAL_ID.rst 371 372 373 .. _misattribution-in-inconsistency-list: 374 375 Misattribution In Inconsistencies 376 --------------------------------- 377 378 This section lists cases where the sender account record of an incoming wire 379 transfer differs between the exchange and the bank. This may cause funds to 380 be sent to the wrong account should the reserve be closed with a remaining 381 balance, as that balance would be credited to the original account. 382 383 .. include:: auditor/get-monitoring-misattribution-in-inconsistency.rst 384 385 386 387 .. include:: auditor/patch-monitoring-misattribution-in-inconsistency-SERIAL_ID.rst 388 389 390 391 .. _deposit-confirmations-list: 392 393 Deposit Confirmations 394 --------------------- 395 396 This section contains a list of deposits confirmations that an exchange 397 provided to merchants but *failed* to store in its own database. This is 398 indicative of potential fraud by the exchange operator, as the exchange should 399 only issue deposit confirmations after storing the respective deposit records 400 in its database. Not storing the deposit data means that the exchange would 401 not pay the merchant (pocketing the money) or allow the customer to 402 double-spend the money (which is naturally also not good). 403 404 Note that entries could appear in this list also because the exchange database 405 replication is delayed. Hence, entries that are only a few seconds old might 406 not be indicative of an actual problem. If entries in this list are more than 407 a few seconds old, the first thing to check is whether or not the database 408 replication from the exchange is working properly. 409 410 .. include:: auditor/get-monitoring-deposit-confirmations.rst 411 412 413 .. include:: auditor/patch-monitoring-deposit-confirmations-SERIAL_ID.rst 414 415 416 .. _denomination-key-validity-withdraw-inconsistency-list: 417 418 Denomination Key Validity Withdraw Inconsistencies 419 -------------------------------------------------- 420 421 This section highlights cases, where denomination keys were used to sign coins 422 withdrawn from a reserve before the denomination was valid or after it was 423 already expired for signing. This doesn't exactly imply any financial loss 424 for anyone, it is mostly weird and may have affected the fees the customer 425 paid. 426 427 .. include:: auditor/get-monitoring-denomination-key-validity-withdraw-inconsistency.rst 428 429 .. include:: auditor/patch-monitoring-denomination-key-validity-withdraw-inconsistency-SERIAL_ID.rst 430 431 .. _amount-arithmetic-inconsistency-list: 432 433 Amount Arithmetic Inconsistencies 434 --------------------------------- 435 436 This endpoint is used to obtain a list of amount arithmetic inconsistencies. 437 438 This section lists cases where the arithmetic of the exchange involving 439 amounts disagrees with the arithmetic of the auditor. Disagreements imply 440 that either the exchange made a loss (sending out too much money), or screwed 441 a customer (and thus at least needs to fix the financial damage done to the 442 customer). The profitable column is set to true if the arithmetic problem was 443 determined to be profitable for the exchange, false if the problem resulted 444 in a net loss for the exchange. 445 446 447 .. include:: auditor/get-monitoring-amount-arithmetic-inconsistency.rst 448 449 450 .. include:: auditor/patch-monitoring-amount-arithmetic-inconsistency-SERIAL_ID.rst 451 452 453 .. _wire-format-inconsistency-list: 454 455 Wire Format Inconsistencies 456 --------------------------- 457 458 This section highlights cases where the wire transfer subject 459 was used more than once and is thus not unique. This indicates 460 a problem with the bank's implementation of the revenue API, as 461 the bank is supposed to warrant uniqueness of wire transfer 462 subjects exposed via the revenue API (and bounce non-unique 463 transfers). 464 465 .. include:: auditor/get-monitoring-wire-format-inconsistency.rst 466 467 468 469 470 .. include:: auditor/patch-monitoring-wire-format-inconsistency-SERIAL_ID.rst 471 472 473 .. _aml-holds-list: 474 475 AML Holds 476 --------- 477 478 This endpoint is used to obtain a list of the wire transfers the exchange 479 aggregated but did not execute. 480 481 The exchange aggregates the deposits it owes to a merchant, decides what the 482 payout should be, records that decision, and only then makes the wire 483 transfer. Between those two steps the money is still the exchange's. An 484 ``aggregation_tracking`` row is therefore not proof that the merchant was 485 paid; a ``wire_out`` row is. This endpoint lists the transfers that are stuck 486 in between, one row per wire transfer identifier, and the row disappears once 487 the transfer is made. 488 489 The exchange has two legitimate reasons to sit on such funds. It may not pay 490 out to an account whose KYC/AML requirements are still open; and it need not 491 make a transfer whose amount would not survive the wire fee, in which case it 492 waits for further deposits to the same account. ``deferral_reason`` says which 493 of the two the exchange gave, or ``NONE`` if it gave neither. The three cases 494 are also totalled separately, as the ``total_aml_hold``, 495 ``total_small_aggregate`` and ``total_transfer_lag`` balances (see 496 :ref:`balances-list`), so that "the exchange is waiting for legitimization 497 data", "the exchange is waiting for more deposits" and "the exchange is not 498 paying" cannot be confused with each other or with having paid. 499 500 Whether a hold is *justified* is a question for a human, not for the auditor: 501 the auditor reports what is being withheld and from whom, and leaves the 502 judgement to the reader. What it does check is that the exchange does not get 503 to withhold money silently, and that the reason it gives is consistent with 504 everything else the auditor can see. 505 506 .. note:: 507 508 ``deferral_reason`` is the exchange's own statement, taken from its 509 append-only ``aggregation_deferrals`` table, which is replicated to the 510 auditor. The auditor does not overrule it, but it does check it: the amount 511 against its own recomputation of what the aggregate is worth, and a ``KYC`` 512 claim against the ``legitimization_measures`` and 513 ``legitimization_processes`` tables. If the exchange names a measure that is 514 not open, the hold is still reported as a ``KYC`` hold and a row 515 inconsistency against ``aggregation_deferrals`` is raised alongside it. An 516 exchange-internal audit (the ``-i`` option of 517 **taler-helper-auditor-transfer**) additionally compares the claim with the 518 live ``aggregation_transient`` table, which cannot be replicated. 519 520 .. include:: auditor/get-monitoring-aml-holds.rst 521 522 523 .. include:: auditor/patch-monitoring-aml-holds-SERIAL_ID.rst 524 525 526 527 528 .. _closure-lags-list: 529 530 Closure Lags 531 ------------ 532 533 This endpoint is used to obtain a list of closure lags. 534 535 A closure lag happens if a reserve should have closed a reserve and 536 wired (remaining) funds back to the originating account, but did not 537 do so on time. Significant lag may be indicative of fraud, while 538 moderate lag is indicative that the systems may be too slow to handle the 539 load. Small amounts of lag can occur in normal operation. 540 541 If closure lag is experienced, the administrator should check that 542 the **taler-exchange-closer** component is operating correctly. 543 544 545 .. include:: auditor/get-monitoring-closure-lags.rst 546 547 548 .. include:: auditor/patch-monitoring-closure-lags-SERIAL_ID.rst 549 550 551 552 553 .. _wire-out-inconsistency-list: 554 555 Wire Out Inconsistencies 556 ------------------------ 557 558 This section highlights cases where the exchange wired a different amount to a 559 destination account than the auditor expected. 560 561 .. include:: auditor/get-monitoring-wire-out-inconsistency.rst 562 563 564 565 566 567 .. include:: auditor/patch-monitoring-wire-out-inconsistency-SERIAL_ID.rst 568 569 570 .. _reserve-balance-summary-wrong-inconsistency-list: 571 572 Reserve Balance Summary Wrong Inconsistencies 573 --------------------------------------------- 574 575 This section highlights cases, where the exchange's and auditors' 576 expectation of the amount of money left in a reserve differs. 577 578 .. include:: auditor/get-monitoring-reserve-balance-summary-wrong-inconsistency.rst 579 580 .. include:: auditor/patch-monitoring-reserve-balance-summary-wrong-inconsistency-SERIAL_ID.rst 581 582 583 .. _row-minor-inconsistencies-list: 584 585 Row Minor Inconsistencies 586 ------------------------- 587 588 The section highlights inconsistencies where a row in an exchange table has a 589 value that does not satisfy expectations (such as a malformed 590 signature). These are cause for concern, but not necessarily point to a 591 monetary loss (yet). 592 593 .. include:: auditor/get-monitoring-row-minor-inconsistencies.rst 594 595 .. include:: auditor/patch-monitoring-row-minor-inconsistencies-SERIAL_ID.rst 596 597 598 ------------------------- 599 Monitoring Auditor Status 600 ------------------------- 601 602 The following entries specify how to access information the auditor keeps to 603 properly perform audits. These tables do not contain inconsistencies, instead 604 they store information about balances, reserves, purses etc. Values in these 605 tables should not differ from their respective exchanges' version. 606 607 .. _balances-list: 608 609 Balances 610 -------- 611 612 Returns the various balances the auditor tracks for the exchange, such as 613 coins in circulation, fees earned, losses experienced, etc. 614 615 Three of the keys concern money the exchange owes a merchant and has not sent. 616 Which one an amount lands in follows the reason the exchange gave for not 617 sending it: 618 619 ``total_aml_hold`` 620 The exchange says a KYC/AML requirement against the recipient is still open. 621 This is money withheld pending legitimization. 622 623 ``total_small_aggregate`` 624 The exchange says what it has collected for the account so far would not 625 cover the wire fee, so it is waiting for further deposits. This is normal 626 operation rather than an irregularity; it has a key of its own so that it 627 does not inflate the other two, which are not. 628 629 ``total_transfer_lag`` 630 The exchange gave no reason at all. This is money the exchange simply has 631 not paid out. 632 633 All three are current state rather than a running tally: the amount is 634 recomputed from the outstanding transfers on every audit run, so it falls again 635 as transfers are executed, and a transfer moves between the keys if the 636 exchange changes what it says about it. They are distinct from 637 ``total_amount_lag``, which counts deposits the exchange has not aggregated at 638 all. The individual transfers behind all three keys are listed by 639 :ref:`aml-holds-list`. 640 641 .. include:: auditor/get-monitoring-balances.rst 642 643 644 .. _historic-denomination-revenue-list: 645 646 Historic Denomination Revenue 647 ----------------------------- 648 649 This endpoint is used to obtain a list of historic denomination revenue, that 650 is the profits and losses an exchange has made from coins of a particular 651 denomination where the denomination is past its (deposit) expiration and thus 652 all values are final. 653 654 .. include:: auditor/get-monitoring-historic-denomination-revenue.rst 655 656 .. _historic-reserve-summary-list: 657 658 Historic Reserve Summary 659 ------------------------ 660 661 This section summarizes historic profits an exchange 662 made from reserves and associated reserve-specific 663 fees. 664 665 .. include:: auditor/get-monitoring-historic-reserve-summary.rst 666 667 668 .. _reserves-list: 669 670 671 Reserves 672 -------- 673 674 This endpoint is used to obtain a list of open reserves that the auditor is 675 currently tracking balances for. 676 677 .. include:: auditor/get-monitoring-reserves.rst 678 679 680 .. _purses-list: 681 682 Purses 683 ------ 684 685 This endpoint is used to obtain information about open purses. 686 687 .. include:: auditor/get-monitoring-purses.rst 688 689 Progress 690 -------- 691 692 This section contains information about the auditing progress an auditor has made. 693 694 .. include:: auditor/get-monitoring-progress.rst 695 696 ---------- 697 Complaints 698 ---------- 699 700 This endpoint is used by the wallet or merchants to submit proof of 701 misbehavior of an exchange to the auditor. 702 703 .. note:: 704 705 To be designed and implemented. 706 707 .. include:: auditor/put-complain.rst 708 709 Complain about misbehavior to the auditor.