@localauth/cli 0.2.0 → 0.3.0
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/README.md +23 -18
- package/cli/cli.ts +2 -2
- package/cli/config.ts +1 -1
- package/cli/encryption.ts +2 -2
- package/cli/verify.ts +17 -12
- package/package.json +1 -1
- package/shared/sas.ts +55 -44
- package/skills/localauth/SKILL.md +5 -6
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ localauth finish # hand a pasted callback (read from stdin) t
|
|
|
59
59
|
localauth list # this machine's logins and their status
|
|
60
60
|
localauth show <id> # one login with its output (--json for scripts)
|
|
61
61
|
localauth status # account and service this machine is connected to
|
|
62
|
-
localauth verify #
|
|
62
|
+
localauth verify # match a number on the page to trust end-to-end encryption
|
|
63
63
|
localauth logout # disconnect this machine
|
|
64
64
|
```
|
|
65
65
|
|
|
@@ -185,7 +185,7 @@ curl https://localauth.dev/api/v1/runs \
|
|
|
185
185
|
```
|
|
186
186
|
|
|
187
187
|
Permissions are `runs:read`, `runs:write`, `machines:read` and `machines:write`.
|
|
188
|
-
Personal tokens cannot change the account, encryption keys, passkeys, other tokens or
|
|
188
|
+
Personal tokens cannot change the account, encryption keys, passkeys, other tokens or machine
|
|
189
189
|
verification. In Cloudflare Access mode, personal tokens and OAuth are disabled.
|
|
190
190
|
The website uses the Access JWT and the CLI uses its machine token.
|
|
191
191
|
|
|
@@ -198,16 +198,21 @@ even if invalid. Cross-origin clients use explicit header credentials; CORS neve
|
|
|
198
198
|
cookie credentials. Errors return `{ error: { code, message } }`; rate limits return 429
|
|
199
199
|
with `Retry-After`. Machine tokens and link capabilities have separate routes and authority.
|
|
200
200
|
|
|
201
|
+
The first time someone signs in to the iOS app, localauth.dev shows what the app will be able to
|
|
202
|
+
do and asks them to allow it (`/oauth/consent`); the answer is remembered. **Account, Signed-in
|
|
203
|
+
apps** lists each device where the app is signed in and signs one out at once; the same list is
|
|
204
|
+
`GET /api/v1/app-sessions` and `DELETE /api/v1/app-sessions/{id}` (account scope).
|
|
205
|
+
|
|
201
206
|
The iOS app (client `localauth-ios`) signs in with Better Auth's OAuth provider:
|
|
202
207
|
`/api/auth/oauth2/authorize`, `/api/auth/oauth2/token` and `/api/auth/oauth2/revoke`, with S256
|
|
203
208
|
PKCE and an exact redirect allowlist. Access tokens last an hour; refresh tokens last 90 days and
|
|
204
209
|
rotate on use. A retry within 10 seconds gets the same new pair; reusing a rotated refresh token
|
|
205
|
-
later revokes all of the app's tokens for that person. The app stays signed in independently
|
|
206
|
-
|
|
207
|
-
refresh token on sign-out, deleting the account removes every token, and disabling the client
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
210
|
+
later revokes all of the app's tokens for that person. The app stays signed in independently of
|
|
211
|
+
the browser session it signed in through (it asks for `offline_access`). The app revokes its
|
|
212
|
+
refresh token on sign-out, deleting the account removes every token, and disabling the client row
|
|
213
|
+
switches the whole app off. Third-party clients and registration are not offered. The plugin has a
|
|
214
|
+
documented race in that revocation, which this repository patches; see
|
|
215
|
+
[patches/README.md](patches/README.md).
|
|
211
216
|
|
|
212
217
|
End-to-end data stays sealed through the API. A client that needs plaintext must hold the
|
|
213
218
|
account private key, obtained locally from a passkey PRF wrap, and implement the
|
|
@@ -218,8 +223,8 @@ On browsers supporting WebMCP, dashboard and link pages register login tools and
|
|
|
218
223
|
and device page register machine approval tools. They use the page's existing decryption,
|
|
219
224
|
sealing, callback checks and confirmation dialogs. A link page sees only its run. A locked
|
|
220
225
|
browser asks the person to unlock on the page. Machine output and names are untrusted data.
|
|
221
|
-
There are no WebMCP tools for
|
|
222
|
-
sign-out or deletion. A person still
|
|
226
|
+
There are no WebMCP tools for machine verification, account, encryption, passkey or token changes,
|
|
227
|
+
sign-out or deletion. A person still taps the matching number after approving an E2E machine.
|
|
223
228
|
|
|
224
229
|
## Encryption
|
|
225
230
|
|
|
@@ -252,15 +257,15 @@ public-key-only envelopes, and messages from a different account key. The servic
|
|
|
252
257
|
private key, so it cannot forge or alter these messages. Input is bound to the current attempt
|
|
253
258
|
and deduplicated by an authenticated message id. Ciphertexts bind their kind and record to prevent swapping.
|
|
254
259
|
|
|
255
|
-
A machine trusts the account public key only after a short
|
|
260
|
+
A machine trusts the account public key only after a short number check, so the service can't
|
|
256
261
|
hand it a key of its own. `localauth verify` (and `localauth login` on an end-to-end account)
|
|
257
262
|
prints a link; the page and the machine exchange ephemeral ECDH keys through the service, the
|
|
258
|
-
machine having committed to its key before seeing the browser's, and both derive
|
|
259
|
-
from the shared secret and everything exchanged
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
263
|
+
machine having committed to its key before seeing the browser's, and both derive a three-digit
|
|
264
|
+
number from the shared secret and everything exchanged. The terminal prints the number; the page
|
|
265
|
+
offers it among two decoys and "None of these match", like a phone sign-in prompt, so nobody
|
|
266
|
+
types anything. Tapping the right number sends a MAC of the exchange that the machine checks
|
|
267
|
+
before pinning the key. A service in the middle would have to guess the number, a 1 in 1000
|
|
268
|
+
chance per attempt, and every failed attempt shows a warning on both sides. The browser also
|
|
264
269
|
stores the account's MAC over the machine's key so other browsers show it as verified.
|
|
265
270
|
|
|
266
271
|
Until it is verified, a machine refuses to run logins for an end-to-end account. If the service
|
|
@@ -394,7 +399,7 @@ npm run design:qa # screenshots of every design preview, light and dark, ph
|
|
|
394
399
|
```
|
|
395
400
|
|
|
396
401
|
While `npm run dev` runs, http://localhost:8787/design shows every page in every state (signed
|
|
397
|
-
out, waiting logins, failed retries,
|
|
402
|
+
out, waiting logins, failed retries, number verification, dialogs, …) with made-up data, and
|
|
398
403
|
`/design/<id>` opens one with a switcher in the bottom right for states and light/dark. They are
|
|
399
404
|
for tuning the design: no real data, no API calls, and they don't exist in deployed Workers.
|
|
400
405
|
|
package/cli/cli.ts
CHANGED
|
@@ -36,7 +36,7 @@ Usage:
|
|
|
36
36
|
(reads it from stdin when omitted, keeping it out of ps)
|
|
37
37
|
localauth list [--json] This machine's logins and requests
|
|
38
38
|
localauth show <id> [--json] One login or request with its output
|
|
39
|
-
localauth verify
|
|
39
|
+
localauth verify Match a number on the page to trust the account's encryption key
|
|
40
40
|
localauth status Which account and service this machine is connected to
|
|
41
41
|
localauth url The page to open to finish logins
|
|
42
42
|
localauth logout Disconnect this machine
|
|
@@ -231,7 +231,7 @@ async function login(url: string, name: string): Promise<number> {
|
|
|
231
231
|
terminal.writeLine(`${styles.green('✓')} Connected as ${styles.bold(reply.data.user.email)}.`)
|
|
232
232
|
let me = await createService(url, connection)<{ accountKey: { publicKey: string } | null }>('GET', '/api/v1/machine/me')
|
|
233
233
|
if (me.status === 200 && me.data.accountKey) {
|
|
234
|
-
terminal.writeLine('This account uses end-to-end encryption, so check this machine with
|
|
234
|
+
terminal.writeLine('This account uses end-to-end encryption, so check this machine with a number.')
|
|
235
235
|
if (!(await verifyMachine(connection, (line) => terminal.writeLine(line)))) return 1
|
|
236
236
|
}
|
|
237
237
|
terminal.writeLine(`Run logins with: localauth run -- <command> Finish them at ${url}/`)
|
package/cli/config.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface Connection {
|
|
|
16
16
|
publicKey: string
|
|
17
17
|
accountPublicKey?: string
|
|
18
18
|
accountFingerprint?: string
|
|
19
|
-
/** True once the account key was confirmed with
|
|
19
|
+
/** True once the account key was confirmed with a number (localauth verify), not just trusted on first sight. */
|
|
20
20
|
accountVerified?: boolean
|
|
21
21
|
user: { email: string; name: string }
|
|
22
22
|
/** A Cloudflare Access service token, when the service sits behind Access. */
|
package/cli/encryption.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { createService, messageOf } from './service.ts'
|
|
|
6
6
|
export const KEY_CHANGED = 'the account key changed; run localauth verify to check and trust the new one'
|
|
7
7
|
export const KEY_REMOVED = 'end-to-end encryption was reset for this account; run localauth login to reconnect this machine'
|
|
8
8
|
export const NEEDS_VERIFY = 'this account uses end-to-end encryption; verify this machine first: localauth verify'
|
|
9
|
-
/** A pinned key that changed needs a new
|
|
9
|
+
/** A pinned key that changed needs a new number check; one that vanished needs a new connection, never a quiet downgrade. */
|
|
10
10
|
export function checkPin(pinned: string | undefined, reported: string | null) {
|
|
11
11
|
if (pinned && !reported) throw new Error(KEY_REMOVED)
|
|
12
12
|
if (pinned && pinned !== reported) throw new Error(KEY_CHANGED)
|
|
@@ -24,7 +24,7 @@ export async function refreshPin(connection: Connection, say: (text: string) =>
|
|
|
24
24
|
if (reply.status !== 200) throw new Error(messageOf(reply))
|
|
25
25
|
let publicKey = reply.data.accountKey?.publicKey ?? null
|
|
26
26
|
checkPin(connection.accountPublicKey, publicKey)
|
|
27
|
-
// An account key is trusted only after the person
|
|
27
|
+
// An account key is trusted only after the person matched a number (localauth verify), never on sight.
|
|
28
28
|
if (publicKey && !connection.accountPublicKey) throw new Error(NEEDS_VERIFY)
|
|
29
29
|
void say
|
|
30
30
|
return { publicKey, machineName: reply.data.machine?.name }
|
package/cli/verify.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fingerprint } from '../shared/e2e.ts'
|
|
2
|
-
import { checkConfirmation, commitment, deriveSas, ephemeral,
|
|
2
|
+
import { checkConfirmation, commitment, deriveSas, ephemeral, type Transcript } from '../shared/sas.ts'
|
|
3
3
|
import { saveConnection, type Connection } from './config.ts'
|
|
4
4
|
import { createService, messageOf } from './service.ts'
|
|
5
5
|
|
|
@@ -15,21 +15,22 @@ interface MachineView {
|
|
|
15
15
|
const POLL_MS = 1500
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Verify the account key with a browser that holds it (shared/sas.ts): print a link, print
|
|
19
|
-
*
|
|
20
|
-
* the person
|
|
18
|
+
* Verify the account key with a browser that holds it (shared/sas.ts): print a link, print a
|
|
19
|
+
* three-digit number once the page has answered, and trust the account key only after the browser
|
|
20
|
+
* confirms that the person tapped the same number there. Returns true when this machine now trusts a verified account key.
|
|
21
21
|
*/
|
|
22
22
|
export async function verifyMachine(connection: Connection, say: Say, timeoutMs = 10 * 60 * 1000): Promise<boolean> {
|
|
23
23
|
let service = createService(connection.url, connection)
|
|
24
24
|
let own = await ephemeral()
|
|
25
25
|
let started = await service<{ id: string }>('POST', '/api/v1/machine/verifications', {
|
|
26
26
|
commitment: await commitment(own.publicKey, connection.publicKey),
|
|
27
|
+
version: 2,
|
|
27
28
|
})
|
|
28
29
|
if (started.status === 409) throw new Error('This account has no end-to-end encryption to verify. Add a passkey on the Account page first.')
|
|
29
30
|
if (started.status !== 201) throw new Error(messageOf(started))
|
|
30
31
|
let id = started.data.id
|
|
31
32
|
say(`To verify this machine, open ${connection.url}/verify/${id}`)
|
|
32
|
-
say('The
|
|
33
|
+
say('The number to tap there appears here once the page is open.')
|
|
33
34
|
|
|
34
35
|
let deadline = Date.now() + timeoutMs
|
|
35
36
|
let view = await waitFor(service, id, deadline, (v) => v.status !== 'committed')
|
|
@@ -44,18 +45,22 @@ export async function verifyMachine(connection: Connection, say: Say, timeoutMs
|
|
|
44
45
|
machineEphemeral: own.publicKey,
|
|
45
46
|
browserEphemeral: view.browserEphemeral,
|
|
46
47
|
}
|
|
47
|
-
let {
|
|
48
|
+
let { code, macKey } = await deriveSas(own.privateKey, view.browserEphemeral, transcript)
|
|
48
49
|
say('')
|
|
49
|
-
say(`On the page,
|
|
50
|
+
say(`On the page, tap ${code}`)
|
|
50
51
|
say('')
|
|
51
52
|
|
|
52
53
|
view = await waitFor(service, id, deadline, (v) => v.status === 'confirmed' || v.status === 'rejected')
|
|
53
|
-
|
|
54
|
+
// The MAC vouches for the transcript only, so trust nothing else from this reply: a relay could
|
|
55
|
+
// keep a valid MAC and report a key of its own next to it.
|
|
56
|
+
let unchanged = view.accountPublicKey === transcript.accountPublicKey && view.browserEphemeral === transcript.browserEphemeral
|
|
57
|
+
if (view.status !== 'confirmed' || !unchanged || !view.confirmation || !(await checkConfirmation(macKey, transcript, view.confirmation))) {
|
|
54
58
|
return refused(say, view)
|
|
55
59
|
}
|
|
56
|
-
let
|
|
57
|
-
connection.accountPublicKey
|
|
58
|
-
connection.
|
|
60
|
+
let accountPublicKey = transcript.accountPublicKey
|
|
61
|
+
let changed = connection.accountPublicKey && connection.accountPublicKey !== accountPublicKey
|
|
62
|
+
connection.accountPublicKey = accountPublicKey
|
|
63
|
+
connection.accountFingerprint = await fingerprint(accountPublicKey)
|
|
59
64
|
connection.accountVerified = true
|
|
60
65
|
saveConnection(connection)
|
|
61
66
|
say(changed ? '✓ Verified the new account key. This machine now encrypts to it.' : '✓ Verified. Logins from this machine are end-to-end encrypted to your account.')
|
|
@@ -75,7 +80,7 @@ async function waitFor(service: ReturnType<typeof createService>, id: string, de
|
|
|
75
80
|
function refused(say: Say, view: MachineView): false {
|
|
76
81
|
say(
|
|
77
82
|
view.status === 'rejected'
|
|
78
|
-
? '✗ Not verified: the page said the
|
|
83
|
+
? '✗ Not verified: the page said the number did not match, or the request was declined.'
|
|
79
84
|
: '✗ Not verified: the confirmation from the page did not check out.',
|
|
80
85
|
)
|
|
81
86
|
say(' Someone may be intercepting this connection. Do not send secrets to this machine until it verifies.')
|
package/package.json
CHANGED
package/shared/sas.ts
CHANGED
|
@@ -7,31 +7,22 @@ import { fromBase64Url, generateKeyPair, importPrivateKey, importPublicKey, toBa
|
|
|
7
7
|
* 1. The machine makes an ephemeral ECDH key and sends only a commitment to it.
|
|
8
8
|
* 2. The browser sends its ephemeral key and the account public key.
|
|
9
9
|
* 3. The machine reveals its ephemeral key; the browser checks it against the commitment.
|
|
10
|
-
* 4. Both derive
|
|
10
|
+
* 4. Both derive a short number and a MAC key from ECDH(ephemerals) and the whole transcript.
|
|
11
11
|
*
|
|
12
12
|
* Someone in the middle must fix their key toward the browser before seeing the browser's, and
|
|
13
13
|
* toward the machine before seeing the machine's, so they can't search for keys that make both
|
|
14
|
-
* sides show the same
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* sides show the same number: each attempt succeeds with probability 10^-SAS_DIGITS, and every
|
|
15
|
+
* failed one shows the person a warning. The terminal prints the number; the page offers it among
|
|
16
|
+
* decoys, like a phone sign-in prompt, and the person taps the one that matches. The browser then
|
|
17
|
+
* confirms with a MAC.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
['🎁', 'Gift'], ['💡', 'Light bulb'], ['📕', 'Book'], ['✏️', 'Pencil'], ['📎', 'Paperclip'], ['✂️', 'Scissors'], ['🔒', 'Lock'], ['🔑', 'Key'],
|
|
27
|
-
['🔨', 'Hammer'], ['☎️', 'Telephone'], ['🏁', 'Flag'], ['🚂', 'Train'], ['🚲', 'Bicycle'], ['✈️', 'Aeroplane'], ['🚀', 'Rocket'], ['🏆', 'Trophy'],
|
|
28
|
-
['⚽', 'Ball'], ['🎸', 'Guitar'], ['🎺', 'Trumpet'], ['🔔', 'Bell'], ['⚓', 'Anchor'], ['🎧', 'Headphones'], ['📁', 'Folder'], ['📌', 'Pin'],
|
|
29
|
-
]
|
|
30
|
-
|
|
31
|
-
/** Four indexes into SAS_EMOJI. */
|
|
32
|
-
export type Sas = [number, number, number, number]
|
|
33
|
-
|
|
34
|
-
/** Everything both sides must agree on; any difference changes the emoji and the MAC key. */
|
|
20
|
+
/** Digits in the code. The owner chose three: one chance in a thousand per attempt. */
|
|
21
|
+
export const SAS_DIGITS = 3
|
|
22
|
+
/** Numbers the page offers: the right one and decoys. */
|
|
23
|
+
export const SAS_CHOICES = 3
|
|
24
|
+
|
|
25
|
+
/** Everything both sides must agree on; any difference changes the number and the MAC key. */
|
|
35
26
|
export interface Transcript {
|
|
36
27
|
verificationId: string
|
|
37
28
|
machinePublicKey: string
|
|
@@ -43,7 +34,7 @@ export interface Transcript {
|
|
|
43
34
|
const enc = new TextEncoder()
|
|
44
35
|
|
|
45
36
|
export async function commitment(machineEphemeral: string, machinePublicKey: string): Promise<string> {
|
|
46
|
-
let digest = await crypto.subtle.digest('SHA-256', enc.encode(`localauth/sas/
|
|
37
|
+
let digest = await crypto.subtle.digest('SHA-256', enc.encode(`localauth/sas/v2/commit|${machineEphemeral}|${machinePublicKey}`))
|
|
47
38
|
return toBase64Url(new Uint8Array(digest))
|
|
48
39
|
}
|
|
49
40
|
|
|
@@ -53,28 +44,51 @@ export async function ephemeral() {
|
|
|
53
44
|
return { publicKey: pair.publicKey, privateKey: await importPrivateKey(pair.privateKey) }
|
|
54
45
|
}
|
|
55
46
|
|
|
56
|
-
/**
|
|
47
|
+
/** What the browser pins from the verification before it sends its own ephemeral key. */
|
|
48
|
+
export interface Pinned {
|
|
49
|
+
commitment: string
|
|
50
|
+
machineId: string
|
|
51
|
+
machinePublicKey: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Whether the machine's revealed ephemeral is the one it committed to, judged only against values
|
|
56
|
+
* pinned before the browser sent its own key. A service that could change the commitment or the
|
|
57
|
+
* machine key afterwards would see the browser's key first and could try keys until the numbers
|
|
58
|
+
* match, which defeats the commitment.
|
|
59
|
+
*/
|
|
60
|
+
export async function honestReveal(
|
|
61
|
+
pinned: Pinned,
|
|
62
|
+
revealed: { commitment: string; machineId: string; machinePublicKey: string; machineEphemeral: string | null },
|
|
63
|
+
): Promise<boolean> {
|
|
64
|
+
if (!revealed.machineEphemeral) return false
|
|
65
|
+
if (revealed.commitment !== pinned.commitment || revealed.machineId !== pinned.machineId || revealed.machinePublicKey !== pinned.machinePublicKey) return false
|
|
66
|
+
return (await commitment(revealed.machineEphemeral, pinned.machinePublicKey)) === pinned.commitment
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The code and the confirmation MAC key, from our ephemeral private key and the peer's ephemeral. */
|
|
57
70
|
export async function deriveSas(ownEphemeral: CryptoKey, peerEphemeral: string, transcript: Transcript) {
|
|
58
71
|
let shared = new Uint8Array(await crypto.subtle.deriveBits({ name: 'ECDH', public: await importPublicKey(peerEphemeral) }, ownEphemeral, 256))
|
|
59
72
|
let material = await crypto.subtle.importKey('raw', shared, 'HKDF', false, ['deriveBits'])
|
|
60
73
|
let bits = new Uint8Array(
|
|
61
74
|
await crypto.subtle.deriveBits(
|
|
62
|
-
{ name: 'HKDF', hash: 'SHA-256', salt: enc.encode('localauth/sas/
|
|
75
|
+
{ name: 'HKDF', hash: 'SHA-256', salt: enc.encode('localauth/sas/v2'), info: enc.encode(transcriptText(transcript)) },
|
|
63
76
|
material,
|
|
64
|
-
(
|
|
77
|
+
(4 + 32) * 8,
|
|
65
78
|
),
|
|
66
79
|
)
|
|
67
|
-
|
|
68
|
-
let
|
|
69
|
-
let
|
|
70
|
-
|
|
80
|
+
// A 32-bit number reduced to SAS_DIGITS digits: the bias is below one part in four million.
|
|
81
|
+
let n = new DataView(bits.buffer).getUint32(0)
|
|
82
|
+
let code = String(n % 10 ** SAS_DIGITS).padStart(SAS_DIGITS, '0')
|
|
83
|
+
let macKey = await crypto.subtle.importKey('raw', bits.slice(4), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign', 'verify'])
|
|
84
|
+
return { code, macKey }
|
|
71
85
|
}
|
|
72
86
|
|
|
73
87
|
function transcriptText(t: Transcript): string {
|
|
74
|
-
return ['localauth/sas/
|
|
88
|
+
return ['localauth/sas/v2', t.verificationId, t.machinePublicKey, t.accountPublicKey, t.machineEphemeral, t.browserEphemeral].join('|')
|
|
75
89
|
}
|
|
76
90
|
|
|
77
|
-
/** The browser's confirmation that the person picked the matching
|
|
91
|
+
/** The browser's confirmation that the person picked the matching number. */
|
|
78
92
|
export async function confirmation(macKey: CryptoKey, transcript: Transcript): Promise<string> {
|
|
79
93
|
let mac = await crypto.subtle.sign('HMAC', macKey, enc.encode(`confirm|${transcriptText(transcript)}`))
|
|
80
94
|
return toBase64Url(new Uint8Array(mac))
|
|
@@ -88,27 +102,28 @@ export async function checkConfirmation(macKey: CryptoKey, transcript: Transcrip
|
|
|
88
102
|
}
|
|
89
103
|
}
|
|
90
104
|
|
|
91
|
-
|
|
92
|
-
|
|
105
|
+
/** Positions where two codes differ. */
|
|
106
|
+
function distance(a: string, b: string) {
|
|
107
|
+
return [...a].filter((digit, i) => digit !== b[i]).length
|
|
93
108
|
}
|
|
94
109
|
|
|
95
110
|
/**
|
|
96
111
|
* Wrong answers to show next to the right one: random, distinct, and each differing from the right
|
|
97
|
-
* one and from each other in at least two
|
|
112
|
+
* one and from each other in at least two digits, so a glance can't confuse them.
|
|
98
113
|
*/
|
|
99
|
-
export function decoys(correct:
|
|
100
|
-
let chosen:
|
|
101
|
-
let far = (a:
|
|
114
|
+
export function decoys(correct: string, count = SAS_CHOICES - 1, random: (n: number) => number = randomBelow): string[] {
|
|
115
|
+
let chosen: string[] = []
|
|
116
|
+
let far = (a: string, b: string) => distance(a, b) >= Math.min(2, SAS_DIGITS)
|
|
102
117
|
while (chosen.length < count) {
|
|
103
|
-
let candidate =
|
|
118
|
+
let candidate = Array.from({ length: SAS_DIGITS }, () => random(10)).join('')
|
|
104
119
|
if (far(candidate, correct) && chosen.every((other) => far(candidate, other))) chosen.push(candidate)
|
|
105
120
|
}
|
|
106
121
|
return chosen
|
|
107
122
|
}
|
|
108
123
|
|
|
109
|
-
/** The right
|
|
110
|
-
export function options(correct:
|
|
111
|
-
let all = [correct, ...decoys(correct,
|
|
124
|
+
/** The right code and the decoys in random order. */
|
|
125
|
+
export function options(correct: string, random: (n: number) => number = randomBelow): string[] {
|
|
126
|
+
let all = [correct, ...decoys(correct, SAS_CHOICES - 1, random)]
|
|
112
127
|
for (let i = all.length - 1; i > 0; i--) {
|
|
113
128
|
let j = random(i + 1)
|
|
114
129
|
;[all[i], all[j]] = [all[j], all[i]]
|
|
@@ -125,10 +140,6 @@ function randomBelow(n: number): number {
|
|
|
125
140
|
}
|
|
126
141
|
}
|
|
127
142
|
|
|
128
|
-
export function sasText(sas: Sas): string {
|
|
129
|
-
return sas.map((i) => `${SAS_EMOJI[i][0]} ${SAS_EMOJI[i][1]}`).join(' ')
|
|
130
|
-
}
|
|
131
|
-
|
|
132
143
|
/**
|
|
133
144
|
* Cross-device record that this account verified a machine's key: an HMAC under a key only holders
|
|
134
145
|
* of the account private key can derive (ECDH of the account key with itself), so the service
|
|
@@ -16,9 +16,9 @@ Tokens are created on this machine.
|
|
|
16
16
|
For scripts, the public API is documented at https://localauth.dev/docs/api and
|
|
17
17
|
https://localauth.dev/api/v1/openapi.json. The owner can create a scoped personal token on the
|
|
18
18
|
Account page and send it as `Authorization: Bearer lat_…`. It cannot change the account,
|
|
19
|
-
encryption, passkeys, tokens or
|
|
19
|
+
encryption, passkeys, tokens or machine verification. End-to-end API data stays sealed; a client
|
|
20
20
|
needs the account key to read or answer it. Browser agents may use the page's WebMCP login
|
|
21
|
-
and machine-pairing tools; a person still
|
|
21
|
+
and machine-pairing tools; a person still taps the matching number. CLI 0.2.0 uses `/api/v1/machine/*`;
|
|
22
22
|
link clients use `/api/v1/links/*`.
|
|
23
23
|
After the API upgrade, CLI 0.1.0 receives HTTP 410 with the update instruction. Ask the owner
|
|
24
24
|
to update it; never change an installed CLI or its config without authorization.
|
|
@@ -34,9 +34,8 @@ localauth status
|
|
|
34
34
|
- "not verified yet: run localauth verify" (or a command refusing with "verify this machine
|
|
35
35
|
first"): the account uses end-to-end encryption and this machine hasn't checked its key. Run
|
|
36
36
|
`localauth verify` in the background and send the user the link it prints. Once they open it,
|
|
37
|
-
the command prints a
|
|
38
|
-
|
|
39
|
-
match". It exits 0 when verified. If it reports a mismatch, stop: someone may be intercepting
|
|
37
|
+
the command prints a three-digit number ("On the page, tap 482"): send that number too. On the
|
|
38
|
+
page they tap the same number among three, or "None of these match". It exits 0 when verified. If it reports a mismatch, stop: someone may be intercepting
|
|
40
39
|
the connection, and the user should not send secrets to this machine.
|
|
41
40
|
- "the account key changed": run `localauth verify` as above. "end-to-end encryption was reset":
|
|
42
41
|
reconnect with `localauth login`. Never edit the config to get around either.
|
|
@@ -47,7 +46,7 @@ localauth status
|
|
|
47
46
|
To connect, run `localauth login` in the background (it waits for approval) and send the user the
|
|
48
47
|
link it prints, with the code it shows. They open it, sign in, check the code and tap **Connect**;
|
|
49
48
|
`localauth login` then exits by itself. If the account uses end-to-end encryption, it then prints
|
|
50
|
-
|
|
49
|
+
a three-digit number: send it, and the user taps the same number on the same page. If it says to
|
|
51
50
|
sign in at the service first (a self-hosted copy behind Cloudflare Access), pass that on too.
|
|
52
51
|
Links contain only the device code or a verification id, never keys.
|
|
53
52
|
|