Compare commits

...

5 Commits

Author SHA1 Message Date
Thorsten Sommer
56f0a8dd64 Merge branch 'master' of github.com:SommerEngineering/SSHTunnel 2016-03-16 08:08:08 +01:00
Thorsten Sommer
c85e21231b Version 1.3.0
In case the password must provided interactively, it is now invisible.
2016-03-16 08:05:56 +01:00
Thorsten Sommer
6146f74c72 Update README.md 2015-09-28 16:07:29 +02:00
Thorsten Sommer
c2a03bfdcf Update README.md 2015-09-28 16:07:00 +02:00
Thorsten Sommer
a16b99af6e Version 1.2.0 2015-09-28 15:28:11 +02:00
12 changed files with 308 additions and 287 deletions

23
Main.go
View File

@ -2,14 +2,18 @@ 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:
fmt.Println(`SSHTunnel v1.1.0`)
log.Println(`SSHTunnel v1.3.0`)
// Allow Go to use all CPUs:
runtime.GOMAXPROCS(runtime.NumCPU())
@ -22,25 +26,32 @@ func main() {
if password == `` {
// Promt for the password:
fmt.Println(`Please provide the password for the connection:`)
fmt.Scanln(&password)
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(passwordCallback),
ssh.KeyboardInteractive(keyboardInteractiveChallenge),
ssh.PasswordCallback(Tunnel.PasswordCallback),
ssh.KeyboardInteractive(Tunnel.KeyboardInteractiveChallenge),
},
}
// Create the local end-point:
localListener := createLocalEndPoint()
localListener := Tunnel.CreateLocalEndPoint(localAddrString)
// Accept client connections (will block forever):
acceptClients(localListener, config)
Tunnel.AcceptClients(localListener, config, serverAddrString, remoteAddrString)
}

View File

@ -1,6 +0,0 @@
package main
// Just a callback function for the password request.
func passwordCallback() (string, error) {
return password, nil
}

View File

@ -22,6 +22,7 @@ SSHTunnel is a tiny small program to tunnel something through a SSH without any
- At the moment, SSHTunnel uses only the password authentication methods. Therefore, it is currently not possible to use e.g. a certificate, etc. Nevertheless, the implementation of this feature is possible.
- The configuration must be provided by using the command-line arguments. It is currently not possible to use e.g. a configuration file.
- You can avoid the password argument if you prefer to provide the password on demand.
- [Ocean Remote Connections](https://github.com/SommerEngineering/OceanRemoteConnections) is a simple GUI for SSH Tunnel, PuTTY, RDP and WinSCP.
### Download
Go and get the latest release from the [release page](https://github.com/SommerEngineering/SSHTunnel/releases).

View File

@ -1,4 +1,4 @@
package main
package Tunnel
import (
"golang.org/x/crypto/ssh"
@ -6,7 +6,7 @@ import (
"net"
)
func acceptClients(connection net.Listener, config *ssh.ClientConfig) {
func AcceptClients(connection net.Listener, config *ssh.ClientConfig, serverAddrString, remoteAddrString string) {
// Endless loop
for {
@ -22,7 +22,7 @@ func acceptClients(connection net.Listener, config *ssh.ClientConfig) {
log.Println(`Client accepted.`)
// Start the forwarding:
go forward(localConn, config)
go forward(localConn, config, serverAddrString, remoteAddrString)
}
}
}

View File

@ -1,4 +1,4 @@
package main
package Tunnel
const (
maxRetriesLocal = 16 // How many retries are allowed to create the local end-point?

View File

@ -1,4 +1,4 @@
package main
package Tunnel
import (
"log"
@ -6,7 +6,7 @@ import (
"time"
)
func createLocalEndPoint() (localListener net.Listener) {
func CreateLocalEndPoint(localAddrString string) (localListener net.Listener) {
// Loop for the necessary retries
for {

View File

@ -1,4 +1,4 @@
package main
package Tunnel
import (
"golang.org/x/crypto/ssh"
@ -7,7 +7,7 @@ import (
"time"
)
func forward(localConn net.Conn, config *ssh.ClientConfig) {
func forward(localConn net.Conn, config *ssh.ClientConfig, serverAddrString, remoteAddrString string) {
defer localConn.Close()
currentRetriesServer := 0

View File

@ -1,11 +1,11 @@
package main
package Tunnel
import (
"log"
)
// Another auth. method.
func keyboardInteractiveChallenge(user, instruction string, questions []string, echos []bool) (answers []string, err error) {
func KeyboardInteractiveChallenge(user, instruction string, questions []string, echos []bool) (answers []string, err error) {
// Log all the provided data:
log.Println(`User: ` + user)
@ -22,7 +22,7 @@ func keyboardInteractiveChallenge(user, instruction string, questions []string,
// We expect that in this case (only one question is asked), that the server want to know the password ;-)
answers = make([]string, countQuestions, countQuestions)
answers[0] = password
answers[0] = callbackPassword
} else if countQuestions > 1 {

View File

@ -0,0 +1,10 @@
package Tunnel
// Just a callback function for the password request.
func PasswordCallback() (string, error) {
return callbackPassword, nil
}
func SetPassword4Callback(password string) {
callbackPassword = password
}

View File

@ -1,4 +1,4 @@
package main
package Tunnel
import (
"io"

6
Tunnel/Variables.go Normal file
View File

@ -0,0 +1,6 @@
package Tunnel
var (
currentRetriesLocal = 0 // Check how many retries are occur for creating the local end-point
callbackPassword = ``
)

View File

@ -1,10 +1,9 @@
package main
var (
username = `` // The SSH user's name
password = `` // The user's password
serverAddrString = `` // The SSH server address
localAddrString = `` // The local end-point
remoteAddrString = `` // The remote end-point (on the SSH server's side)
currentRetriesLocal = 0 // Check how many retries are occur for creating the local end-point
username = `` // The SSH user's name
password = `` // The user's password
serverAddrString = `` // The SSH server address
localAddrString = `` // The local end-point
remoteAddrString = `` // The remote end-point (on the SSH server's side)
)