Skip to content

Rebuild the sealed Touch ID calibration from this Mac's factory records - #26

Closed
erikwb wants to merge 1 commit into
aurora-silicon:mainfrom
erikwb:aurora-sep/keep-sealed-calibration
Closed

erikwb wants to merge 1 commit into
aurora-silicon:mainfrom
erikwb:aurora-sep/keep-sealed-calibration

Conversation

@erikwb

@erikwb erikwb commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

prepare-sep-calibration runs before aurora-sep.service at every start, to prepare the Touch ID calibration.

The bug

On Macs whose calibration is a standalone FSC2 image (J700, J713), the enclave refuses the bare image (LOAD_CALIBRATION fails). It loads the calibration only resealed with the Mac's own factory records:

comb { fdrd: IMG4 { IM4P, [0] seal-<CHIP>-<ECID> }, secb: trust bundle }

The helper cached the carved bare image by partition identity, and every start wrote it over that sealed record.

The fix

Every start now rebuilds the sealed record from this Mac's factory cache, then installs it only if the installed bytes differ.

Source of truth. The helper reads FactoryData/System/Library/Caches/com.apple.factorydata read-only from the Hardware volume of the iBoot System Container. The APFS reader in the helper is deliberately narrow:

  • the newest checkpoint whose checksum is valid;
  • the container and volume object maps;
  • the file-system tree, with hashed or plain directory keys;
  • uncompressed regular files on an unencrypted volume.

Every object it reads is checksummed. Anything else is refused, with bounds on block size, tree size and depth, file count and file size. On this J713 the whole read takes about 80 ms. There is no cache.

Admission. A record is rebuilt only when all of these hold:

  • Seal: exactly one seal-<CHIP>-<ECID>.
    • Its CHIP and ECID must equal the running Mac's, taken from the boot's local policy manifest in the device tree.
    • Its MANP must carry the device tree's serial-number as SrNm.
    • If any of these values is missing, nothing is admitted.
  • Calibration: exactly one FSC2-<sensor> record, an exact IMG4 { IM4P { FSC2, version, payload }, [0] IM4M }. The seal's FSC2 object must list the IM4P's SHA-384 as its DGST.
  • Trust bundle: the named trustobject-<sha256> whose digest and bytes match trustobject-current. Without trustobject-current, the only named bundle is used, and it must match its own name. This follows aurora-installer's sensor-root-key.md.
  • Strict DER:
    • IM4M properties are walked as private-class elements whose tag must spell the name. Nothing is matched as bytes inside an OCTET STRING.
    • Duplicate objects or properties in one scope are refused, while distinct objects may each carry their own DGST.
    • Lengths and identifiers must be minimal, with no trailing data.
    • Limits: 4 MiB per source, 16 MiB per record, depth 32, and 16,384 elements.

Installation.

  • Matching record: kept, and its mode is fixed to 0600 if needed.
  • Different record: the old bytes go to private rollback evidence (/var/lib/aurora-sep/rollback, the newest four). The rebuilt record is then written atomically with mode 0600, fsynced and read back.
  • Link or other non-regular file at the target: moved aside without being followed.

Refusal.

  • When: the records can't be admitted (wrong or unknown identity, a missing or wrong trust bundle, an unreadable container, and so on).
  • The bare image is never installed.
  • Quarantine: a malformed record, a bare image or another Mac's record at the target moves to private quarantine (/var/lib/aurora-sep/quarantine), out of the firmware search path.
  • Plausible record: one that may be this Mac's but can't be confirmed stays where it is.
  • Logging: the helper logs "needs a calibration refresh" with the reason.

Readiness.

  • The marker: Touch ID is ready only when the installed record is the one just admitted. Each attempt first clears /run/aurora-sep/calibration-ready, and it is written again only after a successful install. It names the target and the digests of the source, the IM4P, the seal, the trust bundle and the installed record.
  • The gates: aurora-sep-ready.service and fprintd now also need aurora-sep-calibration-ready. That check re-reads the installed record without following links and compares its SHA-256 with the marker. A record changed later, or opened up to other users, is therefore not ready either.
  • Trusted keys: aurora-sep.service still starts for SEP trusted keys either way, so sensorless Macs are unaffected.

