Repository navigation
feat(app): manage SSH private keys in a key manager - #308
TooonyChen wants to merge 4 commits into
Conversation
Import a private key once, with its passphrase, into the system's credential store, split over entries of at most 2,048 bytes with a manifest written last; connections choose it by name in the editor's new Key select, whose last item "Key file" keeps today's key file row. keys.json lists the keys on this device only; hosts refer to a key by ID and fingerprint, and show it missing until one with the same fingerprint is imported. Closes #306 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015nMqJEvqPnRmPgi6dnraZM
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4e014e5cc8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if err := a.saveKeyRing(); err != nil { | ||
| a.keys = before | ||
| if d.edit == nil { // the new key is not listed: not kept either | ||
| a.deleteKeySecret(id, func(error) {}) |
There was a problem hiding this comment.
Restore the stored key when replacement metadata cannot be saved
When replacing an existing key, if writing keys.json fails, this branch restores only the old metadata. By this point putKey has replaced the credential-store payload and deleted the old generation, so the old fingerprint now identifies different private-key material. Existing connections consequently attempt authentication with the replacement despite the dialog reporting failure, and the original managed key may be irrecoverable if its source file was deleted. Retain the previous secret until metadata persistence succeeds, or restore it when persistence fails.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 603776f. When keys.json cannot be saved, a new key is removed from the ring and deleted from the credential store; an edited key gets its old ring entry back and its old content is written back to the store. If that restore fails too, the dialog says so. Covered by TestKeyReplaceRollback.
Generated by Claude Code
| for _, h := range users { | ||
| h.KeyID, h.KeyFingerprint = k.ID, k.Fingerprint | ||
| } | ||
| a.saveHosts(a.hosts) |
There was a problem hiding this comment.
Handle failures when persisting rotated host references
When a key replacement succeeds but saving hosts.json fails, the error is discarded and the dialog closes as though everything was saved. This breaks connections after restart when they previously resolved the key by fingerprint using another device's ID: their persisted reference still contains the old fingerprint, while the local key now has the replacement fingerprint, so KeyRing.Resolve finds neither. Check this save result and retain a recoverable error state rather than silently reporting success.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 603776f. A failed hosts.json save after a replace now shows the error and keeps the dialog open; the hosts stay updated in memory and saving again writes them. Covered by TestKeyReplaceHostsSaveFails.
Generated by Claude Code
| a.keyUI.sel = id | ||
| a.closeWindow(WindowKeyDialog) |
There was a problem hiding this comment.
Avoid closing a newer dialog from an earlier store callback
While a credential-store write is pending, Cancel and the window-close shortcuts remain available. If the user closes that dialog and opens another Import or Edit dialog before the write completes, this callback unconditionally closes the newer dialog, discarding its inputs. Unlike the preceding inspection callback, the store completion does not check a.keyUI.dlg == d. Complete any necessary persistence independently, but only close the dialog that initiated the operation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 603776f. The store callback only changes or closes the dialog that started it. If that dialog is gone, an error is shown in the key manager instead, and Cancel stays enabled while the store is busy. Covered by TestKeyImportDialogClosedWhileStoring.
Generated by Claude Code
The missing-key state in the connection editor is a warning now: OK saves the rest of the host and keeps keyId and keyFingerprint unless another key or "Key file" is chosen. A replace whose keys.json cannot be saved puts the key's old content back in the store; a failed hosts.json save keeps the dialog open with the error; a store write that finishes after its dialog closed no longer touches the dialog opened since. The connection manager opens 1000 wide so that its toolbar keeps the Keys button out of the overflow with wider fonts. Refs #306 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015nMqJEvqPnRmPgi6dnraZM
The folder filter and the search field now give way, down to 80 and 90 DIPs, before any toolbar button goes into the overflow menu: their widths come from the room left beside the buttons, measured with ui.ShapeText in the theme's font plus a 15% margin. The fit test runs with text 1.2, 1.35 and 1.5 times larger, in both languages. Refs #306 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015nMqJEvqPnRmPgi6dnraZM
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015nMqJEvqPnRmPgi6dnraZM
Summary
Adds the key manager from #306. You import a private key once, together with its passphrase, into the system's credential store. Connections then pick it by name, and the original file is no longer needed.
.ppk, which key-file login cannot read either), a file over 64 KB, and an unreadable file.keys.json.sshx.Dialthrough a newOptions.Key, and zeroes the bytes once the signers have parsed them. A managed-key host never opens a passphrase prompt.Design decisions
mygo.Secrets.Setrefuses values overMaxSecretSize= 2,560 bytes on every platform, not just Windows, and refuses keys longer than 256 bytes.secret_password_store_binary, also none. The effective limit is therefore 2,560 everywhere.internal/keystorepackage stores the payload{"key": <file bytes, base64>, "passphrase": "…"}in parts namedsshkey/<id>/<gen>/<n>, each at most 2,048 bytes. A manifestsshkey/<id>=v1 <gen> <parts> <sha256 hex>is written last.{"version":1,"keys":[{"id","name","type","bits","fingerprint","encrypted","createdAt"}]}. Nothing secret is in it.hostSecretNames.keyIdandkeyFingerprint, withkeyPathcleared.KeyRing.Resolve) tries the ID first, then the fingerprint. So a host synced from another device, where the key has a different ID, works once a key with the same fingerprint is imported.keyId/keyFingerprintstay as they are unless another key or "Key file" is chosen, so the reference is never changed silently.keys.jsonthat the store does not have counts as missing too.keyId/keyFingerprintset to this key's ID and new fingerprint, andhosts.jsonis saved. Other devices then see the new fingerprint and show the key missing until the rotated key is imported there.Platformsecret API takes strings, so the store calls hold immutable string copies that cannot be zeroed.Differences from the mockup
TestManagerToolbarFitschecks font scales 1 to 1.5 in both languages.Closes #306
Testing
go build ./...,go vet ./...,GOOS=windows go vet .,GOOS=darwin go vet .,go tool mygo vet, and the toolchain's gofmt: all clean.go test -race -count=1 -timeout 30m ./...: all packages pass.Tests added, by acceptance criterion:
TestKeyImportcovers RSA 2048, RSA 4096 with passphrase, ECDSA 256 and 384 with passphrase, Ed25519, and legacy PEM RSA with passphrase, all through the dialog. AlsoTestKeyManagerList,TestKeyEdit,TestKeyDelete,TestKeyDeleteUnused, and sshxTestInspectKey.TestManagedKeyLogin(twosshtestservers) and sshxTestDialManagedKey.TestKeyImportErrorscovers wrong passphrase, missing passphrase, duplicate key (including a legacy PEM key that is compared after its passphrase is given), duplicate name in another case, empty name, public key, text file, and missing file. Also sshxTestInspectKeyRefuses.TestRSA4096RoundTripsUnderTheLimit. The app's fake store also enforces 2,560 inTestKeyImportandTestManagedKeyLogin. PlusTestFailedWriteLeavesNoHalfKey,TestIncompleteKeyDetected,TestDeleteManifestFirst,TestNoStore,TestErrorsHoldNoSecret.TestKeyDelete.TestSyncedHostMissingKey: raw JSON with another device's ID; editor and connect show the missing state; importing the same key makes it connect; the saved reference keeps the foreign ID; the sync payload carries the reference and nothing from the key manager. Also configTestKeyResolveandTestKeyReferenceKeptByOlderVersions.TestEditorKeyFileHostUnchanged,TestEditorKeySelect, and the existing editor and passphrase tests, which pass unchanged.TestKeyManagerNoStore.TestKeyManagerButton.sshtest.NewKey); none are committed. UI checks look for texts and accessibility nodes, not pixel widths.Screenshots:
go run ./tools/screenshotson this branch and on unmodified main. Onlyconnection-manager-en.pngandconnection-manager-zh-CN.pngdiffer (the new button); they are committed.Not tested: real Windows Credential Manager, macOS Keychain and Secret Service, which cannot run here. A fake store stands in for them (
fakeSecretsin the app tests,limitedStorein keystore), refusing values over 2,560 bytes and, in some tests, failing set/delete calls or reportingerrors.ErrUnsupportedlike a missing store. Also not tested: native nested sheets on macOS (the key dialog is modal to the key manager, which is modal to the connection manager). The sizes are chosen so each sheet fits inside its parent.Generated by Claude Code