diff --git a/mac-manual/content/04-security.md b/mac-manual/content/04-security.md index 38aa3262..c738aa55 100644 --- a/mac-manual/content/04-security.md +++ b/mac-manual/content/04-security.md @@ -39,11 +39,17 @@ If a bug ever writes that shared state wrongly, the enclave stops accepting it a - With FileVault on, macOS can't unlock its disk and won't start, and the startup picker may not open. Getting the Mac back takes a DFU restore, which erases it. - With FileVault off, macOS resets its keychain and Touch ID fingerprints and shows a warning. +On the M1 MacBook Air and the 16-inch 2021 MacBook Pro with M1 Max, setup requires a kernel that guards the shared records during first setup. The M1 Max also requires the driver's enrollment and verification startup fixes. Setup checks the driver at every boot before permitting writes. If the driver was already running when you agreed, restart your Mac and open fingerprint setup again. If setup asks for a compatible kernel, install one with those features and restart. + +Fingerprint setup and fingerprint sign-in pause if the running M1 driver cannot confirm safe storage. This also affects an attached USB reader because the fingerprint service checks every reader when it starts. Use your password while the driver starts, or restart with a compatible kernel if setup still reports the problem. + +An interrupted first setup can leave a key store whose creation the Secure Enclave never confirmed. If setup reports `unsupported:recovery`, use your password and leave the keybag and guard list in place. Contact Omarchy Mac support with the setup message and your kernel version from `uname -r`. If `journalctl -b -u omarchy-mac-touchid-load` shows a load error, include it. Keep the keybag, guard list and calibration files private. A confirmed refusal can be retried automatically on the next guarded load if no shared record was pinned. Existing fingerprints and their key store are kept. + On a MacBook Neo or a 16-inch MacBook Pro with M4 Pro, setup also reads the sensor's key (and on the M4 Pro its calibration) from the factory records the installer left on the boot partition, into firmware files only root can read. Turning Touch ID off deletes those files, and turning it on again rebuilds them. After five fingerprints that don't match, Touch ID locks, and it stays locked after a restart, as on macOS. Your password at a `sudo` prompt or an administrator dialog unlocks it again. The lock screen's password doesn't yet, so use one of those once if Touch ID keeps refusing your finger. -Turning Touch ID off later removes your fingerprints and stops the driver loading. The key store stays. +Turning Touch ID off later removes your fingerprints and the package's authorization to write. The key store stays. A kernel that uses the Secure Enclave for the M1 microphones can still load its driver read-only. ## Resetting the Mac for a new owner diff --git a/omarchy-mac/README.md b/omarchy-mac/README.md index 80bfd67b..a2893771 100644 --- a/omarchy-mac/README.md +++ b/omarchy-mac/README.md @@ -26,7 +26,10 @@ The Mac's hardware data lives in the platform root, `/usr/share/omarchy-platform - `display-cutouts.json`: the notch of each MacBook panel (the 14" Pro measured at 64 physical rows, the 16" Pro inferred at 64 and the Airs at 56), which the bar keeps clear of. A notched panel not listed gets no floor until the file lists it; `[bar] notch-height` in `shell.toml` only adjusts the floor of a listed panel. An entry may also name `cutoutWidth`, a centered notch's measured width in physical columns. Support for placing center status content beside that notch remains proposed for the canonical desktop in [omacom/omarchy#17744](https://github.com/omacom/omarchy/pull/17744); this schema alone does not change placement. A runtime without that support, or a panel without the key, keeps its current layout. - `displays.conf`: `omarchy-hw-display` never picks the Touch Bar's `display-pipe` or `228600000.dsi.0` backlight and prefers the Retina panel's `apple-panel-bl` (no GPU backlight exists), and `omarchy-brightness-display` probes an external monitor over DDC only when its connector has a `ddc` node, since Apple's display driver registers no DDC channel and a probe would walk the SoC's SMBus for about 3 s. - `audio.json`: the audio panel and microphone widget leave out asahi-audio's DSP internals: the speaker graph's output stream into the raw speakers (`effect_output.jNNN-convolver`, and the desktops' `mini`/`studio`), the microphone graph's always-running capture of the raw array (`audio_effect.jNNN-mic`), the raw devices asahi-audio marks do-not-use (`RawSpeakers`, `RawMics`), the mapper's own capture of the DSP microphone (`input.omarchy_asahi_mic`), which would otherwise count as an app recording, and the mono DSP microphone while the mapper's stereo `omarchy_asahi_mic` exists. A runtime older than the platform root reads no audio hints and keeps its own Apple checks. -- `fingerprint-readers`: Touch ID. `omarchy-hw-fingerprint` finds the sensor once `/run/omarchy-mac/touchid` reads `ready`, or `available` before the owner has turned it on. Nothing loads the Secure Enclave driver until the owner agrees. At boot, `omarchy-mac-touchid-status.service` (`lib/touchid-status`, pulled in by the package's `multi-user.target.wants` link, before the greeter and `fprintd`) asks `lib/touchid-eligibility`, which reads only the device tree and installed files: `available` needs a sensor node, a board the aurora driver has a profile for (M2, M2 Pro and Max, the M3 Air J613 and J615, the MacBook Neo, and the 16-inch M4 Pro J616s and M4 Max J616c, whose sensor sits at the root of the tree rather than under `/soc`; M1-family Macs wait for their xART guard path), `/chosen/apfs-preboot-uuid`, a way to the calibration (under the name the sensor's `firmware-name` gives, `apple/mesacal-.bin`, or `apple/mesa_calibration.bin` on M2 Pro and Max) and, on the Neo, the J616s and the J616c, a way to the sensor root key (the second `firmware-name` entry, or `apple/msrk-j700.bin`), an installed one or the factory records on the ESP with `python` to rebuild it from; the J616s's and J616c's calibration is rebuilt the same way (the extractors need `python`, which linux-aurora only suggests), and an Omarchy whose `omarchy-lifecycle-dispatch` resolves `enable-fingerprint`, since the invitation comes once and an older setup would enrol a reader nothing turned on; anything else records `unsupported:`, which no detector line names. Omarchy's fingerprint setup then runs `omarchy-lifecycle-dispatch enable-fingerprint` (`entrypoints/enable-fingerprint`, as root) before enrolling. With no status file (a Mac without a sensor records nothing, and a status service can fail) it works eligibility out again. Where Touch ID can't be set up it lets the setup go on, so a USB reader enrols on a Mac mini, a Studio or an M1 Mac as it would without Touch ID. A Mac whose owner already agreed is never asked again: it gets any missing options and, unless Touch ID reads `ready`, is told to restart, and the setup goes on. It stops the setup only when the owner says no, or turning Touch ID on or writing its options fails. It says in three lines that Touch ID is experimental and can be unstable, that it shares the Secure Enclave with macOS so macOS should be backed up first, and that the Mac manual has the details, then asks. The manual's Encryption and passwords page carries the rest: the key store Linux creates stays, the enclave's anti-replay state moves forward and is one file in the iBoot System Container that macOS updates too, and a bug that writes it wrongly can cost macOS data (with FileVault on, macOS won't start and the Mac needs a DFU restore; with FileVault off, macOS resets its keychain and fingerprints). FileVault's state isn't checked: the owner can change it after installing, so the manual names both cases. On yes, `lib/touchid-enable` carves what is missing from this Mac's own iBoot System Container into `/usr/lib/firmware/updates` (the calibration with linux-aurora's `extract-mesa-calibration`, except on the Neo, whose installer writes the sealed form, and the J616s and J616c, whose `apple/mesacal-j616s.bin` and `apple/mesacal-j616c.bin` are resealed from their `FSC2` factory records with `lib/touchid-root-key --record FSC2`; the sensor root key, `apple/msrk-j700.bin` on the Neo and `apple/msrk-j616s.bin` and `apple/msrk-j616c.bin` on the J616s and J616c, root-only `0600`, rebuilt with `lib/touchid-root-key`, which takes the SoC the seal record must name with `--chip`), records the agreement in `/etc/omarchy-mac/touchid-on` and in the driver's options (`/etc/modprobe.d/omarchy-mac-touchid.conf`: `xart_writes=1 provision_keybag=1`, today's defaults, which a kernel that loads `apple_sep` read-only by default, omacom/linux-aurora#180, writes only with; the name sorts after `apple-sep.conf`, so the owner's agreement wins over any `apple-sep.conf`, while `apple_sep.xart_writes=0` on the kernel command line still wins over both, and no initramfs hook includes `apple_sep`, so only the root's copy of the options is read), loads `apple-sep` now (a driver already running keeps the options it loaded with, so on a kernel that loads it read-only, and a Mac with no key store yet, the agreement stands and Touch ID turns on after a restart), and succeeds only once the activation records `ready`, restarting an `fprintd` that started without the reader; a failure after the record is written removes it again, so the next boot offers Touch ID again instead of loading a driver that never came up. A driver that loaded but never came up stays that way until a restart, so the status then reads `failed` and setup doesn't offer Touch ID again that boot; when `/dev/sep-bio` or the keybag never appeared, the activation never ran, and the error points to `journalctl -k`, the driver's own log. While the record exists, `omarchy-mac-touchid-load.service` (pulled in by a `multi-user.target.wants` link) loads `apple-sep` at every boot once `udevadm wait` sees `/dev/disk/by-partlabel/iBootSystemContainer`, since the driver opens that link as it probes and does not retry, and before the greeter and `fprintd`. The wait is part of the service rather than a device dependency, because systemd waits for a unit's devices before it checks its condition: a dependency would hold up every boot, agreed or not, and the greeter on a machine without the partition until the device timed out. A key store from an earlier load (`/var/lib/aurora-sep-keybag.bin`) is not agreement: that owner never saw this text, so they are asked too, told that the existing key store is used. `omarchy-lifecycle-dispatch disable-fingerprint`, after the fingerprints are deleted, removes the record and the options, so the driver stops loading from the next boot and the status offers Touch ID again; the key store stays. A record or options that can't be written, or removed, fails the operation rather than reporting success, and a carved calibration, like the sensor key, takes its name only once it is whole. On a kernel with omacom/linux-aurora#180, udev loads `apple_sep` on every Mac, read-only unless the options file exists, and a read-only driver always reports `matching` as `blocked`. The activation runs only on the owner's record, so a Mac whose owner hasn't agreed, or turned Touch ID off, keeps the boot's `available` and is offered Touch ID; and `enable-fingerprint` writes the options for a Mac agreed before they existed whatever its status, so one that reads `blocked` reaches `ready` after a restart. The Neo's, the J616s's and the J616c's sensor keys (`apple/msrk-j700.bin`, `apple/msrk-j616s.bin`, `apple/msrk-j616c.bin`) and the J616s's and J616c's calibration (`apple/mesacal-j616s.bin`, `apple/mesacal-j616c.bin`) are device-private, so nothing reads them before the owner agrees. asahi-installer copies this Mac's factory records (`com.apple.factorydata`) into the ESP's fallback firmware archive, `asahi/all_firmware.tar.gz`, on every install; an image install mounts the ESP at `/boot/efi` with `umask=0077`, so only root can read it there, and that mount is where the archive is read; on yes, `lib/touchid-root-key` (Python's standard library only) reads the `MSRk` record (`FSC2` for the J616s's calibration), the `seal` record, which must name the Mac's SoC, and the trust bundle from it in memory, rebuilds the file as omarchy-mac-installer's `factory_root_key()` does on macOS (the `MSRk` record's `IM4P` under the FDR sealing manifest, with the trust bundle as `secb`), checks its envelope, and refuses records that aren't all found byte for byte in this Mac's own iBoot System Container, so an archive from another Mac, or one swapped on the ESP, gives no file. It writes the file root-only (`0600`) under a temporary name, synced, then renames it. Nothing is kept when the owner says no, and a yes that then fails to turn Touch ID on takes back the key, and on the J616s and J616c the calibration, it rebuilt along with the agreement; `disable-fingerprint` deletes both from `/usr/lib/firmware/updates`, and the next yes rebuilds them. A factory reset gives the factory root no key, since the ESP survives it and the next owner's yes rebuilds it. Every Neo, J616s and J616c install has the archive, since upstream asahi-installer writes it on every install, so none needs the installer to collect the key. A Neo without the archive (removed by hand) or without `python` reads `unsupported:no-root-key`, and a J616s or J616c reads `unsupported:no-calibration` unless its calibration is already installed; the boot status looks for the archive, so `omarchy-mac-touchid-status.service` runs after `boot-efi.mount`. Carved files under `/usr/lib/firmware/updates` belong to no package, so a root rollback can remove them. An agreed Mac isn't asked again, so its setup doesn't carve them back: turning Touch ID off (Omarchy's fingerprint removal) and on again does. The two operations, and `available`, need the matching Omarchy change before this file ships. `omarchy-mac-touchid-activate.service` (`lib/touchid-activate`) runs only on the owner's record, so it never opens a driver something else loaded without agreement (fprintd still opens `/dev/sep-bio` when it probes its readers, so on a kernel with omacom/linux-aurora#180, which loads the driver on every Mac, fprintd's allowance for the node needs the same gate first), and writes `/run/omarchy-mac/touchid`, `0644` so the session user can read it, and only when all four of the Secure Enclave driver's `diag` attributes say Touch ID can enrol and match, as the driver's ABI document asks: `touchid` reads `ready`, `sensor_attach` reads `attached`, `restore` reads `restored` or `empty`, and `matching` reads `usable` or `unverified`. `diag/touchid` alone can read `ready` while the sensor is uncalibrated, the enrolled fingerprints are unproven, or the xART guard blocks a match, as on a cold-booting M1-family Mac, and the invitation that follows comes only once. Anything else writes the reason instead (`failed`, `not-ready`, `unproven` or `blocked`) and says why in the unit's journal. Touch ID activates only on the first open of `/dev/sep-bio`, so `94-omarchy-mac-touchid.rules` starts the unit, which opens it once, read-only, as soon as the kernel publishes it; nothing needs enabling. The kernel activates Touch ID inside that open, and activation lasts the rest of the boot after the close. So does a failed activation, so the unit opens the node only once the kernel has made this Mac's keybag, `/var/lib/aurora-sep-keybag.bin`. The node takes one opener at a time, so a node `fprintd` holds is already activated. The attach retries once about 10 s after a short fall, so the script waits until 45 s after it starts for a settled answer, and `TimeoutStartSec=60s` bounds an open that blocks. A missing attribute ends it at once. An update runs it again, and a `ready` from earlier in the boot stands while `sensor_attach` reads `attached`, unless a final failure (`failed`, `unproven` or `blocked`) appears, since `diag/touchid` follows every later bring-up and one can fall short and recover. On the install or update that brings the rule, `/dev/sep-bio` already exists and no add event comes, and the boot-time status unit hasn't run on the update that first installs it, so `90-omarchy-mac-touchid.hook` starts the status unit and then the activation after the transaction, and the same session's post-update check sees the result. On a Mac with no agreement, that status run records `available` and the activation is skipped, whatever loaded the driver, unless Touch ID failed to come up earlier that boot: a reason that failure recorded (`failed`, `not-ready`, `unproven` or `blocked`) stands until a restart, and setup says to restart. The hook is skipped in a chroot, which includes `pacman --root`, or an unbooted root, and never fails the transaction: a unit that fails says why in its journal. The post-update fingerprint invitation then reaches the owner, and the fingerprint setup installs `libfprint-git`, whose aarch64 build carries the Touch ID driver (omacom/omarchy-pkgs#806) and owns `fprintd`'s allowance for `/dev/sep-bio`. systemd resolves that allowance when `fprintd` starts, so the drop-in `fprintd.service.d/50-omarchy-mac-touchid.conf` orders `fprintd` after `omarchy-mac-touchid-wait.service`, which follows the boot-time load, waits up to 15 s for the node where the Secure Enclave driver has a device and returns at once on a Mac without one, and after the activation, so `fprintd` never takes the node while the activation holds it: when both start together, at boot or from the pacman hook, `fprintd` waits for the activation, up to 60 s on a Mac whose attach is still settling. It adds no allowance of its own, and it's inert until Omarchy's setup installs `fprintd`. No sleep hook: the kernel ends a capture before suspend, and on a MacBook Neo the lock screen took the finger on the first touch after resume. Ship this file only once a boot without `aurora-touchid` shows enrolment, verification and suspend working, which still needs: Omarchy's `enable-fingerprint` and `disable-fingerprint` operations and their calls from the fingerprint setup and removal, since `apple-sep` is a module (`APPLE_SEP=m`: built in, it probes before udev has made the iBoot System Container's partition link and fails without retrying) with no modalias, which loads only on the owner's record; and m1n1 that forwards `/chosen/apfs-preboot-uuid`, which selects this install's own lane in the Secure Enclave. Keep that source stable: changing it (boot entries with and without `apple_sep.os_uuid_hi`/`os_uuid_lo`, or a stub reinstall) orphans the Linux enrolments. Without all of that the invitation, which comes once, leads to a setup that cannot finish. The script follows the aurora kernel's naming (the `apple_sep` driver and its `diag` attributes): a kernel that renames them stops the invitation without an error, so move the script together with the kernel pin. +- `fingerprint-readers`: Touch ID. `omarchy-hw-fingerprint` finds the sensor once `/run/omarchy-mac/touchid` reads `ready`, or `available` before the owner has turned it on. This package loads the Secure Enclave driver only after the owner agrees. At boot, `omarchy-mac-touchid-status.service` (`lib/touchid-status`, pulled in by the package's `multi-user.target.wants` link, before the greeter and `fprintd`) asks `lib/touchid-eligibility`, which reads only the device tree and installed files: `available` needs a sensor node, a board the aurora driver has a profile for (M2, M2 Pro and Max, the M3 Air J613 and J615, the MacBook Neo, and the 16-inch M4 Pro J616s and M4 Max J616c, whose sensor sits at the root of the tree rather than under `/soc`; the M1 Air J313 and 16-inch M1 Max J316c require a driver with guard pinning and separate write and keybag controls; other M1-family boards wait), `/chosen/apfs-preboot-uuid`, a way to the calibration (under the name the sensor's `firmware-name` gives, `apple/mesacal-.bin`, or `apple/mesa_calibration.bin` on M2 Pro and Max) and, on the Neo, the J616s and the J616c, a way to the sensor root key (the second `firmware-name` entry, or `apple/msrk-j700.bin`), an installed one or the factory records on the ESP with `python` to rebuild it from; the J616s's and J616c's calibration is rebuilt the same way (the extractors need `python`, which linux-aurora only suggests), and an Omarchy whose `omarchy-lifecycle-dispatch` resolves `enable-fingerprint`, since the invitation comes once and an older setup would enrol a reader nothing turned on; anything else records `unsupported:`, which no detector line names. Omarchy's fingerprint setup then runs `omarchy-lifecycle-dispatch enable-fingerprint` (`entrypoints/enable-fingerprint`, as root) before enrolling. With no status file (a Mac without a sensor records nothing, and a status service can fail) it works eligibility out again. Where Touch ID can't be set up it lets the setup go on, so a USB reader enrols on a Mac mini, a Studio or an M1 Mac as it would without Touch ID. A Mac whose owner already agreed is never asked again: it gets any missing options and, unless Touch ID reads `ready`, is told to restart, and the setup goes on. It stops the setup only when the owner says no, or turning Touch ID on or writing its options fails. It says in three lines that Touch ID is experimental and can be unstable, that it shares the Secure Enclave with macOS so macOS should be backed up first, and that the Mac manual has the details, then asks. The manual's Encryption and passwords page carries the rest: the key store Linux creates stays, the enclave's anti-replay state moves forward and is one file in the iBoot System Container that macOS updates too, and a bug that writes it wrongly can cost macOS data (with FileVault on, macOS won't start and the Mac needs a DFU restore; with FileVault off, macOS resets its keychain and fingerprints). FileVault's state isn't checked: the owner can change it after installing, so the manual names both cases. On yes, `lib/touchid-enable` carves what is missing from this Mac's own iBoot System Container into `/usr/lib/firmware/updates` (the calibration with linux-aurora's `extract-mesa-calibration`, except on the Neo, whose installer writes the sealed form, and the J616s and J616c, whose `apple/mesacal-j616s.bin` and `apple/mesacal-j616c.bin` are resealed from their `FSC2` factory records with `lib/touchid-root-key --record FSC2`; the sensor root key, `apple/msrk-j700.bin` on the Neo and `apple/msrk-j616s.bin` and `apple/msrk-j616c.bin` on the J616s and J616c, root-only `0600`, rebuilt with `lib/touchid-root-key`, which takes the SoC the seal record must name with `--chip`), records the agreement in `/etc/omarchy-mac/touchid-on` and, on boards other than the guarded M1 models below, in the driver's options (`/etc/modprobe.d/omarchy-mac-touchid.conf`: `xart_writes=1 provision_keybag=1`, today's defaults, which a kernel that loads `apple_sep` read-only by default, omacom/linux-aurora#180, writes only with; the name sorts after `apple-sep.conf`, so the owner's agreement wins over any `apple-sep.conf`, while `apple_sep.xart_writes=0` on the kernel command line still wins over both, and no initramfs hook includes `apple_sep`, so only the root's copy of the options is read), loads `apple-sep` now (a driver already running keeps the options it loaded with, so on a kernel that loads it read-only, and a Mac with no key store yet, the agreement stands and Touch ID turns on after a restart), and succeeds only once the activation records `ready`, restarting an `fprintd` that started without the reader; a failure after the record is written removes it again, so the next boot offers Touch ID again instead of loading a driver that never came up. A driver that loaded but never came up stays that way until a restart, so the status then reads `failed` and setup doesn't offer Touch ID again that boot; when `/dev/sep-bio` or the keybag never appeared, the activation never ran, and the error points to `journalctl -k`, the driver's own log. While the record exists, `omarchy-mac-touchid-load.service` (pulled in by a `multi-user.target.wants` link) loads `apple-sep` at every boot once `udevadm wait` sees `/dev/disk/by-partlabel/iBootSystemContainer`, since the driver opens that link as it probes and does not retry, and before the greeter and `fprintd`. The wait is part of the service rather than a device dependency, because systemd waits for a unit's devices before it checks its condition: a dependency would hold up every boot, agreed or not, and the greeter on a machine without the partition until the device timed out. A key store from an earlier load (`/var/lib/aurora-sep-keybag.bin`) is not agreement: that owner never saw this text, so they are asked too, told that the existing key store is used. `omarchy-lifecycle-dispatch disable-fingerprint`, after the fingerprints are deleted, removes the record and the options, so the driver stops loading from the next boot and the status offers Touch ID again; the key store stays. A record or options that can't be written, or removed, fails the operation rather than reporting success, and a carved calibration, like the sensor key, takes its name only once it is whole. On a kernel with omacom/linux-aurora#180, udev can load `apple_sep` read-only before consent. On other boards the options file then permits writes after a restart, and a read-only driver always reports `matching` as `blocked`. The activation runs only on the owner's record, so a Mac whose owner hasn't agreed, or turned Touch ID off, keeps the boot's `available` and is offered Touch ID; and `enable-fingerprint` writes the options for a Mac agreed before they existed whatever its status, so one that reads `blocked` reaches `ready` after a restart. The Neo's, the J616s's and the J616c's sensor keys (`apple/msrk-j700.bin`, `apple/msrk-j616s.bin`, `apple/msrk-j616c.bin`) and the J616s's and J616c's calibration (`apple/mesacal-j616s.bin`, `apple/mesacal-j616c.bin`) are device-private, so nothing reads them before the owner agrees. asahi-installer copies this Mac's factory records (`com.apple.factorydata`) into the ESP's fallback firmware archive, `asahi/all_firmware.tar.gz`, on every install; an image install mounts the ESP at `/boot/efi` with `umask=0077`, so only root can read it there, and that mount is where the archive is read; on yes, `lib/touchid-root-key` (Python's standard library only) reads the `MSRk` record (`FSC2` for the J616s's calibration), the `seal` record, which must name the Mac's SoC, and the trust bundle from it in memory, rebuilds the file as omarchy-mac-installer's `factory_root_key()` does on macOS (the `MSRk` record's `IM4P` under the FDR sealing manifest, with the trust bundle as `secb`), checks its envelope, and refuses records that aren't all found byte for byte in this Mac's own iBoot System Container, so an archive from another Mac, or one swapped on the ESP, gives no file. It writes the file root-only (`0600`) under a temporary name, synced, then renames it. Nothing is kept when the owner says no, and a yes that then fails to turn Touch ID on takes back the key, and on the J616s and J616c the calibration, it rebuilt along with the agreement; `disable-fingerprint` deletes both from `/usr/lib/firmware/updates`, and the next yes rebuilds them. A factory reset gives the factory root no key, since the ESP survives it and the next owner's yes rebuilds it. Every Neo, J616s and J616c install has the archive, since upstream asahi-installer writes it on every install, so none needs the installer to collect the key. A Neo without the archive (removed by hand) or without `python` reads `unsupported:no-root-key`, and a J616s or J616c reads `unsupported:no-calibration` unless its calibration is already installed; the boot status looks for the archive, so `omarchy-mac-touchid-status.service` runs after `boot-efi.mount`. Carved files under `/usr/lib/firmware/updates` belong to no package, so a root rollback can remove them. An agreed Mac isn't asked again, so its setup doesn't carve them back: turning Touch ID off (Omarchy's fingerprint removal) and on again does. The two operations, and `available`, need the matching Omarchy change before this file ships. `omarchy-mac-touchid-activate.service` (`lib/touchid-activate`) runs only on the owner's record, so it never opens a driver something else loaded without agreement (fprintd's separate reader check covers the open that libfprint makes while enumerating devices), and writes `/run/omarchy-mac/touchid`, `0644` so the session user can read it, and only when all four of the Secure Enclave driver's `diag` attributes say Touch ID can enrol and match, as the driver's ABI document asks: `touchid` reads `ready`, `sensor_attach` reads `attached`, `restore` reads `restored` or `empty`, and `matching` reads `usable` or `unverified`. `diag/touchid` alone can read `ready` while the sensor is uncalibrated, the enrolled fingerprints are unproven, or the xART guard blocks a match, as on a cold-booting M1-family Mac, and the invitation that follows comes only once. Anything else writes the reason instead (`failed`, `not-ready`, `unproven` or `blocked`) and says why in the unit's journal. Touch ID activates only on the first open of `/dev/sep-bio`, so `94-omarchy-mac-touchid.rules` starts the unit, which opens it once, read-only, as soon as the kernel publishes it; nothing needs enabling. The kernel activates Touch ID inside that open, and activation lasts the rest of the boot after the close. So does a failed activation, so the unit opens the node only once the kernel has made this Mac's keybag, `/var/lib/aurora-sep-keybag.bin`. The node takes one opener at a time, so a node `fprintd` holds is already activated. The attach retries once about 10 s after a short fall, so the script waits until 45 s after it starts for a settled answer, and `TimeoutStartSec=60s` bounds an open that blocks. A missing attribute ends it at once. An update runs it again, and a `ready` from earlier in the boot stands while `sensor_attach` reads `attached`, unless a final failure (`failed`, `unproven` or `blocked`) appears, since `diag/touchid` follows every later bring-up and one can fall short and recover. On the install or update that brings the rule, `/dev/sep-bio` already exists and no add event comes, and the boot-time status unit hasn't run on the update that first installs it, so `90-omarchy-mac-touchid.hook` starts the status unit and then the activation after the transaction, and the same session's post-update check sees the result. On a Mac with no agreement, that status run records `available` and the activation is skipped, whatever loaded the driver, unless Touch ID failed to come up earlier that boot: a reason that failure recorded (`failed`, `not-ready`, `unproven` or `blocked`) stands until a restart, and setup says to restart. The hook is skipped in a chroot, which includes `pacman --root`, or an unbooted root, and never fails the transaction: a unit that fails says why in its journal. The post-update fingerprint invitation then reaches the owner, and the fingerprint setup installs `libfprint-git`, whose aarch64 build carries the Touch ID driver (omacom/omarchy-pkgs#806) and owns `fprintd`'s allowance for `/dev/sep-bio`. systemd resolves that allowance when `fprintd` starts, so the drop-in `fprintd.service.d/50-omarchy-mac-touchid.conf` orders `fprintd` after `omarchy-mac-touchid-wait.service`, which follows the boot-time load, waits up to 15 s for the node where the Secure Enclave driver has a device and returns at once on a Mac without one, and after the activation, so `fprintd` never takes the node while the activation holds it: when both start together, at boot or from the pacman hook, `fprintd` waits for the activation, up to 60 s on a Mac whose attach is still settling. It adds no allowance of its own, and it's inert until Omarchy's setup installs `fprintd`. No sleep hook: the kernel ends a capture before suspend, and on a MacBook Neo the lock screen took the finger on the first touch after resume. Ship this file only once a boot without `aurora-touchid` shows enrolment, verification and suspend working, which still needs: Omarchy's `enable-fingerprint` and `disable-fingerprint` operations and their calls from the fingerprint setup and removal, since `apple-sep` is a module (`APPLE_SEP=m`: built in, it probes before udev has made the iBoot System Container's partition link and fails without retrying) with no modalias, which loads only on the owner's record; and m1n1 that forwards `/chosen/apfs-preboot-uuid`, which selects this install's own lane in the Secure Enclave. Keep that source stable: changing it (boot entries with and without `apple_sep.os_uuid_hi`/`os_uuid_lo`, or a stub reinstall) orphans the Linux enrolments. Without all of that the invitation, which comes once, leads to a setup that cannot finish. The script follows the aurora kernel's naming (the `apple_sep` driver and its `diag` attributes): a kernel that renames them stops the invitation without an error, so move the script together with the kernel pin. +- On the M1 Air J313 and 16-inch M1 Max J316c, the owner's agreement blacklists the driver modalias and sets automatic loads read-only. The 89-omarchy-mac-touchid-options hook replaces earlier guarded writable options, including during an offline update, before the kernel transaction’s 90-mkinitcpio and 91-omarchy-mac-boot-initramfs hooks. The shipped Mac initramfs hooks do not include apple-sep. A custom early-boot image that contains both apple-sep and old writable options must be rebuilt before it is booted. The boot and setup paths take the same lock. They check a private copy of the module for `xart_guard_pins_abi=1` (the guarded storage contract from omacom/linux-aurora#506), its four write, provisioning and guard parameters, and on J316c `t6000_registration=1` (the enrollment and verification recoveries from omacom/linux-aurora#525). The loader inserts that exact image once with four explicit options. A matching administrator install command or soft-dependency rule prevents direct insertion. Explicit read-only settings and custom OS identities survive a failed setup, opt-out and later opt-in. On a kernel with the SEP modalias and both read-only controls but without guarded setup, the boot service can still start SEP read-only for the M1 microphones. A loaded driver can defer guarded setup until a restart. The setup entrypoint and fprintd service check the running module before any reader enumeration, including USB, D-Bus and PAM requests. Any potentially writable M1 reader requires owner consent, a checked build ID, an effective level-1 guard and pins, an attached and ready sensor, and matching and restore diagnostics that permit enrollment or verification. A binding driver, an unknown board with a SEP node, or a writable unsupported M1 blocks enumeration. An absent SEP or a positively read-only M1 driver permits enumeration. A read-only SEP may still register as a reader. The status unit stops a running fprintd when an unsafe reader appears or the package is updated. These checks cover the package and the system fprintd service. Privileged software that loads a module or opens a device directly controls its own access. +- A retry on either guarded M1 preserves committed keybags and their guard lists. Before inserting a driver, setup can archive a guard list containing only the spent-window marker if the kernel recorded a definitive keybag creation refusal. The refusal stays in place so a power loss cannot separate its proof from the retry. An outstanding creation intent, an unrecognized keybag header, a missing keybag beside a nonempty list, or a refused keybag beside pinned or unrecognized records needs inspection. Setup leaves those files in place and reports `unsupported:recovery`. The owner-facing setup hook never moves an active driver's files. A restart with a confirmed refusal allows the boot loader to perform the same recovery. +- For a previously enrolled guarded M1, kernel status `matching=legacy` means that the existing bag's original provisioning cannot be proven. When the sensor is attached and ready, the platform exposes restored prints for a real verification, or allows enrollment if the restore found no prints. Both cases reuse the existing pins. A failed restore or a refused write blocks it. Authentication still requires a fingerprint match. - Touch ID's re-arm: on the 7.3 aurora kernel, five failed matches lock Touch ID until a verified password calls `SEP_BIO_REARM`, and the lock outlasts a restart. aurora-touchid-rearm (omarchy-pkgs) ships `pam_aurora_touchid.so` and a root-only, socket-activated helper that checks the password again before re-arming; the drop-in `aurora-touchid-rearm@.service.d/50-omarchy-mac-touchid.conf` lets it run only on the owner's record and a kernel with `/dev/sep-bio-rearm`. While `/etc/omarchy-mac/touchid-on` and the module both exist, `lib/touchid-pam` keeps a managed block (a comment line, then `-auth optional pam_aurora_touchid.so`) straight after the `auth include system-auth` line of `/etc/pam.d/sudo` and `/etc/pam.d/polkit-1`, and only where that include is the stack's single and last auth line, so no factor or jump follows it. Every run checks that placement, as Linux-PAM reads the stack (indented lines, the type in any case), and takes out a block that auth lines now follow. Otherwise, or with `--remove`, it takes out that block and nothing else. It reads the record under its lock, leaves a symlinked stack alone, and renames a new stack into place only when the text has the expected line count and the stack hasn't changed since it was read. `touchid-enable` and `enable-fingerprint` run it once Touch ID is on, `disable-fingerprint` after removing the record, `omarchy-mac-touchid-pam.service` at every boot before logins open (Omarchy writes polkit's stack after enrolling, so polkit gets the block from the next boot), `91-omarchy-mac-touchid-pam.hook` after the update that brings it or the module, and `91-omarchy-mac-touchid-pam-remove.hook` with `--remove` before either is removed, stopping the removal if that fails. Omarchy's own edits of those stacks take no lock; nothing here runs during its fingerprint setup, and the check before the rename narrows what's left. The lock screen's stack, `omarchy-lock-password`, isn't covered: Omarchy rewrites it whole and its PAM runs as the user, which the helper refuses. - `keyrings`: `asahi-alarm-keyring`, the signing keyring of the `[asahi-alarm]` repository. `omarchy update` reinstalls every installed keyring this file names, with Arch Linux ARM's, before the system upgrade, so an Asahi key rotation never fails that upgrade's signature checks. diff --git a/omarchy-mac/entrypoints/disable-fingerprint b/omarchy-mac/entrypoints/disable-fingerprint index 70e9547d..f1ee09ec 100755 --- a/omarchy-mac/entrypoints/disable-fingerprint +++ b/omarchy-mac/entrypoints/disable-fingerprint @@ -21,11 +21,16 @@ fi rebuilt=(/usr/lib/firmware/updates/apple/msrk-j700.bin /usr/lib/firmware/updates/apple/msrk-j616s.bin /usr/lib/firmware/updates/apple/mesacal-j616s.bin /usr/lib/firmware/updates/apple/msrk-j616c.bin /usr/lib/firmware/updates/apple/mesacal-j616c.bin) -records=(/etc/omarchy-mac/touchid-on /etc/modprobe.d/omarchy-mac-touchid.conf) present=() -for file in "${records[@]}" "${rebuilt[@]}" "${rebuilt[@]/%/.new}"; do +for file in /etc/omarchy-mac/touchid-on "${rebuilt[@]}" "${rebuilt[@]/%/.new}"; do [[ -e $file ]] && present+=("$file") done +# Keep administrator settings (including OS identity and read-only denials) +# across opt-out, even when an earlier setup already removed its consent. +if ! /usr/lib/omarchy-mac/touchid-options --remove; then + echo "Touch ID could not be turned off: its driver options could not be cleared." >&2 + exit 1 +fi if (( ${#present[@]} )); then # A record left behind, on a read-only root say, loads the driver again. if ! rm -f "${present[@]}"; then @@ -36,8 +41,11 @@ if (( ${#present[@]} )); then echo "Touch ID could not be turned off: remove ${left[*]}" >&2 exit 1 fi - echo "Touch ID stops loading at the next boot. The key store for Linux stays on this Mac." + echo "Touch ID setup stops at the next boot. The key store for Linux stays on this Mac." fi +# An enrolled reader may still be open in fprintd following fingerprint +# removal. Revoke its access as soon as the owner's agreement is gone. +/usr/lib/omarchy-mac/touchid-status --withdraw || exit 1 # Without the record this takes the re-arm out of sudo's and polkit's stacks. /usr/lib/omarchy-mac/touchid-pam || exit 1 exit 0 diff --git a/omarchy-mac/entrypoints/enable-fingerprint b/omarchy-mac/entrypoints/enable-fingerprint index dc444b63..b44fbaac 100755 --- a/omarchy-mac/entrypoints/enable-fingerprint +++ b/omarchy-mac/entrypoints/enable-fingerprint @@ -2,7 +2,21 @@ # omarchy-lifecycle-dispatch enable-fingerprint: Omarchy's fingerprint setup runs # this as root before enrolling. It asks the owner before Touch ID is turned on, # since that leaves state in the Secure Enclave that can't be removed. -omarchy-hw-apple-silicon || exit 0 +recovery_help() { + echo "Touch ID kept the keybag and guard list. Leave both files in place and use your password." + echo "For help, report this setup message and your kernel version (uname -r). Include any error from journalctl -b -u omarchy-mac-touchid-load." +} + +can_enumerate() { + /usr/lib/omarchy-mac/touchid-kernel-ready reader && return 0 + echo "Fingerprint setup paused because the running Touch ID driver cannot confirm safe storage." >&2 + echo "If the driver is still starting, try again after it binds. Otherwise restart this Mac with a compatible kernel." >&2 + return 1 +} +if ! omarchy-hw-apple-silicon; then + can_enumerate + exit $? +fi status=$(cat /run/omarchy-mac/touchid 2>/dev/null) recorded_status=${status:-no status} @@ -12,53 +26,57 @@ if [[ -z $status ]]; then status=$(/usr/lib/omarchy-mac/touchid-eligibility 2>/dev/null) fi if [[ -e /etc/omarchy-mac/touchid-on ]]; then - # A Mac turned on before the record came with driver options gets them now, - # whatever its status: on a kernel that loads the driver read-only, the - # options are what lets it reach ready after a restart. - options=/etc/modprobe.d/omarchy-mac-touchid.conf - if [[ ! -e $options ]]; then - # Under the Touch ID lock, so a removal running now can't be undone here. - lock=/run/omarchy-mac/touchid.lock - if ! { mkdir -p -m 0755 "${lock%/*}" && exec {lock_fd}>>"$lock"; } 2>/dev/null; then - echo "Touch ID's driver options could not be written: its lock, $lock, could not be opened." >&2 - exit 1 - elif ! flock -w 300 "$lock_fd"; then - echo "Touch ID's driver options could not be written: another Touch ID setup or removal is still running." >&2 - exit 1 - fi - if [[ ! -e /etc/omarchy-mac/touchid-on ]]; then - echo "Touch ID was turned off while this ran, so setup goes on without it." - exit 0 - elif [[ ! -e $options ]]; then - # The 16-inch M4 Max's kernel profile leaves the xART guard off (aurora - # 7.3.0.aurora1-40), and Touch ID was tried there only with it on, so keep - # Linux to its own xART records. Other Macs keep the kernel's level: the guard - # blocks matching on M1-family Macs. - driver_options="xart_writes=1 provision_keybag=1" - if tr '\0' '\n' /dev/null | grep -Fxq apple,j616c; then - driver_options+=" xart_guard=1" - fi - { mkdir -p -m 0755 "${options%/*}" && - printf '%s\n' "# The owner turned on Touch ID; omarchy-mac's disable-fingerprint removes this." \ - "options apple_sep $driver_options" >"$options.new" && - chmod 0644 "$options.new" && mv -fT "$options.new" "$options"; } || - { rm -f "$options.new" 2>/dev/null; echo "Touch ID's driver options could not be written to $options" >&2; exit 1; } - fi - exec {lock_fd}>&- + # An earlier agreement may still have writable M1 autoload options. + lock=/run/omarchy-mac/touchid.lock + if ! { mkdir -p -m 0755 "${lock%/*}" && exec {lock_fd}>>"$lock"; } 2>/dev/null; then + echo "Touch ID's driver options could not be written: its lock, $lock, could not be opened." >&2 + exit 1 + elif ! flock -w 300 "$lock_fd"; then + echo "Touch ID's driver options could not be written: another Touch ID setup or removal is still running." >&2 + exit 1 + fi + if [[ ! -e /etc/omarchy-mac/touchid-on ]]; then + echo "Touch ID was turned off while this ran, so setup goes on without it." + can_enumerate + exit $? fi + /usr/lib/omarchy-mac/touchid-options --ensure || { + echo "Touch ID's driver options could not be written." >&2 + exit 1 + } + exec {lock_fd}>&- + can_enumerate || exit 1 # A Mac agreed before the re-arm existed gets its PAM lines here too. /usr/lib/omarchy-mac/touchid-pam || echo "Touch ID is on, but a password won't end a lockout until its PAM lines are fixed (see above)." >&2 # The owner agreed already, so they are never asked again: a Touch ID that # isn't ready yet needs a restart, and setup goes on with any other reader. - if [[ $status != "ready" ]]; then + eligibility=$(/usr/lib/omarchy-mac/touchid-eligibility 2>/dev/null) + if [[ $status != "ready" || $eligibility == unsupported:* ]]; then + case $eligibility in + unsupported:kernel) + echo "Touch ID is turned on, but this kernel can't set it up on this Mac." + echo "Boot a kernel with the guarded Touch ID driver for this Mac, then set" + echo "up the fingerprint again. Setup goes on with any other fingerprint reader." + exit 0 ;; + unsupported:restart) + echo "The running Touch ID driver cannot confirm guarded setup. Restart this Mac to load the checked driver." + exit 0 ;; + unsupported:recovery) + recovery_help + exit 0 ;; + esac echo "Touch ID is turned on but isn't ready yet ($recorded_status)." echo "Restart this Mac, then set up the fingerprint again. If it still isn't" echo "ready, see journalctl -u omarchy-mac-touchid-activate." fi exit 0 fi -# Only a Touch ID that can be set up stops the setup: anywhere else it goes on, -# so a USB reader enrols as it would without Touch ID. +can_enumerate || exit 1 +# A status recorded while a driver was binding or before an update can change. +case $status in + unsupported:restart|unsupported:kernel|unsupported:recovery) + status=$(/usr/lib/omarchy-mac/touchid-eligibility 2>/dev/null) ;; +esac case $status in available | ready) ;; none | "") @@ -69,7 +87,8 @@ case $status in echo "any other fingerprint reader." # A driver that came up wrong this boot stays so until a restart. case $status in - failed | not-ready | unproven | blocked) echo "Restart this Mac, then set up the fingerprint again to retry Touch ID." ;; + unsupported:recovery) recovery_help ;; + failed | not-ready | unproven | blocked | unsupported:restart) echo "Restart this Mac, then set up the fingerprint again to retry Touch ID." ;; esac exit 0 ;; diff --git a/omarchy-mac/install b/omarchy-mac/install index 03af96ba..c53830ee 100755 --- a/omarchy-mac/install +++ b/omarchy-mac/install @@ -5,7 +5,10 @@ cd -- "$(dirname -- "${BASH_SOURCE[0]}")" destination=${1:?Usage: ./install DESTDIR} [[ $destination == /* && $destination != "/" ]] || { echo "Use an absolute staging directory" >&2; exit 1; } for file in bin/*; do install -Dm755 "$file" "$destination/usr/bin/${file##*/}"; done -for file in lib/*; do install -Dm755 "$file" "$destination/usr/lib/omarchy-mac/${file##*/}"; done +for file in lib/*; do + if [[ -x $file ]]; then mode=755; else mode=644; fi + install -Dm"$mode" "$file" "$destination/usr/lib/omarchy-mac/${file##*/}" +done for file in entrypoints/*; do install -Dm755 "$file" "$destination/usr/lib/omarchy/mac/${file##*/}"; done while IFS= read -r -d '' file; do install -Dm644 "$file" "$destination/usr/lib/${file#vendor/}" diff --git a/omarchy-mac/lib/touchid-activate b/omarchy-mac/lib/touchid-activate index 08fac94c..7f23eba8 100755 --- a/omarchy-mac/lib/touchid-activate +++ b/omarchy-mac/lib/touchid-activate @@ -60,7 +60,12 @@ for ((attempt = 1; attempt <= attempts && SECONDS < 45; attempt++)); do finish unproven "the enrolled fingerprints could not be proven (restore unproven)" elif [[ $matching == "blocked" ]]; then finish blocked "a match could not save its state (matching blocked)" - elif [[ $sensor_attach == "attached" && ($previous == "ready" || ($touchid == "ready" && ($restore == "restored" || $restore == "empty") && ($matching == "usable" || $matching == "unverified"))) ]]; then + # The driver recognized this historical bag and its existing pins. It + # can enroll its first print or try a real verify without a new pin window. + elif [[ $matching == "legacy" && $touchid == "ready" && $sensor_attach == "attached" && + ($restore == "restored" || $restore == "empty") ]]; then + finish ready + elif [[ $matching != "legacy" && $sensor_attach == "attached" && ($previous == "ready" || ($touchid == "ready" && ($restore == "restored" || $restore == "empty") && ($matching == "usable" || $matching == "unverified"))) ]]; then finish ready elif [[ $sensor_attach == "not-ready" ]]; then finish not-ready "the sensor did not come online (sensor_attach not-ready)" diff --git a/omarchy-mac/lib/touchid-board.sh b/omarchy-mac/lib/touchid-board.sh new file mode 100644 index 00000000..3b06be26 --- /dev/null +++ b/omarchy-mac/lib/touchid-board.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# Board predicates shared by the Touch ID helpers. +tree=${OMARCHY_MAC_TOUCHID_TREE:-/proc/device-tree} + +compatible() { + [[ -r $tree/compatible ]] && tr '\0' '\n' <"$tree/compatible" | grep -Fxq "$1" +} + +touchid_sensor() { + local node + for node in "$tree"/soc/*/fingerprint@* "$tree"/*/fingerprint@*; do + if [[ -r $node/compatible ]] && tr '\0' '\n' <"$node/compatible" | grep -Fxq apple,mesa-fingerprint && + [[ ! -r $node/status || $(tr -d '\0' <"$node/status") == "okay" ]]; then + printf '%s\n' "$node" + return 0 + fi + done + return 1 +} + +guarded_m1() { + { compatible apple,t8103 && compatible apple,j313; } || + { compatible apple,t6001 && compatible apple,j316c; } +} + +m1_family() { + compatible apple,t8103 || compatible apple,t6000 || compatible apple,t6001 +} + +sealed_board() { + { compatible apple,t6040 && compatible apple,j616s; } || + { compatible apple,t6041 && compatible apple,j616c; } +} + +other_touchid_board() { + compatible apple,t8112 || compatible apple,t6020 || compatible apple,t6021 || compatible apple,t8140 || + { compatible apple,t8122 && { compatible apple,j613 || compatible apple,j615; }; } || sealed_board +} diff --git a/omarchy-mac/lib/touchid-eligibility b/omarchy-mac/lib/touchid-eligibility index f593b8b2..124e0739 100755 --- a/omarchy-mac/lib/touchid-eligibility +++ b/omarchy-mac/lib/touchid-eligibility @@ -5,14 +5,13 @@ tree=${OMARCHY_MAC_TOUCHID_TREE:-/proc/device-tree} firmware=${OMARCHY_MAC_TOUCHID_FIRMWARE:-/usr/lib/firmware} +helpers=${OMARCHY_MAC_TOUCHID_HELPERS:-/usr/lib/omarchy-mac} extractors=${OMARCHY_MAC_TOUCHID_EXTRACTORS:-/usr/lib/linux-aurora} python=${OMARCHY_MAC_TOUCHID_PYTHON:-python3} esp=${OMARCHY_MAC_TOUCHID_ESP:-/boot/efi} omarchy-hw-apple-silicon || exit 0 -compatible() { - [[ -r $tree/compatible ]] && tr '\0' '\n' <"$tree/compatible" | grep -Fxq "$1" -} +source "$helpers/touchid-board.sh" || exit 1 installed() { local directory @@ -29,16 +28,9 @@ can_extract() { [[ -x $extractors/$1 ]] && command -v "$python" >/dev/null } -sensor="" # The sensor sits on an SPI controller under /soc, or at the root on the M4 Pro # and M4 Max. -for node in "$tree"/soc/*/fingerprint@* "$tree"/*/fingerprint@*; do - if [[ -r $node/compatible ]] && tr '\0' '\n' <"$node/compatible" | grep -Fxq apple,mesa-fingerprint && - [[ ! -r $node/status || $(tr -d '\0' <"$node/status") == "okay" ]]; then - sensor=$node - break - fi -done +sensor=$(touchid_sensor) if [[ ${1:-} == "sensor" ]]; then printf '%s\n' "$sensor" exit 0 @@ -47,21 +39,23 @@ elif [[ -z $sensor ]]; then exit 0 fi -# The 16-inch M4 Pro and M4 Max: on each, Touch ID has enrolled, matched, and -# matched again after a restart. Their sensor loads a calibration and a root key that are both -# rebuilt from sealed factory records. -sealed_board() { - { compatible apple,t6040 && compatible apple,j616s; } || { compatible apple,t6041 && compatible apple,j616c; } -} - -# The boards the aurora driver has a profile for. M1-family Macs cold-boot -# their enclave behind an xART guard that blocks matching, so they wait. -if compatible apple,t8103 || compatible apple,t6000 || compatible apple,t6001; then +# These cold-boot Macs need a kernel that can pin setup records under the guard. +if guarded_m1; then + "$helpers/touchid-kernel-ready" 2>/dev/null + case $? in + 0) ;; + 2) echo unsupported:restart; exit 0 ;; + *) echo unsupported:kernel; exit 0 ;; + esac + if [[ ! -d ${OMARCHY_MAC_TOUCHID_MODULE:-/sys/module/apple_sep} ]] && + ! "$helpers/touchid-retry-aside" --check 2>/dev/null; then + echo unsupported:recovery + exit 0 + fi +elif m1_family; then echo unsupported:m1-family exit 0 -elif ! compatible apple,t8112 && ! compatible apple,t6020 && ! compatible apple,t6021 && ! compatible apple,t8140 && - ! { compatible apple,t8122 && { compatible apple,j613 || compatible apple,j615; }; } && - ! sealed_board; then +elif ! other_touchid_board; then echo unsupported:board exit 0 fi diff --git a/omarchy-mac/lib/touchid-enable b/omarchy-mac/lib/touchid-enable index b7aff53f..256c250e 100755 --- a/omarchy-mac/lib/touchid-enable +++ b/omarchy-mac/lib/touchid-enable @@ -33,7 +33,9 @@ rebuilt_calibration=0 root_key=apple/msrk-j700.bin fail() { if (( recorded )); then - rm -f "$agreed" "$options" + rm -f "$agreed" + "$helpers/touchid-options" --remove || echo "Touch ID could not clear its managed options in $options." >&2 + "$helpers/touchid-status" --withdraw || echo "Touch ID could not stop fingerprint access after removing its agreement." >&2 fi if (( rebuilt )); then rm -f "$firmware/updates/$root_key" @@ -157,35 +159,27 @@ fi { mkdir -p -m 0755 "${agreed%/*}" && printf '%s\n' "# The owner turned on Touch ID; omarchy-mac's disable-fingerprint removes this." >"$agreed" && chmod 0644 "$agreed"; } || fail "the owner's agreement could not be recorded in $agreed" -# The driver's options say so too. Today's kernels write by default, so this -# changes nothing yet; a kernel that loads apple_sep read-only by default -# (omacom/linux-aurora#180) writes only with it. A driver already running -# keeps the options it was loaded with until the next boot. preloaded=0 if [[ -d $module && ! -e $options && ! -e $loaded ]]; then preloaded=1 fi -# The 16-inch M4 Max's kernel profile leaves the xART guard off (aurora -# 7.3.0.aurora1-40), and Touch ID was tried there only with it on, so keep -# Linux to its own xART records. Other Macs keep the kernel's level: the guard -# blocks matching on M1-family Macs. -driver_options="xart_writes=1 provision_keybag=1" -if tr '\0' '\n' <"$tree/compatible" | grep -Fxq apple,j616c; then - driver_options+=" xart_guard=1" +"$helpers/touchid-options" --write || fail "the driver's options could not be written to $options" +load_result=0 +"$helpers/touchid-load" || load_result=$? +if (( load_result == 2 )); then + echo "The driver was already running. Restart this Mac to load Touch ID with the guarded options, then set up the fingerprint again." >&2 + exit 1 +elif (( load_result == 3 )); then + echo "Your Touch ID agreement was kept. Restart this Mac before trying again. If this repeats, check the kernel package for a missing build ID." >&2 + exit 1 +elif (( load_result )); then + fail "the Secure Enclave driver did not load; see the messages above" fi -# A write that fails partway never replaces the options, since a file without -# them would load a read-only driver at every boot. -{ mkdir -p -m 0755 "${options%/*}" && - printf '%s\n' "# The owner turned on Touch ID; omarchy-mac's disable-fingerprint removes this." \ - "options apple_sep $driver_options" >"$options.new" && - chmod 0644 "$options.new" && mv -fT "$options.new" "$options"; } || - { rm -f "$options.new" 2>/dev/null; fail "the driver's options could not be written to $options"; } -mkdir -p -m 0755 "${loaded%/*}" -touch "$loaded" -modprobe apple-sep || fail "the Secure Enclave driver did not load" +touch "$loaded" || fail "the driver load could not be recorded" # The node and keybag appear a few seconds after the driver binds. Their add -# event starts the activation; starting it here too waits for its answer. +# event can start activation before the build ID is saved. Start it again +# now that the running driver can be checked, and wait for its answer. echo "Starting Touch ID..." for ((attempt = 0; attempt < 200; attempt++)); do if [[ -e $node_path && -e $keybag ]]; then @@ -194,7 +188,8 @@ for ((attempt = 0; attempt < 200; attempt++)); do sleep 0.1 done systemctl start omarchy-mac-touchid-activate.service 2>/dev/null -if [[ $(cat "$status_file" 2>/dev/null) == "ready" ]]; then +if "$helpers/touchid-kernel-ready" activate && [[ $(cat "$status_file" 2>/dev/null) == "ready" ]] && + "$helpers/touchid-kernel-ready" reader; then # An fprintd that started without the reader found none and kept no # allowance for its node, so it starts again with both. systemctl try-restart fprintd.service 2>/dev/null diff --git a/omarchy-mac/lib/touchid-kernel-ready b/omarchy-mac/lib/touchid-kernel-ready new file mode 100755 index 00000000..72e268ed --- /dev/null +++ b/omarchy-mac/lib/touchid-kernel-ready @@ -0,0 +1,92 @@ +#!/bin/bash +# Exit 1 for an incompatible module image, 2 for a driver that needs a restart. +helpers=${OMARCHY_MAC_TOUCHID_HELPERS:-/usr/lib/omarchy-mac} +modinfo=${OMARCHY_MAC_TOUCHID_MODINFO:-modinfo} +module=${OMARCHY_MAC_TOUCHID_MODULE:-/sys/module/apple_sep} +driver=${OMARCHY_MAC_TOUCHID_DRIVER:-/sys/bus/platform/drivers/apple_sep} +status=${OMARCHY_MAC_TOUCHID_STATUS:-/run/omarchy-mac/touchid} +mode=${1:-} +node=${OMARCHY_MAC_TOUCHID_NODE:-/dev/sep-bio} +agreed=${OMARCHY_MAC_TOUCHID_AGREED:-/etc/omarchy-mac/touchid-on} +if [[ $mode == "reader" && ! -d $module && ! -e $node ]]; then + exit 0 +fi +omarchy-hw-apple-silicon || exit 1 +source "$helpers/touchid-board.sh" || exit 1 +if [[ $mode == "reader" && ! -e $node && -r $tree/compatible ]]; then + # An SEP autoload for another function need not publish a fingerprint + # device. On M1 laptops with a sensor, wait for the pending driver to bind. + if ! m1_family || ! touchid_sensor >/dev/null; then exit 0; fi +fi +checked_board=1 +if ! guarded_m1; then + if other_touchid_board; then + exit 0 + elif [[ $mode == "reader" && -s $tree/compatible ]]; then + checked_board=0 + else + exit 1 + fi +fi + +# Test the file we will insert, even if pacman replaces the installed module. +disk_ready() { + local image=$1 parameters parameter + [[ $("$modinfo" -F xart_guard_pins_abi "$image") == "1" ]] || return 1 + if compatible apple,j316c; then + [[ $("$modinfo" -F t6000_registration "$image") == "1" ]] || return 1 + fi + parameters=$("$modinfo" -p "$image") || return 1 + for parameter in xart_guard xart_guard_pins xart_writes provision_keybag; do + grep -q "^$parameter:" <<<"$parameters" || return 1 + done +} + +case ${1:-} in + image) disk_ready "${2:?missing module image}"; exit $? ;; + activate|reader) ;; + "") disk_ready apple_sep || exit 1 ;; + *) exit 1 ;; +esac + +# No diagnostics yet is normal during binding. Setup can record consent for the +# next boot, but activation always requires proof from this running driver. +if [[ -d $module ]]; then + shopt -s nullglob + diagnostics=("$driver"/*/diag) + if (( ${#diagnostics[@]} == 1 )); then + diag=${diagnostics[0]} + if [[ $mode == "reader" && -r $diag/xart && $(<"$diag/xart") == "disabled" ]]; then + # Newer drivers can reopen a read-only store for writing during attach. + # If the running driver advertises its policy, require both controls off. + if [[ -e $diag/policy ]]; then + policy=$(cat "$diag/policy") || exit 2 + [[ " $policy " == *" xart_writes=0 "* && " $policy " == *" provision_keybag=0 "* ]] || exit 2 + fi + exit 0 + elif [[ -r $diag/xart && $(<"$diag/xart") == "enabled" ]]; then + (( checked_board )) || exit 2 + [[ $mode != "reader" || -e $agreed ]] || exit 2 + [[ -r $diag/xart_guard && $(<"$diag/xart_guard") == 1 && + -r $diag/xart_guard_pins && $(<"$diag/xart_guard_pins") == 1 && + -s ${status%/*}/touchid-guarded-build-id ]] && + cmp -s "${status%/*}/touchid-guarded-build-id" "$module/notes/.note.gnu.build-id" || exit 2 + if [[ $mode == "reader" ]]; then + # Opening the node is reserved to the activation unit until the + # current driver reports a working sensor and a safe, usable bag. + for attribute in touchid sensor_attach restore matching; do + [[ -r $diag/$attribute ]] || exit 2 + done + [[ $(<"$diag/touchid") == "ready" && $(<"$diag/sensor_attach") == "attached" ]] || exit 2 + case $(<"$diag/restore") in empty|restored) ;; *) exit 2 ;; esac + case $(<"$diag/matching") in usable|unverified|legacy) ;; *) exit 2 ;; esac + fi + exit 0 + elif [[ -r $diag/xart && $(<"$diag/xart") != "disabled" ]]; then + exit 2 + fi + elif (( ${#diagnostics[@]} > 1 )); then + exit 2 + fi +fi +[[ $mode != "activate" && $mode != "reader" ]] || exit 2 diff --git a/omarchy-mac/lib/touchid-load b/omarchy-mac/lib/touchid-load new file mode 100755 index 00000000..e46271d9 --- /dev/null +++ b/omarchy-mac/lib/touchid-load @@ -0,0 +1,116 @@ +#!/bin/bash +# Called under the setup/removal lock, from setup or the boot service. +helpers=${OMARCHY_MAC_TOUCHID_HELPERS:-/usr/lib/omarchy-mac} +agreed=${OMARCHY_MAC_TOUCHID_AGREED:-/etc/omarchy-mac/touchid-on} +status=${OMARCHY_MAC_TOUCHID_STATUS:-/run/omarchy-mac/touchid} +module=${OMARCHY_MAC_TOUCHID_MODULE:-/sys/module/apple_sep} +modinfo=${OMARCHY_MAC_TOUCHID_MODINFO:-modinfo} +omarchy-hw-apple-silicon || exit 1 +source "$helpers/touchid-board.sh" || exit 1 +[[ -e $agreed ]] || exit 1 +if ! guarded_m1; then + other_touchid_board || exit 1 + exec modprobe apple-sep +fi +"$helpers/touchid-options" --write || exit 1 +if [[ -d $module ]]; then + "$helpers/touchid-kernel-ready" activate || exit 2 + exit 0 +fi + +# A package update can replace the module between modinfo and insertion. +# Keep its compression suffix; libkmod can insert compressed modules directly. +path=$("$modinfo" -n apple_sep) || exit 1 +[[ $path == /* && -f $path ]] || exit 1 +directory=$(mktemp -d "${status%/*}/touchid-module-XXXXXXXX") || exit 1 +trap 'rm -rf -- "$directory"' EXIT +image=$directory/${path##*/} +cp --reflink=auto -- "$path" "$image" || exit 1 +writable=1 +if ! "$helpers/touchid-kernel-ready" image "$image"; then + # The M1 microphones also use SEP. On a kernel that normally autoloads + # apple,sep (#180), keep that boot-time read-only function after a downgrade. + [[ ${1:-} == "--boot" ]] || exit 1 + "$modinfo" -F alias "$image" | grep -Fxq 'of:N*T*Capple,sep' || exit 1 + parameters=$("$modinfo" -p "$image") && + grep -q '^xart_writes:' <<<"$parameters" && grep -q '^provision_keybag:' <<<"$parameters" || exit 1 + writable=0 +fi + +# insmod inserts exactly this image once, without merging options a second +# time. Preserve other numeric apple_sep options such as the identity UUID, +# and honor conflicting admin settings by declining the writable load. +configuration=$(modprobe --showconfig) || exit 1 +if (( writable )); then + settings=(xart_writes=1 provision_keybag=1 xart_guard=1 xart_guard_pins=1) +else + settings=(xart_writes=0 provision_keybag=0) +fi +declare -A additional=() +passive=0 +while read -r directive name arguments; do + case $directive in + install|softdep) + # kmod applies these directives by pattern, including to named loads. + if [[ apple_sep == $name ]]; then + echo "Touch ID cannot bypass the configured $directive for $name." >&2 + exit 1 + fi + continue ;; + options) [[ $name == "apple_sep" ]] || continue ;; + *) continue ;; + esac + if [[ $arguments == "xart_writes=0 provision_keybag=0" ]] && (( ! passive )); then + passive=1 + continue + fi + read -r -a fields <<<"$arguments" + for field in "${fields[@]}"; do + key=${field%%=*} + key=${key//-/_} + value=${field#*=} + if [[ $value == \"*\" ]]; then value=${value:1:-1}; fi + [[ $field == *=* && $key =~ ^[a-zA-Z0-9_]+$ && + $value =~ ^[+-]?([0-9]+|0[xX][[:xdigit:]]+|0[bB][01]+|0[oO][0-7]+)$ ]] || exit 1 + case $key in + xart_writes|provision_keybag|xart_guard|xart_guard_pins) + if (( ! writable )) || [[ $value == 1 ]]; then + continue + fi + echo "Touch ID cannot override apple_sep $field." >&2 + exit 1 ;; + esac + if [[ -v additional[$key] && ${additional[$key]} != "$key=$value" ]]; then + echo "Touch ID cannot choose between conflicting apple_sep $key values." >&2 + exit 1 + fi + additional[$key]="$key=$value" + done +done <<<"$configuration" +(( passive )) || exit 1 +settings+=("${additional[@]}") + +depends=$("$modinfo" -F depends "$image") || exit 1 +if [[ -n $depends ]]; then + [[ $depends =~ ^[[:alnum:]_-]+(,[[:alnum:]_-]+)*$ ]] || exit 1 + IFS=, read -r -a dependencies <<<"$depends" + modprobe -a -- "${dependencies[@]}" || exit 1 +fi +if (( ! writable )); then + insmod "$image" "${settings[@]}" + exit $? +fi +"$helpers/touchid-retry-aside" --recover || { + echo "Touch ID kept the existing keybag and guard list. Their state does not prove a safe retry." >&2 + exit 1 +} +rm -f "${status%/*}/touchid-guarded-build-id" || exit 1 +insmod "$image" "${settings[@]}" || exit 1 +# The kernel rejects an already-loaded module. Tie activation to the build we +# just inserted, even if a later package update changes the module on disk. +note=$module/notes/.note.gnu.build-id +if [[ ! -s $note ]] || ! cp "$note" "$directory/build-id" || + ! mv -T "$directory/build-id" "${status%/*}/touchid-guarded-build-id"; then + echo "The writable Secure Enclave driver loaded, but its build ID could not be recorded. Fingerprint activation is blocked." >&2 + exit 3 +fi diff --git a/omarchy-mac/lib/touchid-options b/omarchy-mac/lib/touchid-options new file mode 100755 index 00000000..1e8da767 --- /dev/null +++ b/omarchy-mac/lib/touchid-options @@ -0,0 +1,116 @@ +#!/bin/bash +# Guarded M1 writes are authorized for one checked insertion only. An automatic +# load on an older kernel must never inherit permission to write or provision. +helpers=${OMARCHY_MAC_TOUCHID_HELPERS:-/usr/lib/omarchy-mac} +options=${OMARCHY_MAC_TOUCHID_OPTIONS:-/etc/modprobe.d/omarchy-mac-touchid.conf} +agreed=${OMARCHY_MAC_TOUCHID_AGREED:-/etc/omarchy-mac/touchid-on} +action=${1:-} +managed_comment="# The owner turned on Touch ID; omarchy-mac's disable-fingerprint removes this." +saved_comment="# Read-only defaults for retained Apple SEP driver settings." +passive='options apple_sep xart_writes=0 provision_keybag=0' +guarded=0 + +if [[ $action == "--migrate" ]]; then + [[ -f $options ]] || exit 0 + status=${OMARCHY_MAC_TOUCHID_STATUS:-/run/omarchy-mac/touchid} + lock=${status%/*}/touchid.lock + mkdir -p -m 0755 "${lock%/*}" && exec {lock_fd}>>"$lock" && flock -w 300 "$lock_fd" || exit 1 + [[ -f $options ]] || exit 0 + # Earlier M1 options identify the board even in an offline target. + if grep -Eq '^options apple_sep .*xart_guard_pins=1([[:space:]]|$)' "$options" || + { omarchy-hw-apple-silicon && source "$helpers/touchid-board.sh" && guarded_m1; }; then + guarded=1 + if [[ -e $agreed ]]; then action=--write; else action=--remove; fi + else + exit 0 + fi +else + omarchy-hw-apple-silicon || exit 1 + source "$helpers/touchid-board.sh" || exit 1 + if guarded_m1; then + guarded=1 + elif [[ $action != "--remove" ]] && ! other_touchid_board; then + exit 1 + fi +fi + +if (( guarded )); then + settings=$(printf '%s\n' 'blacklist apple_sep' "$passive") +elif compatible apple,j616c; then + settings='options apple_sep xart_writes=1 provision_keybag=1 xart_guard=1' +else + settings='options apple_sep xart_writes=1 provision_keybag=1' +fi +case $action in + "") printf '%s\n' "$settings"; exit 0 ;; + --ensure) (( guarded )) || [[ ! -e $options ]] || exit 0 ;; + --remove) [[ -e $options || -L $options ]] || exit 0 ;; + --write) ;; + *) exit 1 ;; +esac + +custom_settings() { + [[ -e $options || -L $options ]] || return 0 + [[ -f $options ]] || return 1 + # Remove our old options, preserving custom UUIDs, stricter settings and + # unrelated directives. An ambiguous write setting becomes an explicit deny. + awk -v header="$managed_comment" -v saved="$saved_comment" -v passive="$passive" ' + { + while (sub(/\\$/, "")) { + if ((getline suffix) != 1) exit 1 + $0 = $0 suffix + } + } + $0 == header { managed = 1; next } + $0 == saved { managed = 3; next } + $0 == "blacklist apple_sep" && managed == 1 { managed = 2; next } + $0 == passive && managed == 2 { managed = 0; next } + managed == 3 && /^options apple_sep (xart_writes=0( provision_keybag=0)?|provision_keybag=0)$/ { managed = 0; next } + { managed = 0 } + $1 == "options" && ($2 == "apple_sep" || $2 == "apple-sep") { + opts = "" + for (i = 3; i <= NF; i++) { + field = $i + split(field, parts, "=") + key = parts[1] + gsub(/-/, "_", key) + if (key == "xart_writes" || key == "provision_keybag") { + if (field == parts[1] "=1") continue + if (denied[key]++) continue + field = key "=0" + } else if ((key == "xart_guard" || key == "xart_guard_pins") && field == parts[1] "=1") continue + opts = opts " " field + } + if (opts) print "options apple_sep" opts + next + } + { print } + ' "$options" +} +custom=$(custom_settings) || exit 1 +if [[ $action == "--remove" ]]; then + if [[ -z ${custom//[[:space:]]/} ]]; then + rm -f "$options" + exit $? + elif (( guarded )); then + defaults=() + for option in xart_writes=0 provision_keybag=0; do + grep -Eq "^options apple_sep (.*[[:space:]])?$option([[:space:]]|$)" <<<"$custom" || defaults+=("$option") + done + content=$custom + if (( ${#defaults[@]} )); then + content=$(printf '%s\n' "$saved_comment" "options apple_sep ${defaults[*]}" "$custom") + fi + else + content=$custom + fi +else + content=$(printf '%s\n' "$managed_comment" "$settings") + [[ -z $custom ]] || content+=$'\n'"$custom" +fi + +cmp -s "$options" <(printf '%s\n' "$content") && exit 0 +mkdir -p -m 0755 "${options%/*}" || exit 1 +temporary=$(mktemp "${options%/*}/.omarchy-mac-touchid.XXXXXX") || exit 1 +trap 'rm -f "$temporary"' EXIT +printf '%s\n' "$content" >"$temporary" && chmod 0644 "$temporary" && mv -fT "$temporary" "$options" diff --git a/omarchy-mac/lib/touchid-retry-aside b/omarchy-mac/lib/touchid-retry-aside new file mode 100755 index 00000000..34a1c01f --- /dev/null +++ b/omarchy-mac/lib/touchid-retry-aside @@ -0,0 +1,48 @@ +#!/bin/bash +# Check recovery before a guarded load. Only the loader may move a failed +# attempt's unused guard list, under the Touch ID lock and before driver probe. +helpers=${OMARCHY_MAC_TOUCHID_HELPERS:-/usr/lib/omarchy-mac} +keybag=${OMARCHY_MAC_TOUCHID_KEYBAG:-/var/lib/aurora-sep-keybag.bin} +guard_list=${OMARCHY_MAC_TOUCHID_GUARD_LIST:-/var/lib/aurora-sep-xart-owned.bin} +module=${OMARCHY_MAC_TOUCHID_MODULE:-/sys/module/apple_sep} +omarchy-hw-apple-silicon || exit 1 +source "$helpers/touchid-board.sh" || exit 1 +guarded_m1 || exit 0 +[[ ${1:-} == "--check" || ${1:-} == "--recover" ]] || exit 1 +[[ ! -d $module ]] || exit 1 + +# A keybag intent (v2 state 0) may already name an enclave-side creation. +# The driver retries only absence or an explicit refusal, never unknown data. +for file in "$keybag" "$guard_list"; do + [[ ! -L $file && (! -e $file || (-f $file && -r $file)) ]] || exit 1 +done +if [[ ! -e $keybag ]]; then + [[ ! -s $guard_list ]] + exit $? +fi +read -r version state < <(od -An -tu4 --endian=little -j16 -N8 "$keybag") || exit 1 +[[ $(head -c16 "$keybag") == "APPLE-SEP-KBAG01" && $version == 2 ]] || exit 1 +case $state in + 1|3) exit 0 ;; # Keep committed keybags and their complete lists. + 2) ;; + *) exit 1 ;; +esac +# The exact v2 REFUSED header (empty body, UUID and secret, CRC16 0x0ae8). +[[ $(stat -c %s "$keybag") == 52 && $(sha256sum <"$keybag") == '534d2a855bfd7902d45036510647f6ed006eef5fc5ac04304468e8144173a54e -' ]] || exit 1 +[[ -s $guard_list ]] || exit 0 +# Only one AXGO spent-window marker, in either on-disk format. Any pin, +# owned record, completion marker or unrecognized entry preserves the list. +[[ $(stat -c %s "$guard_list") == 32 ]] || exit 1 +digest=$(sha256sum <"$guard_list") || exit 1 +case ${digest%% *} in + f106a4e397a632b9645a063cbc7a5817881c095ae16dfed42b5151cc81d26b8b) ;; # first setup used + 16e3f5d3b0e54ed0a62c27add201db50db58bceec1be1350e006c5cc0ecd2259) ;; # cold setup spent + *) exit 1 ;; +esac +[[ $1 == "--recover" ]] || exit 0 +aside=$(mktemp -d "${guard_list%/*}/aurora-sep-touchid-retry-XXXXXXXX") || exit 1 +# Keep the refusal in place. The only state transition is this one rename on +# the same filesystem, so an interrupted retry cannot split a bag/list pair. +mv -T "$guard_list" "$aside/${guard_list##*/}" || exit 1 +sync -f "$aside" || exit 1 +echo "The refused Touch ID attempt's unused guard list is kept in $aside." diff --git a/omarchy-mac/lib/touchid-status b/omarchy-mac/lib/touchid-status index a6192e43..e66930bd 100755 --- a/omarchy-mac/lib/touchid-status +++ b/omarchy-mac/lib/touchid-status @@ -7,6 +7,24 @@ status_file=${OMARCHY_MAC_TOUCHID_STATUS:-/run/omarchy-mac/touchid} agreed=${OMARCHY_MAC_TOUCHID_AGREED:-/etc/omarchy-mac/touchid-on} helpers=${OMARCHY_MAC_TOUCHID_HELPERS:-/usr/lib/omarchy-mac} omarchy-hw-apple-silicon || exit 0 +# An already-running fprintd may have acquired the node allowance before +# this update. Its next D-Bus start must pass the current reader condition. +if ! "$helpers/touchid-kernel-ready" reader; then + state=$(systemctl show -p ActiveState --value fprintd.service) || { + echo "Touch ID could not check whether fprintd still has access." >&2 + exit 1 + } + # A missing optional fprintd unit also reports inactive. For an explicit + # withdrawal wait even for a stop that is already in progress. + if [[ $state != "inactive" && $state != "failed" ]]; then + if [[ ${1:-} == "--withdraw" ]]; then + systemctl stop fprintd.service || exit 1 + else + systemctl --no-block stop fprintd.service || exit 1 + fi + fi +fi +[[ ${1:-} != "--withdraw" ]] || exit 0 # Turned on: omarchy-mac-touchid-load.service loads the driver, and the # activation records the status. diff --git a/omarchy-mac/share/libalpm/hooks/89-omarchy-mac-touchid-options.hook b/omarchy-mac/share/libalpm/hooks/89-omarchy-mac-touchid-options.hook new file mode 100644 index 00000000..5fdb1d10 --- /dev/null +++ b/omarchy-mac/share/libalpm/hooks/89-omarchy-mac-touchid-options.hook @@ -0,0 +1,10 @@ +[Trigger] +Type = Path +Operation = Install +Operation = Upgrade +Target = usr/lib/omarchy-mac/touchid-options + +[Action] +Description = Migrating guarded Touch ID module options... +When = PostTransaction +Exec = /usr/lib/omarchy-mac/touchid-options --migrate diff --git a/omarchy-mac/test/platform-test.sh b/omarchy-mac/test/platform-test.sh index 4f60dc59..9c04dfed 100644 --- a/omarchy-mac/test/platform-test.sh +++ b/omarchy-mac/test/platform-test.sh @@ -24,6 +24,7 @@ done chmod +x "$work/bin/"* export CALLS="$work/calls" for entry in "$ROOT"/bin/* "$ROOT"/lib/*; do + [[ -x $entry ]] || continue # Sourced libraries have no entrypoint. name=${entry##*/} sed "s|/usr/lib/omarchy-mac/|$ROOT/lib/|g" "$entry" >"$work/entry/$name" chmod +x "$work/entry/$name" diff --git a/omarchy-mac/test/touchid-activate-test.sh b/omarchy-mac/test/touchid-activate-test.sh index 97bea4a0..a5594302 100644 --- a/omarchy-mac/test/touchid-activate-test.sh +++ b/omarchy-mac/test/touchid-activate-test.sh @@ -11,7 +11,7 @@ rule=$work/root/usr/lib/udev/rules.d/94-omarchy-mac-touchid.rules unit=$work/root/usr/lib/systemd/system/omarchy-mac-touchid-activate.service script=$work/root/usr/lib/omarchy-mac/touchid-activate [[ -f $rule && -f $unit && -x $script ]] || fail 'the Touch ID rule, unit and script are staged' -grep -Fxq 'ACTION=="add", SUBSYSTEM=="misc", KERNEL=="sep-bio", TAG+="systemd", ENV{SYSTEMD_WANTS}+="omarchy-mac-touchid-activate.service"' "$rule" || +grep -Fxq 'ACTION=="add", SUBSYSTEM=="misc", KERNEL=="sep-bio", TAG+="systemd", ENV{SYSTEMD_WANTS}+="omarchy-mac-touchid-status.service omarchy-mac-touchid-activate.service"' "$rule" || fail 'the rule starts the unit when the Secure Enclave publishes sep-bio, and only then' [[ $(grep -v '^#' "$rule") != *RUN* ]] || fail 'the rule runs nothing itself' grep -Fxq 'ExecStart=/usr/lib/omarchy-mac/touchid-activate' "$unit" && grep -Fxq 'Type=oneshot' "$unit" && @@ -22,6 +22,9 @@ grep -Fxq 'ConditionPathExists=/var/lib/aurora-sep-keybag.bin' "$unit" || grep -Fxq 'ConditionPathExists=/etc/omarchy-mac/touchid-on' "$unit" || fail "the unit opens /dev/sep-bio only once the owner has agreed, whatever loaded the driver" grep -Fxq 'Before=fprintd.service' "$unit" || fail 'fprintd starts after the unit, not alongside it' +grep -Fxq 'ExecCondition=/usr/lib/omarchy-mac/touchid-kernel-ready activate' "$unit" && + grep -Fxq 'After=omarchy-mac-touchid-load.service' "$unit" || + fail 'udev and pacman activation require the running guarded driver after boot loading' ! grep -q '^StandardInput=' "$unit" || fail 'the platform check does not open /dev/sep-bio as well' ! grep -q '^\[Install\]' "$unit" || fail 'the unit needs no enabling: the rule pulls it in' pass 'the Touch ID rule, unit and script are staged, and the rule alone starts the unit' @@ -85,6 +88,17 @@ activate || fail 'Touch ID that is ready, attached, restored and usable succeeds [[ $(stat -c %a "$status") == 644 && $(stat -c %a "${status%/*}") == 755 ]] || fail 'the session user can read the status, whatever the umask' "$(stat -c %a "${status%/*}" "$status")" [[ ! -e $status.new ]] || fail 'the status is replaced in one step' +attributes ready attached restored legacy +activate && [[ $(<"$status") == ready ]] || fail 'a restored historical bag can try a real match' +attributes ready attached empty legacy +activate && [[ $(<"$status") == ready ]] || fail 'a validated empty historical bag can enroll its first fingerprint' +attributes ready attached empty blocked +! run_script && [[ $(<"$status") == blocked ]] || fail 'a refused write blocks even a previously ready empty bag' +attributes ready attached empty legacy +activate +attributes not-ready attached restored legacy +! OMARCHY_MAC_TOUCHID_ATTEMPTS=1 run_script && [[ $(<"$status") == not-ready ]] || + fail 'an earlier ready cannot stand in for the historical reader being ready this boot' attributes ready attached empty unverified activate && [[ $(<"$status") == "ready" ]] || fail 'nothing enrolled yet, behind a guard that has refused nothing, is ready' rm "$fixture/sep-bio" @@ -178,7 +192,8 @@ fi dropin=$work/root/usr/lib/systemd/system/fprintd.service.d/50-omarchy-mac-touchid.conf wait_unit=$work/root/usr/lib/systemd/system/omarchy-mac-touchid-wait.service [[ -f $dropin && -f $wait_unit ]] || fail 'the fprintd drop-in and the wait unit are staged' -grep -Fxq 'Wants=omarchy-mac-touchid-wait.service' "$dropin" && +grep -Fxq 'ExecCondition=/usr/lib/omarchy-mac/touchid-kernel-ready reader' "$dropin" && + grep -Fxq 'Wants=omarchy-mac-touchid-wait.service' "$dropin" && grep -Fxq 'After=omarchy-mac-touchid-load.service omarchy-mac-touchid-wait.service omarchy-mac-touchid-activate.service' "$dropin" || fail 'fprintd starts after the wait and the activation' ! grep -qE '^(DeviceAllow|DevicePolicy|ExecStartPre)=' "$dropin" || diff --git a/omarchy-mac/test/touchid-consent-test.sh b/omarchy-mac/test/touchid-consent-test.sh index 7ffc416b..a43229c0 100644 --- a/omarchy-mac/test/touchid-consent-test.sh +++ b/omarchy-mac/test/touchid-consent-test.sh @@ -18,7 +18,7 @@ grep -Fxq 'ExecStart=/usr/lib/omarchy-mac/touchid-status' "$units/omarchy-mac-to grep -Fxq 'Before=display-manager.service fprintd.service' "$units/omarchy-mac-touchid-status.service" || fail 'the status is recorded before the greeter or fprintd look for a reader' load=$units/omarchy-mac-touchid-load.service -grep -Fxq 'ConditionPathExists=/etc/omarchy-mac/touchid-on' "$load" && grep -Fxq 'ExecStart=/usr/bin/modprobe apple-sep' "$load" && +grep -Fxq 'ConditionPathExists=/etc/omarchy-mac/touchid-on' "$load" && grep -Fxq 'ExecStart=/usr/bin/flock -w 20 /run/omarchy-mac/touchid.lock /usr/lib/omarchy-mac/touchid-load --boot' "$load" && grep -Fxq 'ExecStartPre=/usr/bin/udevadm wait --timeout=20 /dev/disk/by-partlabel/iBootSystemContainer' "$load" || fail "the driver loads at boot only on the owner's record, after the iBoot System Container's link it opens" ! grep -Eq '^(Wants|Requires|BindsTo|After)=.*\.device' "$load" || @@ -36,13 +36,83 @@ mkdir -p "$fixture/bin" "$fixture/extractors" printf '#!/bin/sh\nexit 0\n' >"$fixture/bin/omarchy-hw-apple-silicon" # The stub keeps the driver options it was loaded with, as modprobe reads them. # With no-node or no-keybag, the driver loads but that never appears. -printf '#!/bin/sh\necho modprobe "$@" >>"%s"\ncp "%s" "%s" 2>/dev/null\n[ -e "%s" ] && exit 1\nmkdir -p "%s"\n[ -e "%s" ] || touch "%s"\n[ -e "%s" ] || touch "%s"\n' \ - "$fixture/calls" "$fixture/etc/modprobe.conf" "$fixture/options-at-load" "$fixture/modprobe-fails" \ - "$fixture/module" "$fixture/no-node" "$fixture/sep-bio" "$fixture/no-keybag" "$fixture/keybag" >"$fixture/bin/modprobe" -printf '#!/bin/sh\necho systemctl "$@" >>"%s"\n[ "$1" = start ] && printf "%%s\\n" "$(cat "%s")" >"%s"\nexit 0\n' \ - "$fixture/calls" "$fixture/activation" "$fixture/run/touchid" >"$fixture/bin/systemctl" +cat >"$fixture/bin/modprobe" <<'SH' +#!/bin/bash +fixture=${OMARCHY_MAC_TOUCHID_TREE%/*} +case $1 in + --showconfig) cat "$OMARCHY_MAC_TOUCHID_OPTIONS" "$fixture/admin-options"; exit $? ;; + -a) + echo "modprobe $*" >>"$fixture/calls" + [[ ! -f $fixture/replace-image ]] || echo old >"$fixture/apple-sep.ko.zst" + exit 0 ;; +esac +echo "modprobe $*" >>"$fixture/calls" +cp "$OMARCHY_MAC_TOUCHID_OPTIONS" "$fixture/options-at-load" +[[ ! -e $fixture/modprobe-fails ]] || exit 1 +mkdir -p "$fixture/module" +[[ -e $fixture/no-node ]] || touch "$fixture/sep-bio" +[[ -e $fixture/no-keybag ]] || touch "$fixture/keybag" +SH +cat >"$fixture/bin/systemctl" <<'SH' +#!/bin/bash +fixture=${OMARCHY_MAC_TOUCHID_TREE%/*} +echo "systemctl $*" >>"$fixture/calls" +if [[ $1 == show ]]; then + [[ ! -e $fixture/fprintd-query-fails ]] || exit 1 + cat "$fixture/fprintd-state" 2>/dev/null || echo inactive +fi +if [[ $1 == start ]]; then + if [[ -f $fixture/real-activation ]]; then + "$OMARCHY_MAC_TOUCHID_HELPERS/touchid-kernel-ready" activate && + "$OMARCHY_MAC_TOUCHID_HELPERS/touchid-activate" + else + cat "$fixture/activation" >"$fixture/run/touchid" + fi +fi +SH printf '#!/bin/sh\n[ -e "%s" ] || echo /usr/lib/omarchy/mac/enable-fingerprint\n' "$fixture/no-hook" >"$fixture/bin/omarchy-lifecycle-dispatch" printf '#!/bin/sh\nexit 0\n' >"$fixture/bin/sleep" +cat >"$fixture/bin/mv" <<'SH' +#!/bin/bash +fixture=${OMARCHY_MAC_TOUCHID_TREE%/*} +case $* in + *".omarchy-mac-touchid."*) [[ ! -e $fixture/options-mv-fails ]] || exit 1 ;; +esac +exec /usr/bin/mv "$@" +SH +# The module in the fixture carries its own metadata. A replacement between +# the capability check and insertion changes only the installed copy. +cat >"$fixture/bin/modinfo" <<'SH' +#!/bin/bash +fixture=${OMARCHY_MAC_TOUCHID_TREE%/*} +image=${!#} +[[ $image != apple_sep ]] || image="$fixture/apple-sep.ko.zst" +case $1 in + -n) printf '%s\n' "$image" ;; + -p) sed -n 's/^param=//p' "$image" ;; + -F) sed -n "s/^$2=//p" "$image" ;; + *) exit 1 ;; +esac +SH +cat >"$fixture/bin/insmod" <<'SH' +#!/bin/bash +fixture=${OMARCHY_MAC_TOUCHID_TREE%/*} +image=$1 +shift +echo "insmod $*" >>"$fixture/calls" +[[ ! -d $fixture/module && ! -e $fixture/raced-load ]] || exit 1 +cmp -s "$image" "$fixture/expected-image" || exit 1 +mkdir -p "$fixture/module/notes" "$fixture/driver/test.sep/diag" +[[ -e $fixture/no-build-id ]] || echo guarded-build >"$fixture/module/notes/.note.gnu.build-id" +echo enabled >"$fixture/driver/test.sep/diag/xart" +echo 1 >"$fixture/driver/test.sep/diag/xart_guard" +echo 1 >"$fixture/driver/test.sep/diag/xart_guard_pins" +for attribute in touchid:ready sensor_attach:attached restore:empty matching:unverified; do + echo "${attribute#*:}" >"$fixture/driver/test.sep/diag/${attribute%:*}" +done +touch "$fixture/sep-bio" +[[ -e $fixture/keybag ]] || touch "$fixture/keybag" +SH printf '#!/bin/sh\necho calibration >>"%s"\nprintf calibration >"$2"\n' "$fixture/calls" >"$fixture/extractors/extract-mesa-calibration" chmod +x "$fixture/bin/"* "$fixture/extractors/"* @@ -167,7 +237,12 @@ key_copies() { # A device tree: the machine's compatible list, a sensor node, and the identity. machine() { rm -rf "$tree" "$fixture/firmware" "$fixture/run" "$fixture/etc" "$fixture/sep-bio" "$fixture/keybag" "$fixture/calls" "$fixture/no-hook" "$fixture/no-node" "$fixture/no-keybag" "$fixture/options-at-load" "$fixture/module" \ - "$fixture/esp" + "$fixture/esp" "$fixture/modinfo-params" "$fixture/guard-list" "$fixture/list-at-load" "$fixture/mv-fails" "$fixture"/aurora-sep-touchid-retry-* + rm -rf "$fixture/driver" "$fixture/raced-load" "$fixture/no-build-id" "$fixture/replace-image" "$fixture/options-mv-fails" "$fixture/eligibility" "$fixture/real-activation" + : >"$fixture/admin-options" + printf '%s\n' xart_guard_pins_abi=1 t6000_registration=1 depends=macsmc,ecdh_generic \ + param=xart_guard: param=xart_guard_pins: param=xart_writes: param=provision_keybag: >"$fixture/apple-sep.ko.zst" + cp "$fixture/apple-sep.ko.zst" "$fixture/expected-image" mkdir -p "$tree/soc/spi@39b108000/fingerprint@0" "$tree/chosen" "$fixture/firmware" "$fixture/run" printf '%s\0' "$@" >"$tree/compatible" printf 'apple,mesa-fingerprint\0' >"$tree/soc/spi@39b108000/fingerprint@0/compatible" @@ -183,15 +258,18 @@ neo() { cp "$work/factory/all_firmware.tar.gz" "$fixture/esp/asahi/" } run() { + local executable=$ROOT/lib/$1 + [[ $1 != /* ]] || executable=$1 PATH="$fixture/bin:$PATH" OMARCHY_MAC_TOUCHID_TREE=$tree OMARCHY_MAC_TOUCHID_FIRMWARE=$fixture/firmware \ OMARCHY_MAC_TOUCHID_EXTRACTORS=$fixture/extractors OMARCHY_MAC_TOUCHID_AGREED=$fixture/etc/touchid-on \ - OMARCHY_MAC_TOUCHID_OPTIONS=$fixture/etc/modprobe.conf OMARCHY_MAC_TOUCHID_MODULE=$fixture/module \ + OMARCHY_MAC_TOUCHID_OPTIONS=$fixture/etc/modprobe.conf OMARCHY_MAC_TOUCHID_MODULE=$fixture/module OMARCHY_MAC_TOUCHID_DRIVER=$fixture/driver \ OMARCHY_MAC_TOUCHID_STATUS=$fixture/run/touchid OMARCHY_MAC_TOUCHID_HELPERS=$ROOT/lib \ OMARCHY_MAC_TOUCHID_NODE=$fixture/sep-bio OMARCHY_MAC_TOUCHID_KEYBAG=$fixture/keybag \ + OMARCHY_MAC_TOUCHID_GUARD_LIST=$fixture/guard-list \ OMARCHY_MAC_TOUCHID_ESP=$fixture/esp OMARCHY_MAC_TOUCHID_CONTAINER=${container:-$work/factory/isc.img} \ OMARCHY_MAC_TOUCHID_PYTHON=${python:-python3} OMARCHY_MAC_PAMD=$fixture/pam.d \ OMARCHY_MAC_TOUCHID_PAM_LOCK=$fixture/run/touchid-pam.lock OMARCHY_MAC_TOUCHID_PAM_MODULE=$fixture/pam_aurora_touchid.so \ - "$ROOT/lib/$1" "${@:2}" + "$executable" "${@:2}" } eligibility() { run touchid-eligibility @@ -209,6 +287,65 @@ printf 'disabled\0' >"$tree/soc/spi@39b108000/fingerprint@0/status" [[ $(eligibility) == "none" ]] || fail 'a disabled sensor node is no Touch ID' machine apple,j314s apple,t6000 apple,arm-platform [[ $(eligibility) == "unsupported:m1-family" ]] || fail 'M1-family Macs wait for their xART guard path' +machine apple,j314c apple,t6001 apple,arm-platform +[[ $(eligibility) == "unsupported:m1-family" ]] || fail 'the 14-inch M1 Max still waits for a board test' +passive_options=$'blacklist apple_sep\noptions apple_sep xart_writes=0 provision_keybag=0' +for board in "apple,j313 apple,t8103" "apple,j316c apple,t6001"; do + read -r model chip <<<"$board" + machine "$model" "$chip" apple,arm-platform + [[ $(eligibility) == available && $(run touchid-options) == "$passive_options" ]] || + fail "$model requires guarded setup and keeps automatic loads read-only" + for capability in param=xart_guard: param=xart_guard_pins: param=xart_writes: param=provision_keybag: xart_guard_pins_abi=1; do + grep -Fxv "$capability" "$fixture/expected-image" >"$fixture/apple-sep.ko.zst" + [[ $(eligibility) == unsupported:kernel ]] || fail "$model requires $capability" + done + grep -Fxv t6000_registration=1 "$fixture/expected-image" >"$fixture/apple-sep.ko.zst" + if [[ $model == apple,j316c ]]; then + [[ $(eligibility) == unsupported:kernel ]] || fail 'J316c requires both sensor registration recoveries' + else + [[ $(eligibility) == available ]] || fail 'J313 has no T6000 registration dependency' + fi + cp "$fixture/expected-image" "$fixture/apple-sep.ko.zst" + diag=$fixture/driver/test.sep/diag + mkdir -p "$fixture/module/notes" "$diag" + [[ $(eligibility) == available ]] && ! run touchid-kernel-ready activate || fail 'binding may finish after the invitation' + echo disabled >"$diag/xart" + [[ $(eligibility) == available ]] && ! run touchid-kernel-ready activate || fail 'a read-only load can record consent only' + echo enabled >"$diag/xart" + echo running >"$fixture/module/notes/.note.gnu.build-id" + cp "$fixture/module/notes/.note.gnu.build-id" "$fixture/run/touchid-guarded-build-id" + echo 1 >"$diag/xart_guard_pins" + echo 0 >"$diag/xart_guard" + [[ $(eligibility) == unsupported:restart ]] || fail "$model rejects writable, unguarded preloads" + echo 1 >"$diag/xart_guard" + echo 0 >"$diag/xart_guard_pins" + [[ $(eligibility) == unsupported:restart ]] || fail "$model rejects writable preloads without pins" + echo 1 >"$diag/xart_guard_pins" + echo previous >"$fixture/run/touchid-guarded-build-id" + [[ $(eligibility) == unsupported:restart ]] && ! run touchid-kernel-ready activate || fail 'another running module cannot inherit authorization' + cp "$fixture/module/notes/.note.gnu.build-id" "$fixture/run/touchid-guarded-build-id" + [[ $(eligibility) == available ]] && run touchid-kernel-ready activate || fail 'activation verifies the running module and its effective policy' + mkdir -p "$fixture/etc" + for attribute in touchid:ready sensor_attach:attached restore:empty matching:legacy; do + echo "${attribute#*:}" >"$diag/${attribute%:*}" + done + ! run touchid-kernel-ready reader || fail 'writable enumeration awaits consent even with valid live evidence' + touch "$fixture/etc/touchid-on" + run touchid-kernel-ready reader || fail 'a ready historical reader with consent can enroll' + echo restored >"$diag/restore" + run touchid-kernel-ready reader || fail 'a restored historical reader with consent can verify' + for attribute in restore:unproven matching:blocked touchid:failed sensor_attach:not-ready; do + saved=$(cat "$diag/${attribute%:*}") + echo "${attribute#*:}" >"$diag/${attribute%:*}" + ! run touchid-kernel-ready reader || fail "a current $attribute stops fprintd even after an earlier ready" + echo "$saved" >"$diag/${attribute%:*}" + done +done +machine apple,j293 apple,t8103 apple,arm-platform +[[ $(eligibility) == "unsupported:m1-family" ]] || fail 'other M1 machines remain out of scope' +machine apple,j414c apple,t6021 apple,arm-platform +: >"$fixture/modinfo-params" +run touchid-kernel-ready || fail "the boot-time load never checks the pins on a Mac other than the M1 Air" machine apple,j504 apple,t8122 apple,arm-platform [[ $(eligibility) == "unsupported:board" ]] || fail 'a T8122 board whose wiring the driver has not read is unsupported' machine apple,j613 apple,t8122 apple,arm-platform @@ -288,6 +425,165 @@ grep -Fxq 'options apple_sep xart_writes=1 provision_keybag=1' "$fixture/options [[ $(<"$fixture/calls") == $'calibration\nmodprobe apple-sep\nsystemctl start omarchy-mac-touchid-activate.service\nsystemctl try-restart fprintd.service' ]] || fail 'it carves, loads the driver, waits for the activation, then restarts a running fprintd' "$(<"$fixture/calls")" [[ $out == *"Touch ID is on."* ]] || fail 'it says so' "$out" +! grep -q xart_guard "$fixture/etc/modprobe.conf" || fail 'a Mac other than the M1 Air gets no xART guard option' +# Build the two fixed records from the driver's little-endian formats. Its +# refused keybag proves that no bag was created. An intent never proves that. +recovery_records() { + python3 - "$fixture" "${1:-cold setup spent}" <<'PYTHON' +import binascii, pathlib, struct, sys, zlib +root = pathlib.Path(sys.argv[1]) +crc = binascii.crc_hqx(struct.pack("<4I", 2, 2, 0, 0) + bytes(16), 0xffff) +(root / "keybag").write_bytes(b"APPLE-SEP-KBAG01" + struct.pack("<4I", 2, 2, 0, crc) + bytes(20)) +entry = b"AXGO" + bytes(4) + sys.argv[2].encode("ascii") +(root / "guard-list").write_bytes(entry + struct.pack(""$tree/soc/spi@39b108000/fingerprint@0/firmware-name" + echo ready >"$fixture/activation" + echo 'options apple_sep xart_guard=1 os-uuid-hi="0x1234" os_uuid_lo=+0o777' >"$fixture/admin-options" + if [[ $model == apple,j313 ]]; then recovery_records 'first setup used'; else recovery_records; fi + cp "$fixture/guard-list" "$work/spent" + cp "$fixture/keybag" "$work/refused" + touch "$fixture/replace-image" + out=$(run touchid-enable 2>&1) || fail "$model turns on after a confirmed refusal" "$out" + aside=("$fixture"/aurora-sep-touchid-retry-*) + cmp -s "${aside[0]}/guard-list" "$work/spent" && cmp -s "$fixture/keybag" "$work/refused" && + [[ ! -e $fixture/guard-list && $(<"$fixture/firmware/updates/apple/mesacal-m1.bin") == calibration ]] || + fail 'only the unused guard list was archived before loading the driver' + grep -Fxq 'modprobe -a -- macsmc ecdh_generic' "$fixture/calls" && + grep '^insmod xart_writes=1 provision_keybag=1 xart_guard=1 xart_guard_pins=1 ' "$fixture/calls" | grep -qw os_uuid_hi=0x1234 && + grep '^insmod ' "$fixture/calls" | grep -Fqw os_uuid_lo=+0o777 && + ! grep -Eq '(xart_writes|provision_keybag)=1' "$fixture/etc/modprobe.conf" && + [[ $(<"$fixture/apple-sep.ko.zst") == old ]] || + fail 'insertion uses the checked module bytes and one value for each parameter, including the existing identity' "$(<"$fixture/calls")" + + for result in intent corrupt refused-with-pins unknown-record missing-with-list; do + machine "$model" "$chip" + recovery_records + case $result in + intent) printf '\0' | dd of="$fixture/keybag" bs=1 seek=20 conv=notrunc status=none ;; + corrupt) printf 'damaged' >>"$fixture/keybag" ;; + refused-with-pins) printf 'earlier pin' >>"$fixture/guard-list" ;; + unknown-record) dd if=/dev/zero of="$fixture/guard-list" bs=32 count=1 status=none ;; + missing-with-list) rm "$fixture/keybag" ;; + esac + cp "$fixture/guard-list" "$work/original-list" + [[ $(eligibility) == unsupported:recovery ]] && ! run touchid-enable >/dev/null 2>&1 && + ! compgen -G "$fixture/aurora-sep-touchid-retry-*" >/dev/null && cmp -s "$fixture/guard-list" "$work/original-list" || + fail "$model preserves indeterminate state ($result)" + done + for state in 1 3; do + machine "$model" "$chip" + recovery_records + printf "\\$(printf %o "$state")" | dd of="$fixture/keybag" bs=1 seek=20 conv=notrunc status=none + run touchid-retry-aside --recover && [[ -e $fixture/guard-list ]] || fail "committed state $state keeps its guard list" + done +done +machine apple,j316c apple,t6001 +recovery_records +mkdir -p "$fixture/module" +out=$(run touchid-enable 2>&1) && fail 'a binding module must wait for restart' +[[ $out == *'Restart this Mac'* && -s $fixture/guard-list && -e $fixture/etc/touchid-on ]] && + ! grep -Eq 'insmod|systemctl start' "$fixture/calls" || fail 'a preload defers activation and recovery without losing consent' "$out" +machine apple,j316c apple,t6001 +mkdir -p "$fixture/etc" +touch "$fixture/etc/touchid-on" +sed -i '/^xart_guard_pins_abi=/d' "$fixture/apple-sep.ko.zst" +echo 'alias=of:N*T*Capple,sep' >>"$fixture/apple-sep.ko.zst" +cp "$fixture/apple-sep.ko.zst" "$fixture/expected-image" +recovery_records +run touchid-load --boot && grep -Fxq 'insmod xart_writes=0 provision_keybag=0' "$fixture/calls" && + [[ -s $fixture/guard-list && ! -e $fixture/run/touchid-guarded-build-id ]] && ! run touchid-kernel-ready activate || + fail 'an autoloading kernel without guarded setup can still boot SEP for the M1 microphones read-only' +for control in xart_writes provision_keybag; do + machine apple,j316c apple,t6001 + mkdir -p "$fixture/etc" + touch "$fixture/etc/touchid-on" + sed -i "/^param=$control:/d" "$fixture/apple-sep.ko.zst" + echo 'alias=of:N*T*Capple,sep' >>"$fixture/apple-sep.ko.zst" + cp "$fixture/apple-sep.ko.zst" "$fixture/expected-image" + ! run touchid-load --boot && ! grep -q insmod "$fixture/calls" || fail "passive boot needs a working $control switch" +done +machine apple,j316c apple,t6001 +touch "$fixture/no-build-id" +! out=$(run touchid-enable 2>&1) && [[ $out == *'driver loaded, but its build ID could not be recorded'* && + -d $fixture/module && -e $fixture/etc/touchid-on && ! -e $fixture/run/touchid-guarded-build-id ]] && + ! run touchid-kernel-ready activate && ! run touchid-kernel-ready reader && + ! grep -q 'systemctl start' "$fixture/calls" || fail 'an unidentified writable load keeps consent and blocks activation' "$out" +machine apple,j313 apple,t8103 +echo 'options apple_sep xart_writes=0' >"$fixture/admin-options" +! out=$(run touchid-enable 2>&1) && [[ $out == *'cannot override'* ]] && ! grep -q insmod "$fixture/calls" || + fail 'an explicit read-only setting cannot be overridden' "$out" +for variant in guarded readonly; do + for policy in 'install apple_* /bin/false' 'softdep apple_?ep pre: dependency'; do + machine apple,j316c apple,t6001 + mkdir -p "$fixture/etc" + touch "$fixture/etc/touchid-on" + if [[ $variant == readonly ]]; then + sed -i '/^xart_guard_pins_abi=/d' "$fixture/apple-sep.ko.zst" + echo 'alias=of:N*T*Capple,sep' >>"$fixture/apple-sep.ko.zst" + cp "$fixture/apple-sep.ko.zst" "$fixture/expected-image" + fi + echo "$policy" >"$fixture/admin-options" + ! out=$(run touchid-load --boot 2>&1) && [[ $out == *'cannot bypass'* ]] && ! grep -q insmod "$fixture/calls" || + fail "$variant insertion respects kmod policy $policy" "$out" + done +done +# A first-enable failure must never erase a denial, or the next attempt would +# select another OS identity and silently become writable. +machine apple,j316c apple,t6001 +mkdir -p "$fixture/etc" +printf '%s\n' 'options apple_sep os_uuid_hi=0x1234 xart_writes=0' >"$fixture/etc/modprobe.conf" +for attempt in 1 2; do + ! out=$(run touchid-enable 2>&1) && [[ $out == *'cannot override'* && ! -e $fixture/etc/touchid-on ]] && + grep -Fxq 'options apple_sep os_uuid_hi=0x1234 xart_writes=0' "$fixture/etc/modprobe.conf" && + [[ $(grep -o 'xart_writes=0' "$fixture/etc/modprobe.conf" | wc -l) == 1 ]] && + ! grep -q '^blacklist apple_sep$' "$fixture/etc/modprobe.conf" && ! grep -q insmod "$fixture/calls" || + fail "a failed setup keeps explicit denial and OS identity on attempt $attempt" "$out" +done +machine apple,j316c apple,t6001 +mkdir -p "$fixture/etc" +printf '%s\n' 'options apple_sep xart_writes=1 provision_keybag=1 xart_guard=1 xart_guard_pins=1' >"$fixture/etc/modprobe.conf" +echo 'options apple_sep os_uuid_hi=0x1234 os_uuid_lo=0xabcd' >>"$fixture/etc/modprobe.conf" +touch "$fixture/etc/touchid-on" +rm -rf "$tree" +run touchid-options --migrate && ! grep -q 'writes=1' "$fixture/etc/modprobe.conf" && + grep -Fxq 'blacklist apple_sep' "$fixture/etc/modprobe.conf" && + grep -Fxq 'options apple_sep os_uuid_hi=0x1234 os_uuid_lo=0xabcd' "$fixture/etc/modprobe.conf" || + fail 'upgrading an offline guarded installation withdraws persistent writes and preserves its identity' +# Full owner entrypoint with real packaged helpers and activation. Fixed +# production paths are mapped into this root. Only hardware and services are simulated. +machine apple,j316c apple,t6001 +sed -e "s|/usr/lib/omarchy-mac/|$ROOT/lib/|g" -e "s|/run/omarchy-mac/|$fixture/run/|g" \ + -e "s|/etc/omarchy-mac/touchid-on|$fixture/etc/touchid-on|g" "$ROOT/entrypoints/enable-fingerprint" >"$work/owner-setup" +chmod +x "$work/owner-setup" +touch "$fixture/real-activation" +run touchid-status +out=$(run "$work/owner-setup" <<&1) && [[ $(<"$fixture/run/touchid") == ready && -e $fixture/etc/touchid-on ]] || + fail 'the J316c owner can accept, load the checked driver and activate through the packaged entrypoint' "$out" +rm -rf "$fixture/module" "$fixture/driver" "$fixture/run" +mkdir "$fixture/run" +sed -i '/^xart_guard_pins_abi=/d' "$fixture/apple-sep.ko.zst" +: >"$fixture/calls" +! run touchid-load && ! run touchid-kernel-ready activate && ! grep -qE 'insmod|modprobe [^ -]' "$fixture/calls" && + ! grep -q 'writes=1' "$fixture/etc/modprobe.conf" || fail 'an agreed M1 on an older kernel grants no automatic or explicit writes' +machine apple,j316c apple,t6001 +touch "$fixture/raced-load" +! run touchid-enable >/dev/null 2>&1 && [[ ! -e $fixture/run/touchid-guarded-build-id && ! -e $fixture/etc/touchid-on ]] && + ! grep -q 'systemctl start' "$fixture/calls" || fail 'a concurrent external insertion never acquires activation permission' +machine apple,j316c apple,t6001 +printf '#!/bin/sh\nexit 1\n' >"$fixture/bin/omarchy-hw-apple-silicon" +! run touchid-options --write && [[ ! -e $fixture/etc/modprobe.conf ]] || fail 'off Apple Silicon no empty options file can be installed' +printf '#!/bin/sh\nexit 0\n' >"$fixture/bin/omarchy-hw-apple-silicon" +# A Mac other than the M1 Air never moves its list. +machine apple,j414c apple,t6021 apple,arm-platform +printf 'kept' >"$fixture/guard-list" +echo ready >"$fixture/activation" +out=$(run touchid-enable 2>&1) || fail 'an M2 Max turns on' "$out" +[[ $(<"$fixture/guard-list") == "kept" ]] || fail "an M2 Max's guard list is never set aside" "$out" # A Neo's sensor key is rebuilt only now, from its factory records on the ESP, # byte for byte, root-only, and nowhere else. neo @@ -513,7 +809,8 @@ mkdir -p "$fixture/etc/modprobe.conf/in-the-way" ! grep -q modprobe "$fixture/calls" || fail "options that can't be written fail, take the agreement back and load nothing" "$out" machine apple,j414c apple,t6021 apple,arm-platform -mkdir -p "$fixture/etc/modprobe.conf.new/in-the-way" +mkdir -p "$fixture/etc" +touch "$fixture/options-mv-fails" touch "$fixture/etc/touchid-on" printf 'options apple_sep xart_writes=1 provision_keybag=1\n' >"$fixture/etc/modprobe.conf" ! run touchid-enable >/dev/null 2>&1 && grep -Fxq 'options apple_sep xart_writes=1 provision_keybag=1' "$fixture/etc/modprobe.conf" && @@ -562,12 +859,15 @@ for name in enable-fingerprint disable-fingerprint; do -e "s|/usr/lib/omarchy-mac/touchid-enable|$fixture/bin/enable-stub|g" -e "s|/etc/omarchy-mac/touchid-on|$fixture/etc/touchid-on|g" \ -e "s|/usr/lib/omarchy-mac/touchid-eligibility|$fixture/bin/eligibility-stub|g" \ -e "s|/usr/lib/omarchy-mac/touchid-pam|$fixture/bin/pam-stub|g" \ + -e "s|/usr/lib/omarchy-mac/touchid-status|OMARCHY_MAC_TOUCHID_TREE=$tree OMARCHY_MAC_TOUCHID_HELPERS=$ROOT/lib OMARCHY_MAC_TOUCHID_MODULE=$fixture/module OMARCHY_MAC_TOUCHID_NODE=$fixture/sep-bio OMARCHY_MAC_TOUCHID_DRIVER=$fixture/driver OMARCHY_MAC_TOUCHID_AGREED=$fixture/etc/touchid-on OMARCHY_MAC_TOUCHID_STATUS=$fixture/run/touchid $ROOT/lib/touchid-status|g" \ + -e "s|/usr/lib/omarchy-mac/touchid-kernel-ready|OMARCHY_MAC_TOUCHID_TREE=$tree OMARCHY_MAC_TOUCHID_HELPERS=$ROOT/lib OMARCHY_MAC_TOUCHID_MODULE=$fixture/module OMARCHY_MAC_TOUCHID_NODE=$fixture/sep-bio OMARCHY_MAC_TOUCHID_DRIVER=$fixture/driver OMARCHY_MAC_TOUCHID_AGREED=$fixture/etc/touchid-on OMARCHY_MAC_TOUCHID_STATUS=$fixture/run/touchid $ROOT/lib/touchid-kernel-ready|g" \ + -e "s|/usr/lib/omarchy-mac/touchid-options|OMARCHY_MAC_TOUCHID_TREE=$tree OMARCHY_MAC_TOUCHID_OPTIONS=$fixture/etc/modprobe.conf OMARCHY_MAC_TOUCHID_HELPERS=$ROOT/lib $ROOT/lib/touchid-options|g" \ -e "s|/etc/modprobe.d/omarchy-mac-touchid.conf|$fixture/etc/modprobe.conf|g" -e "s|/usr/lib/firmware/updates/|$fixture/firmware/updates/|g" \ -e "s|/proc/device-tree/compatible|$tree/compatible|g" -e "s|flock -w 300|flock -w 0|" "$ROOT/entrypoints/$name" >"$entry/$name" chmod +x "$entry/$name" done printf '#!/bin/sh\necho enable >>"%s"\nexit 0\n' "$fixture/calls" >"$fixture/bin/enable-stub" -printf '#!/bin/sh\ncat "%s"\n' "$fixture/eligibility" >"$fixture/bin/eligibility-stub" +printf '#!/bin/sh\ncat "%s" 2>/dev/null || echo available\n' "$fixture/eligibility" >"$fixture/bin/eligibility-stub" printf '#!/bin/sh\nif [ -e "%s" ]; then echo add >>"%s"; else echo remove >>"%s"; fi\n' \ "$fixture/etc/touchid-on" "$fixture/pam-calls" "$fixture/pam-calls" >"$fixture/bin/pam-stub" chmod +x "$fixture/bin/enable-stub" "$fixture/bin/eligibility-stub" "$fixture/bin/pam-stub" @@ -599,12 +899,27 @@ ask ready '' && [[ ! -s $fixture/calls && ! -s $fixture/out ]] || fail 'a Touch [[ $(cat "$fixture/pam-calls" 2>/dev/null) == "add" ]] || fail 'a Touch ID turned on before the re-arm existed gets its PAM lines' grep -Fxq 'options apple_sep xart_writes=1 provision_keybag=1' "$fixture/etc/modprobe.conf" || fail 'a Touch ID turned on before the driver options existed gets them' +echo 'options apple_sep os_uuid_hi=99' >>"$fixture/etc/modprobe.conf" +ask ready '' && grep -Fxq 'options apple_sep os_uuid_hi=99' "$fixture/etc/modprobe.conf" || + fail 'revisiting an agreed M2 preserves its existing driver settings' +machine apple,j313 apple,t8103 apple,arm-platform +mkdir -p "$fixture/etc" +touch "$fixture/etc/touchid-on" +ask ready '' && grep -Fxq 'options apple_sep xart_writes=0 provision_keybag=0' "$fixture/etc/modprobe.conf" || + fail 'an M1 Air turned on before the driver options existed gets passive boot options' "$(<"$fixture/out")" +machine apple,j414c apple,t6021 apple,arm-platform +mkdir -p "$fixture/etc" +touch "$fixture/etc/touchid-on" +[[ ! -e $fixture/etc/modprobe.conf ]] || fail "the M1 Air's options are gone before the M2 Max runs" +ask ready '' && grep -Fxq 'options apple_sep xart_writes=1 provision_keybag=1' "$fixture/etc/modprobe.conf" || + fail 'an agreed M2 Max gets its options again, with no pin' "$(<"$fixture/etc/modprobe.conf")" # No options yet, and none can be written. rm "$fixture/etc/modprobe.conf" -mkdir -p "$fixture/etc/modprobe.conf.new/in-the-way" +mkdir -p "$fixture/etc" +touch "$fixture/options-mv-fails" ! ask ready '' && grep -q 'options could not be written' "$fixture/out" && [[ ! -e $fixture/etc/modprobe.conf ]] || fail "options that can't be written for an earlier agreement fail" "$(<"$fixture/out")" -rm -rf "$fixture/etc/modprobe.conf.new" +rm -f "$fixture/options-mv-fails" machine apple,j616c apple,t6041 apple,arm-platform mkdir -p "$fixture/etc" && touch "$fixture/etc/touchid-on" ask ready '' && grep -Fxq 'options apple_sep xart_writes=1 provision_keybag=1 xart_guard=1' "$fixture/etc/modprobe.conf" || @@ -640,6 +955,103 @@ rm -f "$fixture/etc/modprobe.conf" ask blocked '' && grep -Fxq 'options apple_sep xart_writes=1 provision_keybag=1' "$fixture/etc/modprobe.conf" && grep -q 'Restart this Mac' "$fixture/out" && [[ ! -s $fixture/calls ]] || fail 'an agreed Mac that reads blocked gets its options and is told to restart' "$(<"$fixture/out")" +# The setup hook cannot move the driver's open files, even when an old status +# says activation failed or systemd has not started the new activation yet. +machine apple,j316c apple,t6001 +mkdir -p "$fixture/etc" +touch "$fixture/etc/touchid-on" +recovery_records +echo available >"$fixture/eligibility" +for status in available unsupported:board not-ready failed unproven blocked; do + ask "$status" '' && [[ -s $fixture/guard-list && -s $fixture/keybag ]] || + fail "an agreed owner hook keeps the open state files for $status" +done +echo unsupported:kernel >"$fixture/eligibility" +ask blocked '' && grep -q "this kernel can't set it up" "$fixture/out" && ! grep -q 'Restart this Mac' "$fixture/out" || + fail 'a kernel missing capabilities gets kernel upgrade guidance' +echo unsupported:restart >"$fixture/eligibility" +ask blocked '' && grep -q 'Restart this Mac' "$fixture/out" && ! grep -q 'Boot a kernel' "$fixture/out" || + fail 'an unsafe preload on a compatible kernel gets reboot guidance' +machine apple,j316c apple,t6001 +mkdir -p "$fixture/etc" +touch "$fixture/etc/touchid-on" +printf '%s\n' 'options apple_sep xart_writes=1 provision_keybag=1 xart_guard=1 xart_guard_pins=1 os_uuid_lo=0xabc' >"$fixture/etc/modprobe.conf" +run touchid-options --ensure && PATH="$fixture/bin:$PATH" "$entry/disable-fingerprint" >"$fixture/out" 2>&1 && + [[ ! -e $fixture/etc/touchid-on ]] && grep -Fxq 'options apple_sep os_uuid_lo=0xabc' "$fixture/etc/modprobe.conf" && + ! grep -Eq '^blacklist |xart_writes=1|provision_keybag=1' "$fixture/etc/modprobe.conf" || + fail 'opting out keeps OS identity and removes consent to write and the auto-load blacklist' +echo ready >"$fixture/activation" +run touchid-enable >/dev/null && grep -Fxq 'insmod xart_writes=1 provision_keybag=1 xart_guard=1 xart_guard_pins=1 os_uuid_lo=0xabc' "$fixture/calls" || + fail 'opting back in loads exactly the original OS identity' +touch "$fixture/fprintd-query-fails" +! PATH="$fixture/bin:$PATH" "$entry/disable-fingerprint" >"$fixture/out" 2>&1 && + grep -q 'whether fprintd still has access' "$fixture/out" || fail 'opt-out reports an unconfirmed withdrawal' +rm "$fixture/fprintd-query-fails" +echo deactivating >"$fixture/fprintd-state" +PATH="$fixture/bin:$PATH" "$entry/disable-fingerprint" >/dev/null && + grep -Fxq 'systemctl stop fprintd.service' "$fixture/calls" && ! run touchid-kernel-ready reader || + fail 'opting out synchronously withdraws access from an already active fingerprint daemon' +rm "$fixture/fprintd-state" +# The dispatcher's success permits GetDefaultDevice and fprintd-enroll. Both +# the owner hook and the fprintd ExecCondition must withhold that permission +# for a writable/unproven device, with or without agreement or cached status. +for consent in yes no; do + machine apple,j316c apple,t6001 + mkdir -p "$fixture/etc" "$fixture/module" + [[ $consent == no ]] || touch "$fixture/etc/touchid-on" + touch "$fixture/sep-bio" + for status in available ready unsupported:kernel unsupported:restart; do + ! ask "$status" yes && ! grep -Fxq enable "$fixture/calls" && + ! run touchid-kernel-ready reader || fail "an unknown driver blocks reader enumeration ($consent, $status)" + done + diag=$fixture/driver/test.sep/diag + mkdir -p "$diag" + echo enabled >"$diag/xart" + echo 0 >"$diag/xart_guard" + ! ask ready yes && ! run touchid-kernel-ready reader || fail 'a writable unsafe reader stops enrollment and D-Bus activation' + : >"$fixture/calls" + echo active >"$fixture/fprintd-state" + run touchid-status && grep -Fxq 'systemctl --no-block stop fprintd.service' "$fixture/calls" || + fail 'a previously running fprintd is stopped on an unsafe device addition or update' + rm "$fixture/fprintd-state" + : >"$fixture/calls" + run touchid-status && ! grep -Fq 'stop fprintd' "$fixture/calls" || fail 'status can still run before fprintd is installed' + echo disabled >"$diag/xart" + run touchid-kernel-ready reader || fail 'positive read-only storage lets fprintd serve other readers' + rm -rf "$fixture/module" "$fixture/sep-bio" + run touchid-kernel-ready reader || fail 'a USB reader remains available when SEP is absent' +done +machine apple,j293 apple,t8103 +mkdir -p "$fixture/module" "$fixture/driver/test.sep/diag" +touch "$fixture/sep-bio" +! ask unsupported:m1-family '' && ! run touchid-kernel-ready reader || fail 'the unsupported M1 cannot expose a driver that is still binding' +echo enabled >"$fixture/driver/test.sep/diag/xart" +! ask unsupported:m1-family '' && ! run touchid-kernel-ready reader || fail 'the unsupported M1 cannot delegate enrollment to a writable driver' +echo disabled >"$fixture/driver/test.sep/diag/xart" +ask unsupported:m1-family '' && run touchid-kernel-ready reader || fail 'the read-only M1 can delegate safe enumeration' +rm "$tree/compatible" +! run touchid-kernel-ready reader || fail 'an unidentified board with a SEP node cannot authorize reader enumeration' +for board in "apple,j504 apple,t8122" "apple,j274 apple,t8103"; do + read -r model chip <<<"$board" + machine "$model" "$chip" + mkdir -p "$fixture/module" + rm -rf "$tree/soc" + ask unsupported:board '' && run touchid-kernel-ready reader || fail 'a Mac with a sensorless SEP autoload can use USB' + mkdir -p "$fixture/driver/test.sep/diag" + touch "$fixture/sep-bio" + diag=$fixture/driver/test.sep/diag + echo disabled >"$diag/xart" + run touchid-kernel-ready reader || fail "$model with read-only SEP can use USB" + echo 'xart_writes=0 provision_keybag=1' >"$diag/policy" + ! run touchid-kernel-ready reader || fail "$model cannot treat a provisioning driver as read-only" + echo 'xart_writes=0 provision_keybag=0' >"$diag/policy" + run touchid-kernel-ready reader || fail "$model permits a confirmed passive reader" + echo enabled >"$diag/xart" + ! run touchid-kernel-ready reader || fail "$model cannot enumerate a writable SEP" +done +machine apple,j414c apple,t6021 apple,arm-platform +mkdir -p "$fixture/etc" +touch "$fixture/etc/touchid-on" "$fixture/etc/modprobe.conf" # An agreed Mac whose activation hasn't answered is never asked again, so a no # can't claim to leave on a Touch ID that is on. without_status available n && ! grep -qE 'experimental|stays off' "$fixture/out" && grep -q "isn't ready yet (no status)" "$fixture/out" && @@ -822,7 +1234,7 @@ pass 'the 16-inch M4 Max rebuilds its calibration and sensor key from its own fa if command -v systemd-analyze >/dev/null; then stub_systemd_boot_targets "$work/root" mkdir -p "$work/root/usr/bin" - for command in omarchy-hw-apple-silicon modprobe udevadm; do + for command in omarchy-hw-apple-silicon flock install udevadm; do printf '#!/bin/sh\nexit 0\n' >"$work/root/usr/bin/$command" chmod +x "$work/root/usr/bin/$command" done diff --git a/omarchy-mac/vendor/systemd/system/fprintd.service.d/50-omarchy-mac-touchid.conf b/omarchy-mac/vendor/systemd/system/fprintd.service.d/50-omarchy-mac-touchid.conf index 40bee0d8..329710e7 100644 --- a/omarchy-mac/vendor/systemd/system/fprintd.service.d/50-omarchy-mac-touchid.conf +++ b/omarchy-mac/vendor/systemd/system/fprintd.service.d/50-omarchy-mac-touchid.conf @@ -4,3 +4,6 @@ [Unit] Wants=omarchy-mac-touchid-wait.service After=omarchy-mac-touchid-load.service omarchy-mac-touchid-wait.service omarchy-mac-touchid-activate.service + +[Service] +ExecCondition=/usr/lib/omarchy-mac/touchid-kernel-ready reader diff --git a/omarchy-mac/vendor/systemd/system/omarchy-mac-touchid-activate.service b/omarchy-mac/vendor/systemd/system/omarchy-mac-touchid-activate.service index 37e772ee..677fe286 100644 --- a/omarchy-mac/vendor/systemd/system/omarchy-mac-touchid-activate.service +++ b/omarchy-mac/vendor/systemd/system/omarchy-mac-touchid-activate.service @@ -10,11 +10,13 @@ ConditionPathExists=/dev/sep-bio # A failed activation stays failed for the rest of the boot, so open the node # only once the kernel has made this Mac's keybag. ConditionPathExists=/var/lib/aurora-sep-keybag.bin +After=omarchy-mac-touchid-load.service Before=fprintd.service [Service] Type=oneshot ExecCondition=/usr/bin/omarchy-hw-apple-silicon +ExecCondition=/usr/lib/omarchy-mac/touchid-kernel-ready activate ExecStart=/usr/lib/omarchy-mac/touchid-activate # The script waits up to 45 s for the attach's later retry; this bounds a # blocked open, which would otherwise hold up the pacman hook. diff --git a/omarchy-mac/vendor/systemd/system/omarchy-mac-touchid-load.service b/omarchy-mac/vendor/systemd/system/omarchy-mac-touchid-load.service index db81fb3e..e27f91c2 100644 --- a/omarchy-mac/vendor/systemd/system/omarchy-mac-touchid-load.service +++ b/omarchy-mac/vendor/systemd/system/omarchy-mac-touchid-load.service @@ -15,5 +15,6 @@ Before=display-manager.service fprintd.service Type=oneshot ExecCondition=/usr/bin/omarchy-hw-apple-silicon ExecStartPre=/usr/bin/udevadm wait --timeout=20 /dev/disk/by-partlabel/iBootSystemContainer -ExecStart=/usr/bin/modprobe apple-sep +ExecStartPre=/usr/bin/install -d -m 0755 /run/omarchy-mac +ExecStart=/usr/bin/flock -w 20 /run/omarchy-mac/touchid.lock /usr/lib/omarchy-mac/touchid-load --boot TimeoutStartSec=30s diff --git a/omarchy-mac/vendor/systemd/system/omarchy-mac-touchid-status.service b/omarchy-mac/vendor/systemd/system/omarchy-mac-touchid-status.service index a7c6ff41..3a19bc65 100644 --- a/omarchy-mac/vendor/systemd/system/omarchy-mac-touchid-status.service +++ b/omarchy-mac/vendor/systemd/system/omarchy-mac-touchid-status.service @@ -5,7 +5,7 @@ # Pulled in by the package's multi-user.target.wants link. [Unit] Description=Check whether Touch ID can be set up -After=local-fs.target boot-efi.mount systemd-modules-load.service +After=omarchy-mac-touchid-load.service local-fs.target boot-efi.mount systemd-modules-load.service Before=display-manager.service fprintd.service [Service] diff --git a/omarchy-mac/vendor/udev/rules.d/94-omarchy-mac-touchid.rules b/omarchy-mac/vendor/udev/rules.d/94-omarchy-mac-touchid.rules index 5a7aae5d..65ef197b 100644 --- a/omarchy-mac/vendor/udev/rules.d/94-omarchy-mac-touchid.rules +++ b/omarchy-mac/vendor/udev/rules.d/94-omarchy-mac-touchid.rules @@ -1,2 +1,2 @@ # Activate Touch ID as soon as the Secure Enclave publishes it (omarchy-mac-touchid-activate.service). -ACTION=="add", SUBSYSTEM=="misc", KERNEL=="sep-bio", TAG+="systemd", ENV{SYSTEMD_WANTS}+="omarchy-mac-touchid-activate.service" +ACTION=="add", SUBSYSTEM=="misc", KERNEL=="sep-bio", TAG+="systemd", ENV{SYSTEMD_WANTS}+="omarchy-mac-touchid-status.service omarchy-mac-touchid-activate.service" diff --git a/test/integration/fingerprint-readers-test.sh b/test/integration/fingerprint-readers-test.sh index 9cb2d16d..54d5f124 100755 --- a/test/integration/fingerprint-readers-test.sh +++ b/test/integration/fingerprint-readers-test.sh @@ -42,6 +42,14 @@ detects() { detects && fail "a Mac whose Touch ID was never activated has no reader" touch_id ready attached restored usable detects || fail "a Mac whose Touch ID can enrol and match has a reader" +touch_id ready attached restored legacy +detects || fail "restored historical enrollments can attempt a real match" +touch_id ready attached empty legacy +detects || fail "a historical bag with an empty restore can enroll its first print" +touch_id ready attached empty blocked +detects && fail "a storage refusal still blocks the empty reader" +touch_id ready attached unproven legacy +detects && fail "historical provenance cannot bypass a failed restore" touch_id ready attached empty unverified detects || fail "a Mac with nothing enrolled yet, behind a guard that has refused nothing, has a reader" pass "the runtime finds Touch ID where omarchy-mac names it, once it can enrol and match" @@ -74,3 +82,44 @@ printf '27c6\n' >"$tmp/usb/1-0/idVendor" printf '1234\n' >"$tmp/usb/1-0/idProduct" detects || fail "a USB reader is found beside a Touch ID that is not ready" pass "a Touch ID that is not ready leaves a USB reader to be found" + +# Follow the actual setup -> --resolve -> privileged dispatch -> owner hook +# contract. Restrict all privilege and device access to the staged root. +helpers=$tmp/pkg/usr/lib/omarchy-mac +owner=$tmp/pkg/usr/lib/omarchy/mac/enable-fingerprint +sed -e "s|/usr/lib/omarchy-mac/|$helpers/|g" -e "s|/etc/omarchy-mac/|$tmp/pkg/etc/omarchy-mac/|g" \ + -e "s|/run/omarchy-mac/|$tmp/run/omarchy-mac/|g" "$MAC/entrypoints/enable-fingerprint" >"$owner" +sed -i -e "s|:-/usr/lib/omarchy-mac|:-$helpers|g" -e "s|:-/sys/module/apple_sep|:-$tmp/module|g" \ + -e "s|:-/sys/bus/platform/drivers/apple_sep|:-$tmp/sys/apple_sep|g" -e "s|:-/dev/sep-bio|:-$tmp/sep-bio|g" \ + -e "s|:-/etc/omarchy-mac/touchid-on|:-$tmp/pkg/etc/omarchy-mac/touchid-on|g" \ + -e "s|:-/run/omarchy-mac/touchid|:-$tmp/run/omarchy-mac/touchid|g" "$helpers/touchid-kernel-ready" +sed -i "s|:-/proc/device-tree|:-$tmp/tree|g" "$helpers/touchid-board.sh" +sed -e "s|^fixed_path=.*|fixed_path=$tmp/stub:/usr/bin|" -e "s|^ root=\"\"| root=$tmp/pkg|" \ + "$ROOT/bin/omarchy-lifecycle-dispatch" >"$tmp/bin/omarchy-lifecycle-dispatch" +printf '#!/bin/bash\necho %s\n' "$(runtime_platform aarch64-apple)" >"$tmp/bin/omarchy-hw-platform" +printf '#!/bin/bash\nexit 1\n' >"$tmp/stub/omarchy-pkg-missing" +cat >"$tmp/stub/sudo" <<'SH' +#!/bin/bash +case "$*" in + "-n true") exit 0 ;; + "omarchy-lifecycle-dispatch enable-fingerprint"|fprintd-enroll*) exec "$@" ;; + *) exit 1 ;; +esac +SH +for command in busctl fprintd-enroll; do + printf '#!/bin/bash\necho "%s $*" >>"%s"\nexit 1\n' "$command" "$tmp/probes" >"$tmp/stub/$command" +done +chmod +x "$tmp/bin/"* "$tmp/stub/"* +mkdir -p "$tmp/module" "$tmp/tree" +printf 'apple,j293\0apple,t8103\0' >"$tmp/tree/compatible" +echo unsupported:m1-family >"$tmp/run/omarchy-mac/touchid" +setup() { + OMARCHY_USB_DEVICES_PATH="$tmp/usb" OMARCHY_LIFECYCLE_ROOT="$tmp/pkg" PATH="$tmp/bin:$tmp/stub:/usr/bin" \ + "$ROOT/bin/omarchy-setup-security-fingerprint" "$tmp/setup-output" 2>&1 +} +! setup && grep -q 'nothing was enrolled' "$tmp/setup-output" && [[ ! -e $tmp/probes ]] || + fail "the actual dispatcher stops setup before fprintd opens an unproven SEP alongside USB" "$(cat "$tmp/setup-output")" +rm -rf "$tmp/module" "$tmp/sep-bio" +! setup && grep -q GetDefaultDevice "$tmp/probes" && grep -q fprintd-enroll "$tmp/probes" || + fail "the same setup reaches USB enumeration and enrollment with SEP absent" "$(cat "$tmp/setup-output")" +pass "fingerprint setup honors the owner hook before D-Bus or enrollment, including with a USB reader attached"