Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

home/ios bento/connect: identity rigs on the macOS job, a fixture floor, no software keys in release (#784)

nyblnet8670030c207e
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 64560fe0..53bf1686 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -869,20 +869,20 @@ jobs:
# the document's origin. Compiles the real HostDocStore; skips off Apple.
run: node scripts/test-home-docstore-ios.mjs
- - name: home/ios bento/id keys rig
+ - name: home/ios bento/connect keys rig
# The agent's keys: the account key, the Secure Enclave routine and consent
# keys, raw low-S signatures (verified in WebCrypto), never minting over a
# store it could not read, and the §29 biometric-enrolment notice outbox.
# Apple toolchains only; skips elsewhere.
run: node scripts/test-home-id-keys.mjs
- - name: home/ios bento/id statements rig
+ - name: home/ios bento/connect statements rig
# The Swift statements against kernel/fixtures/identity-v1.json: verdict
# and reason on every row, round trips, tampering, transcripts, low-S,
# purposes, addresses, spendCalled and the frozen display table.
run: node scripts/test-home-id-statements.mjs
- - name: home/ios bento/id agent rig
+ - name: home/ios bento/connect agent rig
# sign() routing and the host-stamped consent statement (§2e (A)): what
# the page can name, what only the host stamps, and the verifier refusing
# a relay, replay, payload swap or docId swap.
@@ -2743,7 +2743,15 @@ jobs:
shell: bash
run: |
set -o pipefail
- for rig in test-tray-releases.mjs test-home-origin.mjs test-home-docstore-ios.mjs; do
+ rigs=(
+ test-tray-releases.mjs
+ test-home-origin.mjs
+ test-home-docstore-ios.mjs
+ test-home-id-keys.mjs
+ test-home-id-statements.mjs
+ test-home-id-agent.mjs
+ )
+ for rig in "${rigs[@]}"; do
echo "::group::$rig"
node "scripts/$rig" | tee "$RUNNER_TEMP/rig.out"
echo "::endgroup::"
diff --git a/home/ios/IdentityKeys.swift b/home/ios/IdentityKeys.swift
index ad9e0850..e4e7a2a9 100644
--- a/home/ios/IdentityKeys.swift
+++ b/home/ios/IdentityKeys.swift
@@ -6,7 +6,7 @@ import Foundation
import LocalAuthentication
import Security
-/// bento/id's keys on this device (I1). The document side of the contract is
+/// bento/connect's keys on this device (I1). The document side of the contract is
/// kernel/src/identity.ts; this is what answers it.
///
/// - **The account key** is the person. It's a software P-256 key in the Keychain,
@@ -31,6 +31,13 @@ import Security
/// The simulator has no Secure Enclave. It gets software keys behind the same
/// interface, and its consent key checks presence with an explicit device-owner
/// authentication. That stand-in exists ONLY in the simulator.
+
+// Software device keys stand in for the Secure Enclave on the simulator and in
+// the rigs. A release or archive build must never have them: a real device
+// would silently get keys that aren't hardware-bound.
+#if BENTO_SOFTWARE_DEVICE_KEYS && !DEBUG
+#error("BENTO_SOFTWARE_DEVICE_KEYS is for DEBUG builds only; a release build uses the Secure Enclave")
+#endif
enum IdentityKeys {
enum Role: String { case routine, consent }
diff --git a/scripts/test-home-id-agent.mjs b/scripts/test-home-id-agent.mjs
index 571c219b..b99565c0 100644
--- a/scripts/test-home-id-agent.mjs
+++ b/scripts/test-home-id-agent.mjs
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2026 The Bento authors
/**
- * bento/id on iOS and the Mac — the agent's sign() and host-stamped consent
+ * bento/connect on iOS and the Mac — the agent's sign() and host-stamped consent
* (home/ios/IdentityAgent.swift).
*
* node scripts/test-home-id-agent.mjs
@@ -122,7 +122,7 @@ const dir = mkdtempSync(join(tmpdir(), 'bento-idagent-'))
let out
try {
writeFileSync(join(dir, 'main.swift'), main)
- execFileSync('swiftc', ['-O', '-D', 'BENTO_SOFTWARE_DEVICE_KEYS', '-o', join(dir, 'a'), ...SRC, join(dir, 'main.swift')], { stdio: 'pipe' })
+ execFileSync('swiftc', ['-O', '-D', 'DEBUG', '-D', 'BENTO_SOFTWARE_DEVICE_KEYS', '-o', join(dir, 'a'), ...SRC, join(dir, 'main.swift')], { stdio: 'pipe' })
out = Object.fromEntries(execFileSync(join(dir, 'a')).toString().trim().split('\n').map((l) => l.split(/=(.*)/s).slice(0, 2)))
} catch (err) { console.error('swiftc or run failed:\n' + (err.stderr?.toString() ?? err.message)); process.exit(2) }
finally { try { rmSync(dir, { recursive: true, force: true }) } catch {} }
diff --git a/scripts/test-home-id-keys.mjs b/scripts/test-home-id-keys.mjs
index 637c4378..87f0a845 100644
--- a/scripts/test-home-id-keys.mjs
+++ b/scripts/test-home-id-keys.mjs
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2026 The Bento authors
/**
- * bento/id on iOS and the Mac — the agent's keys (home/ios/IdentityKeys.swift).
+ * bento/connect on iOS and the Mac — the agent's keys (home/ios/IdentityKeys.swift).
*
* node scripts/test-home-id-keys.mjs
*
@@ -201,11 +201,24 @@ const dir = mkdtempSync(join(tmpdir(), 'bento-idkeys-'))
let out
try {
writeFileSync(join(dir, 'main.swift'), main)
- execFileSync('swiftc', ['-O', '-D', 'BENTO_SOFTWARE_DEVICE_KEYS', '-o', join(dir, 'k'), ...SRC, join(dir, 'main.swift')], { stdio: 'pipe' })
+ execFileSync('swiftc', ['-O', '-D', 'DEBUG', '-D', 'BENTO_SOFTWARE_DEVICE_KEYS', '-o', join(dir, 'k'), ...SRC, join(dir, 'main.swift')], { stdio: 'pipe' })
out = Object.fromEntries(execFileSync(join(dir, 'k'), { maxBuffer: 1 << 26 }).toString().trim().split('\n').map((l) => l.split(/=(.*)/s).slice(0, 2)))
} catch (err) { console.error('swiftc or run failed:\n' + (err.stderr?.toString() ?? err.message)); process.exit(2) }
finally { try { rmSync(dir, { recursive: true, force: true }) } catch {} }
+// A release build (no DEBUG) that sets the software-keys flag must not compile.
+let releaseRefused = false, releaseError = ''
+{
+ const rd = mkdtempSync(join(tmpdir(), 'bento-idkeys-rel-'))
+ try {
+ writeFileSync(join(rd, 'main.swift'), 'print("built")\n')
+ execFileSync('swiftc', ['-O', '-D', 'BENTO_SOFTWARE_DEVICE_KEYS', '-o', join(rd, 'r'), ...SRC, join(rd, 'main.swift')], { stdio: 'pipe' })
+ } catch (err) {
+ releaseError = err.stderr?.toString() ?? ''
+ releaseRefused = /BENTO_SOFTWARE_DEVICE_KEYS is for DEBUG builds only/.test(releaseError)
+ } finally { try { rmSync(rd, { recursive: true, force: true }) } catch {} }
+}
+
const d64 = (s) => Buffer.from(s.replace(/-/g, '+').replace(/_/g, '/'), 'base64')
const halfN = BigInt('0x7FFFFFFF800000007FFFFFFFFFFFFFFFDE737D56D38BCF4279DCE5617E3192A8')
const lowS = (sig) => BigInt('0x' + d64(sig).subarray(32).toString('hex')) <= halfN
@@ -279,5 +292,7 @@ ok(out['trip.gained'] === 'true', 'biometrics added where there were none is CHA
ok(out['trip.accepted'] === 'true', 'after a re-confirmed consent the new enrolment is the baseline, and the old one would now be a change')
ok(out['trip.norecord'] === 'true', 'a consent key with no recorded enrolment (made before the check) is CHANGED, re-confirmed once')
ok(out['trip.unreadable'] === 'true', 'a record that cannot be read is UNKNOWN — the consent is refused, the check never skipped')
+console.log('release builds:')
+ok(releaseRefused, 'a build without DEBUG that sets BENTO_SOFTWARE_DEVICE_KEYS does not compile' + (releaseRefused ? '' : ` (${releaseError.split('\n')[0] || 'it compiled'})`))
console.log(`\n${checks - failures}/${checks} checks passed`)
process.exit(failures ? 1 : 0)
diff --git a/scripts/test-home-id-statements.mjs b/scripts/test-home-id-statements.mjs
index ee69c914..8fa5045b 100644
--- a/scripts/test-home-id-statements.mjs
+++ b/scripts/test-home-id-statements.mjs
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2026 The Bento authors
/**
- * bento/id on iOS and the Mac — the Swift statements against the conformance
+ * bento/connect on iOS and the Mac — the Swift statements against the conformance
* contract, kernel/fixtures/identity-v1.json.
*
* node scripts/test-home-id-statements.mjs (ID_FIXTURE=<path> to point elsewhere)
@@ -23,7 +23,7 @@
* Apple platforms only (CryptoKit); skips elsewhere.
*/
import { execFileSync } from 'node:child_process'
-import { existsSync, mkdtempSync, writeFileSync, rmSync } from 'node:fs'
+import { existsSync, mkdtempSync, writeFileSync, rmSync, readFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join, resolve, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
@@ -32,6 +32,27 @@ const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
const FIXTURE = process.env.ID_FIXTURE || join(ROOT, 'kernel/fixtures/identity-v1.json')
const SRC = ['HostDocStore.swift', 'IdentityKeys.swift', 'IdentityDisplayTable.swift', process.env.ID_STATEMENTS_SRC || 'IdentityStatements.swift'].map((f) => f.includes('/') ? f : join(ROOT, 'home/ios', f))
if (!existsSync(FIXTURE)) { console.log(`home id statements: the fixture is missing (${FIXTURE}) — it lands with K2.`); process.exit(1) }
+// A floor on the fixture: a shrunken or truncated file must not pass quietly
+// with fewer rows to fail. These are the counts the fixture had when this rig
+// was written; raise them as it grows, never lower them.
+{
+ const F = JSON.parse(readFileSync(FIXTURE, 'utf8'))
+ const n = {
+ statements: F.statements?.length ?? 0,
+ cns: (F.statements ?? []).filter((r) => r.type === 'cns').length,
+ transcripts: F.transcripts?.length ?? 0,
+ purposes: F.purposes?.length ?? 0,
+ addresses: F.addresses?.length ?? 0,
+ displayRanges: F.displayForbidden?.ranges?.length ?? 0,
+ }
+ const FLOOR = { statements: 95, cns: 15, transcripts: 5, purposes: 15, addresses: 23, displayRanges: 746 }
+ const short = Object.entries(FLOOR).filter(([k, min]) => n[k] < min)
+ if (short.length) {
+ console.log(`home id statements: the fixture is SHORT: ${short.map(([k, min]) => `${k} ${n[k]} < ${min}`).join(', ')}`)
+ process.exit(1)
+ }
+ console.log(`fixture floor met: ${Object.entries(n).map(([k, v]) => `${k} ${v}`).join(', ')}`)
+}
// Apple platforms only: the Linux CI runner has swiftc but no CryptoKit, Security
// or LocalAuthentication, so probe for xcrun, which only Apple toolchains ship.
try { execFileSync('xcrun', ['--find', 'swiftc'], { stdio: 'pipe' }) } catch { console.log('home id statements: SKIPPED — needs an Apple toolchain (CryptoKit, Security).'); process.exit(0) }