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:
Aere Network committed 2026-10-15 02:43:18 +03:00
1 parent ed4d3d79d8
commit 86779c8334
8 files changed
+263 -100

No files matched your search

+60 -28
View File
@@ -66,7 +66,13 @@ const hashOf = (o) => hex0x(sha(Buffer.from(canonical(o), 'utf8')));
const ob = (x) => !!x && typeof x === 'object' && !Array.isArray(x);
const sir = (x) => typeof x === 'string' && x.length > 0 && x.length <= 256;
const iso = (d) => new Date(d).toISOString();
function data(s, ce) { if (typeof s !== 'string' || !DATA.test(s) || Number.isNaN(Date.parse(s))) throw new Error(`aere-device: ${ce} is not an RFC 3339 UTC time`); return Date.parse(s); }
/**
* The day a text of the form of DATA names exists. A date parser MOVES a day that does not exist (2026-02-30 becomes March 2, T24:00:00
* the next day) and reads nothing from what it cannot (month 13, second 60): in every case the day of the instant read is not the day
* written (an hour or a month cannot overflow without moving the day), and a text read as nothing has no day at all.
*/
const exista = (s) => new Date(Date.parse(s)).getUTCDate() === Number(String(s).slice(8, 10));
function data(s, ce) { if (typeof s !== 'string' || !DATA.test(s) || !exista(s)) throw new Error(`aere-device: ${ce} is not an RFC 3339 UTC time`); return Date.parse(s); }
// `a` is an identity that a form check, or the signature check of a record, already required to be an object; `b` may be absent (a
// chain that keeps no owner)
const aceeasi = (a, b) => ob(b) && a.id === b.id && canonical(a.keys) === canonical(b.keys);
@@ -88,17 +94,28 @@ export const linkHash = (l) => hashOf(l);
* (\xNN, \uNNNN), and a backslash is doubled so that the form cannot be forged. What is printed stays on its line, and a terminal
* executes nothing a bundle wrote. The rows of verifyDevice carry the text as it came: print them through this.
*/
// the code points replaced: C0, DEL and C1, the two marks of direction, the line and paragraph separators with the bidirectional
// embeddings and overrides after them, the bidirectional isolates, the byte order mark
const DE_ARATAT = [[0x00, 0x1f], [0x7f, 0x9f], [0x200e, 0x200f], [0x2028, 0x202e], [0x2066, 0x2069], [0xfeff, 0xfeff]];
// the code points replaced: C0, DEL and C1, the arabic letter mark and the two marks of direction (with the embeddings, overrides and
// isolates below, the characters Unicode gives the property Bidi_Control), the line and paragraph separators, the byte order mark
const DE_ARATAT = [[0x00, 0x1f], [0x7f, 0x9f], [0x061c, 0x061c], [0x200e, 0x200f], [0x2028, 0x202e], [0x2066, 0x2069], [0xfeff, 0xfeff]];
const deAratat = (n) => DE_ARATAT.some(([de, la]) => n >= de && n <= la);
export function visible(s) {
let out = '';
for (const c of String(s)) { const n = c.codePointAt(0);
if (n === 0x5c) out += '\\\\';
else if (DE_ARATAT.some(([de, la]) => n >= de && n <= la)) { const h = n.toString(16); out += h.length <= 2 ? '\\x' + h.padStart(2, '0') : '\\u' + h.padStart(4, '0'); }
else if (deAratat(n)) { const h = n.toString(16); out += h.length <= 2 ? '\\x' + h.padStart(2, '0') : '\\u' + h.padStart(4, '0'); }
else out += c; }
return out;
}
/**
* A value as JSON text in which every code point visible() replaces is written as a \u escape. JSON.stringify escapes only C0: DEL, C1,
* the marks of direction and the line separators would reach the terminal as they came. The text parses to exactly the same value.
* (What it replaces from DEL up can stand only inside a string; the C0 left in the text are the line feeds of its layout.)
*/
export function visibleJson(v, spatiu = 1) {
let out = '';
for (const c of JSON.stringify(v, null, spatiu)) { const n = c.codePointAt(0); out += n >= 0x7f && deAratat(n) ? '\\u' + n.toString(16).padStart(4, '0') : c; }
return out;
}
// ---------------------------------------------------------------- the device key K (ML-DSA-65 alone)
function cheiaDispozitivului(b64) {
@@ -301,7 +318,10 @@ export function verifyDevice(b, { now = new Date(), nonce = null, audience = nul
const ok = (rule, link, name, pass, detail = '') => { if (!REGULI.includes(rule)) throw new Nedeclarata('aere-device: undeclared rule ' + rule); rows.push({ link, name, pass: !!pass, detail: pass ? '' : detail, rule }); return !!pass; };
const nejudecat = (cauza, link, name, detail) => { if (!NEJUDECATE.includes(cauza)) throw new Nedeclarata('aere-device: undeclared cause ' + cauza); rows.push({ link, name, pass: null, detail, unjudged: cauza }); };
// the verifier's own configuration is validated first (a mistake of the verifier is not an invalid bundle)
const acum = new Date(now).getTime(); if (Number.isNaN(acum)) throw new Error('verifyDevice: now is not a time');
// the verifier's clock: a Date, a number of milliseconds since 1970, or an RFC 3339 UTC text, and nothing else. A date parser reads a
// text without a zone as local time and '1' as the year 2001: a clock read so would judge on a time nobody chose
const acum = now instanceof Date ? now.getTime() : typeof now === 'number' ? now : typeof now === 'string' && DATA.test(now) && exista(now) ? Date.parse(now) : NaN;
if (!Number.isFinite(acum)) throw new Error('verifyDevice: now is not a time (a Date, milliseconds since 1970, or an RFC 3339 UTC text)');
if (!Number.isInteger(clockSkewS) || clockSkewS < 0 || clockSkewS > 600) throw new Error('verifyDevice: clockSkewS is 0..600 seconds');
if (!Number.isInteger(maxAgeS) || maxAgeS < 1) throw new Error('verifyDevice: maxAgeS is a positive number of seconds');
if (trustedManufacturers != null && !Array.isArray(trustedManufacturers)) throw new Error('verifyDevice: trustedManufacturers is a list of ids or public keys');
@@ -374,6 +394,31 @@ export function verifyDevice(b, { now = new Date(), nonce = null, audience = nul
}
// ---- 2. firmware: which bytes, which version, signed by whom, still allowed
// The policies signed by the SAME signer for this model. Of those, the ones in force on the verifier's clock that can be READ
// (the version this verifier reads, a floor that is a whole number, a list of digests) are judged; with several, the strictest
// holds (a retraction is not lifted). One that is signed, not out of its validity, and cannot be read is NOT read as a clean
// policy: what it retracts cannot be seen, and the verdict says so (PARTIAL), whatever the other policies say. What is judged is
// the release shown or, when the bundle brings none, the firmware the device attests (`fw`: model, signer, digest, sequence).
const judecaPolitici = (fw, t) => {
const ale = FP.filter((p) => { try { const q = p.statement; return q.model === fw.model && aceeasi(q.issuer, fw.signer) && verifica('firmware-policy', q, p.signature, fw.signer.keys); } catch { return false; } });
const curente = [], necitite = [];
for (const p of ale) { const q = p.statement; let inVigoare = null;
if (q.v !== VERSION) { necitite.push('it is of a version this verifier does not read'); continue; }
try { inVigoare = data(q.validFrom, 'policy validFrom') - sk <= acum && acum <= data(q.validUntil, 'policy validUntil'); } catch { /* a validity that is not a time: below */ }
if (inVigoare === false) continue; // expired, or not yet in force: it says nothing about now
if (inVigoare === null) necitite.push('its validity is not a time');
else if (!(Number.isInteger(q.minSequence) && q.minSequence >= 0)) necitite.push('its floor is not a whole number from 0 up');
else if (!(Array.isArray(q.retracted) && q.retracted.every((x) => typeof x === 'string' && DIGEST_SCRIS.test(x)))) necitite.push('its retracted list has an entry that is not a digest (0x and 64 hex digits)');
else curente.push(p); }
if (necitite.length) nejudecat('firmware-policy-unread', 'firmware', 'firmware: a policy that cannot be read', `${necitite.length} of the firmware policies signed by the manufacturer for this model cannot be read (${[...new Set(necitite)].join('; ')}): what such a policy retracts and the floor it sets cannot be seen, so it is not read as a policy that allows ${t.ce}`);
if (!curente.length) { if (!necitite.length) nejudecat('firmware-policy-unread', 'firmware', 'firmware: still allowed', ale.length ? `the firmware policies given are not valid at ${iso(acum)}: fetch a current one` : 'no firmware policy of the manufacturer for this model was handed to the verifier; a retracted or outdated firmware cannot be seen'); }
else {
const scris = (x) => String(x).toLowerCase(); // a digest written in upper case by the manufacturer's own tooling is the same digest
const retras = curente.some((p) => p.statement.retracted.some((x) => scris(x) === fw.digest)), prag = Math.max(...curente.map((p) => p.statement.minSequence));
ok('firmware-retracted', 'firmware', t.neretras, !retras /*PAZA:firmware-retracted*/, t.retras);
ok('firmware-rollback', 'firmware', t.prag(prag), fw.sequence >= prag /*PAZA:firmware-rollback*/, t.subPrag(prag));
}
};
const F = b.firmware; let R = null;
if (F == null) nejudecat('firmware-missing', 'firmware', 'firmware: release', 'the bundle brings no firmware release: the digest the device attests names nothing a manufacturer signed');
else {
@@ -385,28 +430,9 @@ export function verifyDevice(b, { now = new Date(), nonce = null, audience = nul
ok('firmware-signer', 'firmware', 'firmware: released by the manufacturer of the device', idDin(R.signer.keys) === R.signer.id && (S === null || aceeasi(R.signer, S.issuer)) /*PAZA:firmware-signer*/, `released by ${R.signer.id}` + (S ? `, the device was made by ${S.issuer.id}` : ', an id not derived from its keys'));
ok('firmware-signature', 'firmware', 'firmware: signed by who released it (Ed25519 and ML-DSA-65, both)', numai(F, LEGATURA) && verifica('firmware', R, F.signature, R.signer.keys) /*PAZA:firmware-signature*/, 'the hybrid signature does not verify with the signer\'s keys');
if (S) ok('firmware-model', 'firmware', `firmware: built for model ${S.claims.model}`, R.model === S.claims.model /*PAZA:firmware-model*/, `the release is for model ${R.model}`);
// The policies signed by the SAME signer for this model. Of those, the ones in force on the verifier's clock that can be READ
// (the version this verifier reads, a floor that is a whole number, a list of digests) are judged; with several, the strictest
// holds (a retraction is not lifted). One that is signed, not out of its validity, and cannot be read is NOT read as a clean
// policy: what it retracts cannot be seen, and the verdict says so (PARTIAL), whatever the other policies say.
const ale = FP.filter((p) => { try { const q = p.statement; return q.model === R.model && aceeasi(q.issuer, R.signer) && verifica('firmware-policy', q, p.signature, R.signer.keys); } catch { return false; } });
const curente = [], necitite = [];
for (const p of ale) { const q = p.statement; let inVigoare = null;
if (q.v !== VERSION) { necitite.push('it is of a version this verifier does not read'); continue; }
try { inVigoare = data(q.validFrom, 'policy validFrom') - sk <= acum && acum <= data(q.validUntil, 'policy validUntil'); } catch { /* a validity that is not a time: below */ }
if (inVigoare === false) continue; // expired, or not yet in force: it says nothing about now
if (inVigoare === null) necitite.push('its validity is not a time');
else if (!(Number.isInteger(q.minSequence) && q.minSequence >= 0)) necitite.push('its floor is not a whole number from 0 up');
else if (!(Array.isArray(q.retracted) && q.retracted.every((x) => typeof x === 'string' && DIGEST_SCRIS.test(x)))) necitite.push('its retracted list has an entry that is not a digest (0x and 64 hex digits)');
else curente.push(p); }
if (necitite.length) nejudecat('firmware-policy-unread', 'firmware', 'firmware: a policy that cannot be read', `${necitite.length} of the firmware policies signed by the manufacturer for this model cannot be read (${[...new Set(necitite)].join('; ')}): what such a policy retracts and the floor it sets cannot be seen, so it is not read as a policy that allows this release`);
if (!curente.length) { if (!necitite.length) nejudecat('firmware-policy-unread', 'firmware', 'firmware: still allowed', ale.length ? `the firmware policies given are not valid at ${iso(acum)}: fetch a current one` : 'no firmware policy of the manufacturer for this model was handed to the verifier; a retracted or outdated firmware cannot be seen'); }
else {
const scris = (x) => String(x).toLowerCase(); // a digest written in upper case by the manufacturer's own tooling is the same digest
const retras = curente.some((p) => p.statement.retracted.some((x) => scris(x) === R.digest)), prag = Math.max(...curente.map((p) => p.statement.minSequence));
ok('firmware-retracted', 'firmware', 'firmware: not retracted', !retras /*PAZA:firmware-retracted*/, `the manufacturer retracted the firmware ${R.digest}`);
ok('firmware-rollback', 'firmware', `firmware: sequence ${R.sequence} is at or above the floor ${prag}`, R.sequence >= prag /*PAZA:firmware-rollback*/, `version ${R.version} (sequence ${R.sequence}) is older than the lowest sequence the manufacturer still allows (${prag})`);
}
judecaPolitici({ model: R.model, signer: R.signer, digest: R.digest, sequence: R.sequence }, {
ce: 'this release', neretras: 'firmware: not retracted', retras: `the manufacturer retracted the firmware ${R.digest}`,
prag: (p) => `firmware: sequence ${R.sequence} is at or above the floor ${p}`, subPrag: (p) => `version ${R.version} (sequence ${R.sequence}) is older than the lowest sequence the manufacturer still allows (${p})` });
if (R.softwareAttestationHash !== undefined) {
if (softwareAttestation == null) nejudecat('software-unread', 'firmware', 'firmware: Proof of Software', 'the release names a Proof of Software attestation that was not handed to the verifier');
else ok('firmware-software', 'firmware', 'firmware: the Proof of Software attestation named covers this image', softwareAttestation.statementHash === R.softwareAttestationHash && softwareCovers(softwareAttestation, R.digest) /*PAZA:firmware-software*/, 'the attestation given is not the one the release names, or does not list an artifact with the firmware digest');
@@ -465,6 +491,12 @@ export function verifyDevice(b, { now = new Date(), nonce = null, audience = nul
if (q.hardwareRoot != null) nejudecat('hardware-root', 'attestation', 'attestation: hardware root', 'the attestation carries a hardware root; this verifier does not judge one, so nothing here says the key lives in hardware');
}
}
// ---- 2 (again), when the bundle brings no release: the firmware the DEVICE says it runs, judged against the policies of the
// manufacturer of the credential for its model. Leaving the release out keeps the verdict from VALID (firmware-missing); it does not
// hide a digest the manufacturer retracted, nor a sequence below its floor, that the device itself attests.
if (F == null && S !== null && Q !== null) judecaPolitici({ model: S.claims.model, signer: S.issuer, digest: Q.firmware.digest, sequence: Q.firmware.sequence }, {
ce: 'the firmware the device attests', neretras: 'firmware: the firmware the device attests is not retracted (no release was brought)', retras: `the device says it runs ${Q.firmware.digest}, which the manufacturer retracted`,
prag: (p) => `firmware: the sequence the device attests (${Q.firmware.sequence}) is at or above the floor ${p} (no release was brought)`, subPrag: (p) => `the device says it runs sequence ${Q.firmware.sequence}, older than the lowest sequence the manufacturer still allows (${p})` });
// the device the authorization and the registry are about: the one the manufacturer made; with no credential, the one that attests
const dev = idDispozitiv !== null ? idDispozitiv : Q !== null ? Q.deviceId : null;