FSCl Macs. When the factory cache has no FSC2 record, the carved FSCl comb record is installed as carved, as before. It now goes through the same replace-only-if-different, rollback and readiness path. It is checked only as far as the extractor checks it (no FSCl hardware here), and an FSCl record is never quarantined.

Limits. These are provenance and structure checks. The enclave alone verifies the seal's signature chain and the sensor binding.

The same helper and gates ship in aurora-silicon/fedora-aurora#28 and aurora-silicon/nixos-aurora#27.

Testing

  • Unit tests (tests/test_sep_calibration.py): 35 tests, all on synthetic APFS images, manifests and records. They cover:
    • APFS reads: hashed and unhashed directory keys; the newest checkpoint, and a damaged one skipped; refusal of a checksum error, an encrypted volume, a compressed record, a missing Hardware volume or factory cache, and non-APFS input.
    • Manifests: properties walked as DER; digest and serial bytes hidden in an opaque value not counted; duplicate, misnamed, non-minimal, trailing and unsigned manifests refused; trailing data after a record refused.
    • Admission:
      • a valid rebuild;
      • trust bundles: current preferred over an old named one, arbitrary bytes, a missing named copy, mismatched bytes, two named with no current, a misnamed single;
      • identity: unknown ECID or serial, another ECID, another Mac's seal, another serial, two seals;
      • seal coverage;
      • changed calibration and seal;
      • a manifest-only source change, which is recorded in the marker.
    • Prepare:
      • install and readiness;
      • an identical record kept and its mode fixed;
      • each start reading current records;
      • a new trust bundle replacing the record, with rollback;
      • damaged, world-readable and bare records replaced, never by the bare image;
      • a link at the target moved aside without being followed;
      • a failed replacement leaving the old bytes, their rollback copy and no readiness;
      • another Mac's record quarantined;
      • an unknown identity leaving a plausible record but unready;
      • an unreadable container quarantining a bare image;
      • readiness cleared before each attempt;
      • readiness following the installed bytes;
      • FSCl records, including the extractor's loose layout, installed and never quarantined;
      • a sensorless Mac;
      • links at the state and firmware directories;
      • the device-tree firmware name.
  • Mutation check: 15 of 16 mutants of the checks are caught. The one survivor removes the explicit unknown-identity guard, and the comparisons after it still refuse.
  • Full suite: 122 tests pass.
  • J713 (M4 Air), real records:
    • From both a backup image of the iBoot System Container and the live partition (opened read-only), the rebuilt record is byte-identical to the sealed calibration this Mac uses for Touch ID.
    • The packaged helper on the live system kept that record (same bytes and inode), wrote the readiness marker, and aurora-sep-calibration-ready passed.

pkgrel stays at this PR's 7, with hashes updated. The package also installs /usr/libexec/aurora-sep-calibration-ready.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Urgent for J700 on the Arch/Omarchy path packaged in current main. aurora-sep 1-6 installs this helper at /usr/libexec/aurora/prepare-sep-calibration; aurora-sep.service runs it as ExecStartPre before the explicit loader. Main unconditionally replaces the DT-selected firmware file with the cached or newly carved calibration. For an FSC2 Mac, that replaces the installer-provided combined record with the bare IMG4 that the enclave refuses. An already loaded copy can conceal the disk damage until another boot or service cycle.

The preservation decision needs a stronger contract before it can be called a valid sealed copy. It currently checks only the incoming IMG4 label, a private regular destination file and its opening comb label. It does not validate DER lengths, compare the embedded calibration, bind the seal to this Mac or establish current firmware/trust-bundle provenance. Even an eight-byte malformed comb prefix is accepted. The PARTUUID/hash metadata binds the carved cache, not the installed combined record, and PARTUUID alone does not track a firmware update.

