@le-space/orbitdb-identity-provider-webauthn-did 0.12.1 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +7 -2
- package/docs/API.md +7 -2
- package/package.json +1 -1
- package/src/keystore/derived-signing-key.js +8 -1
- package/src/keystore/prf-keys.js +17 -1
- package/src/webauthn/config.js +8 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 0.12.2
|
|
4
|
+
|
|
5
|
+
A request that names a passkey asks that passkey. Until now this entry stood under 0.12.1, but
|
|
6
|
+
0.12.1 was tagged before it merged and does not have it.
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
|
|
10
|
+
- **A PRF output came from whichever passkey answered.** With discoverable credentials on (the
|
|
11
|
+
default), `buildCredentialRequestOptions` dropped the credential id it was given, so the browser
|
|
12
|
+
let any passkey of the relying party answer: two passkeys of one site in one keychain, or two
|
|
13
|
+
security keys plugged in. Every request that names a credential now carries it in
|
|
14
|
+
`allowCredentials`; discoverable credentials decide only what a request without one does.
|
|
15
|
+
`readPrfOutput` also checks which credential answered and refuses another one
|
|
16
|
+
(`WebAuthnAuthenticationError`), and the provider's own read for the signing key derives nothing
|
|
17
|
+
from it. Found in simple-todo's invoice01: a second passkey's vault slot was sealed under the
|
|
18
|
+
first one's PRF output, and the second passkey could not open it. Le-Space/belege has asked with
|
|
19
|
+
`discoverableCredentials: false` since its #429 for this reason; Le-Space/invoice and
|
|
20
|
+
simple-todo's archived01 ask without it, and are fixed by updating to 0.12.2.
|
|
21
|
+
|
|
22
|
+
Tested in `tests/prf-keys.test.js` with discoverable credentials on: a request names the credential
|
|
23
|
+
it asks, and another credential's answer is refused.
|
|
24
|
+
|
|
3
25
|
## 0.12.1
|
|
4
26
|
|
|
5
27
|
A peer loads another peer's varsig identity from IPFS again, with Helia 7.
|
package/README.md
CHANGED
|
@@ -74,9 +74,14 @@ Behavior:
|
|
|
74
74
|
|
|
75
75
|
- `discoverableCredentials: true`
|
|
76
76
|
- registration requests resident/discoverable credentials
|
|
77
|
-
- assertion
|
|
77
|
+
- an assertion that names no credential omits `allowCredentials`, and the
|
|
78
|
+
browser offers the passkeys it has
|
|
78
79
|
- `discoverableCredentials: false`
|
|
79
|
-
- assertion
|
|
80
|
+
- every assertion names its credential
|
|
81
|
+
- Either way, an assertion that names a credential asks that one, in
|
|
82
|
+
`allowCredentials` (since 0.12.2). Before, discoverable mode dropped the
|
|
83
|
+
name, and another passkey of the site could answer — with its own PRF
|
|
84
|
+
output, which looks as random as the right one.
|
|
80
85
|
|
|
81
86
|
## Memory Keystore Quick Start
|
|
82
87
|
|
package/docs/API.md
CHANGED
|
@@ -283,9 +283,14 @@ bytes that never come back.
|
|
|
283
283
|
- `prfInput` — overrides the credential's. Leave it out when the output also
|
|
284
284
|
goes to the identity provider, which asks with the credential's.
|
|
285
285
|
|
|
286
|
+
It asks this credential only (`allowCredentials`), and checks that this
|
|
287
|
+
credential answered: another passkey of the same site would answer with its own
|
|
288
|
+
PRF output, and every key derived from it would quietly be the wrong one.
|
|
289
|
+
|
|
286
290
|
Throws `PrfUnavailableError` when the authenticator answers without a PRF
|
|
287
|
-
output
|
|
288
|
-
|
|
291
|
+
output, and `WebAuthnAuthenticationError` when another credential answers. A
|
|
292
|
+
refused prompt stays the browser's `NotAllowedError`, so "the user said no" and
|
|
293
|
+
"this authenticator has no PRF" can be told apart.
|
|
289
294
|
|
|
290
295
|
#### `deriveSubkey(prfOutput, info, { length = 32 })`
|
|
291
296
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@le-space/orbitdb-identity-provider-webauthn-did",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "WebAuthn-based DID identity provider for OrbitDB for hardware-secured wallets and biometric Passkey authentication",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
import { CRYPTO_ALGORITHMS, KEY_TYPES } from '../constants.js';
|
|
37
37
|
import { buildCredentialRequestOptions } from '../webauthn/config.js';
|
|
38
38
|
import { prfInputForRelyingParty } from '../webauthn/prf-input.js';
|
|
39
|
-
import { hkdfSha256 } from './prf-keys.js';
|
|
39
|
+
import { hkdfSha256, sameBytes } from './prf-keys.js';
|
|
40
40
|
|
|
41
41
|
const log = logger('orbitdb-identity-provider-webauthn-did:derived-key');
|
|
42
42
|
|
|
@@ -145,6 +145,13 @@ export async function getPrfOutput(credential, { rpId } = {}) {
|
|
|
145
145
|
})
|
|
146
146
|
);
|
|
147
147
|
|
|
148
|
+
// Another passkey's PRF output would derive another passkey's key, under
|
|
149
|
+
// this DID: refused like an answer without PRF.
|
|
150
|
+
const answered = assertion?.rawId ? new Uint8Array(assertion.rawId) : null;
|
|
151
|
+
if (answered && !sameBytes(answered, rawCredentialId)) {
|
|
152
|
+
log('another credential answered; no key derived from it');
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
148
155
|
const results = assertion?.getClientExtensionResults?.()?.prf?.results;
|
|
149
156
|
if (!results?.first) {
|
|
150
157
|
log('authenticator returned no PRF output');
|
package/src/keystore/prf-keys.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* the identity asks the passkey once.
|
|
21
21
|
*/
|
|
22
22
|
import { CRYPTO_ALGORITHMS } from '../constants.js';
|
|
23
|
-
import { PrfUnavailableError } from '../errors.js';
|
|
23
|
+
import { PrfUnavailableError, WebAuthnAuthenticationError } from '../errors.js';
|
|
24
24
|
import { buildCredentialRequestOptions } from '../webauthn/config.js';
|
|
25
25
|
import { prfInputForRelyingParty } from '../webauthn/prf-input.js';
|
|
26
26
|
|
|
@@ -39,6 +39,11 @@ function toBytes(value) {
|
|
|
39
39
|
return undefined;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/** @param {Uint8Array} a @param {Uint8Array} b */
|
|
43
|
+
export function sameBytes(a, b) {
|
|
44
|
+
return a.length === b.length && a.every((byte, i) => byte === b[i]);
|
|
45
|
+
}
|
|
46
|
+
|
|
42
47
|
/**
|
|
43
48
|
* HKDF-SHA-256 with an empty salt.
|
|
44
49
|
*
|
|
@@ -113,8 +118,13 @@ function assertInfo(info, caller) {
|
|
|
113
118
|
* @param {string} [options.rpId] - Relying party id; defaults to this page's
|
|
114
119
|
* hostname.
|
|
115
120
|
* @param {Uint8Array} [options.prfInput] - Overrides the credential's input.
|
|
121
|
+
* The request names the credential, and the answer is checked against it:
|
|
122
|
+
* another passkey of the same relying party would answer with its own PRF
|
|
123
|
+
* output, and every key derived from that would belong to the wrong one.
|
|
124
|
+
*
|
|
116
125
|
* @returns {Promise<Uint8Array>} The PRF output, 32 bytes.
|
|
117
126
|
* @throws {PrfUnavailableError} When the authenticator answers without one.
|
|
127
|
+
* @throws {WebAuthnAuthenticationError} When another credential answers.
|
|
118
128
|
*/
|
|
119
129
|
export async function readPrfOutput(credential, { rpId, prfInput } = {}) {
|
|
120
130
|
if (!credential || typeof credential !== 'object') {
|
|
@@ -140,6 +150,12 @@ export async function readPrfOutput(credential, { rpId, prfInput } = {}) {
|
|
|
140
150
|
})
|
|
141
151
|
);
|
|
142
152
|
|
|
153
|
+
const answered = toBytes(assertion?.rawId);
|
|
154
|
+
if (answered && !sameBytes(answered, rawCredentialId)) {
|
|
155
|
+
throw new WebAuthnAuthenticationError(
|
|
156
|
+
'Another passkey answered than the one asked for its PRF output'
|
|
157
|
+
);
|
|
158
|
+
}
|
|
143
159
|
const first = assertion?.getClientExtensionResults?.()?.prf?.results?.first;
|
|
144
160
|
if (!first) {
|
|
145
161
|
throw new PrfUnavailableError(
|
package/src/webauthn/config.js
CHANGED
|
@@ -138,7 +138,14 @@ export function buildCredentialRequestOptions(options = {}) {
|
|
|
138
138
|
...(rpId ? { rpId } : {}),
|
|
139
139
|
userVerification,
|
|
140
140
|
...(extensions ? { extensions } : {}),
|
|
141
|
-
|
|
141
|
+
// A request that names a credential asks that credential. Discoverable
|
|
142
|
+
// credentials decide only what a request without one does: the browser
|
|
143
|
+
// offers the passkeys it has. Left to the browser, a request that named
|
|
144
|
+
// one was answered by whichever passkey the person picked or the
|
|
145
|
+
// authenticator chose — with that passkey's PRF output, which nothing can
|
|
146
|
+
// tell from the right one: a vault slot sealed under another key, a
|
|
147
|
+
// signing key derived from another passkey.
|
|
148
|
+
...(credentialId
|
|
142
149
|
? {
|
|
143
150
|
allowCredentials: [
|
|
144
151
|
{
|