# Security model

What the UMIS SDK protects against when it is used as documented, how, and what it leaves to the integrator. The
[limitations](limitations.md) list the boundaries in one place; the [profile](profile-v1.md) defines the formats. To
report a vulnerability, see [SECURITY.md](../SECURITY.md).

## Parties and assets

- **Issuer**: an organisation that signs credentials and status lists with its issuer keys.
- **Holder**: a person whose wallet keeps credentials and the holder key each credential is bound to (`cnf.jwk`).
- **Verifier**: a checkpoint (door, warehouse, gate station), the counterpart in a mutual exchange, or an OpenID4VP
  provider. It decides from its own registry of trusted issuers, the status lists it holds, its policy, its replay store
  and, for authority checks, its ledger.
- **Relay**: the actuator of a door, which obeys signed relay commands only.

The assets are the issuer keys, the holder keys, the registry of each verifier, the replay store and ledger of each
verifier, and the decision journal.

## What is guaranteed

When every verification of a deployment uses the same replay store and the verifier's clock is right:

- **Issuer authenticity**: a credential is accepted only from an issuer in the verifier's own signed registry, with a
  signature that verifies under a key of that entry ([I-8](#i-8), [I-12](#i-12)).
- **Holder binding**: only the holder key of the credential can make a presentation of it ([I-18](#i-18)).
- **Freshness within S**: a decision uses a status list that is at most S old ([I-7](#i-7)).
- **Single use**: a presentation, an answer, a login response and a relay command are each accepted once ([I-1](#i-1) to
  [I-4](#i-4)).
- **Delegation never wider than its parent** and **limits counted inclusively** ([I-9](#i-9), [I-10](#i-10)).
- **No disclosure beyond the request** on the wallet side ([I-19](#i-19)).
- **Offline decisions**: no network input or output except an explicit `fetchStatusList` ([I-20](#i-20)).

## What is not guaranteed

- A revocation reaches an offline verifier only when it holds a newer status list: after up to S (72 h at a `low` door,
  24 h in the `medium` class), within Δ for an online one.
- A one-way QR code can be relayed to another verifier of the same organisation during its 30 seconds, which is why it
  is allowed in the `low` class only. No channel proves that the holder is physically present.
- Limits per shift, day, week or month are counted by each verifier on its own; several offline verifiers do not add up
  their totals.
- Keys made in Expo Go are software keys in the device's secret store; hardware-backed keys need a development build,
  and the key store reports which kind each key is.
- There is no device or key attestation: a verifier cannot tell a hardware key from a software key.
- Biometric confirmation is enforced by the wallet app (or by the secure hardware of a development build) and cannot be
  proven to a verifier.
- The demo world and the test vectors use keys from public seeds; they protect nothing.
- Credentials are linkable: the same credential shown to two verifiers can be recognised as the same.
- The SDK has not been independently audited, and its 0.x API may change.

## Threats, mitigations and residual risk

| Threat                                       | Mitigation                                                                                              | Residual risk                                                                              |
| -------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| Forged or altered credential                 | issuer signature checked with the keys of the verifier's own registry entry; disclosure digests checked | a stolen issuer key works until every verifier holds a registry that suspends it           |
| Credential shown by someone else             | key-binding JWT or one-way token signed by the holder key                                               | a stolen and unlocked phone; a software key on a compromised phone                         |
| Replay of a captured presentation or command | nonces and identifiers remembered once in a replay store                                                | verifiers that do not share one store accept the same one-way token each within its 30 s   |
| Relay of a live QR code                      | one-way tokens only in `low` and at most 30 s; answers bound to the verifier's nonce and audience       | real-time relay is not detected; choose a class whose channels fit the place               |
| Revoked credential used offline              | status list at most S old, from the issuer's own entry                                                  | visible only after up to S                                                                 |
| Delegate claims more than the delegator      | delegation rules checked by issuer and verifier, parent status checked, chain cannot be hidden          | none beyond the issuer's own key safety                                                    |
| Amount above the limit                       | inclusive limit, exact unit and object match, per-verifier period budget booked only on accept          | totals across verifiers are not enforced                                                   |
| Malicious QR text, frame, list or request    | size limits before decoding, strict parsers, verifiers that never throw and give one reason             | signature checks still cost CPU for inputs that pass the size limits                       |
| Over-asking or impersonating verifier        | the wallet discloses only what is asked; an unsigned request names its address, not a vouched identity  | `client_name` is the verifier's own word; a wallet must show the host of `response_uri`    |
| Forged door command                          | relay commands signed, bound to the exact body and the relay, single use, at most 30 s                  | status calls of the emulator need no credentials; a real relay's network must be protected |
| Signature malleability                       | no identifier is derived from signature bytes                                                           | none known                                                                                 |
| Secrets in the repository                    | public keys only in vectors, environment variables by name, secret scanning                             | demo keys are public by design                                                             |

## Invariants

Each invariant has an id that the test titles use. A test named after an id fails when the invariant breaks.

| Id            | Invariant                                                 | Reason codes                                                                                                                |
| ------------- | --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| [I-1](#i-1)   | a one-way token is accepted once                          | REPLAY                                                                                                                      |
| [I-2](#i-2)   | the nonce of a request or login is accepted once          | REPLAY                                                                                                                      |
| [I-3](#i-3)   | the nonce of a mutual exchange is accepted once           | REPLAY                                                                                                                      |
| [I-4](#i-4)   | a relay command is single use and bound to its exact body | REPLAY, SIGNATURE_INVALID                                                                                                   |
| [I-5](#i-5)   | every presentation and command is bound to its audience   | AUDIENCE_MISMATCH                                                                                                           |
| [I-6](#i-6)   | a one-way token lives at most 30 s                        | PRESENTATION_TOO_LONG_LIVED, PRESENTATION_EXPIRED                                                                           |
| [I-7](#i-7)   | freshness S is inclusive                                  | STATUS_LIST_STALE                                                                                                           |
| [I-8](#i-8)   | trust only through the verifier's own registry            | ISSUER_UNTRUSTED, ISSUER_VCT_NOT_ALLOWED, ISSUER_SUSPENDED, ISSUER_KEY_UNKNOWN, STATUS_LIST_INVALID                         |
| [I-9](#i-9)   | a delegation is never wider than its parent               | DELEGATION_WIDER_THAN_PARENT, DELEGATION_DEPTH_EXCEEDED, DELEGATION_OUTLIVES_PARENT, PARENT_REVOKED, DELEGATION_UNDISCLOSED |
| [I-10](#i-10) | limits are inclusive, exact and per verifier              | AUTHORITY_LIMIT_EXCEEDED, AUTHORITY_MISSING, AUTHORITY_EXPIRED, AUTHORITY_PERIOD_EXCEEDED                                   |
| [I-11](#i-11) | disclosures cannot be altered, repeated or added          | MALFORMED, HOLDER_BINDING_INVALID, UNSUPPORTED_FORMAT                                                                       |
| [I-12](#i-12) | JWS hardening                                             | UNSUPPORTED_FORMAT, MALFORMED, SIGNATURE_INVALID                                                                            |
| [I-13](#i-13) | input bounds                                              | MALFORMED, STATUS_LIST_INVALID                                                                                              |
| [I-14](#i-14) | a verifier never throws and gives exactly one reason      | any                                                                                                                         |
| [I-15](#i-15) | high-S signatures are accepted                            | none                                                                                                                        |
| [I-16](#i-16) | browser and React Native packages hold no Node built-ins  | none                                                                                                                        |
| [I-17](#i-17) | no secrets in the repository                              | none                                                                                                                        |
| [I-18](#i-18) | holder binding                                            | HOLDER_BINDING_INVALID                                                                                                      |
| [I-19](#i-19) | the wallet never discloses beyond the request             | none                                                                                                                        |
| [I-20](#i-20) | no network input or output except `fetchStatusList`       | none                                                                                                                        |

### I-1

A one-way token is accepted once: its id is `ow:<cred_ref>|<iat>|<ctr>`, and a token that passed the holder binding is
spent even when a later step rejects it. Tests:
[verifier/test/oneway.test.ts](../packages/verifier/test/oneway.test.ts).

### I-2

The nonce of a request is accepted once (`req:<nonce>`), and so is the nonce of an OpenID4VP login (`vp:<nonce>`); a
second answer to the same request is REPLAY. Tests: [verifier/test/s1.test.ts](../packages/verifier/test/s1.test.ts),
[verifier/test/oid4vp.test.ts](../packages/verifier/test/oid4vp.test.ts),
[transports/test/transports.test.ts](../packages/transports/test/transports.test.ts),
[testkit/test/hero.test.ts](../packages/testkit/test/hero.test.ts).

### I-3

The nonce of a mutual exchange is accepted once (`mutual:<nonce>`). Tests:
[verifier/test/mutual.test.ts](../packages/verifier/test/mutual.test.ts).

### I-4

A relay command is accepted once (`relay:<jti>`, claimed last, so a command refused for another reason is not used up)
and only with the body whose SHA-256 it carries in `bh`. Tests:
[gateway/test/relay-command.test.ts](../packages/gateway/test/relay-command.test.ts),
[gateway/test/emulator.test.ts](../packages/gateway/test/emulator.test.ts).

### I-5

A one-way token's `aud` must be one of the verifier's `audiences`; a key-binding JWT's `aud` must be the request's
`aud`; an OpenID4VP answer's `aud` must be the client id with its `redirect_uri:` prefix; a relay command's `aud` must
be a relay identity the relay lists. Tests: [verifier/test/oneway.test.ts](../packages/verifier/test/oneway.test.ts),
[verifier/test/s1.test.ts](../packages/verifier/test/s1.test.ts),
[verifier/test/oid4vp.test.ts](../packages/verifier/test/oid4vp.test.ts),
[wallet/test/oid4vp.test.ts](../packages/wallet/test/oid4vp.test.ts),
[gateway/test/relay-command.test.ts](../packages/gateway/test/relay-command.test.ts),
[transports/test/transports.test.ts](../packages/transports/test/transports.test.ts).

### I-6

A one-way token with `exp − iat` above 30 s is PRESENTATION_TOO_LONG_LIVED, and one at `exp` plus the clock skew is
PRESENTATION_EXPIRED. Tests: [verifier/test/oneway.test.ts](../packages/verifier/test/oneway.test.ts).

### I-7

A status list whose age is S is accepted, one of S + 1 second is STATUS_LIST_STALE, and so is a list past its `exp`. The
age counts from the list's `iat`, not from when the device fetched it. Tests:
[status-list/test/token.test.ts](../packages/status-list/test/token.test.ts),
[verifier/test/status.test.ts](../packages/verifier/test/status.test.ts),
[testkit/test/autonomy.test.ts](../packages/testkit/test/autonomy.test.ts).

### I-8

An issuer is trusted only through the verifier's own registry entry, and a status list is read only through the entry of
the credential's issuer and only when signed by a key of that entry. Tests:
[registry/test/registry.test.ts](../packages/registry/test/registry.test.ts),
[verifier/test/status.test.ts](../packages/verifier/test/status.test.ts),
[verifier/test/oneway.test.ts](../packages/verifier/test/oneway.test.ts).

### I-9

A delegated credential is refused when it is wider than its parent in items, period, object, validity, depth or
lifetime, when its parent is revoked, and when it is shown without the delegation it holds. Tests:
[core/test/authority.test.ts](../packages/core/test/authority.test.ts),
[issuer/test/delegation.test.ts](../packages/issuer/test/delegation.test.ts),
[verifier/test/delegation.test.ts](../packages/verifier/test/delegation.test.ts).

### I-10

`amount ≤ limit` is inclusive (10 t of 10 accepted, 10 t of 8 rejected), units and objects match exactly, and the period
budget is kept per verifier and booked only on accept. Tests:
[core/test/authority.test.ts](../packages/core/test/authority.test.ts),
[policy/test/policy.test.ts](../packages/policy/test/policy.test.ts),
[verifier/test/s1.test.ts](../packages/verifier/test/s1.test.ts),
[verifier/test/ledger.test.ts](../packages/verifier/test/ledger.test.ts).

### I-11

An altered, repeated or unlisted disclosure and an `sd_hash` that does not match are rejected. Tests:
[core/test/sdjwt.test.ts](../packages/core/test/sdjwt.test.ts),
[verifier/test/tamper.test.ts](../packages/verifier/test/tamper.test.ts).

### I-12

Only ES256, the exact `typ` of each kind, no `crit`, no unknown header members and 64-byte signatures. Tests:
[core/test/jws.test.ts](../packages/core/test/jws.test.ts).

### I-13

A QR text above 4 296 characters is refused before decoding, an inflated frame above 16 KiB and a status list above 1
MiB are refused while inflating, base45 and base64url must be canonical, and BLE reassembly is capped. Tests:
[core/test/bytes.test.ts](../packages/core/test/bytes.test.ts),
[core/test/frame.test.ts](../packages/core/test/frame.test.ts),
[status-list/test/token.test.ts](../packages/status-list/test/token.test.ts),
[gateway/test/gateway.test.ts](../packages/gateway/test/gateway.test.ts),
[transports/test/transports.test.ts](../packages/transports/test/transports.test.ts).

### I-14

`verifyAtCheckpoint`, `verifyResponseQr`, `verifyCounterparty`, `verifyVpResponse` and `verifyRelayCommand` never throw
for anything a presenter sends, and a reject carries exactly one reason. Tests:
[verifier/test/tamper.test.ts](../packages/verifier/test/tamper.test.ts),
[verifier/test/oid4vp.test.ts](../packages/verifier/test/oid4vp.test.ts),
[gateway/test/relay-command.test.ts](../packages/gateway/test/relay-command.test.ts).

### I-15

ES256 signatures are accepted with `s` in either half of the curve order, by both crypto providers and by `verifyJws`:
WebCrypto and secure hardware produce high-S signatures, and refusing them would refuse those keys. A JWS signature is
therefore malleable: anyone can turn a valid signature into a second valid one. No identifier in the SDK is derived from
signature bytes: the replay ids are built from nonces, credential ids and `jti` values (see
[replay protection](#replay-protection)), and the journal chains the canonical JSON of each event.

Refusing high-S in the verification of the noble provider turns five tests in three files red in every run:
[core/test/jws.test.ts](../packages/core/test/jws.test.ts) (the RFC 7515 appendix A.3 signature, and the high-S twin of
a signature made by either provider: three tests), [core/test/noble.test.ts](../packages/core/test/noble.test.ts) (each
provider verifies what the other signs, high-S twins included: one test) and
[wallet-rn/test/keystore.test.ts](../packages/wallet-rn/test/keystore.test.ts) (hardware signatures verify whichever
half of the curve order `s` is in: one test). The jose interoperability test of `jws.test.ts` (`jose.CompactSign`
output passes `verifyJws` with the noble provider) checks one signature made with a random nonce and is red only in the
runs where its `s` happens to be high, about every second run.

### I-16

The packages that run in browsers and in React Native (`core`, `status-list`, `policy`, `registry`, `issuer`,
`verifier`, `wallet`, `wallet-rn`, `transports` and the main entry of `gateway`) import no Node built-in and use no
`Buffer`, `process`, `URL` or `URLSearchParams`. Lint enforces it on the sources
([eslint.config.js](../eslint.config.js)) and [scripts/check-browser.mjs](../scripts/check-browser.mjs) on the built
bundles, in CI.

### I-17

The repository holds no private key and no secret value: the test vectors hold public keys only, environment variables
are referred to by name, and contributors scan every commit with gitleaks ([.gitleaks.toml](../.gitleaks.toml)). Tests:
[testkit/test/vectors.test.ts](../packages/testkit/test/vectors.test.ts).

### I-18

A key-binding JWT or one-way token signed by any key other than the credential's `cnf.jwk` is HOLDER_BINDING_INVALID,
and so is a presentation without one. Tests: [verifier/test/oneway.test.ts](../packages/verifier/test/oneway.test.ts),
[verifier/test/tamper.test.ts](../packages/verifier/test/tamper.test.ts),
[core/test/sdjwt.test.ts](../packages/core/test/sdjwt.test.ts).

### I-19

A wallet refuses, before anything is sent, to disclose a claim the request does not ask for or to present a credential
of a type the request does not accept. Tests: [wallet/test/response.test.ts](../packages/wallet/test/response.test.ts),
[wallet/test/oid4vp.test.ts](../packages/wallet/test/oid4vp.test.ts).

### I-20

A verifier makes no network call: status lists come from the context, or from `fetchStatusList` when the integrator
gives one (an online OpenID4VP provider). Tests:
[verifier/test/status.test.ts](../packages/verifier/test/status.test.ts),
[verifier/test/oid4vp.test.ts](../packages/verifier/test/oid4vp.test.ts),
[testkit/test/hero.test.ts](../packages/testkit/test/hero.test.ts),
[testkit/test/bench.test.ts](../packages/testkit/test/bench.test.ts).

## Replay protection

Single use holds only when **all verifications of one deployment share one `ReplayStore`**: `verifyAtCheckpoint`,
`verifyResponseQr`, `verifyCounterparty`, `verifyVpResponse` and `verifyRelayCommand`. The ids it holds:

| Id                                       | Remembered for                                  |
| ---------------------------------------- | ----------------------------------------------- |
| `ow:<cred_ref>\|<iat>\|<ctr>`            | a one-way token                                 |
| `kb:<issuer>\|<credential jti>\|<nonce>` | a full presentation with the holder's own nonce |
| `req:<nonce>`                            | the answer to a request                         |
| `mutual:<nonce>`                         | a mutual exchange                               |
| `vp:<nonce>`                             | an OpenID4VP login response                     |
| `relay:<jti>`                            | a relay command                                 |

Each id is kept until the presentation it stands for can no longer be accepted. `createMemoryReplayStore()` holds at
most 100 000 ids that have not expired (`max`) and refuses new ids while it is full, so a full store rejects instead of
forgetting. It never reads a clock: it takes the time from `opts.now`, or else from the verification calls that use it.
`verifyVpResponse` without a `replay` store remembers nothing across calls. A deployment with several processes or
devices needs a store they share (any object with `checkAndRemember(id, expiresAt)`), or it accepts each id once per
store.

## Keys on the phone

`@umis/wallet-rn` makes holder keys in the Secure Enclave (iOS) or in StrongBox or the Trusted Execution Environment
(Android) in a development build, and in the device's secret store in Expo Go. A development build falls back to a
software key only when the hardware module is not installed, the device has no secure hardware, no biometrics are
enrolled or the module refuses to make the key; any other failure is CRYPTO_UNAVAILABLE. Every signer reports
`protection: 'hardware' | 'software'`; claim a hardware-backed key only where the signer reports it. See the
[package README](../packages/wallet-rn/README.md).