Please preserve a candidate only with explicit trusted provenance/validation, and report stale or mismatched material clearly rather than silently declaring it sealed. Do not replace a rejected candidate with bare FSC2. Add malformed/truncated, changed-source, mismatched-calibration and wrong-device/current-bundle cases. The installer documentation at macOS/docs/sensor-root-key.md requires this Mac's seal and current trust bundle and explicitly says structural admission does not verify the certificate chain or sensor binding.

Fedora also packages this helper in RPM aurora-sep, at the same /usr/libexec/aurora/prepare-sep-calibration path. The current fedora-aurora 1-7 recipe and service contain the identical unconditional rewrite, so that package needs the corresponding fix too. This is packaging-source evidence; the daily Neo's installed RPM and active-unit provenance are still awaiting an approved inventory record within this no-hardware review.

The software gates are queued through an ordinary buildslot. I will update this same comment with the exact build and test results. No hardware test was performed in this review.

Keep this urgent, with the preservation/provenance checks fixed and tested before an affected Touch ID boot. No private factory records are needed in the PR or its tests.

@erikwb

erikwb commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Updated (2aa81ec). The keep decision now rests on checks that tie the installed record to this Mac, rather than on its opening label:

  • Strict DER: comb { fdrd: IMG4 { IM4P(FSC2), [0] IM4M }, secb }, with definite minimal lengths, exact nesting, no trailing data and a non-empty secb. The 8-byte comb record is refused.
  • Calibration bound to this Mac: the embedded IM4P must equal the one just carved from this Mac's iBoot System Container, and the seal must list its SHA-384. The FDR seal carries one DGST per factory record; on J713 the carved FSC2's IM4P digest is among them.
  • Device bound: where the device tree has serial-number (m1n1 publishes it), the seal's SrNm must match.
  • Stale or mismatched material is reported with the reason and left in place, never replaced with the bare FSC2. A damaged record that still opens with comb counts as sealed, so it's never overwritten.
  • Not checked: whether the trust bundle is current. That needs the Hardware volume, so it's the enclave's to check.

New cases: malformed and truncated, changed source, mismatched calibration, a seal without this calibration, and wrong device. They use synthetic records only and fail against the current script. Suite: 100/100. On J713 with real records, the sealed calibration was verified and kept, and the corrupted variants were each refused.

Other packages: Fedora is aurora-silicon/fedora-aurora#28 (release 8; the test is test_sep_prepare_calibration.py, since test_sep_calibration.py there covers the extractor). nixos-aurora ships the same helper, so aurora-silicon/nixos-aurora#27 carries the same fix.

@RyanTheTide

RyanTheTide commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

HOLD on 2aa81ec5750e74af7a0acd60e2e7f12297b81d0f. The overwrite bug is real, and the new DER/payload checks improve the first revision. The keep decision still does not establish current source, seal or trust-bundle provenance.

I reproduced these gaps using synthetic records against this exact helper:

  • Warm the cache with calibration A, then change the extractor's source to B without changing PARTUUID. prepare() still logs keeping the sealed calibration for A. Lines 217-235 compare the cached bytes with their own hash, not the current source. The new changed-source test starts with an empty cache and misses this upgrade path.
  • Change only the carved IMG4 manifest while keeping IM4P unchanged. sealed_problem() still accepts the installed record because it discards the carved manifest. Neither firmware identity nor the current seal/trust epoch participates in the decision.
  • Replace secb with b'not a trust bundle'. It is accepted. Nonempty bytes do not prove that this is the current bundle.
  • Put encoded DGST and SrNm byte strings inside one opaque OCTET STRING following the IM4M label. That is also accepted. manifest_values() searches bytes rather than the manifest's DER property structure, so the digest need not be an actual covered property.
  • Pass serial=None. The candidate is accepted with no device identity comparison. A missing identity must mean unknown, not valid. Comparing a cleartext serial or finding a digest is also not signature verification.
  • Damage the combined record's first header byte, or install the otherwise valid combined record with mode 0644. The regular(target) and opens_combined(...) gate is bypassed and the active target is overwritten with bare FSC2. Conversely, a detected wrong-device seal is reported but left at the active firmware path. Recognition/permissions must not select a fallback that installs unusable FSC2, and rejection needs a real readiness/quarantine result.

