Skip to content

fix(setup): validate keystore output path in perry setup android#1291

Merged
proggeramlug merged 1 commit into
mainfrom
fix/perry-android-keystore-path-validation
May 21, 2026
Merged

fix(setup): validate keystore output path in perry setup android#1291
proggeramlug merged 1 commit into
mainfrom
fix/perry-android-keystore-path-validation

Conversation

@proggeramlug
Copy link
Copy Markdown
Contributor

Summary

  • perry setup android crashes the whole wizard when the user mistypes the keystore path. Concrete repro: typing ~/../release-key.keystore expands to /Users/<you>/../release-key.keystore = /Users/release-key.keystore, which keytool can't write to. The wizard bail!s after the user has already entered an alias + password.
  • Add a prompt_output_path helper that expands ~/, canonicalizes the parent through any .., probes write-access by creating + deleting a tiny .perry-write-test-<pid> file (because permissions().readonly() doesn't honor effective-uid on Unix), and re-prompts on failure instead of bailing.
  • Wire it into the keystore-generation branch of android.rs — alias + password prompts now only run once the path is known good.

Why a probe instead of a permission check

On Unix, metadata.permissions().readonly() only reflects whether the owner-write bit is set on the file, not whether the current process can actually create entries in that directory. Trying to create a probe file is the only check that matches what keytool (or any subsequent open(O_CREAT) call) will hit.

Test plan

  • cargo build --release -p perry — green
  • cargo fmt --all -- --check — clean
  • Manually re-run perry setup android with ~/../release-key.keystore: now prints ✗ Cannot write to /Users (permission denied) and re-prompts instead of crashing. Typing ~/release-key.keystore succeeds and proceeds to alias/password.
  • CI: lint, cargo-test, api-docs-drift, security-audit

Out of scope

The same helper would also fit tvos.rs / visionos.rs / watchos.rs / macos.rs "save this generated cert" prompts, but I kept the change scoped to the path that actually broke. Happy to roll those into a follow-up if it's worth it.

…d re-prompt instead of crashing

`perry setup android` invokes `keytool -genkeypair` with whatever path
the user typed at the "Output path" prompt. A typo like
`~/../release-key.keystore` expands to `/Users/<you>/../release-key.keystore`
= `/Users/release-key.keystore`, which the user almost certainly cannot
write to. keytool then exits non-zero, the wizard bails, and the user
loses their alias + password entries.

Add a `prompt_output_path` helper that:

- expands `~/` (existing behavior),
- canonicalizes the *parent* directory (collapsing `..` segments so the
  error message names the directory the OS will actually refuse),
- probes write access with a `.perry-write-test-<pid>` create/remove
  round-trip — `permissions().readonly()` lies about effective-uid
  permission on Unix, so a real probe is the only honest check,
- on failure prints a red ✗ + the resolved-parent + errno kind and
  re-prompts.

Wire it into android.rs's keystore-generation branch in place of the
prior `Input::interact_text` + `expand_tilde` pair. The other inputs
(alias, password) come after the path now succeeds, so a slip on the
path no longer wastes the user's password retype.

Reuse target later: the same helper fits the other wizards' "where do I
save this generated cert/key" prompts, but no behavior change there
yet — staying scoped to the bug Ralph hit.
@proggeramlug proggeramlug merged commit f697494 into main May 21, 2026
9 checks passed
@proggeramlug proggeramlug deleted the fix/perry-android-keystore-path-validation branch May 21, 2026 19:27
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