diff options
| author | ishaan <contact@ishaan.cc> | 2026-07-19 18:33:40 +0530 |
|---|---|---|
| committer | ishaan <contact@ishaan.cc> | 2026-07-19 18:33:40 +0530 |
| commit | e48a02646f60b6fdff8db5c4105896756584ac63 (patch) | |
| tree | 3371785e68bfe6b14065589ba7fd417d75742595 /internal/crypt/ssh_key_io.go | |
| parent | d6449a232e6bd9eb46132c7403a05ac1a756b619 (diff) | |
reorganize
Diffstat (limited to 'internal/crypt/ssh_key_io.go')
| -rw-r--r-- | internal/crypt/ssh_key_io.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/internal/crypt/ssh_key_io.go b/internal/crypt/ssh_key_io.go new file mode 100644 index 0000000..59ea448 --- /dev/null +++ b/internal/crypt/ssh_key_io.go @@ -0,0 +1,39 @@ +package crypt + +import ( + "fmt" + "os" + "os/signal" + "syscall" + + "github.com/charmbracelet/x/term" +) + +func promptSSHKeyPassphrase(privKeyPath string) []byte { + fd := os.Stdin.Fd() + oldState, err := term.GetState(fd) + if err != nil { + fmt.Fprintf(os.Stderr, "eno: failed to get terminal state: %v\n", err) + return nil + } + + sigCh := make(chan os.Signal, 1) + signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM) + defer signal.Stop(sigCh) + + go func() { + <-sigCh + term.Restore(fd, oldState) + os.Exit(130) + }() + + fmt.Fprintf(os.Stderr, "Enter passphrase for SSH key %s: ", privKeyPath) + passphrase, err := term.ReadPassword(fd) + fmt.Fprintln(os.Stderr) + if err != nil { + fmt.Fprintf(os.Stderr, "eno: failed to read passphrase: %v\n", err) + return nil + } + + return passphrase +} |