Please make the keep path depend on an admitted, device-local provisioning record. A concrete implementation contract is:

  1. Re-extract from the admitted current ISC under the lock on every preparation, or validate a trustworthy source-generation token before using a cache. PARTUUID plus a self-hash is insufficient. Record the full carved IMG4 digest as well as its IM4P digest, and invalidate on source or firmware-generation changes, including a manifest-only change.
  2. Extend the installer/import handoff with private, root-owned provenance for this Mac's hardware identity (ECID and sensor identity where available), ISC identity, firmware generation, selected seal-<ECID>, current trust-bundle digest, source digest and sealed-result digest. Verify the handoff against the live machine and independently current firmware information. A JSON file containing only hashes of neighboring cached files does not establish freshness or device provenance. If Linux has no current firmware/trust authority, return unknown and require a refreshed handoff.
  3. Parse the exact admitted DER schema with explicit limits, for example the existing 4 MiB carved-source limit, the installer's 16 MiB combined-record limit, and the extractor's depth 32 / 16,384-node limits. Require minimal lengths/identifiers, exact fields and no trailing data. Reject duplicate properties within one object scope; distinct factory objects may each legitimately carry DGST. Walk actual IM4M properties, never regex-match inside OCTET STRING payloads. Require complete payload equivalence and exact equality of the installed seal and secb with the admitted device-local records. Where cryptographic validation is available, verify the seal chain and sensor/device binding; otherwise describe the checks as provenance/structural checks, leaving enclave acceptance as a separate gate.
  4. The bundle must be the named trustobject-<sha256> whose digest and bytes match trustobject-current. Only when trustobject-current is absent may exactly one named bundle be admitted, with its digest checked. Require exactly one device-local seal and matching factory sensor records. This follows the installer contract, which explicitly distinguishes structural admission from certificate-chain/sensor-binding verification.
  5. Keep only if all those checks succeed. On a source, firmware, seal or bundle change, validate a replacement built from the refreshed local records and atomically install it with mode 0600 and fsync. Preserve the old bytes as private rollback evidence. With no valid replacement, report refresh-required, quarantine a rejected or wrong-device copy outside the active firmware search path as private evidence, and gate biometric readiness. Do not claim success for that file or substitute bare FSC2. Keep trusted-key-only startup available on sensorless machines.

A concrete readiness implementation is a root-private marker under /run/aurora-sep/, cleared before each attempt and created atomically only after successful current admission/installation. Bind it to the admitted source/firmware generation and target digest. Gate both aurora-sep-ready.service and fprintd on that result in addition to physical reader presence, and keep aurora-sep.service able to load trusted-key support. The marker must be transient across boots and must not be a persistent success bit that survives a failed refresh. NixOS needs the equivalent gates in modules/sep.nix.

Concrete control-flow change in prepare(): branch on the fully validated carved source type first. Put atomic_write(target, data) only behind the validated already-combined FSCl path. The FSC2 path must never fall through to writing the bare source, including when the target is absent, has a damaged header, or is not mode 0600. Separate regular-file ownership/link checks from the privacy-mode check, read the bounded candidate once without following symlinks, and either validate/secure it, install a validated replacement, or return refresh-required with biometric readiness disabled.

The decision should be equivalent to:

current = extract_current_source(admitted_isc)  # not the PARTUUID-only cache
inputs = admit_current_device_handoff(live_identity, current_firmware)
expected = reseal(current, inputs.seal, inputs.current_trust)
validate(expected, current, inputs)
if installed == expected:
    mark_biometric_ready()
else:
    preserve_private_rollback(installed)
    atomic_install(expected)

