2015-01-02 15:51:37 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-09-23 18:30:44 +00:00
|
|
|
"fmt"
|
2015-01-02 15:51:37 +00:00
|
|
|
"golang.org/x/crypto/ssh"
|
2015-01-02 17:01:52 +00:00
|
|
|
"runtime"
|
2015-01-02 15:51:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
2015-09-23 18:30:44 +00:00
|
|
|
// Show the current version:
|
|
|
|
fmt.Println(`SSHTunnel v1.1.0`)
|
|
|
|
|
2015-01-02 17:01:52 +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-01-02 17:01:52 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-02 17:01:52 +00:00
|
|
|
// Create the SSH configuration:
|
2015-01-02 15:51:37 +00:00
|
|
|
config := &ssh.ClientConfig{
|
|
|
|
User: username,
|
|
|
|
Auth: []ssh.AuthMethod{
|
|
|
|
ssh.Password(password),
|
|
|
|
ssh.PasswordCallback(passwordCallback),
|
|
|
|
ssh.KeyboardInteractive(keyboardInteractiveChallenge),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-01-02 17:01:52 +00:00
|
|
|
// Create the local end-point:
|
|
|
|
localListener := createLocalEndPoint()
|
2015-01-02 15:51:37 +00:00
|
|
|
|
2015-01-02 17:01:52 +00:00
|
|
|
// Accept client connections (will block forever):
|
|
|
|
acceptClients(localListener, config)
|
2015-01-02 15:51:37 +00:00
|
|
|
}
|