device-identity: third adversarial review and its repairs (with the release left out of a bundle, the firmware the device attests is still judged against the manufacturer's policies; a verifier clock and every time read strictly as RFC 3339 UTC, days that do not exist refused; C1, DEL and direction marks escaped on the terminal; a key file is never overwritten); probe 372/372, negative control 220/220. conformance: the halves of the device verifier mapped again (263/263 under the negative control) and the present-tense counts brought to the measurement of 2026-10-14 (467 vectors, 467/467 with the AIP-23 verifier as served)
This commit is contained in:
1 parent
ed4d3d79d8
commit
86779c8334
8 files changed
+263
-100
No files matched your search
@@ -407,10 +407,10 @@ spune('M. a member more in a link or in its signature is another text of it, and
|
||||
|
||||
// ================================================================ V. text from a bundle, made visible
|
||||
{ const C = (...n) => String.fromCodePoint(...n);
|
||||
const ascunse = [0x00, 0x09, 0x0a, 0x0d, 0x1b, 0x1f, 0x7f, 0x80, 0x9b, 0x9f, 0x200e, 0x200f, 0x2028, 0x2029, 0x202a, 0x202e, 0x2066, 0x2069, 0xfeff], lasate = [0x20, 0x7e, 0xa0, 0xe9, 0x200d, 0x2027, 0x202f, 0x2065, 0x206a, 0xfefe, 0x1f600];
|
||||
const ascunse = [0x00, 0x09, 0x0a, 0x0d, 0x1b, 0x1f, 0x7f, 0x80, 0x9b, 0x9f, 0x061c, 0x200e, 0x200f, 0x2028, 0x2029, 0x202a, 0x202e, 0x2066, 0x2069, 0xfeff], lasate = [0x20, 0x7e, 0xa0, 0xe9, 0x061b, 0x061d, 0x200d, 0x2027, 0x202f, 0x2065, 0x206a, 0xfefe, 0x1f600];
|
||||
const totAscuns = ascunse.every((n) => { const v = D.visible('a' + C(n) + 'b'); return v === 'a' + (n < 256 ? '\\x' + n.toString(16).padStart(2, '0') : '\\u' + n.toString(16).padStart(4, '0')) + 'b'; });
|
||||
const totLasat = lasate.every((n) => D.visible('a' + C(n) + 'b') === 'a' + C(n) + 'b');
|
||||
cer('V01', `visible(): each of ${ascunse.length} control characters (the edges of C0, DEL, C1, the marks of direction, the line and paragraph separators, the bidirectional controls, the byte order mark) becomes its visible form, each of ${lasate.length} neighbours of those ranges is left as it is, and a backslash is doubled so that the form cannot be forged`,
|
||||
cer('V01', `visible(): each of ${ascunse.length} control characters (the edges of C0, DEL, C1, the arabic letter mark and the marks of direction, the line and paragraph separators, the bidirectional controls, the byte order mark) becomes its visible form, each of ${lasate.length} neighbours of those ranges is left as it is, and a backslash is doubled so that the form cannot be forged`,
|
||||
totAscuns && totLasat && D.visible('a\\x1b') === 'a\\\\x1b' && D.visible('plain text, 100%') === 'plain text, 100%' && D.visible(7) === '7'); }
|
||||
|
||||
// ================================================================ R. the form of each link, one field at a time (after a search for conditions without a row, 2026-10-06)
|
||||
@@ -573,6 +573,44 @@ if (!REPEDE) { let aruncate = 0, cazuri = 0; const b0 = B({ anchor: PLIC }); con
|
||||
{ let a = 0; for (const o of [{ trustedManufacturers: 'x' }, { statusRecords: null }, { clockSkewS: 9999 }, { now: 'not a time' }]) { try { D.verifyDevice(B(), O(o)); } catch { a++; } }
|
||||
cer('C76', 'a configuration of the VERIFIER that cannot be read throws (it is the verifier\'s mistake, not an invalid bundle)', a === 4); }
|
||||
|
||||
// ================================================================ W. what a third adversarial review found (2026-10-14)
|
||||
spune('W. the release left out, a link left out, a day that does not exist, the verifier\'s clock, the JSON that is printed');
|
||||
{ const fara = (o = {}) => B({ firmware: null, ...o }); // the bundle with its release left out by whoever hands it
|
||||
const retrage = (d) => politica({ retracted: [d] });
|
||||
atac('W01', 'THE RELEASE LEFT OUT: the device attests the digest the manufacturer retracted, and the bundle is handed without the release. Refused all the same (the device itself says what it runs), and the release is still named as not brought',
|
||||
fara(), O({ firmwarePolicies: [retrage(fw2.statement.digest)] }), ['firmware-retracted'], (r) => r.unjudged.includes('firmware-missing') && r.rows.some((x) => x.rule === 'firmware-retracted' && x.pass === false && x.detail.includes('the device says it runs')));
|
||||
atac('W02', 'the release left out: the device attests a sequence below the floor of the current policy', fara({ attestation: atest({ firmware: fw1 }) }), O({ firmwarePolicies: [politica({ minSequence: 2 })] }), ['firmware-rollback'], (r) => r.unjudged.includes('firmware-missing'));
|
||||
partial('W03', 'the release left out: the device attests a sequence AT the floor (the edge is allowed, and it is judged): PARTIAL for the release alone', fara(), O({ firmwarePolicies: [politica({ minSequence: 2 })] }), ['firmware-missing'],
|
||||
(r) => r.rows.some((x) => x.rule === 'firmware-rollback' && x.pass === true) && r.rows.some((x) => x.rule === 'firmware-retracted' && x.pass === true));
|
||||
atac('W04', 'the release left out: the retraction is written in upper case by the manufacturer\'s tooling', fara(), O({ firmwarePolicies: [reSemn('firmware-policy', retrage(fw2.statement.digest), mfr, (st) => { st.retracted = ['0x' + st.retracted[0].slice(2).toUpperCase()]; })] }), ['firmware-retracted']);
|
||||
partial('W05', 'the release left out: a policy of ANOTHER model of the same manufacturer retracts the attested digest: it is not this model\'s policy', fara(), O({ firmwarePolicies: [politica(), politica({ model: 'AX-300', minSequence: 9, retracted: [fw2.statement.digest] })] }), ['firmware-missing']);
|
||||
partial('W06', 'the release left out: a STRANGER\'s policy for this model retracts the attested digest: it is not the manufacturer\'s policy', fara(),
|
||||
O({ firmwarePolicies: [politica(), D.firmwarePolicy({ manufacturer: strain, model: 'AX-200', minSequence: 9, retracted: [fw2.statement.digest], validFrom: at(-3600), validUntil: at(ZI), now: cand(-3600) })] }), ['firmware-missing']);
|
||||
partial('W07', 'the release left out and no firmware policy handed: what the device attests cannot be judged either, and that is said', fara(), O({ firmwarePolicies: [] }), ['firmware-missing', 'firmware-policy-unread']);
|
||||
// found by the search for conditions without a row (mutanti-device.mjs) the same day: nothing told "only when the release is left out" from "always"
|
||||
atac('W14', 'WITH the release in the bundle, it is the release the policy judges: the release shown is allowed and the device attests ANOTHER firmware, one the policy retracts; refused for not running the release shown (attestation-firmware), and for that alone',
|
||||
B({ attestation: atest({ firmware: fw1 }) }), O({ firmwarePolicies: [retrage(fw1.statement.digest)] }), ['attestation-firmware']);
|
||||
// whoever hands the bundle chooses which links it brings: a link left out never turns an INVALID into a VALID
|
||||
const casuri = [['manufacture', B(), O({ statusRecords: [activ, stare(mfr, 'retired', 1, null)] }), 'manufacture-missing'], ['firmware', B(), O({ firmwarePolicies: [retrage(fw2.statement.digest)] }), 'firmware-missing'],
|
||||
['authorization', B({ authorization: aut(strain, cap1) }), O(), 'authorization-missing'], ['attestation', B({ attestation: atest({ nonce: 'old' }) }), O(), 'attestation-missing']];
|
||||
const rez = casuri.map(([l, b, o, c]) => { const cu = judeca(b, o), farl = judeca({ ...b, [l]: undefined }, o); return { l, cu: cu.verdict, fara: farl.verdict, numit: farl.unjudged.includes(c), valid: farl.valid }; });
|
||||
// the four bundles are INVALID only while the four rules hold: the row expects them (a rule taken out leaves a case with nothing to show)
|
||||
const parti = rez.filter((x) => x.fara === 'PARTIAL');
|
||||
cer('W08', 'A LINK LEFT OUT NEVER MAKES AN INVALID BUNDLE VALID: the manufacturer\'s retirement, a retracted release, a stranger\'s authorization and an old nonce are each INVALID; with the refused link left out each is at best PARTIAL, with the link named as not brought (and `valid`, "no rule refused", is then true: it is not a verdict)',
|
||||
rez.every((x) => x.cu === 'INVALID' && x.fara !== 'VALID' && x.numit) && parti.length > 0 && parti.every((x) => x.valid === true), JSON.stringify(rez), ['status-retired', 'firmware-retracted', 'authorization-owner', 'nonce']);
|
||||
atac('W09', 'an authorization signed by the owner valid until 2099-02-30, a day that does not exist (a date parser moves it to March 2): not a time', B({ authorization: reSemn('authorization', A1, op, (st) => { st.notAfter = '2099-02-30T00:00:00Z'; }) }), O(), ['unreadable']);
|
||||
atac('W10', 'an authorization whose end is written T24:00:00 (a date parser reads it as the next day): not an RFC 3339 time', B({ authorization: reSemn('authorization', A1, op, (st) => { st.notAfter = at(ZI).slice(0, 10) + 'T24:00:00Z'; }) }), O(), ['unreadable']);
|
||||
valid('W11', 'the last day of February of a leap year, the last day of a month of 31 days and the last instant of a day are times', B({ authorization: reSemn('authorization', A1, op, (st) => { st.notAfter = '2028-02-29T23:59:59.999Z'; }) }),
|
||||
O({ statusRecords: [stare(op, 'active', 1, cap1, { validUntil: '2036-12-31T23:59:59Z' })] }));
|
||||
const bune = [at(65), cand(65), cand(65).getTime()].map((n) => judeca(B(), O({ now: n })).verdict);
|
||||
const rele = [at(65).slice(0, 10) + 'T12:00:00.000', '1', at(65).slice(0, 10), '2026-02-30T00:00:00Z', null, true, new Date(NaN), Infinity, [at(65)]].filter((n) => { try { judeca(B(), O({ now: n })); return true; } catch (e) { return !/^verifyDevice: now is not a time/.test(e.message); } });
|
||||
cer('W12', 'the verifier\'s clock is a Date, a number of milliseconds or an RFC 3339 UTC text and nothing else: the three forms of one instant give one verdict (VALID); a text without a zone (local time to a date parser), "1" (the year 2001 to it), a date alone, a day that does not exist, null, true, an invalid Date, Infinity and a list each throw `verifyDevice:`, never a verdict on a clock nobody chose',
|
||||
la(bune) === 'VALID,VALID,VALID' && !rele.length, `${bune}; taken as a clock: ${rele.map((x) => JSON.stringify(x))}`);
|
||||
const v = { a: 'x\u009b2J\u007f\u2028\u2029\u202e\u061c\u200e\u2066\ufeffy', b: 'back\\slash ESC\u001b é 😀', c: [1, null, true] }; let t = '', p = null; try { t = D.visibleJson(v, 1); p = JSON.parse(t); } catch { /* not JSON, or no such function: a red row, not a broken probe */ }
|
||||
const crud = [0x9b, 0x7f, 0x2028, 0x2029, 0x202e, 0x061c, 0x200e, 0x2066, 0xfeff, 0x1b].filter((n) => t.includes(String.fromCodePoint(n)));
|
||||
cer('W13', 'visibleJson(), what verify --json prints: DEL, C1, the bidirectional controls, the line and paragraph separators and the byte order mark are written as \\u escapes (JSON.stringify escapes only C0); the text parses to exactly the same value, keeps its line layout, holds none of them raw, and leaves letters and emoji as they are',
|
||||
p !== null && JSON.stringify(p) === JSON.stringify(v) && !crud.length && t.includes('\n') && t.includes('é 😀'), `parses: ${p !== null}; raw: ${crud.map((n) => n.toString(16))}`); }
|
||||
|
||||
// ================================================================ D. keys, producers, the envelope under the reference verifier, the command line
|
||||
spune('D. keys, producers, the envelope, the command line');
|
||||
{ const f = D.exportDeviceKey(dev), k2 = D.importDeviceKey(clona(f)); let refuz = 0; try { D.importDeviceKey({ ...clona(f), publicKey: clonaDev.publicKey, deviceId: clonaDev.deviceId }); } catch { refuz++; }
|
||||
@@ -655,22 +693,37 @@ if (!REPEDE) { // the command line, through files and processes only
|
||||
scrJ('rau.json', D.bundle({ manufacture: credZ, firmware: fwZ, authorization: D.authorize({ owner: atacator, deviceId: dz.deviceId, ownership: capZ, actions: ['door.unlock'], notBefore: iso2(-3600000), notAfter: iso2(3600000), now: new Date(acum - 3600000) }),
|
||||
attestation: D.attest({ device: dz, nonce: 'n-1', audience: 'https://gateway.example', firmware: fwZ, ownership: capZ, action: 'door.unlock', now: new Date(acum - 1000) }) }));
|
||||
// and a status record nobody signed whose signer id carries new lines, a false verdict line, a C1 control and a line separator
|
||||
scrJ('rau-stare.json', { statement: { v: 1, kind: 'aere-device-status', deviceId: activF.statement.deviceId, state: 'retired', seq: 1, ownership: null, by: { id: 'x)' + NL + NL + 'INVALID (refused by: status-retired)' + NL + E + '[8m' + String.fromCharCode(0x9b) + '2J' + String.fromCharCode(0x2028) + 'VALID' }, at: iso2(-600000), validUntil: iso2(86400000) }, signature: {} });
|
||||
const SEMNATAR = 'x)' + NL + NL + 'INVALID (refused by: status-retired)' + NL + E + '[8m' + String.fromCharCode(0x9b) + '2J' + String.fromCharCode(0x2028) + 'VALID' + String.fromCharCode(0x061c, 0x202e, 0x7f);
|
||||
scrJ('rau-stare.json', { statement: { v: 1, kind: 'aere-device-status', deviceId: activF.statement.deviceId, state: 'retired', seq: 1, ownership: null, by: { id: SEMNATAR }, at: iso2(-600000), validUntil: iso2(86400000) }, signature: {} });
|
||||
const brut = (...a) => spawnSync(process.execPath, [path.join(AICI, 'device-cli.mjs'), ...a], { cwd: T }); // no encoding: stdout is a Buffer
|
||||
const r1 = brut('verify', '--bundle', 'rau.json', '--nonce', 'n-1', '--audience', 'https://gateway.example', '--trust', mid), r2 = brut(...comun.filter((x) => x !== '--json'), '--nonce', 'n-123', '--status', 'rau-stare.json');
|
||||
const curat = (buf) => { for (let i = 0; i < buf.length; i++) { const o = buf[i]; if ((o < 0x20 && o !== 0x0a) || o === 0x7f) return false; if (o === 0xc2 && buf[i + 1] >= 0x80 && buf[i + 1] <= 0x9f) return false; if (o === 0xe2 && buf[i + 1] === 0x80 && (buf[i + 2] === 0xa8 || buf[i + 2] === 0xa9)) return false; } return true; };
|
||||
// no control byte but LF, no DEL, no C1 (C2 80..9F), no U+061C (D8 9C), no mark of direction (E2 80 8E/8F), no line or paragraph separator nor
|
||||
// embedding or override (E2 80 A8..AE), no isolate (E2 81 A6..A9), no byte order mark (EF BB BF)
|
||||
const curat = (buf) => { for (let i = 0; i < buf.length; i++) { const o = buf[i], u = buf[i + 1], w = buf[i + 2]; if ((o < 0x20 && o !== 0x0a) || o === 0x7f) return false; if (o === 0xc2 && u >= 0x80 && u <= 0x9f) return false; if (o === 0xd8 && u === 0x9c) return false;
|
||||
if (o === 0xe2 && u === 0x80 && (w === 0x8e || w === 0x8f || (w >= 0xa8 && w <= 0xae))) return false; if (o === 0xe2 && u === 0x81 && w >= 0xa6 && w <= 0xa9) return false; if (o === 0xef && u === 0xbb && w === 0xbf) return false; } return true; };
|
||||
const verdicte = (buf) => buf.toString('utf8').split(NL).filter((l) => /^(VALID|INVALID|PARTIAL)( |$)/.test(l)), t1b = r1.stdout.toString('utf8'), t2b = r2.stdout.toString('utf8');
|
||||
cer('D10', 'device-cli.mjs: text a bundle or a registry file wrote is SHOWN, never sent to the terminal. Read as bytes, the output of verify holds no control byte but the line feeds the command itself writes (no ESC, no C1, no line separator), exactly one verdict line, and the hostile text in its visible form: for a manufacture model that clears the screen and writes "VALID" (the verdict stays INVALID, exit 1) and for an unsigned status record whose signer id writes a line "INVALID (...)" (the verdict stays VALID, exit 0)',
|
||||
r1.status === 1 && r2.status === 0 && curat(r1.stdout) && curat(r2.stdout) && la(verdicte(r1.stdout)) === 'INVALID (refused by: manufacturer-trusted)' && la(verdicte(r2.stdout)) === 'VALID' && t1b.includes('AX-200\\x1b[2J\\x1b[Hok') && t1b.includes('\\x0a\\x0aVALID\\x0a\\x1b[8m') && t2b.includes('(x)\\x0a\\x0aINVALID (refused by: status-retired)\\x0a\\x1b[8m\\x9b2J\\u2028VALID)'),
|
||||
r1.status === 1 && r2.status === 0 && curat(r1.stdout) && curat(r2.stdout) && la(verdicte(r1.stdout)) === 'INVALID (refused by: manufacturer-trusted)' && la(verdicte(r2.stdout)) === 'VALID' && t1b.includes('AX-200\\x1b[2J\\x1b[Hok') && t1b.includes('\\x0a\\x0aVALID\\x0a\\x1b[8m') && t2b.includes('(x)\\x0a\\x0aINVALID (refused by: status-retired)\\x0a\\x1b[8m\\x9b2J\\u2028VALID\\u061c\\u202e\\x7f)'),
|
||||
`exits ${r1.status} ${r2.status}; clean ${curat(r1.stdout)} ${curat(r2.stdout)}; verdict lines [${verdicte(r1.stdout)}] [${verdicte(r2.stdout)}]`, ['manufacturer-trusted']);
|
||||
const rj = spawnSync(process.execPath, [path.join(AICI, 'device-cli.mjs'), 'verify', '--bundle', 'rau.json', '--nonce', 'n-1', '--audience', 'https://gateway.example', '--trust', mid, '--json'], { cwd: T }); let pj = null; try { pj = JSON.parse(rj.stdout.toString('utf8')); } catch { /* not JSON */ }
|
||||
cer('D10b', 'and --json stays JSON: it parses, its strings carry the model exactly as the bundle wrote it (escaped by JSON), and no ESC byte is in the output', pj !== null && pj.verdict === 'INVALID' && JSON.stringify(pj).includes('[2J') && pj.rows.some((x) => x.name.includes(MODEL)) && !rj.stdout.includes(27), '', ['manufacturer-trusted']); }
|
||||
const rj2 = brut(...comun, '--nonce', 'n-123', '--status', 'rau-stare.json'); let pj2 = null; try { pj2 = JSON.parse(rj2.stdout.toString('utf8')); } catch { /* not JSON */ }
|
||||
cer('D10b', 'and --json stays JSON: it parses, its strings carry the model and the signer id exactly as they were written, and its BYTES hold no control byte but its line feeds: no ESC, and (since 2026-10-14) no DEL, C1, mark of direction, override or line separator either, which JSON.stringify writes as they came',
|
||||
pj !== null && pj.verdict === 'INVALID' && JSON.stringify(pj).includes('[2J') && pj.rows.some((x) => x.name.includes(MODEL)) && !rj.stdout.includes(27) && curat(rj.stdout)
|
||||
&& pj2 !== null && pj2.verdict === 'VALID' && pj2.rows.some((x) => x.unjudged === 'status-ignored' && x.detail.includes(SEMNATAR)) && curat(rj2.stdout), `clean ${curat(rj.stdout)} ${curat(rj2.stdout)}`, ['manufacturer-trusted']); }
|
||||
// ---- an input that cannot be read has an exit code of its own: 0, 1 and 2 are verdicts and nothing else
|
||||
{ scrJ('stricat.json', '{ not json'); const faraVerdict = (r) => !/^(VALID|INVALID|PARTIAL)/m.test(r.stdout) && !/"verdict"/.test(r.stdout);
|
||||
const lipsa = cli(...comun, '--nonce', 'n-123', '--status', 'lipsa.json'), stricat = cli(...comun, '--nonce', 'n-123', '--status', 'stricat.json'), ceas = cli('verify', '--bundle', 'bundle.json', '--now', 'not-a-time', '--status', 'status.json'), fara = cli('verify'), alta = cli('no-such-command');
|
||||
// since 2026-10-14: a clock written without a zone (local time to a date parser) and a trusted manufacturer given as a JSON file that holds no keys
|
||||
const ceasLocal = cli(...comun, '--nonce', 'n-123', '--now', new Date().toISOString().slice(0, 10) + 'T12:00:00'), incredereRea = cli(...comun, '--nonce', 'n-123', '--trust', 'status.json');
|
||||
const prod = cli('status', '--by', 'owner.keys.json', '--manufacture', 'manufacture.json', '--transfer', 't1.json', '--state', 'destroyed', '--seq', '1', '--hours', '24', '--out', 'x.json');
|
||||
cer('D11', 'device-cli.mjs: 0, 1 and 2 are verdicts only. A status file that is missing, one that is not JSON, a clock that is not a time, a missing --bundle and an unknown command each exit 3 with no verdict printed; a command other than verify that fails (a state that does not exist) exits 1 and writes no file',
|
||||
[lipsa, stricat, ceas, fara, alta].every((r) => r.status === 3 && faraVerdict(r) && /device-cli: /.test(r.stderr)) && prod.status === 1 && !fs.existsSync(path.join(T, 'x.json')), `exits ${[lipsa, stricat, ceas, fara, alta, prod].map((r) => r.status)}`); }
|
||||
cer('D11', 'device-cli.mjs: 0, 1 and 2 are verdicts only. A status file that is missing, one that is not JSON, a clock that is not a time, a clock written without a zone, a trusted manufacturer file that holds no keys, a missing --bundle and an unknown command each exit 3 with no verdict printed; a command other than verify that fails (a state that does not exist) exits 1 and writes no file',
|
||||
[lipsa, stricat, ceas, ceasLocal, incredereRea, fara, alta].every((r) => r.status === 3 && faraVerdict(r) && /device-cli: /.test(r.stderr)) && prod.status === 1 && !fs.existsSync(path.join(T, 'x.json')), `exits ${[lipsa, stricat, ceas, ceasLocal, incredereRea, fara, alta, prod].map((r) => r.status)}`); }
|
||||
// ---- a key file is created, never written over (since 2026-10-14): the key it holds would be lost, and a file that exists keeps its own mode
|
||||
{ const inainte = ['mfr.keys.json', 'dev.key.json'].map((f) => fs.readFileSync(path.join(T, f)));
|
||||
const peste = [cli('new-identity', '--out', 'mfr.keys.json'), cli('new-device', '--out', 'dev.key.json')], nou = cli('new-identity', '--out', 'nou.keys.json');
|
||||
const dupa = ['mfr.keys.json', 'dev.key.json'].map((f) => fs.readFileSync(path.join(T, f)));
|
||||
cer('D12', 'device-cli.mjs: new-identity and new-device refuse to write a key over a file that exists (exit 3, the bytes of the file unchanged, so the key it held is not lost); into a new file they write one (exit 0)',
|
||||
peste.every((r) => r.status === 3 && /never written over/.test(r.stderr)) && inainte.every((b, i) => b.equals(dupa[i])) && nou.status === 0 && /"private"/.test(fs.readFileSync(path.join(T, 'nou.keys.json'), 'utf8')), `exits ${peste.map((r) => r.status)} ${nou.status}; unchanged ${inainte.map((b, i) => b.equals(dupa[i]))}`); }
|
||||
} finally { fs.rmSync(T, { recursive: true, force: true }); } }
|
||||
|
||||
{ // the evidence recorded on testnet 28001 (proba-device-ancora-testnet.mjs: two envelopes notarized there, each read back by the published
|
||||
|
||||
Reference in new issue
Block a user