From 66995c3c06f755fe1192e5e8277bfa873a18a4ea Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Fri, 17 May 2024 11:42:44 -0400 Subject: [PATCH] Implement initial support for passphrase-protected SSH keyfiles --- src/cli/init.go | 7 +++++-- src/cli/utilitiesMisc.go | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cli/init.go b/src/cli/init.go index b1508c9..c3a2b42 100644 --- a/src/cli/init.go +++ b/src/cli/init.go @@ -5,6 +5,7 @@ import ( "github.com/rwinkhart/MUTN/src/backend" "github.com/rwinkhart/MUTN/src/sync" "os" + "strconv" ) // TempInitCli initializes the MUTN environment based on user input @@ -31,13 +32,15 @@ func TempInitCli() { configSSH := inputBinary("Configure SSH settings (for synchronization)?") if configSSH { // necessary SSH info + fmt.Print(AnsiBold+"Note:"+backend.AnsiReset, "Only key-based authentication is supported (keys may optionally be passphrase-protected).\nThe remote server must already be in your ~/.ssh/known_hosts file.\n\n") sshUser := input("Remote SSH username:") sshIP := input("Remote SSH IP address:") sshPort := input("Remote SSH port:") - sshIdentity := input("SSH private identity file path:") // TODO implement generator and selector + sshKey := input("SSH private identity file path:") // TODO implement generator and selector + sshKeyProtected := inputBinary("Is the identity file password-protected?") // write config file - backend.TempInit(map[string]string{"textEditor": textEditor, "gpgID": gpgID, "sshUser": sshUser, "sshIP": sshIP, "sshPort": sshPort, "sshIdentity": sshIdentity}) + backend.TempInit(map[string]string{"textEditor": textEditor, "gpgID": gpgID, "sshUser": sshUser, "sshIP": sshIP, "sshPort": sshPort, "sshIdentity": sshKey, "sshIDProtected": strconv.FormatBool(sshKeyProtected)}) // generate device ID sync.DeviceIDGen() diff --git a/src/cli/utilitiesMisc.go b/src/cli/utilitiesMisc.go index 2ebad10..8c68c88 100644 --- a/src/cli/utilitiesMisc.go +++ b/src/cli/utilitiesMisc.go @@ -25,8 +25,8 @@ func input(prompt string) string { return strings.TrimRight(userInput, "\n\r ") // remove trailing newlines, carriage returns, and spaces } -// inputHidden prompts the user for input and returns the input as a string, hiding the input from the terminal -func inputHidden(prompt string) string { +// InputHidden prompts the user for input and returns the input as a string, hiding the input from the terminal +func InputHidden(prompt string) string { fmt.Print("\n" + prompt + " ") byteInput, _ := terminal.ReadPassword(int(os.Stdin.Fd())) password := string(byteInput)