Those names describe proposed interfaces, not functions already present in this repository. Any missing/stale admission must take the refresh-required path before this code runs. Simply raising an exception in this helper is insufficient because main() catches it and the unit continues; carry the biometric readiness result to the reader/ready-service gate.

Add warm-cache source changes, manifest-only firmware changes, old bundle alongside current, wrong-device/missing-identity, opaque property bytes, malformed/duplicate DER properties, and valid replacement/failed replacement with byte-exact rollback tests. Keep all fixtures synthetic. The existing FSCl and sensorless paths need regression coverage too.

Validation on this exact head: 100/100 source tests pass; eight additional synthetic cases reproduce the gaps above. makepkg --verifysource and the complete install-only makepkg --nodeps --cleanbuild package phase pass in an arm64 toolchain under QEMU. The output is aurora-sep-1-7-any.pkg.tar.zst, SHA-256 c0d195ae5d299669305662b73177422fb3a26cc63daf3cf34b4a4db6c2f634ab. The packaged helper is byte-identical to the reviewed helper and the unit invokes its installed path. Runtime dependency resolution was not exercised by the nodeps build.

These package/source gates do not clear the validity and freshness holds. No device test was performed in this review. Rerun affected gates on the corrected source and retain the owner's match-only runtime gate. No merge or contributor-branch change is part of this review.

The enclave loads a standalone FSC2 calibration (J700, J713) only
resealed with the Mac's own factory records:

  comb { fdrd: IMG4 { IM4P, [0] seal-<CHIP>-<ECID> }, secb: trust bundle }

prepare-sep-calibration cached the carved image by partition identity
and wrote it over that record at every start.

Every start now reads the factory cache read-only from the Hardware
volume of the iBoot System Container, and rebuilds the record from it.
The APFS reader is bounded: the newest checksummed checkpoint, the
object maps, the file-system tree and uncompressed regular files only.
The rebuild takes:
- the FSC2 calibration's IM4P;
- the one seal, which must name the running Mac's CHIP and ECID from
  the boot's local policy manifest, carry its serial number, and list
  the IM4P's SHA-384 as its FSC2 digest;
- the trust bundle whose named copy matches trustobject-current.
IM4M properties are walked as strict DER, with limits on size, depth
and element count.

The installed record is replaced only when it differs. The replacement
is written atomically with mode 0600 and read back, and the old bytes
are kept as private rollback evidence. When the records cannot be
admitted, the bare image is never installed, a wrong-device or
malformed record moves to private quarantine, and Touch ID stays
unready. An FSCl comb record is still installed as carved, checked as
the extractor checks it.

Readiness is a per-boot marker in /run/aurora-sep that names the
admitted digests. aurora-sep-ready.service and fprintd now also require
calibration-ready, which checks the installed bytes against the marker.
SEP trusted keys start either way. These are provenance and structure
checks; the enclave verifies the signatures.
@erikwb
erikwb force-pushed the aurora-sep/keep-sealed-calibration branch from 2aa81ec to 0f70c83 Compare October 26, 2026 15:02
@erikwb erikwb changed the title Keep an installed sealed Touch ID calibration Rebuild the sealed Touch ID calibration from this Mac's factory records Oct 26, 2026
@erikwb

