anastasis

Credential backup and recovery protocol and service
Log | Files | Refs | Submodules | README | LICENSE

rest.rst (37367B)


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