rest.rst (39169B)
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 // Payment required to maintain an account to store policy documents for a year. 440 // Users can pay more, in which case the storage time will go up proportionally. 441 annual_fee: Amount; 442 443 // Payment required to upload truth. To be paid per upload. 444 truth_upload_fee: Amount; 445 446 // Limit on the liability that the provider is offering with 447 // respect to the services provided. 448 liability_limit: Amount; 449 450 // Salt value with 128 bits of entropy. 451 // Different providers 452 // will use different high-entropy salt values. The resulting 453 // **provider salt** is then used in various operations to ensure 454 // cryptographic operations differ by provider. A provider must 455 // never change its salt value. 456 provider_salt: string; 457 458 } 459 460 .. _AuthorizationMethodConfig: 461 .. ts:def:: AuthorizationMethodConfig 462 463 interface AuthorizationMethodConfig { 464 // Name of the authorization method. 465 type: string; 466 467 // Fee for accessing key share using this method. 468 cost: Amount; 469 470 } 471 472 .. _terms: 473 474 -------------------------- 475 Receiving Terms of Service 476 -------------------------- 477 478 .. http:get:: /terms 479 480 Obtain the terms of service provided by the escrow provider. 481 482 **Response:** 483 484 Returns the terms of service of the provider, in the best language 485 and format available based on the client's request. 486 487 .. http:get:: /privacy 488 489 Obtain the privacy policy of the service provided by the escrow provider. 490 491 **Response:** 492 493 Returns the privacy policy of the provider, in the best language 494 and format available based on the client's request. 495 496 497 .. _manage-policy: 498 499 500 --------------- 501 Managing policy 502 --------------- 503 504 This API is used by the Anastasis client to deposit or request encrypted 505 recovery documents with the escrow provider. Generally, a client will deposit 506 the same encrypted recovery document with each escrow provider, but provide 507 a different truth to each escrow provider. 508 509 Operations by the client are identified and authorized by ``$ACCOUNT_PUB``, which 510 should be kept secret from third parties. ``$ACCOUNT_PUB`` should be an account 511 public key using the Crockford base32-encoding. 512 513 In the following, UUID is always defined and used according to `RFC 4122`_. 514 515 .. _`RFC 4122`: https://tools.ietf.org/html/rfc4122 516 517 .. http:get:: /policy/$ACCOUNT_PUB/meta[?max_version=$NUMBER] 518 519 Get meta data about a customer's encrypted recovery documents. 520 If ``max_version`` is specified, only return results up to the 521 given version number. The response may not contain meta data 522 for all versions if there are way too many. In this case, 523 ``max_version`` must be used to incrementally fetch more versions. 524 525 **Response**: 526 527 :http:statuscode:`200 OK`: 528 The escrow provider responds with a RecoveryMetaSummary_ object. 529 :http:statuscode:`400 Bad request`: 530 The ``$ACCOUNT_PUB`` is not an EdDSA public key. 531 :http:statuscode:`402 Payment Required`: 532 The account's balance is too low for the specified operation. 533 See the Taler payment protocol specification for how to pay. 534 :http:statuscode:`404 Not found`: 535 The requested resource was not found. 536 537 **Details:** 538 539 .. _RecoveryMetaSummary: 540 .. ts:def:: RecoveryMetaSummary 541 542 interface RecoveryMetaSummary { 543 // Version numbers as a string (!) are used as keys. 544 "$VERSION": MetaData; 545 } 546 547 interface MetaData { 548 // The meta value can be NULL if the document 549 // exists but no meta data was provided. 550 meta: string; 551 552 // Server-time indicative of when the recovery 553 // document was uploaded. 554 upload_time: Timestamp; 555 } 556 557 .. note:: 558 559 Both the version numbers used as keys and the ``upload_time`` are stated by 560 the provider and are not covered by any signature. See the warning under 561 ``GET /policy/$ACCOUNT_PUB`` below before using either of them to decide 562 which recovery document is the most recent one. 563 564 .. http:get:: /policy/$ACCOUNT_PUB[?version=$NUMBER] 565 566 Get the customer's encrypted recovery document. If ``version`` 567 is not specified, the server returns the latest available version. If 568 ``version`` is specified, returns the policy with the respective 569 ``version``. The response must begin with the nonce and 570 an AES-GCM tag and continue with the ciphertext. Once decrypted, the 571 plaintext is expected to contain: 572 573 * the escrow policy 574 * the separately encrypted master public key 575 576 Note that the key shares required to decrypt the master public key are 577 not included, as for this the client needs to obtain authorization. 578 The policy does provide sufficient information for the client to determine 579 how to authorize requests for **truth**. 580 581 The client MAY provide an ``If-None-Match`` header with an Etag. 582 In that case, the server MUST additionally respond with an ``304`` status 583 code in case the resource matches the provided Etag. 584 585 **Response**: 586 587 :http:statuscode:`200 OK`: 588 The escrow provider responds with an EncryptedRecoveryDocument_ object. 589 :http:statuscode:`304 Not modified`: 590 The client requested the same resource it already knows. 591 :http:statuscode:`400 Bad request`: 592 The ``$ACCOUNT_PUB`` is not an EdDSA public key. 593 :http:statuscode:`402 Payment Required`: 594 The account's balance is too low for the specified operation. 595 See the Taler payment protocol specification for how to pay. 596 :http:statuscode:`404 Not found`: 597 The requested resource was not found. 598 599 *Anastasis-Version*: $NUMBER --- The server must return actual version of the encrypted recovery document via this header. 600 If the client specified a version number in the header of the request, the server must return that version. If the client 601 did not specify a version in the request, the server returns latest version of the EncryptedRecoveryDocument_. 602 603 .. warning:: 604 605 The version number is **not** authenticated. The ``Anastasis-Policy-Signature`` 606 of the upload covers the hash of the body and nothing else, so a provider can 607 serve an older but perfectly well-signed recovery document while labelling it 608 with any version number it likes, and it can withhold newer versions entirely. 609 Clients MUST NOT treat the version --- or the ``upload_time`` reported by the 610 ``/meta`` endpoint --- as a trustworthy statement about which document is the 611 most recent one. A client SHOULD still refuse a response whose version does 612 not match the version it explicitly asked for, as that is a mismatch it can 613 detect locally. 614 615 This is an accepted limitation of the protocol, not an oversight: the version 616 is assigned by the provider *after* the upload, so a client cannot sign a 617 value it does not choose. Version numbers are also assigned per provider, so 618 the same document may well carry different version numbers at different 619 providers. A client that needs to determine which of several backups is the 620 newest should place a timestamp, or a comparable ordering value, **inside** 621 the recovery document, where it is covered by the account signature and can 622 be compared across providers. 623 624 *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``. 625 626 *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. 627 The client SHOULD send this header with every request (except for the first request) to avoid unnecessary downloads. 628 629 630 .. http:post:: /policy/$ACCOUNT_PUB 631 632 Upload a new version of the customer's encrypted recovery document. 633 While the document's structure is described in JSON below, the upload 634 should just be the bytestream of the raw data (i.e. 32-byte nonce followed 635 by 16-byte tag followed by the encrypted document). 636 If the request has been seen before, the server should do nothing, and otherwise store the new version. 637 The body must begin with a nonce, an AES-GCM tag and continue with the ciphertext. The format 638 is the same as specified for the response of the GET method. The 639 Anastasis server cannot fully validate the format, but MAY impose 640 minimum and maximum size limits. 641 642 **Request**: 643 644 :query storage_duration=YEARS: 645 For how many years from now would the client like us to 646 store the recovery document? Defaults to 0 (that is, do 647 not extend / prolong existing storage contract). 648 The server will respond with a ``402 Payment required``, but only 649 if the rest of the request is well-formed (account 650 signature must match). Clients that do not actually 651 intend to make a new upload but that only want to pay 652 may attempt to upload the latest backup again, as this 653 option will be checked before the ``304 Not modified`` 654 case. 655 :query timeout_ms=NUMBER: *Optional.* If specified, the Anastasis server will 656 wait up to ``timeout_ms`` milliseconds for completion of the payment before 657 sending the HTTP response. A client must never rely on this behavior, as the 658 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. 659 660 *If-None-Match*: This header MUST be present and set to the SHA512 hash (Etag) of the body by the client. 661 The client SHOULD also set the ``Expect: 100-Continue`` header and wait for ``100 continue`` 662 before uploading the body. The server MUST 663 use the Etag to check whether it already knows the encrypted recovery document that is about to be uploaded. 664 The server MUST refuse the upload with a ``304`` status code if the Etag matches 665 the latest version already known to the server. 666 667 *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. 668 669 *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. 670 671 *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. 672 673 **Response**: 674 675 :http:statuscode:`204 No content`: 676 The encrypted recovery document was accepted and stored. ``Anastasis-Version`` 677 indicates what version was assigned to this encrypted recovery document upload by the server. 678 ``Anastasis-Policy-Expiration`` indicates the time until the server promises to store the policy, 679 in seconds since epoch. 680 :http:statuscode:`304 Not modified`: 681 The same encrypted recovery document was previously accepted and stored. ``Anastasis-Version`` header 682 indicates what version was previously assigned to this encrypted recovery document. 683 :http:statuscode:`400 Bad request`: 684 The ``$ACCOUNT_PUB`` is not an EdDSA public key or mandatory headers are missing. 685 The response body MUST elaborate on the error using a Taler error code in the typical JSON encoding. 686 :http:statuscode:`402 Payment required`: 687 The account's balance is too low for the specified operation. 688 See the Taler payment protocol specification for how to pay. 689 The response body MAY provide alternative means for payment. 690 :http:statuscode:`403 Forbidden`: 691 The required account signature was invalid. The response body may elaborate on the error. 692 :http:statuscode:`413 Request entity too large`: 693 The upload is too large *or* too small. The response body may elaborate on the error. 694 695 **Details:** 696 697 .. _EncryptedRecoveryDocument: 698 .. ts:def:: EncryptedRecoveryDocument 699 700 interface EncryptedRecoveryDocument { 701 // Nonce used to compute the (iv,key) pair for encryption of the 702 // encrypted_compressed_recovery_document. 703 nonce: [32]; //bytearray 704 705 // Authentication tag. 706 aes_gcm_tag: [16]; //bytearray 707 708 // Variable-size encrypted recovery document. After decryption, 709 // this contains a gzip compressed JSON-encoded `RecoveryDocument`. 710 // The salt of the HKDF for this encryption must include the 711 // string "erd". 712 encrypted_compressed_recovery_document: []; //bytearray of undefined length 713 714 } 715 716 .. _RecoveryDocument: 717 .. ts:def:: RecoveryDocument 718 719 interface RecoveryDocument { 720 // Human-readable name of the secret 721 secret_name?: string; 722 723 // Encrypted core secret. 724 encrypted_core_secret: string; // bytearray of undefined length 725 726 // List of escrow providers and selected authentication method. 727 escrow_methods: EscrowMethod[]; 728 729 // List of possible decryption policies. 730 policies: DecryptionPolicy[]; 731 732 } 733 734 .. _EscrowMethod: 735 .. ts:def:: EscrowMethod 736 737 interface EscrowMethod { 738 // URL of the escrow provider (including possibly this Anastasis server). 739 url : string; 740 741 // Type of the escrow method (e.g. security question, SMS etc.). 742 escrow_type: string; 743 744 // UUID of the escrow method (see /truth/ API below). 745 uuid: string; 746 747 // Key used to encrypt the `Truth` this `EscrowMethod` is related to. 748 // Client has to provide this key to the server when using ``/truth/``. 749 truth_key: [32]; //bytearray 750 751 // Salt used to hash the security answer if appliccable. 752 question_salt: [32]; //bytearray 753 754 // Salt from the provider to derive the user ID 755 // at this provider. 756 provider_salt: [32]; //bytearray 757 758 // The instructions to give to the user (i.e. the security question 759 // if this is challenge-response). 760 // (Q: as string in base32 encoding?) 761 // (Q: what is the mime-type of this value?) 762 // 763 // The plaintext challenge is not revealed to the 764 // Anastasis server. 765 instructions: string; 766 767 } 768 769 .. _DecryptionPolicy: 770 .. ts:def:: DecryptionPolicy 771 772 interface DecryptionPolicy { 773 // Salt included to encrypt master key share when 774 // using this decryption policy. 775 master_salt: [32]; //bytearray 776 777 // Master key, AES-encrypted with key derived from 778 // salt and keyshares revealed by the following list of 779 // escrow methods identified by UUID. 780 master_key: [32]; //bytearray 781 782 // List of escrow methods identified by their UUID. 783 uuids: string[]; 784 785 } 786 787 .. _Truth: 788 789 -------------- 790 Managing truth 791 -------------- 792 793 Truth always consists of an encrypted key share and encrypted 794 authentication data. The key share and the authentication data 795 are encrypted using different keys. Additionally, truth includes 796 the name of the authentication method, the mime-type of the 797 authentication data, and an expiration time in 798 cleartext. 799 800 This API is used by the Anastasis client to deposit **truth** or request a (encrypted) **key share** with 801 the escrow provider. 802 803 An **escrow method** specifies an Anastasis provider and how the user should 804 authorize themself. The **truth** API allows the user to provide the 805 (encrypted) key share to the respective escrow provider, as well as auxiliary 806 data required for such a respective escrow method. 807 808 An Anastasis-server may store truth for free for a certain time period, or 809 charge per truth operation using GNU Taler. 810 811 .. http:post:: /truth/$UUID 812 813 **Request:** 814 815 Upload a `TruthUploadRequest`-Object according to the policy the client created before (see `RecoveryDocument`_). 816 If request has been seen before, the server should do nothing, and otherwise store the new object. 817 818 819 :query timeout_ms=NUMBER: *Optional.* If specified, the Anastasis server will 820 wait up to ``timeout_ms`` milliseconds for completion of the payment before 821 sending the HTTP response. A client must never rely on this behavior, as the 822 backend may return a response immediately. 823 824 **Response:** 825 826 :http:statuscode:`204 No content`: 827 Truth stored successfully. 828 :http:statuscode:`304 Not modified`: 829 The same truth was previously accepted and stored under this UUID. The 830 Anastasis server must still update the expiration time for the truth when returning 831 this response code. 832 :http:statuscode:`402 Payment required`: 833 This server requires payment to store truth per item. 834 See the Taler payment protocol specification for how to pay. 835 The response body MAY provide alternative means for payment. 836 :http:statuscode:`409 Conflict`: 837 The server already has some truth stored under this UUID. The client should check that it 838 is generating UUIDs with enough entropy. 839 :http:statuscode:`412 Precondition failed`: 840 The selected authentication method is not supported on this provider. 841 842 843 **Details:** 844 845 .. _TruthUploadRequest: 846 .. ts:def:: TruthUploadRequest 847 848 interface TruthUploadRequest { 849 // Contains the information of an interface `EncryptedKeyShare`, but simply 850 // as one binary block (in Crockford Base32 encoding for JSON). 851 key_share_data: []; //bytearray 852 853 // Key share method, i.e. "security question", "SMS", "e-mail", ... 854 type: string; 855 856 // Variable-size truth. After decryption, 857 // this contains the ground truth, i.e. H(challenge answer), 858 // phone number, e-mail address, picture, fingerprint, ... 859 // **base32 encoded**. 860 // 861 // The nonce of the HKDF for this encryption must include the 862 // string "ECT". 863 encrypted_truth: []; //bytearray 864 865 // MIME type of truth, i.e. text/ascii, image/jpeg, etc. 866 truth_mime?: string; 867 868 // For how many years from now would the client like us to 869 // store the truth? 870 storage_duration_years: number; 871 872 } 873 874 875 .. http:post:: /truth/$UUID/solve 876 877 Solve the challenge and get the stored encrypted key share. 878 Also, the user has to provide the correct *truth_encryption_key* with the request (see below). 879 The encrypted key share is returned simply as a byte array and not in JSON format. 880 881 **Request**: 882 883 Upload a `TruthSolutionRequest`_-Object. 884 885 :query timeout_ms=NUMBER: *Optional.* If specified, the Anastasis server will 886 wait up to ``timeout_ms`` milliseconds for completion of the payment or the 887 challenge before sending the HTTP response. A client must never rely on this 888 behavior, as the backend may return a response immediately. 889 890 **Response**: 891 892 :http:statuscode:`200 OK`: 893 `EncryptedKeyShare`_ is returned in body (in binary). 894 :http:statuscode:`402 Payment required`: 895 The service requires payment for access to truth. 896 See the Taler payment protocol specification for how to pay. 897 The response body MAY provide alternative means for payment. 898 :http:statuscode:`403 Forbidden`: 899 The ``$H_RESPONSE`` provided is not a good response to the challenge associated 900 with the UUID, or at least the answer is not valid yet. A generic 901 response is provided with an error code. 902 :http:statuscode:`404 Not found`: 903 The server does not know any truth under the given UUID. 904 :http:statuscode:`429 Too Many Requests`: 905 The client exceeded the number of allowed attempts at providing 906 a valid response for the given time interval. 907 The response format is given by `RateLimitedMessage`_. 908 :http:statuscode:`503 Service Unavailable`: 909 Server is out of Service. 910 911 **Details:** 912 913 .. _TruthSolutionRequest: 914 .. ts:def:: TruthSolutionRequest 915 916 interface TruthSolutionRequest { 917 918 // Hash over the response that solves the challenge 919 // issued for this truth. This can be the 920 // hash of the security question (as specified before by the client 921 // within the `TruthUploadRequest` (see ``encrypted_truth``)), or the hash of the 922 // PIN code sent via SMS, E-mail or postal communication channels. 923 // Only when ``$H_RESPONSE`` is correct, the server responds with the encrypted key share. 924 h_response: HashCode; 925 926 // Key that was used to encrypt the **truth** (see encrypted_truth within `TruthUploadRequest`) 927 // and which has to provided by the user. The key is stored with 928 // the according `EscrowMethod`. The server needs this key to get the 929 // info out of `TruthUploadRequest` to verify the ``$H_RESPONSE``. 930 truth_decryption_key: ANASTASIS_TruthKeyP; 931 932 // Reference to a payment made by the client to 933 // pay for this request. Optional. 934 payment_secret?: ANASTASIS_PaymentSecretP; 935 } 936 937 938 .. _EncryptedKeyShare: 939 .. ts:def:: EncryptedKeyShare 940 941 interface EncryptedKeyShare { 942 // Nonce used to compute the decryption (iv,key) pair. 943 nonce_i: [32]; //bytearray 944 945 // Authentication tag. 946 aes_gcm_tag_i: [16]; //bytearray 947 948 // Encrypted key-share in base32 encoding. 949 // After decryption, this yields a `KeyShare`. Note that 950 // the `KeyShare` MUST be encoded as a fixed-size binary 951 // block (instead of in JSON encoding). 952 // 953 // HKDF for the key generation must include the 954 // string "eks" as salt. 955 // Depending on the method, 956 // the HKDF may additionally include 957 // bits from the response (i.e. some hash over the 958 // answer to the security question). 959 encrypted_key_share_i: [32]; //bytearray 960 961 } 962 963 .. _KeyShare: 964 .. ts:def:: KeyShare 965 966 interface KeyShare { 967 // Key material to derive the key to decrypt the master key. 968 key_share: [32]; //bytearray 969 } 970 971 972 .. _RateLimitedMessage: 973 .. ts:def:: RateLimitedMessage 974 975 interface RateLimitedMessage { 976 977 // Taler error code, TALER_EC_ANASTASIS_TRUTH_RATE_LIMITED. 978 code: number; 979 980 // How many attempts are allowed per challenge? 981 request_limit: number; 982 983 // At what frequency are new challenges issued? 984 request_frequency: RelativeTime; 985 986 // The error message. 987 hint: string; 988 989 } 990 991 992 .. http:post:: /truth/$UUID/challenge 993 994 NEW API (#7064): 995 996 Initiate process to solve challenge associated with the given truth object. 997 998 **Request**: 999 1000 Upload a `TruthChallengeRequest`_-Object. 1001 1002 **Response**: 1003 1004 :http:statuscode:`200 Ok`: 1005 The escrow provider will respond out-of-band (i.e. SMS). 1006 The body may contain human- or machine-readable instructions on next steps. 1007 In case the response is in JSON, the format is given 1008 by `ChallengeInstructionMessage`_. 1009 :http:statuscode:`402 Payment required`: 1010 The service requires payment to issue a challenge. 1011 See the Taler payment protocol specification for how to pay. 1012 The response body MAY provide alternative means for payment. 1013 :http:statuscode:`403 Forbidden`: 1014 This type of truth does not permit requests to trigger a challenge. 1015 This is the case for security questions and TOTP methods. 1016 :http:statuscode:`404 Not found`: 1017 The server does not know any truth under the given UUID. 1018 :http:statuscode:`424 Failed Dependency`: 1019 The decrypted ``truth`` does not match the expectations of the authentication 1020 backend, i.e. a phone number for sending an SMS is not a number, or 1021 an e-mail address for sending an E-mail is not a valid e-mail address. 1022 :http:statuscode:`503 Service Unavailable`: 1023 Server is out of Service. 1024 1025 **Details:** 1026 1027 .. _TruthChallengeRequest: 1028 .. ts:def:: TruthChallengeRequest 1029 1030 interface TruthChallengeRequest { 1031 1032 // Key that was used to encrypt the **truth** (see encrypted_truth within `TruthUploadRequest`) 1033 // and which has to provided by the user. The key is stored with 1034 // the according `EscrowMethod`. The server needs this key to get the 1035 // info out of `TruthUploadRequest` to verify the ``$H__RESPONSE``. 1036 truth_decryption_key: ANASTASIS_TruthKeyP; 1037 1038 // Reference to a payment made by the client to 1039 // pay for this request. Optional. 1040 payment_secret?: ANASTASIS_PaymentSecretP; 1041 } 1042 1043 1044 .. _ChallengeInstructionMessage: 1045 .. ts:def:: ChallengeInstructionMessage 1046 1047 type ChallengeInstructionMessage = 1048 | FileChallengeInstructionMessage 1049 | IbanChallengeInstructionMessage 1050 | PinChallengeInstructionMessage; 1051 1052 .. _IbanChallengeInstructionMessage: 1053 .. ts:def:: IbanChallengeInstructionMessage 1054 1055 interface IbanChallengeInstructionMessage { 1056 1057 // What kind of challenge is this? 1058 method: "IBAN_WIRE"; 1059 1060 // How much should be wired? 1061 amount: Amount; 1062 1063 // What is the target IBAN? 1064 credit_iban: string; 1065 1066 // What is the receiver name? 1067 business_name: string; 1068 1069 // What is the expected wire transfer subject? 1070 wire_transfer_subject: string; 1071 1072 // What is the numeric code (also part of the 1073 // wire transfer subject) to be hashed when 1074 // solving the challenge? 1075 answer_code: number; 1076 1077 // Hint about the origin account that must be used. 1078 debit_account_hint: string; 1079 1080 } 1081 1082 .. _PinChallengeInstructionMessage: 1083 .. ts:def:: PinChallengeInstructionMessage 1084 1085 interface PinChallengeInstructionMessage { 1086 1087 // What kind of challenge is this? 1088 method: "TAN_SENT"; 1089 1090 // Where was the PIN code sent? Note that this 1091 // address will most likely have been obscured 1092 // to improve privacy. 1093 tan_address_hint: string; 1094 1095 } 1096 1097 .. _FileChallengeInstructionMessage: 1098 .. ts:def:: FileChallengeInstructionMessage 1099 1100 interface FileChallengeInstructionMessage { 1101 1102 // What kind of challenge is this? 1103 method: "FILE_WRITTEN"; 1104 1105 // Name of the file where the PIN code was written. 1106 filename: string; 1107 1108 }