erikwb commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the counterexamples. All three PRs now have a new head, and the helper is identical in each. The body has the details; point by point:

  • Source and freshness (1): there is no cache any more. Every start reads the factory cache read-only from the iBoot System Container's Hardware volume. These are the same FSC2-*, seal-* and trustobject-* records the installer reseals from. The helper rebuilds the expected record and keeps the installed one only if it is byte-identical.
    • A change to the source, seal or trust bundle therefore changes the expected bytes, and the record is replaced, with rollback.
    • A manifest-only change to the factory FSC2 image can't change what the enclave loads, since only the IM4P goes into the resealed record. Its full SHA-384 is still recorded in the readiness marker, alongside the IM4P, seal, trust-bundle and installed-record digests.
  • Provenance (2): I'd rather not route freshness through an installer handoff. Linux now reads the factory records directly from the live container on every start, so they are as current as the container itself.
    • Identity is checked against the running boot: the seal's name must give the CHIP and ECID from the local policy manifest in the device tree, and its SrNm must equal the device tree's serial number.
    • A missing value means unknown, which admits nothing.
    • If the container can't be read, the helper reports a refresh as required and Touch ID stays unready.
  • DER (3): IM4M properties are now walked as private-class elements whose tag must spell the name, with no byte search. Duplicates in one scope, non-minimal lengths or identifiers, and trailing data are refused. The limits are 4 MiB per source, 16 MiB per record, depth 32 and 16,384 elements. These are described as provenance and structure checks; the signature chain and sensor binding stay with the enclave.
  • Trust bundle (4): the named trustobject-<sha256> whose digest and bytes match trustobject-current. Without trustobject-current, exactly one named bundle, which must match its name. Exactly one seal and one FSC2 record.
  • Install, quarantine, readiness (5) and prepare() control flow:
    • FSC2: the bare image can never be written.
    • Replacement: written atomically with mode 0600, fsynced and read back. The old bytes are kept as private rollback evidence.
    • Quarantine: malformed records, bare images and another Mac's record move out of the firmware path into private quarantine.
    • Target checks: the installed record is read once without following links. The ownership and type checks are separate from the mode check.
    • Readiness: /run/aurora-sep/calibration-ready is cleared before each attempt and written only after admission. aurora-sep-ready.service and fprintd have calibration-ready as an ExecCondition, alongside sensor-present; the NixOS module does the same. That check compares the installed record's SHA-256 with the marker.
    • Trusted keys: they still start on sensorless Macs.
    • FSCl: these Macs keep the carved record, checked as the extractor checks it. I have no FSCl hardware, so that path is deliberately not stricter than before.
  • Tests: synthetic only.
    • The warm-cache case is now "each start reads current records". The list also covers a manifest-only change, an old bundle alongside the current one, wrong-device and missing identity, opaque property bytes, malformed and duplicate DER, valid and failed replacement with byte-exact rollback, and the FSCl and sensorless paths. The new APFS reader has its own cases.
    • Fedora's test_sep_preparation.py now asserts that every preparation reads the container again, with no cache.
    • 15 of 16 mutants of the checks are caught. The one survivor is equivalent.
  • J713: from both a backup image and the live partition, the rebuilt record is byte-identical to the sealed calibration Touch ID uses on this Mac. The packaged helper kept it in place and passed the readiness check.

@erikwb

erikwb commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Please hold off on re-reviewing this for now. I'll update it with test results later today, including the full boot on the J713 with fprintd starting through the new readiness gate.

@erikwb

erikwb commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Test results for 0f70c83, as promised:

J713 (M4 Air), real boot. The helper, readiness check and gates installed here are byte-identical to this head; only the packaged install paths differ. On a cold boot:

  • prepare-sep-calibration read the boot container, rebuilt the record, found it identical to the installed one and kept it ("Touch ID calibration ready").
  • aurora-sep-ready.service and fprintd.service both ran sensor-present and calibration-ready as ExecCondition (each exit 0), then started.
  • The driver restored the enrolled fingerprints and armed the sensor as before, and Touch ID unlock with an enrolled finger works.

Gate. On this machine, transient units running the real aurora-sep-calibration-ready as ExecCondition started with the boot's marker. They were skipped, not failed, when the marker's digest did not match the installed record, and when /run/aurora-sep could not be read.

@erikwb

erikwb commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Closing: Ryan cherry-picked this head into main as 1ac87cb (helper, calibration-ready and tests), and #49's aurora-touchid-setup now builds on it, so the packaging changes here are no longer needed. Thanks! With aurora-silicon/linux#457 the J713 device tree names msrk-j713.bin as the second firmware-name entry, which aurora-touchid-setup reads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants