From 47fe645fb99b2904617dd9ff26c7e5e4fbe88ec3 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 21 Nov 2019 11:04:31 +0100 Subject: [PATCH] cmd/puppeth: make ssh prompt more user-friendly --- cmd/puppeth/ssh.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/cmd/puppeth/ssh.go b/cmd/puppeth/ssh.go index 052c97fa1..7e8ba3ccf 100644 --- a/cmd/puppeth/ssh.go +++ b/cmd/puppeth/ssh.go @@ -129,15 +129,20 @@ func dial(server string, pubkey []byte) (*sshClient, error) { fmt.Printf("SSH key fingerprint is %s [MD5]\n", ssh.FingerprintLegacyMD5(key)) fmt.Printf("Are you sure you want to continue connecting (yes/no)? ") - text, err := bufio.NewReader(os.Stdin).ReadString('\n') - switch { - case err != nil: - return err - case strings.TrimSpace(text) == "yes": - pubkey = key.Marshal() - return nil - default: - return fmt.Errorf("unknown auth choice: %v", text) + for { + text, err := bufio.NewReader(os.Stdin).ReadString('\n') + switch { + case err != nil: + return err + case strings.TrimSpace(text) == "yes": + pubkey = key.Marshal() + return nil + case strings.TrimSpace(text) == "no": + return errors.New("users says no") + default: + fmt.Println("Please answer 'yes' or 'no'") + continue + } } } // If a public key exists for this SSH server, check that it matches