rest.rst (40606B)
1 .. 2 This file is part of Anastasis 3 Copyright (C) 2019-2022 Anastasis SARL 4 5 Anastasis 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 2.1, or (at your option) any later version. 8 9 Anastasis 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 Anastasis; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 16 @author Christian Grothoff 17 @author Dominik Meister 18 @author Dennis Neufeld 19 20 21 ======== 22 REST API 23 ======== 24 25 .. _http-common: 26 27 ------------------------- 28 HTTP Request and Response 29 ------------------------- 30 31 Certain response formats are common for all requests. They are documented here 32 instead of with each individual request. Furthermore, we note that clients may 33 theoretically fail to receive any response. In this case, the client should 34 verify that the Internet connection is working properly, and then proceed to 35 handle the error as if an internal error (500) had been returned. 36 37 .. http:any:: /* 38 39 40 **Request:** 41 42 Unless specified otherwise, HTTP requests that carry a message body must 43 have the content type ``application/json``. 44 45 :reqheader Content-Type: application/json 46 47 **Response:** 48 49 :resheader Content-Type: application/json 50 51 :http:statuscode:`200 Ok`: 52 The request was successful. 53 :http:statuscode:`400 Bad request`: 54 One of the arguments to the request is missing or malformed. 55 :http:statuscode:`500 Internal server error`: 56 This always indicates some serious internal operational error of the Anastasis 57 provider, such as a program bug, database problems, etc., and must not be used for 58 client-side problems. When facing an internal server error, clients should 59 retry their request after some delay. We recommended initially trying after 60 1s, twice more at randomized times within 1 minute, then the user should be 61 informed and another three retries should be scheduled within the next 24h. 62 If the error persists, a report should ultimately be made to the auditor, 63 although the auditor API for this is not yet specified. However, as internal 64 server errors are always reported to the exchange operator, a good operator 65 should naturally be able to address them in a timely fashion, especially 66 within 24h. 67 68 Unless specified otherwise, all error status codes (4xx and 5xx) have a message 69 body with an `ErrorDetail` JSON object. 70 71 **Details:** 72 73 .. ts:def:: ErrorDetail 74 75 interface ErrorDetail { 76 77 // Numeric error code unique to the condition, see ``gnu-taler-error-codes`` in GANA. 78 // The other arguments are specific to the error value reported here. 79 code: number; 80 81 // Human-readable description of the error, i.e. "missing parameter", "commitment violation", ... 82 // Should give a human-readable hint about the error's nature. Optional, may change without notice! 83 hint?: string; 84 85 } 86 87 ----------------------- 88 Protocol Version Ranges 89 ----------------------- 90 91 Anastasis services expose the range of API versions they support. Clients in 92 turn have an API version range they support. These version ranges are written 93 down in the `libtool version format 94 <https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html>`__. 95 96 A protocol version is a positive, non-zero integer. A protocol version range consists of three components: 97 98 1. The ``current`` version. This is the latest version of the protocol supported by the client or service. 99 2. The ``revision`` number. This value should usually not be interpreted by the client/server, but serves 100 purely as a comment. Each time a service/client for a protocol is updated while supporting the same 101 set of protocol versions, the revision should be increased. 102 In rare cases, the revision number can be used to work around unintended breakage in deployed 103 versions of a service. This is discouraged and should only be used in exceptional situations. 104 3. The ``age`` number. This non-zero integer identifies with how many previous protocol versions this 105 implementation is compatible. An ``age`` of 0 implies that the implementation only supports 106 the ``current`` protocol version. The ``age`` must be less or equal than the ``current`` protocol version. 107 108 To avoid confusion with semantic versions, the protocol version range is written down in the following format: 109 110 .. code:: none 111 112 current[:revision[:age]] 113 114 The angle brackets mark optional components. If either ``revision`` or ``age`` are omitted, they default to 0. 115 116 Examples: 117 118 * "1" and "1" are compatible 119 * "1" and "2" are **incompatible** 120 * "2:0:1" and "1:0:0" are compatible 121 * "2:5:1" and "1:10:0" are compatible 122 * "4:0:1" and "2:0:0" are **incompatible** 123 * "4:0:1" and "3:0:0" are compatible 124 125 .. note:: 126 127 `Semantic versions <https://semver.org/>`__ are not a good tool for this job, as we concisely want to express 128 that the client/server supports the last ``n`` versions of the protocol. 129 Semantic versions don't support this, and semantic version ranges are too complex for this. 130 131 .. warning:: 132 133 A client doesn't have one single protocol version range. Instead, it has 134 a protocol version range for each type of service it talks to. 135 136 .. warning:: 137 138 For privacy reasons, the protocol version range of a client should not be 139 sent to the service. Instead, the client should just use the two version ranges 140 to decide whether it will talk to the service. 141 142 143 .. _encodings-ref: 144 145 ---------------- 146 Common encodings 147 ---------------- 148 149 This section describes how certain types of values are represented throughout the API. 150 151 .. _base32: 152 153 Binary Data 154 ^^^^^^^^^^^ 155 156 .. ts:def:: foobase 157 158 type Base32 = string; 159 160 Binary data is generally encoded using Crockford's variant of Base32 161 (http://www.crockford.com/wrmg/base32.html), except that "U" is not excluded 162 but also decodes to "V" to make OCR easy. We will still simply use the JSON 163 type "base32" and the term "Crockford Base32" in the text to refer to the 164 resulting encoding. 165 166 167 Hash codes 168 ^^^^^^^^^^ 169 Hash codes are strings representing base32 encoding of the respective 170 hashed data. See `base32`_. 171 172 .. ts:def:: HashCode 173 174 // 64-byte hash code. 175 type HashCode = string; 176 177 .. ts:def:: ShortHashCode 178 179 // 32-byte hash code. 180 type ShortHashCode = string; 181 182 183 184 Large numbers 185 ^^^^^^^^^^^^^ 186 187 Large numbers such as 256 bit keys, are transmitted as other binary data in 188 Crockford Base32 encoding. 189 190 191 Timestamps 192 ^^^^^^^^^^ 193 194 Timestamps are represented by the following structure: 195 196 .. ts:def:: Timestamp 197 198 interface Timestamp { 199 // Milliseconds since epoch, or the special 200 // value "never" to represent an event that will 201 // never happen. 202 t_ms: number | "never"; 203 } 204 205 .. ts:def:: RelativeTime 206 207 interface Duration { 208 // Duration in milliseconds or "forever" 209 // to represent an infinite duration. 210 d_ms: number | "forever"; 211 } 212 213 214 .. _public\ key: 215 216 217 Integers 218 ^^^^^^^^ 219 220 .. ts:def:: Integer 221 222 // JavaScript numbers restricted to integers. 223 type Integer = number; 224 225 Objects 226 ^^^^^^^ 227 228 .. ts:def:: Object 229 230 // JavaScript objects, no further restrictions. 231 type Object = object; 232 233 Keys 234 ^^^^ 235 236 .. ts:def:: EddsaPublicKey 237 238 // EdDSA and ECDHE public keys always point on Curve25519 239 // and represented using the standard 256 bits Ed25519 compact format, 240 // converted to Crockford `Base32`. 241 type EddsaPublicKey = string; 242 243 .. ts:def:: EddsaPrivateKey 244 245 // EdDSA and ECDHE public keys always point on Curve25519 246 // and represented using the standard 256 bits Ed25519 compact format, 247 // converted to Crockford `Base32`. 248 type EddsaPrivateKey = string; 249 250 .. ts:def:: ANASTASIS_PaymentSecretP 251 252 // Random identifier used to later charge a payment. 253 // Always 256 bits of binary data, converted to Crockford `Base32`. 254 type EddsaPrivateKey = string; 255 256 .. _signature: 257 258 Signatures 259 ^^^^^^^^^^ 260 261 262 .. ts:def:: EddsaSignature 263 264 // EdDSA signatures are transmitted as 64-bytes `base32` 265 // binary-encoded objects with just the R and S values (base32_ binary-only). 266 type EddsaSignature = string; 267 268 .. _amount: 269 270 Amounts 271 ^^^^^^^ 272 273 .. ts:def:: Amount 274 275 type Amount = string; 276 277 Amounts of currency are serialized as a string of the format 278 ``<Currency>:<DecimalAmount>``. Taler treats monetary amounts as 279 fixed-precision numbers, with 8 decimal places. Unlike floating point numbers, 280 this allows accurate representation of monetary amounts. 281 282 The following constrains apply for a valid amount: 283 284 1. The ``<Currency>`` part must be at most 11 characters long and may only consist 285 of ASCII letters (``a-zA-Z``). 286 2. The integer part of ``<DecimalAmount>`` may be at most 2^52. 287 3. The fractional part of ``<DecimalAmount>`` may contain at most 8 decimal digits. 288 289 .. note:: 290 291 "EUR:1.50" and "EUR:10" are valid amounts. These are all invalid amounts: "A:B:1.5", "EUR:4503599627370501.0", "EUR:1.", "EUR:.1". 292 293 An amount that is prefixed with a ``+`` or ``-`` character is also used in certain contexts. 294 When no sign is present, the amount is assumed to be positive. 295 296 297 Time 298 ^^^^ 299 300 In signed messages, time is represented using 64-bit big-endian values, 301 denoting microseconds since the UNIX Epoch. ``UINT64_MAX`` represents "never". 302 303 .. sourcecode:: c 304 305 struct GNUNET_TIME_Absolute { 306 uint64_t timestamp_us; 307 }; 308 struct GNUNET_TIME_AbsoluteNBO { 309 uint64_t abs_value_us__; // in network byte order 310 }; 311 struct GNUNET_TIME_Timestamp { 312 // must be round value (multiple of seconds) 313 struct GNUNET_TIME_Absolute abs_time; 314 }; 315 struct GNUNET_TIME_TimestampNBO { 316 // must be round value (multiple of seconds) 317 struct GNUNET_TIME_AbsoluteNBO abs_time; 318 }; 319 320 Cryptographic primitives 321 ^^^^^^^^^^^^^^^^^^^^^^^^ 322 323 All elliptic curve operations are on Curve25519. Public and private keys are 324 thus 32 bytes, and signatures 64 bytes. For hashing, including HKDFs, Taler 325 uses 512-bit hash codes (64 bytes). 326 327 .. sourcecode:: c 328 329 struct GNUNET_HashCode { 330 uint8_t hash[64]; // usually SHA-512 331 }; 332 333 .. _TALER_EcdhEphemeralPublicKeyP: 334 .. sourcecode:: c 335 336 struct TALER_EcdhEphemeralPublicKeyP { 337 uint8_t ecdh_pub[32]; 338 }; 339 340 .. _ANASTASIS_TruthKeyP: 341 .. sourcecode:: c 342 343 struct ANASTASIS_TruthKeyP { 344 struct GNUNET_HashCode key; 345 }; 346 347 .. sourcecode:: c 348 349 struct UUID { 350 uint32_t value[4]; 351 }; 352 353 .. _Signatures: 354 355 Signatures 356 ^^^^^^^^^^ 357 Any piece of signed data, complies to the abstract data structure given below. 358 359 .. sourcecode:: c 360 361 struct Data { 362 struct GNUNET_CRYPTO_EccSignaturePurpose purpose; 363 type1_t payload1; 364 type2_t payload2; 365 ... 366 }; 367 368 /*From gnunet_crypto_lib.h*/ 369 struct GNUNET_CRYPTO_EccSignaturePurpose { 370 /** 371 372 The following constraints apply for a valid amount: 373 374 * This field is used to express the context in 375 * which the signature is made, ensuring that a 376 * signature cannot be lifted from one part of the protocol 377 * to another. See `src/include/taler_signatures.h` within the 378 * exchange's codebase (git://taler.net/exchange). 379 */ 380 uint32_t purpose; 381 /** 382 * This field equals the number of bytes being signed, 383 * namely 'sizeof (struct Data)'. 384 */ 385 uint32_t size; 386 }; 387 388 389 .. _salt: 390 .. _config: 391 392 393 ----------------------- 394 Receiving Configuration 395 ----------------------- 396 397 .. http:get:: /config 398 399 Obtain the configuration details of the escrow provider. 400 This specification corresponds to ``current`` protocol being version **2**. 401 402 **Response:** 403 404 Returns an `EscrowConfigurationResponse`_. 405 406 407 .. _EscrowConfigurationResponse: 408 .. ts:def:: EscrowConfigurationResponse 409 410 interface EscrowConfigurationResponse { 411 412 // Protocol identifier, clarifies that this is an Anastasis provider. 413 name: "anastasis"; 414 415 // libtool-style representation of the Exchange protocol version, see 416 // https://www.gnu.org/software/libtool/manual/html_node/Versioning.html#Versioning 417 // The format is "current:revision:age". 418 version: string; 419 420 // Release version of the source code. 421 // The format is MAJOR.MINOR.MICOR[-GITDATA] 422 // and generally follows the "-v" option of the codebase. 423 // Since **v2**. 424 build_version: string; 425 426 // URN of the implementation (needed to interpret 'revision' in version). 427 // @since v0, may become mandatory in the future. 428 implementation?: string; 429 430 // Name of the business operating the service (for display to the user). 431 business_name?: string; 432 433 // Supported authorization methods. 434 methods: AuthorizationMethodConfig[]; 435 436 // Maximum policy upload size supported. 437 storage_limit_in_megabytes: number; 438 439 // Currencies the provider prices its service in, primary currency 440 // first. Orders created by the provider offer every one of these 441 // as a payable choice, so the wallet decides which one is used. 442 // @since protocol **v3**. 443 currencies?: string[]; 444 445 // Payment required to maintain an account to store policy documents for a year, 446 // in the provider's *primary* currency. 447 // Users can pay more, in which case the storage time will go up proportionally. 448 annual_fee: Amount; 449 450 // Payment required to maintain an account for a year, one entry per 451 // currency in ``currencies``. Empty if the service is free. 452 // Either every entry is zero or none is: a provider that would charge 453 // in one currency and not in another is refusing to price its service 454 // and is rejected by its own configuration check. 455 // @since protocol **v3**. 456 annual_fees?: Amount[]; 457 458 // Payment required to upload truth, in the primary currency. To be paid per upload. 459 truth_upload_fee: Amount; 460 461 // Payment required to upload truth, one entry per currency. 462 // @since protocol **v3**. 463 truth_upload_fees?: Amount[]; 464 465 // Limit on the liability that the provider is offering with 466 // respect to the services provided, in the primary currency. 467 liability_limit: Amount; 468 469 // Limit on the liability, one entry per currency. 470 // @since protocol **v3**. 471 liability_limits?: Amount[]; 472 473 // Salt value with 128 bits of entropy. 474 // Different providers 475 // will use different high-entropy salt values. The resulting 476 // **provider salt** is then used in various operations to ensure 477 // cryptographic operations differ by provider. A provider must 478 // never change its salt value. 479 provider_salt: string; 480 481 } 482 483 .. _AuthorizationMethodConfig: 484 .. ts:def:: AuthorizationMethodConfig 485 486 interface AuthorizationMethodConfig { 487 // Name of the authorization method. 488 type: string; 489 490 // Fee for accessing key share using this method, in the provider's 491 // primary currency. 492 cost: Amount; 493 494 // Fee for accessing key share using this method, one entry per 495 // currency in ``currencies``. Empty means the method is free, 496 // which is what an IBAN-style method wants when the wire transfer 497 // the user has to make is already the cost of using it. 498 // @since protocol **v3**. 499 costs?: Amount[]; 500 501 } 502 503 .. _terms: 504 505 -------------------------- 506 Receiving Terms of Service 507 -------------------------- 508 509 .. http:get:: /terms 510 511 Obtain the terms of service provided by the escrow provider. 512 513 **Response:** 514 515 Returns the terms of service of the provider, in the best language 516 and format available based on the client's request. 517 518 .. http:get:: /privacy 519 520 Obtain the privacy policy of the service provided by the escrow provider. 521 522 **Response:** 523 524 Returns the privacy policy of the provider, in the best language 525 and format available based on the client's request. 526 527 528 .. _manage-policy: 529 530 531 --------------- 532 Managing policy 533 --------------- 534 535 This API is used by the Anastasis client to deposit or request encrypted 536 recovery documents with the escrow provider. Generally, a client will deposit 537 the same encrypted recovery document with each escrow provider, but provide 538 a different truth to each escrow provider. 539 540 Operations by the client are identified and authorized by ``$ACCOUNT_PUB``, which 541 should be kept secret from third parties. ``$ACCOUNT_PUB`` should be an account 542 public key using the Crockford base32-encoding. 543 544 In the following, UUID is always defined and used according to `RFC 4122`_. 545 546 .. _`RFC 4122`: https://tools.ietf.org/html/rfc4122 547 548 .. http:get:: /policy/$ACCOUNT_PUB/meta[?max_version=$NUMBER] 549 550 Get meta data about a customer's encrypted recovery documents. 551 If ``max_version`` is specified, only return results up to the 552 given version number. The response may not contain meta data 553 for all versions if there are way too many. In this case, 554 ``max_version`` must be used to incrementally fetch more versions. 555 556 **Response**: 557 558 :http:statuscode:`200 OK`: 559 The escrow provider responds with a RecoveryMetaSummary_ object. 560 :http:statuscode:`400 Bad request`: 561 The ``$ACCOUNT_PUB`` is not an EdDSA public key. 562 :http:statuscode:`402 Payment Required`: 563 The account's balance is too low for the specified operation. 564 See the Taler payment protocol specification for how to pay. 565 :http:statuscode:`404 Not found`: 566 The requested resource was not found. 567 568 **Details:** 569 570 .. _RecoveryMetaSummary: 571 .. ts:def:: RecoveryMetaSummary 572 573 interface RecoveryMetaSummary { 574 // Version numbers as a string (!) are used as keys. 575 "$VERSION": MetaData; 576 } 577 578 interface MetaData { 579 // The meta value can be NULL if the document 580 // exists but no meta data was provided. 581 meta: string; 582 583 // Server-time indicative of when the recovery 584 // document was uploaded. 585 upload_time: Timestamp; 586 } 587 588 .. note:: 589 590 Both the version numbers used as keys and the ``upload_time`` are stated by 591 the provider and are not covered by any signature. See the warning under 592 ``GET /policy/$ACCOUNT_PUB`` below before using either of them to decide 593 which recovery document is the most recent one. 594 595 .. http:get:: /policy/$ACCOUNT_PUB[?version=$NUMBER] 596 597 Get the customer's encrypted recovery document. If ``version`` 598 is not specified, the server returns the latest available version. If 599 ``version`` is specified, returns the policy with the respective 600 ``version``. The response must begin with the nonce and 601 an AES-GCM tag and continue with the ciphertext. Once decrypted, the 602 plaintext is expected to contain: 603 604 * the escrow policy 605 * the separately encrypted master public key 606 607 Note that the key shares required to decrypt the master public key are 608 not included, as for this the client needs to obtain authorization. 609 The policy does provide sufficient information for the client to determine 610 how to authorize requests for **truth**. 611 612 The client MAY provide an ``If-None-Match`` header with an Etag. 613 In that case, the server MUST additionally respond with an ``304`` status 614 code in case the resource matches the provided Etag. 615 616 **Response**: 617 618 :http:statuscode:`200 OK`: 619 The escrow provider responds with an EncryptedRecoveryDocument_ object. 620 :http:statuscode:`304 Not modified`: 621 The client requested the same resource it already knows. 622 :http:statuscode:`400 Bad request`: 623 The ``$ACCOUNT_PUB`` is not an EdDSA public key. 624 :http:statuscode:`402 Payment Required`: 625 The account's balance is too low for the specified operation. 626 See the Taler payment protocol specification for how to pay. 627 :http:statuscode:`404 Not found`: 628 The requested resource was not found. 629 630 *Anastasis-Version*: $NUMBER --- The server must return actual version of the encrypted recovery document via this header. 631 If the client specified a version number in the header of the request, the server must return that version. If the client 632 did not specify a version in the request, the server returns latest version of the EncryptedRecoveryDocument_. 633 634 .. warning:: 635 636 The version number is **not** authenticated. The ``Anastasis-Policy-Signature`` 637 of the upload covers the hash of the body and nothing else, so a provider can 638 serve an older but perfectly well-signed recovery document while labelling it 639 with any version number it likes, and it can withhold newer versions entirely. 640 Clients MUST NOT treat the version --- or the ``upload_time`` reported by the 641 ``/meta`` endpoint --- as a trustworthy statement about which document is the 642 most recent one. A client SHOULD still refuse a response whose version does 643 not match the version it explicitly asked for, as that is a mismatch it can 644 detect locally. 645 646 This is an accepted limitation of the protocol, not an oversight: the version 647 is assigned by the provider *after* the upload, so a client cannot sign a 648 value it does not choose. Version numbers are also assigned per provider, so 649 the same document may well carry different version numbers at different 650 providers. A client that needs to determine which of several backups is the 651 newest should place a timestamp, or a comparable ordering value, **inside** 652 the recovery document, where it is covered by the account signature and can 653 be compared across providers. 654 655 *Etag*: Set by the server to the Base32-encoded SHA512 hash of the body. Used for caching and to prevent redundancies. The server MUST send the Etag if the status code is ``200 OK``. 656 657 *If-None-Match*: If this is not the very first request of the client, this contains the Etag-value which the client has received before from the server. 658 The client SHOULD send this header with every request (except for the first request) to avoid unnecessary downloads. 659 660 661 .. http:post:: /policy/$ACCOUNT_PUB 662 663 Upload a new version of the customer's encrypted recovery document. 664 While the document's structure is described in JSON below, the upload 665 should just be the bytestream of the raw data (i.e. 32-byte nonce followed 666 by 16-byte tag followed by the encrypted document). 667 If the request has been seen before, the server should do nothing, and otherwise store the new version. 668 The body must begin with a nonce, an AES-GCM tag and continue with the ciphertext. The format 669 is the same as specified for the response of the GET method. The 670 Anastasis server cannot fully validate the format, but MAY impose 671 minimum and maximum size limits. 672 673 **Request**: 674 675 :query storage_duration=YEARS: 676 For how many years from now would the client like us to 677 store the recovery document? Defaults to 0 (that is, do 678 not extend / prolong existing storage contract). 679 The server will respond with a ``402 Payment required``, but only 680 if the rest of the request is well-formed (account 681 signature must match). Clients that do not actually 682 intend to make a new upload but that only want to pay 683 may attempt to upload the latest backup again, as this 684 option will be checked before the ``304 Not modified`` 685 case. 686 :query timeout_ms=NUMBER: *Optional.* If specified, the Anastasis server will 687 wait up to ``timeout_ms`` milliseconds for completion of the payment before 688 sending the HTTP response. A client must never rely on this behavior, as the 689 backend may return a response immediately. If a ``timeout_ms`` is not given, the Anastasis server may apply a default timeout (usually 30s) when talking to the merchant backend. 690 691 *If-None-Match*: This header MUST be present and set to the SHA512 hash (Etag) of the body by the client. 692 The client SHOULD also set the ``Expect: 100-Continue`` header and wait for ``100 continue`` 693 before uploading the body. The server MUST 694 use the Etag to check whether it already knows the encrypted recovery document that is about to be uploaded. 695 The server MUST refuse the upload with a ``304`` status code if the Etag matches 696 the latest version already known to the server. 697 698 *Anastasis-Policy-Meta-Data*: Encrypted meta data to be stored by the server and returned with the respective endpoint to provide an overview of the available policies. Encrypted using a random nonce and a key derived from the user ID using the salt "rmd". The plaintext metadata must consist of the policy hash (for deduplication) and the (human readable) secret name. 699 700 *Anastasis-Policy-Signature*: The client must provide Base-32 encoded EdDSA signature over hash of body with ``$ACCOUNT_PRIV``, affirming desire to upload an encrypted recovery document. 701 702 *Payment-Identifier*: Base-32 encoded 32-byte payment identifier that was included in a previous payment (see ``402`` status code). Used to allow the server to check that the client paid for the upload (to protect the server against DoS attacks) and that the client knows a real secret of financial value (as the **kdf_id** might be known to an attacker). If this header is missing in the client's request (or the associated payment has exceeded the upload limit), the server must return a ``402`` response. When making payments, the server must include a fresh, randomly-generated payment-identifier in the payment request. If a payment identifier is given, the Anastasis backend may block for the payment to be confirmed by Taler as specified by the ``timeout_ms`` argument. 703 704 **Response**: 705 706 :http:statuscode:`204 No content`: 707 The encrypted recovery document was accepted and stored. ``Anastasis-Version`` 708 indicates what version was assigned to this encrypted recovery document upload by the server. 709 ``Anastasis-Policy-Expiration`` indicates the time until the server promises to store the policy, 710 in seconds since epoch. 711 :http:statuscode:`304 Not modified`: 712 The same encrypted recovery document was previously accepted and stored. ``Anastasis-Version`` header 713 indicates what version was previously assigned to this encrypted recovery document. 714 :http:statuscode:`400 Bad request`: 715 The ``$ACCOUNT_PUB`` is not an EdDSA public key or mandatory headers are missing. 716 The response body MUST elaborate on the error using a Taler error code in the typical JSON encoding. 717 :http:statuscode:`402 Payment required`: 718 The account's balance is too low for the specified operation. 719 See the Taler payment protocol specification for how to pay. 720 The response body MAY provide alternative means for payment. 721 :http:statuscode:`403 Forbidden`: 722 The required account signature was invalid. The response body may elaborate on the error. 723 :http:statuscode:`413 Request entity too large`: 724 The upload is too large *or* too small. The response body may elaborate on the error. 725 726 **Details:** 727 728 .. _EncryptedRecoveryDocument: 729 .. ts:def:: EncryptedRecoveryDocument 730 731 interface EncryptedRecoveryDocument { 732 // Nonce used to compute the (iv,key) pair for encryption of the 733 // encrypted_compressed_recovery_document. 734 nonce: [32]; //bytearray 735 736 // Authentication tag. 737 aes_gcm_tag: [16]; //bytearray 738 739 // Variable-size encrypted recovery document. After decryption, 740 // this contains a gzip compressed JSON-encoded `RecoveryDocument`. 741 // The salt of the HKDF for this encryption must include the 742 // string "erd". 743 encrypted_compressed_recovery_document: []; //bytearray of undefined length 744 745 } 746 747 .. _RecoveryDocument: 748 .. ts:def:: RecoveryDocument 749 750 interface RecoveryDocument { 751 // Human-readable name of the secret 752 secret_name?: string; 753 754 // Encrypted core secret. 755 encrypted_core_secret: string; // bytearray of undefined length 756 757 // List of escrow providers and selected authentication method. 758 escrow_methods: EscrowMethod[]; 759 760 // List of possible decryption policies. 761 policies: DecryptionPolicy[]; 762 763 } 764 765 .. _EscrowMethod: 766 .. ts:def:: EscrowMethod 767 768 interface EscrowMethod { 769 // URL of the escrow provider (including possibly this Anastasis server). 770 url : string; 771 772 // Type of the escrow method (e.g. security question, SMS etc.). 773 escrow_type: string; 774 775 // UUID of the escrow method (see /truth/ API below). 776 uuid: string; 777 778 // Key used to encrypt the `Truth` this `EscrowMethod` is related to. 779 // Client has to provide this key to the server when using ``/truth/``. 780 truth_key: [32]; //bytearray 781 782 // Salt used to hash the security answer if appliccable. 783 question_salt: [32]; //bytearray 784 785 // Salt from the provider to derive the user ID 786 // at this provider. 787 provider_salt: [32]; //bytearray 788 789 // The instructions to give to the user (i.e. the security question 790 // if this is challenge-response). 791 // (Q: as string in base32 encoding?) 792 // (Q: what is the mime-type of this value?) 793 // 794 // The plaintext challenge is not revealed to the 795 // Anastasis server. 796 instructions: string; 797 798 } 799 800 .. _DecryptionPolicy: 801 .. ts:def:: DecryptionPolicy 802 803 interface DecryptionPolicy { 804 // Salt included to encrypt master key share when 805 // using this decryption policy. 806 master_salt: [32]; //bytearray 807 808 // Master key, AES-encrypted with key derived from 809 // salt and keyshares revealed by the following list of 810 // escrow methods identified by UUID. 811 master_key: [32]; //bytearray 812 813 // List of escrow methods identified by their UUID. 814 uuids: string[]; 815 816 } 817 818 .. _Truth: 819 820 -------------- 821 Managing truth 822 -------------- 823 824 Truth always consists of an encrypted key share and encrypted 825 authentication data. The key share and the authentication data 826 are encrypted using different keys. Additionally, truth includes 827 the name of the authentication method, the mime-type of the 828 authentication data, and an expiration time in 829 cleartext. 830 831 This API is used by the Anastasis client to deposit **truth** or request a (encrypted) **key share** with 832 the escrow provider. 833 834 An **escrow method** specifies an Anastasis provider and how the user should 835 authorize themself. The **truth** API allows the user to provide the 836 (encrypted) key share to the respective escrow provider, as well as auxiliary 837 data required for such a respective escrow method. 838 839 An Anastasis-server may store truth for free for a certain time period, or 840 charge per truth operation using GNU Taler. 841 842 .. http:post:: /truth/$UUID 843 844 **Request:** 845 846 Upload a `TruthUploadRequest`-Object according to the policy the client created before (see `RecoveryDocument`_). 847 If request has been seen before, the server should do nothing, and otherwise store the new object. 848 849 850 :query timeout_ms=NUMBER: *Optional.* If specified, the Anastasis server will 851 wait up to ``timeout_ms`` milliseconds for completion of the payment before 852 sending the HTTP response. A client must never rely on this behavior, as the 853 backend may return a response immediately. 854 855 **Response:** 856 857 :http:statuscode:`204 No content`: 858 Truth stored successfully. 859 :http:statuscode:`304 Not modified`: 860 The same truth was previously accepted and stored under this UUID. The 861 Anastasis server must still update the expiration time for the truth when returning 862 this response code. 863 :http:statuscode:`402 Payment required`: 864 This server requires payment to store truth per item. 865 See the Taler payment protocol specification for how to pay. 866 The response body MAY provide alternative means for payment. 867 :http:statuscode:`409 Conflict`: 868 The server already has some truth stored under this UUID. The client should check that it 869 is generating UUIDs with enough entropy. 870 :http:statuscode:`412 Precondition failed`: 871 The selected authentication method is not supported on this provider. 872 873 874 **Details:** 875 876 .. _TruthUploadRequest: 877 .. ts:def:: TruthUploadRequest 878 879 interface TruthUploadRequest { 880 // Contains the information of an interface `EncryptedKeyShare`, but simply 881 // as one binary block (in Crockford Base32 encoding for JSON). 882 key_share_data: []; //bytearray 883 884 // Key share method, i.e. "security question", "SMS", "e-mail", ... 885 type: string; 886 887 // Variable-size truth. After decryption, 888 // this contains the ground truth, i.e. H(challenge answer), 889 // phone number, e-mail address, picture, fingerprint, ... 890 // **base32 encoded**. 891 // 892 // The nonce of the HKDF for this encryption must include the 893 // string "ECT". 894 encrypted_truth: []; //bytearray 895 896 // MIME type of truth, i.e. text/ascii, image/jpeg, etc. 897 truth_mime?: string; 898 899 // For how many years from now would the client like us to 900 // store the truth? 901 storage_duration_years: number; 902 903 } 904 905 906 .. http:post:: /truth/$UUID/solve 907 908 Solve the challenge and get the stored encrypted key share. 909 Also, the user has to provide the correct *truth_encryption_key* with the request (see below). 910 The encrypted key share is returned simply as a byte array and not in JSON format. 911 912 **Request**: 913 914 Upload a `TruthSolutionRequest`_-Object. 915 916 :query timeout_ms=NUMBER: *Optional.* If specified, the Anastasis server will 917 wait up to ``timeout_ms`` milliseconds for completion of the payment or the 918 challenge before sending the HTTP response. A client must never rely on this 919 behavior, as the backend may return a response immediately. 920 921 **Response**: 922 923 :http:statuscode:`200 OK`: 924 `EncryptedKeyShare`_ is returned in body (in binary). 925 :http:statuscode:`402 Payment required`: 926 The service requires payment for access to truth. 927 See the Taler payment protocol specification for how to pay. 928 The response body MAY provide alternative means for payment. 929 :http:statuscode:`403 Forbidden`: 930 The ``$H_RESPONSE`` provided is not a good response to the challenge associated 931 with the UUID, or at least the answer is not valid yet. A generic 932 response is provided with an error code. 933 :http:statuscode:`404 Not found`: 934 The server does not know any truth under the given UUID. 935 :http:statuscode:`429 Too Many Requests`: 936 The client exceeded the number of allowed attempts at providing 937 a valid response for the given time interval. 938 The response format is given by `RateLimitedMessage`_. 939 :http:statuscode:`503 Service Unavailable`: 940 Server is out of Service. 941 942 **Details:** 943 944 .. _TruthSolutionRequest: 945 .. ts:def:: TruthSolutionRequest 946 947 interface TruthSolutionRequest { 948 949 // Hash over the response that solves the challenge 950 // issued for this truth. This can be the 951 // hash of the security question (as specified before by the client 952 // within the `TruthUploadRequest` (see ``encrypted_truth``)), or the hash of the 953 // PIN code sent via SMS, E-mail or postal communication channels. 954 // Only when ``$H_RESPONSE`` is correct, the server responds with the encrypted key share. 955 h_response: HashCode; 956 957 // Key that was used to encrypt the **truth** (see encrypted_truth within `TruthUploadRequest`) 958 // and which has to provided by the user. The key is stored with 959 // the according `EscrowMethod`. The server needs this key to get the 960 // info out of `TruthUploadRequest` to verify the ``$H_RESPONSE``. 961 truth_decryption_key: ANASTASIS_TruthKeyP; 962 963 // Reference to a payment made by the client to 964 // pay for this request. Optional. 965 payment_secret?: ANASTASIS_PaymentSecretP; 966 } 967 968 969 .. _EncryptedKeyShare: 970 .. ts:def:: EncryptedKeyShare 971 972 interface EncryptedKeyShare { 973 // Nonce used to compute the decryption (iv,key) pair. 974 nonce_i: [32]; //bytearray 975 976 // Authentication tag. 977 aes_gcm_tag_i: [16]; //bytearray 978 979 // Encrypted key-share in base32 encoding. 980 // After decryption, this yields a `KeyShare`. Note that 981 // the `KeyShare` MUST be encoded as a fixed-size binary 982 // block (instead of in JSON encoding). 983 // 984 // HKDF for the key generation must include the 985 // string "eks" as salt. 986 // Depending on the method, 987 // the HKDF may additionally include 988 // bits from the response (i.e. some hash over the 989 // answer to the security question). 990 encrypted_key_share_i: [32]; //bytearray 991 992 } 993 994 .. _KeyShare: 995 .. ts:def:: KeyShare 996 997 interface KeyShare { 998 // Key material to derive the key to decrypt the master key. 999 key_share: [32]; //bytearray 1000 } 1001 1002 1003 .. _RateLimitedMessage: 1004 .. ts:def:: RateLimitedMessage 1005 1006 interface RateLimitedMessage { 1007 1008 // Taler error code, TALER_EC_ANASTASIS_TRUTH_RATE_LIMITED. 1009 code: number; 1010 1011 // How many attempts are allowed per challenge? 1012 request_limit: number; 1013 1014 // At what frequency are new challenges issued? 1015 request_frequency: RelativeTime; 1016 1017 // The error message. 1018 hint: string; 1019 1020 } 1021 1022 1023 .. http:post:: /truth/$UUID/challenge 1024 1025 NEW API (#7064): 1026 1027 Initiate process to solve challenge associated with the given truth object. 1028 1029 **Request**: 1030 1031 Upload a `TruthChallengeRequest`_-Object. 1032 1033 **Response**: 1034 1035 :http:statuscode:`200 Ok`: 1036 The escrow provider will respond out-of-band (i.e. SMS). 1037 The body may contain human- or machine-readable instructions on next steps. 1038 In case the response is in JSON, the format is given 1039 by `ChallengeInstructionMessage`_. 1040 :http:statuscode:`402 Payment required`: 1041 The service requires payment to issue a challenge. 1042 See the Taler payment protocol specification for how to pay. 1043 The response body MAY provide alternative means for payment. 1044 :http:statuscode:`403 Forbidden`: 1045 This type of truth does not permit requests to trigger a challenge. 1046 This is the case for security questions and TOTP methods. 1047 :http:statuscode:`404 Not found`: 1048 The server does not know any truth under the given UUID. 1049 :http:statuscode:`424 Failed Dependency`: 1050 The decrypted ``truth`` does not match the expectations of the authentication 1051 backend, i.e. a phone number for sending an SMS is not a number, or 1052 an e-mail address for sending an E-mail is not a valid e-mail address. 1053 :http:statuscode:`503 Service Unavailable`: 1054 Server is out of Service. 1055 1056 **Details:** 1057 1058 .. _TruthChallengeRequest: 1059 .. ts:def:: TruthChallengeRequest 1060 1061 interface TruthChallengeRequest { 1062 1063 // Key that was used to encrypt the **truth** (see encrypted_truth within `TruthUploadRequest`) 1064 // and which has to provided by the user. The key is stored with 1065 // the according `EscrowMethod`. The server needs this key to get the 1066 // info out of `TruthUploadRequest` to verify the ``$H__RESPONSE``. 1067 truth_decryption_key: ANASTASIS_TruthKeyP; 1068 1069 // Reference to a payment made by the client to 1070 // pay for this request. Optional. 1071 payment_secret?: ANASTASIS_PaymentSecretP; 1072 } 1073 1074 1075 .. _ChallengeInstructionMessage: 1076 .. ts:def:: ChallengeInstructionMessage 1077 1078 type ChallengeInstructionMessage = 1079 | FileChallengeInstructionMessage 1080 | IbanChallengeInstructionMessage 1081 | PinChallengeInstructionMessage; 1082 1083 .. _IbanChallengeInstructionMessage: 1084 .. ts:def:: IbanChallengeInstructionMessage 1085 1086 interface IbanChallengeInstructionMessage { 1087 1088 // What kind of challenge is this? 1089 method: "IBAN_WIRE"; 1090 1091 // How much should be wired? 1092 amount: Amount; 1093 1094 // What is the target IBAN? 1095 credit_iban: string; 1096 1097 // What is the receiver name? 1098 business_name: string; 1099 1100 // What is the expected wire transfer subject? 1101 wire_transfer_subject: string; 1102 1103 // What is the numeric code (also part of the 1104 // wire transfer subject) to be hashed when 1105 // solving the challenge? 1106 answer_code: number; 1107 1108 // Hint about the origin account that must be used. 1109 debit_account_hint: string; 1110 1111 } 1112 1113 .. _PinChallengeInstructionMessage: 1114 .. ts:def:: PinChallengeInstructionMessage 1115 1116 interface PinChallengeInstructionMessage { 1117 1118 // What kind of challenge is this? 1119 method: "TAN_SENT"; 1120 1121 // Where was the PIN code sent? Note that this 1122 // address will most likely have been obscured 1123 // to improve privacy. 1124 tan_address_hint: string; 1125 1126 } 1127 1128 .. _FileChallengeInstructionMessage: 1129 .. ts:def:: FileChallengeInstructionMessage 1130 1131 interface FileChallengeInstructionMessage { 1132 1133 // What kind of challenge is this? 1134 method: "FILE_WRITTEN"; 1135 1136 // Name of the file where the PIN code was written. 1137 filename: string; 1138 1139 }