Skip to content

Show which key, which caller and why in the Touch ID prompt - #26

Open
0xManyu wants to merge 1 commit into
remko:mainfrom
0xManyu:auth-prompt-reason
Open

0xManyu wants to merge 1 commit into
remko:mainfrom
0xManyu:auth-prompt-reason

Conversation

@0xManyu

@0xManyu 0xManyu commented Nov 18, 2026 •

Copy link
Copy Markdown

Today the Touch ID prompt only says that age-plugin-se wants to use a key. When it pops up while a script or an AI agent is running, it's easy to approve it without knowing which key is being unlocked or who asked for it. This PR makes the prompt say which key, which programs asked, and optionally why, so that reflex approvals are less likely. It is not meant to stop a deliberate attacker; see the section on spoofing below.

This covers the same need as #18, which has gone quiet and now conflicts with main. It takes a different approach to the concerns raised there: the facts the plugin can look up itself come first, and the caller's own text comes last.

What the prompt shows

Before each key operation, the plugin sets the prompt text to up to three lines:

  1. Which key. The plugin looks up the key's recipient in an optional names file, ~/.config/age-plugin-se/names, with one <recipient> <name> per line. If the key isn't listed, the prompt shows a shortened recipient. The identity format doesn't change, so existing identity files keep working.
  2. Who asked. The names of up to five parent processes, outermost first. In practice this is the line that tells you whether a request came from your own shell or from another program.
  3. Why. An optional note from the caller, read from AGE_SE_REASON. It is shown last and labelled as what the caller says.

Line breaks, control characters and bidirectional overrides are removed from all three parts, so one part can't pass itself off as another.

截屏2026-11-18 上午10 16 33 截屏2026-11-18 上午10 17 02

On spoofing

Caller-supplied text alone can't be trusted, which is why it goes last. But nothing inside the plugin can make the prompt trustworthy against a process that is lying on purpose. The identity file holds the Secure Enclave key's wrapped data, and that data isn't tied to the plugin binary: a locally built, ad-hoc signed copy of the plugin uses keys created by the Homebrew build without any problem. So any program running as the user that can read the identity file can load the key itself, set any prompt text it likes, and name its executable age-plugin-se, without going through the plugin at all. The real boundary is who can read the identity file.

So the goal here is narrower: help an honest user catch mistakes, such as an agent reaching for the production key while its note says it is working on staging. The names file and process names can be changed by the user's own programs, and that's acceptable for this goal. The README section added here says so too.

If you'd rather take only part of this, for example only the key name, I'm happy to cut the PR down.

Technical details
  • Most of the code is in a new file, Sources/AuthenticationReason.swift. Crypto gets a setAuthenticationReason(_:) method, which sets localizedReason on the shared LAContext; the default implementation, used by DummyCrypto, does nothing. runIdentityV1 calls it as soon as it knows which identity matches a stanza, before the key is used.
  • The names file is read from $XDG_CONFIG_HOME/age-plugin-se/names, or from ~/.config/age-plugin-se/names if that variable isn't set. A key matches if its age1se, age1tag or age1tagpq recipient is listed.
  • Process names come from each process's argv[0] (read with KERN_PROCARGS2), falling back to the executable's file name. argv[0] comes first because some executables have uninformative file names; Claude Code's executable, for example, is named after its version number. The process lookup only runs on macOS; elsewhere the prompt has no "Requested by" line.
  • Each part is cut to 80 characters. macOS shows the line breaks as-is.
  • Tested by hand on macOS with Touch ID, from a terminal and from an agent. New unit tests cover the names lookup, the cleaning of each part, and the order of the lines. On my fork, the build passes on Linux, Windows, macOS 15 and macOS 26, and make test and make lint pass on macOS 26. Two jobs fail there for reasons unrelated to this change: the macOS 14 runner is no longer available (this also happens on main), and the Alpine package step needs the signing key, which a fork doesn't have. I haven't tested a post-quantum key by hand.

🤖 Generated with Claude Code

The authentication prompt only said that age-plugin-se wanted to use a
key, so it was easy to approve a request without knowing what it was.
Before each key operation the plugin now sets the prompt text to three
lines:

- the key's name, looked up by its recipient in
  ~/.config/age-plugin-se/names (lines of "<recipient> <name>"), or a
  shortened recipient if the key has no name;
- the names of up to five parent processes, outermost first, so you can
  see whether the request came from your own shell or from another
  program such as an AI agent;
- an optional note from the caller, taken from AGE_SE_REASON.

Facts the plugin looks up itself come first and the caller's note comes
last. Line breaks, control characters and bidirectional overrides are
removed from every part, so one part cannot pass itself off as another.

This is meant to prevent approving by reflex, not to stop a deliberate
attacker: any process that can read the identity file can use the
Secure Enclave key directly and show any prompt it likes, and the names
file and process names can be changed by the user's own processes.

The README describes the names file and AGE_SE_REASON, and the new
tests cover the names lookup, the cleaning of each part, and the order
of the lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant