Add ysm: TUI for managing SSH keys with YubiKey support
Lists keys in ~/.ssh, generates regular and FIDO2 (YubiKey) keys, imports resident keys, manages ssh-agent, copies/installs public keys. Passphrases and PINs are handled by ssh-keygen in the handed-over terminal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
6 files changed
+808
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseFingerprint(t *testing.T) {
|
||||
bits, fp, comment, typ, ok := parseFingerprint("256 SHA256:abc me@box two (ED25519-SK)")
|
||||
if !ok || bits != "256" || fp != "SHA256:abc" || comment != "me@box two" || typ != "ED25519-SK" {
|
||||
t.Fatalf("got %q %q %q %q %v", bits, fp, comment, typ, ok)
|
||||
}
|
||||
if _, _, _, _, ok := parseFingerprint(""); ok {
|
||||
t.Fatal("empty line parsed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadKeysAndValidate(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
out, err := exec.Command("ssh-keygen", "-q", "-t", "ed25519", "-N", "", "-C", "test@ysm", "-f", filepath.Join(dir, "id_test")).CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("%v: %s", err, out)
|
||||
}
|
||||
os.WriteFile(filepath.Join(dir, "junk.pub"), []byte("not a key"), 0o600)
|
||||
|
||||
keys, err := loadKeys(dir)
|
||||
if err != nil || len(keys) != 1 {
|
||||
t.Fatalf("keys=%v err=%v", keys, err)
|
||||
}
|
||||
k := keys[0]
|
||||
if k.Name != "id_test" || k.Type != "ED25519" || k.Comment != "test@ysm" || !k.HasPrivate || k.Hardware() {
|
||||
t.Fatalf("bad key %+v", k)
|
||||
}
|
||||
|
||||
for name, wantErr := range map[string]bool{"id_test": true, "": true, "../x": true, "a.pub": true, ".hidden": true, "id_new": false} {
|
||||
if err := validateName(dir, name); (err != nil) != wantErr {
|
||||
t.Errorf("validateName(%q) = %v", name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user