SSHTunnel/Main.go

49 lines
1.1 KiB
Go
Raw Normal View History

2015-01-02 15:51:37 +00:00
package main
import (
2015-09-23 18:30:44 +00:00
"fmt"
2015-09-28 13:28:11 +00:00
"github.com/SommerEngineering/SSHTunnel/Tunnel"
2015-01-02 15:51:37 +00:00
"golang.org/x/crypto/ssh"
"runtime"
2015-01-02 15:51:37 +00:00
)
func main() {
2015-09-23 18:30:44 +00:00
// Show the current version:
2015-09-28 13:28:11 +00:00
fmt.Println(`SSHTunnel v1.2.0`)
2015-09-23 18:30:44 +00:00
// Allow Go to use all CPUs:
runtime.GOMAXPROCS(runtime.NumCPU())
// Read the configuration from the command-line args:
2015-01-02 15:51:37 +00:00
readFlags()
2015-09-23 18:30:44 +00:00
// 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:
2015-09-28 13:28:11 +00:00
Tunnel.SetPassword4Callback(password)
2015-01-02 15:51:37 +00:00
config := &ssh.ClientConfig{
User: username,
Auth: []ssh.AuthMethod{
ssh.Password(password),
2015-09-28 13:28:11 +00:00
ssh.PasswordCallback(Tunnel.PasswordCallback),
ssh.KeyboardInteractive(Tunnel.KeyboardInteractiveChallenge),
2015-01-02 15:51:37 +00:00
},
}
// Create the local end-point:
2015-09-28 13:28:11 +00:00
localListener := Tunnel.CreateLocalEndPoint(localAddrString)
2015-01-02 15:51:37 +00:00
// Accept client connections (will block forever):
2015-09-28 13:28:11 +00:00
Tunnel.AcceptClients(localListener, config, serverAddrString, remoteAddrString)
2015-01-02 15:51:37 +00:00
}