aboutsummaryrefslogtreecommitdiff
path: root/internal/crypt/ssh_key_io.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/crypt/ssh_key_io.go')
-rw-r--r--internal/crypt/ssh_key_io.go39
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
+}