From c85e21231b9aa313f1fe52de7d615c304f1d7287 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Wed, 16 Mar 2016 08:05:56 +0100 Subject: [PATCH] Version 1.3.0 In case the password must provided interactively, it is now invisible. --- Main.go | 105 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 57 insertions(+), 48 deletions(-) diff --git a/Main.go b/Main.go index 19b85bd..2d16cf3 100644 --- a/Main.go +++ b/Main.go @@ -1,48 +1,57 @@ -package main - -import ( - "fmt" - "github.com/SommerEngineering/SSHTunnel/Tunnel" - "golang.org/x/crypto/ssh" - "runtime" -) - -func main() { - - // Show the current version: - fmt.Println(`SSHTunnel v1.2.0`) - - // Allow Go to use all CPUs: - runtime.GOMAXPROCS(runtime.NumCPU()) - - // Read the configuration from the command-line args: - readFlags() - - // Check if the password was provided: - for true { - if password == `` { - // Promt for the password: - fmt.Println(`Please provide the password for the connection:`) - fmt.Scanln(&password) - } else { - break - } - } - - // Create the SSH configuration: - Tunnel.SetPassword4Callback(password) - config := &ssh.ClientConfig{ - User: username, - Auth: []ssh.AuthMethod{ - ssh.Password(password), - ssh.PasswordCallback(Tunnel.PasswordCallback), - ssh.KeyboardInteractive(Tunnel.KeyboardInteractiveChallenge), - }, - } - - // Create the local end-point: - localListener := Tunnel.CreateLocalEndPoint(localAddrString) - - // Accept client connections (will block forever): - Tunnel.AcceptClients(localListener, config, serverAddrString, remoteAddrString) -} +package main + +import ( + "fmt" + "github.com/SommerEngineering/SSHTunnel/Tunnel" + "github.com/howeyc/gopass" + "golang.org/x/crypto/ssh" + "log" + "os" + "runtime" +) + +func main() { + + // Show the current version: + log.Println(`SSHTunnel v1.3.0`) + + // Allow Go to use all CPUs: + runtime.GOMAXPROCS(runtime.NumCPU()) + + // Read the configuration from the command-line args: + readFlags() + + // Check if the password was provided: + for true { + if password == `` { + // Promt for the password: + fmt.Println(`Please provide the password for the connection:`) + if pass, errPass := gopass.GetPasswd(); errPass != nil { + log.Println(`There was an error reading the password securely: ` + errPass.Error()) + os.Exit(1) + return + } else { + password = string(pass) + } + } else { + break + } + } + + // Create the SSH configuration: + Tunnel.SetPassword4Callback(password) + config := &ssh.ClientConfig{ + User: username, + Auth: []ssh.AuthMethod{ + ssh.Password(password), + ssh.PasswordCallback(Tunnel.PasswordCallback), + ssh.KeyboardInteractive(Tunnel.KeyboardInteractiveChallenge), + }, + } + + // Create the local end-point: + localListener := Tunnel.CreateLocalEndPoint(localAddrString) + + // Accept client connections (will block forever): + Tunnel.AcceptClients(localListener, config, serverAddrString, remoteAddrString) +}