Files
orca/src/main/runtime/device-credential.ts
T
Neil 5be70ee00f fix(runtime): a device removed on disk stops authenticating at the next check (#35527)
* fix(runtime): a device removed on disk stops authenticating at the next check

Auth checks (token validate, device-key lookup, per-request principal
recheck) now stat orca-devices.json and, when it changed since this
process last read it, re-read and merge it the same way a save does.
An unchanged file costs one stat; an unreadable or corrupt one changes
nothing.

* fix(runtime): check the device file before handing out a pairing offer

A pending offer an admin removed on disk is never shown as a QR. The
auth-time re-read also skips while this process's own quarantine is the
reason the file is missing.
2026-10-28 19:07:54 -07:00

30 lines
1.0 KiB
TypeScript

import { randomBytes, randomUUID } from 'node:crypto'
import type { DeviceScope } from '../../shared/runtime-types'
import type { RuntimePairingReach } from '../../shared/runtime-pairing-reach'
import type { TokenDeviceEntry } from './device-entry'
import { validGrants } from './device-registry-row-validation'
import type { RuntimeDeviceGrant } from './rpc/rpc-method-permission'
export function mintDeviceCredential(): { deviceId: string; token: string } {
return { deviceId: randomUUID(), token: randomBytes(24).toString('hex') }
}
/** A never-seen token row; it authenticates only once the registry persists it. */
export function mintTokenDevice(
name: string,
scope: DeviceScope,
pairingReach: RuntimePairingReach,
grants: readonly RuntimeDeviceGrant[]
): TokenDeviceEntry {
const validatedGrants = validGrants(grants, scope)
return {
...mintDeviceCredential(),
name,
scope,
pairedAt: Date.now(),
lastSeenAt: 0,
pairingReach,
...(validatedGrants ? { grants: validatedGrants } : {})
}
}