|
| 1 | +--- |
| 2 | +sidebar_position: 2 |
| 3 | +--- |
| 4 | + |
| 5 | +# Credentials |
| 6 | + |
| 7 | +## What is a credential? |
| 8 | + |
| 9 | +In general, FIDO2 works by using public/private key pairs that are generated by a FIDO2 |
| 10 | +authenticator. The private key is protected by the authenticator, and the public key is stored |
| 11 | +server-side by the Relying Party (RP). The authenticator uses the private key to sign challenges |
| 12 | +from a RP, and the RP uses the public key to verify the signature. |
| 13 | + |
| 14 | +According to the [WebAuthn specification](https://www.w3.org/TR/webauthn-3/#public-key-credential), |
| 15 | +a credential is data one entity presents to another in order to authenticate the former to the |
| 16 | +latter. What the term "credential" refers to is generally determined by context, and can be one of |
| 17 | +the following: |
| 18 | + |
| 19 | +<dl> |
| 20 | + <dt>A public key credential source</dt> |
| 21 | + <dd>The data structure that is protected by the authenticator, |
| 22 | + including the private key, and any metadata that is associated with it. For more information see |
| 23 | + [Public Key Credential Source](https://www.w3.org/TR/webauthn-3/#public-key-credential-source).</dd> |
| 24 | + |
| 25 | + <dt>The attested credential public key (corresponding to a public key credential source)</dt> |
| 26 | + <dd>The public key that is stored server-side by the RP.</dd> |
| 27 | + |
| 28 | + <dt>An authentication assertion</dt> |
| 29 | + <dd>The data structure that contains a cryptographic signature.</dd> |
| 30 | +</dl> |
| 31 | + |
| 32 | +In this documentation, the term "credential" refers to the **public key credential source** i.e. the |
| 33 | +private key plus metadata. |
| 34 | + |
| 35 | +## Data structure |
| 36 | + |
| 37 | +### Required fields |
| 38 | + |
| 39 | +Credentials are relatively simple data structures and only require the following fields: |
| 40 | + |
| 41 | +- `credentialId` - Binary data sequence that uniquely identifies the credential. It is either a |
| 42 | + random value, or an encrypted version of the credential (see [Storage Modes](#storage-modality)). |
| 43 | +- `rpId` - The identifier of the RP for which the credential was created. By default assigned the |
| 44 | + effective domain of the application's origin (ex: bitwarden.com). |
| 45 | +- `privateKey` - Private key material, created when generating the public/private key pair. |
| 46 | + |
| 47 | +### Notable optional fields |
| 48 | + |
| 49 | +- `userHandle` - Binary data sequence that uniquely identifies the user account. This data is opaque |
| 50 | + for anyone other than the RP. It is used to associate a credential with a specific user account. |
| 51 | +- `userName` - A human-readable name for the user account. This can be used to display the user |
| 52 | + account in the authenticator's user interface (if supported). |
| 53 | + |
| 54 | +## Storage modality |
| 55 | + |
| 56 | +### Client-side credentials |
| 57 | + |
| 58 | +The credential is stored in persistent storage embedded in the authenticator, client, or client |
| 59 | +device. This is rapidly becoming a common storage mode, as it is the only way to support synced |
| 60 | +credentials across multiple devices. Client-side storage is required. |
| 61 | + |
| 62 | +Hardware security keys also support this storage mode, but they often have a limited capacity (e.g. |
| 63 | +the YubiKey 5 can hold up to 25 client-side credentials). |
| 64 | + |
| 65 | +### Server-side credentials |
| 66 | + |
| 67 | +The credential is encrypted by the authenticator and stored in a database managed by the RP. This is |
| 68 | +the traditional storage mode and is often used in 2FA flows. |
| 69 | + |
| 70 | +This enables the authenticator to have unlimited storage capacity for credentials, since the data is |
| 71 | +stored by the RP instead of by the authenticator. However, this means that a credential stored in |
| 72 | +this way must be retrieved from the RP before the authenticator can use it. |
| 73 | + |
| 74 | +## Discoverability |
| 75 | + |
| 76 | +### Non-discoverable credentials |
| 77 | + |
| 78 | +This is a credential whose `credentialId` must be provided in `allowCredentials` when calling |
| 79 | +`navigator.credentials.get` because it is not client-side discoverable. This is always the case when |
| 80 | +the credential is stored server-side, because the RP must first identify the user in order to |
| 81 | +discover the `credentialId` to supply in the `navigator.credentials.get` call. |
| 82 | + |
| 83 | +### Client-side discoverable credentials |
| 84 | + |
| 85 | +:::info |
| 86 | + |
| 87 | +These credentials have been previously known as resident credentials or resident keys. Due to the |
| 88 | +phrases `ResidentKey` and `residentKey` being widely used in both the WebAuthn API and also in the |
| 89 | +Authenticator Model (e.g. in dictionary member names, algorithm variable names, and operation |
| 90 | +parameters) the usage of resident within their names has not been changed for backwards |
| 91 | +compatibility purposes. |
| 92 | + |
| 93 | +::: |
| 94 | + |
| 95 | +This credential is usable in authentication operations where the RP does not provide any |
| 96 | +`credentialId`, meaning that the RP does not need to identify the user first. |
| 97 | + |
| 98 | +As a result, an authenticator that can handle discoverable credentials can create assertion |
| 99 | +signatures using just an `rpId`. This enables single-click authentication flows where the returned |
| 100 | +assertion data contains everything the RP needs to identify and authenticate the user. |
| 101 | + |
| 102 | +This implies that the source of the credential must be stored either in the authenticator or the |
| 103 | +client platform (see [Client Side Credentials](#client-side-credentials)). |
| 104 | + |
| 105 | +## Storage vs discoverability matrix |
| 106 | + |
| 107 | +As described above, there is a relationship between storage modality and discoverability. This can |
| 108 | +be condensed into the matrix below, which shows the supported combinations of the two. |
| 109 | + |
| 110 | +| | Non-Discoverable | Discoverable | |
| 111 | +| --------------- | ---------------- | ------------ | |
| 112 | +| **Client-Side** | Supported | Supported | |
| 113 | +| **Server-Side** | Supported | - | |
0 commit comments