signing-keys create: reject a duplicate name before generating - #235
Open
mobileoverlord wants to merge 2 commits into
Open
signing-keys create: reject a duplicate name before generating#235mobileoverlord wants to merge 2 commits into
mobileoverlord wants to merge 2 commits into
Conversation
The name collision was only checked after the key had been generated, so `create <existing-name> --algorithm rsa2048` ran openssl and wrote a PEM pair into the keys directory before failing, and the PKCS#11 --generate path burned a slot on the device the same way. Check the name up front when one is given; the keyid fallback is still covered by add_key.
There was a problem hiding this comment.
🟡 Changes recommended
The new test compares unsorted read_dir results, which can be flaky because directory iteration order is not guaranteed.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR prevents avocado signing-keys create <name> from performing any key generation work when <name> already exists in the signing-keys registry, avoiding orphaned files and unintended PKCS#11 key creation.
Changes:
- Move duplicate-name detection to the start of
SigningKeysCreateCommand::execute()when an explicit name is provided. - Add an integration test ensuring a second
createwith the same name fails before RSA/openssl generation and leaves the keys directory unchanged.
File summaries
| File | Description |
|---|---|
src/commands/signing_keys/create.rs |
Checks for duplicate explicit names before any key generation occurs. |
tests/signing_keys_create.rs |
Adds a regression test that verifies duplicate-name failure doesn’t leave new files behind. |
Review details
Suppressed comments (1)
tests/signing_keys_create.rs:40
- Same ordering issue here:
read_diriteration order is filesystem-dependent, so theVecmay not matchafter_firsteven when no files were added/removed. Sort before comparing.
let after_second: Vec<_> = std::fs::read_dir(dir.path())
.unwrap()
.map(|e| e.unwrap().file_name())
.collect();
assert_eq!(after_first, after_second, "second create left files behind");
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
lee-reinhardt
previously approved these changes
Sep 3, 2026
read_dir has no ordering guarantee, so the before/after listings go through a BTreeSet. AVOCADO_SIGNING_KEYS_DIR is process-global, so the test is #[serial] for whatever lands in this binary next. Adds the Fixed entry under [Unreleased].
lee-reinhardt
approved these changes
Sep 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
avocado signing-keys create <name>checked for a name collision only after the key had been generated. Re-running it with an existing name ran the full generation first and then failed:--algorithm rsa2048/rsa4096: shelled out toopenssland wrote a.key/.crtpair into the signing-keys directory before bailing, leaving the orphaned pair behind.--pkcs11-device --generate: created a key on the hardware token, consuming a slot, before bailing.hmac-sha256anded25519: wrote key material to disk before bailing.How
Move the check to the top of
execute(), before any generation, when a name is given. When no name is given it defaults to the key id, which is not known until after generation; that case is still covered byregistry.add_key.importalready checked before doing any work, so it needed no change.Results
New
tests/signing_keys_create.rs: creates a key, then re-runscreatewith the same name and--algorithm rsa2048, and asserts the error is raised and the keys directory is unchanged. Verified the test fails against the previous behavior.cargo fmt --checkandcargo clippy --all-targetsclean.