You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -16,7 +16,7 @@ Currently, this authentication strategy can only be used as a second factor. It
16
16
17
17
## Short summary
18
18
19
-
- This is implemented with the strategy `DeviceAuthn`, in spirit similar to `WebAuthn`
19
+
- This is implemented in the OEL version with the strategy `DeviceAuthn`, in spirit similar to `WebAuthn`
20
20
- The settings flow is used to manage keys (create, delete)
21
21
- The login flow is used to step-up the AAL to AAL2, or in the future AAL3
22
22
- Using the admin API, it is possible to delete all keys for a device on behalf of the user in case of theft or loss
@@ -35,7 +35,107 @@ Currently, this authentication strategy can only be used as a second factor. It
35
35
- TEE: Trusted Execution Environment
36
36
- CA: Certificate Authority
37
37
38
-
## Enrollment
38
+
## Guides
39
+
40
+
### How to implement Device Binding in your Android application
41
+
42
+
We recommend using the Ory Java SDK to communicate with Kratos, although this is not required. Code snippets here use this SDK, and are written in Kotlin.
43
+
44
+
Since Device Binding only is supported on native devices (not in the browser), all corresponding API calls should be done using the endpoints for native apps, to avoid having to pass cookies around manually.
45
+
46
+
1. Ensure that the `DeviceAuthn` strategy is enabled in the Kratos configuration. This strategy implements the settings and login flow. This is done so:
47
+
```yaml
48
+
selfservice:
49
+
methods:
50
+
deviceauthn:
51
+
enabled: true
52
+
```
53
+
1. Implement a runtime check for the Android version. If is lower than 24, Device Binding may not be used, and a fallback should be found, for example using passkeys.
54
+
1. Device Binding is (currently) only a second factor, the UI should only show existing Device Binding keys and related buttons (e.g. to add a key) if the user is currently logged in. This can be confirmed with a `whoami` call.
55
+
1. Create a [settings flow for native apps](https://www.ory.com/docs/reference/api#tag/frontend/operation/updateSettingsFlow). The response contains the list of existing Device Binding keys.
56
+
1. To delete an existing key, [complete the settings flow](https://www.ory.com/docs/reference/api#tag/frontend/operation/updateSettingsFlow) like this:
57
+
```kotlin
58
+
val clientKeyIdToDelete = "..."
59
+
60
+
val apiClient = Configuration.getDefaultApiClient()
61
+
val apiInstance = FrontendApi(apiClien)
62
+
val body = UpdateSettingsFlowBody()
63
+
val method = UpdateSettingsFlowWithDeviceAuthnMethod()
val updatedFlow = apiInstance.updateSettingsFlow(settingsFlow?.id, body, sessionToken, "")
92
+
```
93
+
Once a key is created, the KeyStore APIs can be used to list all keys, query a key using its id, etc. However we recommend that the application keeps track of what keys were created to know which ones can be used on the device, compared to which keys belong to the same identity but reside on other devices.
94
+
Note that there is a maximum number of keys that can be created for an identity, and there is no point to create multiple keys for the same user on the same device, even though the server allows it.
95
+
1. To use a key to step-up the AAL, [complete the settings flow](https://www.ory.com/docs/reference/api#tag/frontend/operation/updateSettingsFlow) like this:
96
+
```kotlin
97
+
val clientKeyId = "..."
98
+
val nonce = extractNonceFromUiNodes(flow?.ui?.nodes ?: emptyList())
99
+
if (nonce == null) {
100
+
throw Exception("No nonce found in UI")
101
+
}
102
+
103
+
val updateMethod = UpdateLoginFlowWithDeviceAuthnMethod()
val apiClient = Configuration.getDefaultApiClient()
118
+
119
+
withContext(Dispatchers.IO) {
120
+
val apiInstance = FrontendApi(apiClient)
121
+
val res = apiInstance.updateLoginFlow(
122
+
/* flow = */ flow.id,
123
+
/* updateLoginFlowBody = */ updateBody,
124
+
/* xSessionToken = */ sessionToken,
125
+
/* cookie = */ ""
126
+
)
127
+
}
128
+
```
129
+
130
+
When running Kratos in development mode, some server-side checks are relaxed, which allows for using the Android emulator to create and use keys. The Android emulator create keys in software.
131
+
132
+
When running Kratos in production mode, only hardware-resident keys are accepted, and thus the Android emulator cannot be used to create or use keys.
133
+
134
+
135
+
136
+
## Reference
137
+
138
+
### Enrollment
39
139
40
140
1. The `DeviceAuthn` strategy is enabled in the Kratos configuration. This strategy implements the settings and login flow. This is done so:
41
141
```yaml
@@ -63,35 +163,35 @@ Currently, this authentication strategy can only be used as a second factor. It
63
163
64
164
At this point the key is enrolled for the identity.
65
165
66
-
## Proof of device enrollment
166
+
### Proof of device enrollment
67
167
68
168
1. When the user creates the login flow with the DeviceAuthn strategy, the client receives a server challenge.
69
169
2. Using the private key in the hardware of the device, the client signs the server challenge using ECDSA. The signature is only emitted after a biometric/PIN prompt has been passed. The client then sends the signature to the server using the login flow update endpoint.
70
170
4. The server:
71
-
2. Checks that the signature is valid using the recorded public key in the database
72
-
3. Checks that no CA in the certificate chain (when the device has been enrolled) has been revoked
73
-
9. Erases the challenge value in the database to prevent re-use.
74
-
6. Replies with 200 with a fresh session token and a higher AAL e.g. AAL2 or AAL3
171
+
1. Checks that the signature is valid using the recorded public key in the database
172
+
1. Checks that no CA in the certificate chain (when the device has been enrolled) has been revoked
173
+
1. Erases the challenge value in the database to prevent re-use.
174
+
1. Replies with 200 with a fresh session token and a higher AAL e.g. AAL2 or AAL3
75
175
76
-
## Key Revocation
176
+
### Key Revocation
77
177
78
178
- The user can revoke a key themselves (e.g. because the device is stolen, lost, broken, etc) using the settings flow.
79
179
This action can be done from any device (e.g. from the browser), as it is the case for other methods e.g. WebAuthn.
80
180
- An admin using the admin API can revoke all keys on a device on behalf of the user. This is useful when the user only owns one device which is the one that should be revoked (e.g. one mobile phone) and which has been lost/stolen
81
181
82
182
Revocation is done by removing the key from the database.
83
183
84
-
## Device list
184
+
### Device list
85
185
86
186
The settings flow contains all keys for the identity. This is used to present the list of keys (including device name) in the UI.
87
187
88
-
## Key lifecycle on the device
188
+
### Key lifecycle on the device
89
189
90
190
- Creation: When the device enrollment process is started for the user
91
191
- Deletion:
92
192
- When the app is uninstalled or when the phone is reset, the mobile OSes automatically remove all keys for the app. This means that if the device was enrolled, the public key subsists server-side but the private key does not exist anymore, so no one can sign any challenge for this public key. This database entry is thus useless, but poses no security risks.
93
193
94
-
## Cryptography
194
+
### Cryptography
95
195
96
196
The security of this design relies on a chain of trust anchored in hardware and standard cryptographic primitives.
97
197
@@ -101,7 +201,7 @@ The security of this design relies on a chain of trust anchored in hardware and
101
201
- **Certificate Chains**: **X.509 certificates** are used to establish the chain of trust. The device's attestation is signed by a key that is, in turn, certified by a platform authority (Apple or Google), ensuring the attestation's authenticity.
102
202
- **No configurability**: Intentionally, for simplicity, performance, auditability, and to avoid downgrade attacks, all cryptographic primitives are fixed.
103
203
104
-
## Attack Surface and Mitigations
204
+
### Attack Surface and Mitigations
105
205
106
206
107
207
@@ -159,15 +259,15 @@ The security of this design relies on a chain of trust anchored in hardware and
159
259
- **Mitigation**:
160
260
- **Challenge bound to the identity id**: The challenge is bound to the identity in the database (stored in the same row). Since the identity is detected from the session token, an attacker cannot tamper with the identity id (unless they steal the session token, at which point they *are* the user, from the server perspective).
161
261
162
-
## Comparison with WebAuthn and Passkeys
262
+
### Comparison with WebAuthn and Passkeys
163
263
164
264
It is useful to compare this custom implementation with the FIDO WebAuthn standard and the user-facing concept of Passkeys. While they share core cryptographic principles, their goals and scope are fundamentally different.
165
265
166
-
### Similarities
266
+
#### Similarities
167
267
168
268
- **Core Cryptography**: Both approaches are built on public-key cryptography (typically ECDSA), and use a challenge-response protocol
169
269
170
-
### Key Differences
270
+
#### Key Differences
171
271
172
272
- **Standard vs. Proprietary**
173
273
- **WebAuthn/Passkeys**: An open, interoperable standard from the W3C and FIDO Alliance, designed to work across different websites, apps, browsers, and operating systems.
@@ -179,7 +279,7 @@ It is useful to compare this custom implementation with the FIDO WebAuthn standa
179
279
- **WebAuthn/Passkeys**: Attestation is an **optional** feature. While a server can request it to verify the properties of an authenticator, many services skip it in favor of a simpler user experience. The focus is on proving possession of the key, not on scrutinizing the device itself.
180
280
- **This Design**: Attestation is **mandatory and central** to the entire security model. The main purpose of the enrollment ceremony is for the server to validate the device's hardware and software integrity.
- iOS: [https://developer.apple.com/documentation/devicecheck/validating-apps-that-connect-to-your-server](https://developer.apple.com/documentation/devicecheck/validating-apps-that-connect-to-your-server) and [https://developer.apple.com/documentation/devicecheck/establishing-your-app-s-integrity](https://developer.apple.com/documentation/devicecheck/establishing-your-app-s-integrity)
0 commit comments