Version 1.2.0
This commit is contained in:
parent
aab3524082
commit
a16b99af6e
12
Main.go
12
Main.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/SommerEngineering/SSHTunnel/Tunnel"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
@ -9,7 +10,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// Show the current version:
|
// Show the current version:
|
||||||
fmt.Println(`SSHTunnel v1.1.0`)
|
fmt.Println(`SSHTunnel v1.2.0`)
|
||||||
|
|
||||||
// Allow Go to use all CPUs:
|
// Allow Go to use all CPUs:
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
@ -29,18 +30,19 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the SSH configuration:
|
// Create the SSH configuration:
|
||||||
|
Tunnel.SetPassword4Callback(password)
|
||||||
config := &ssh.ClientConfig{
|
config := &ssh.ClientConfig{
|
||||||
User: username,
|
User: username,
|
||||||
Auth: []ssh.AuthMethod{
|
Auth: []ssh.AuthMethod{
|
||||||
ssh.Password(password),
|
ssh.Password(password),
|
||||||
ssh.PasswordCallback(passwordCallback),
|
ssh.PasswordCallback(Tunnel.PasswordCallback),
|
||||||
ssh.KeyboardInteractive(keyboardInteractiveChallenge),
|
ssh.KeyboardInteractive(Tunnel.KeyboardInteractiveChallenge),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the local end-point:
|
// Create the local end-point:
|
||||||
localListener := createLocalEndPoint()
|
localListener := Tunnel.CreateLocalEndPoint(localAddrString)
|
||||||
|
|
||||||
// Accept client connections (will block forever):
|
// Accept client connections (will block forever):
|
||||||
acceptClients(localListener, config)
|
Tunnel.AcceptClients(localListener, config, serverAddrString, remoteAddrString)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
// Just a callback function for the password request.
|
|
||||||
func passwordCallback() (string, error) {
|
|
||||||
return password, nil
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package main
|
package Tunnel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
@ -6,7 +6,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
func acceptClients(connection net.Listener, config *ssh.ClientConfig) {
|
func AcceptClients(connection net.Listener, config *ssh.ClientConfig, serverAddrString, remoteAddrString string) {
|
||||||
|
|
||||||
// Endless loop
|
// Endless loop
|
||||||
for {
|
for {
|
||||||
@ -22,7 +22,7 @@ func acceptClients(connection net.Listener, config *ssh.ClientConfig) {
|
|||||||
log.Println(`Client accepted.`)
|
log.Println(`Client accepted.`)
|
||||||
|
|
||||||
// Start the forwarding:
|
// Start the forwarding:
|
||||||
go forward(localConn, config)
|
go forward(localConn, config, serverAddrString, remoteAddrString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package main
|
package Tunnel
|
||||||
|
|
||||||
const (
|
const (
|
||||||
maxRetriesLocal = 16 // How many retries are allowed to create the local end-point?
|
maxRetriesLocal = 16 // How many retries are allowed to create the local end-point?
|
@ -1,4 +1,4 @@
|
|||||||
package main
|
package Tunnel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
@ -6,7 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func createLocalEndPoint() (localListener net.Listener) {
|
func CreateLocalEndPoint(localAddrString string) (localListener net.Listener) {
|
||||||
|
|
||||||
// Loop for the necessary retries
|
// Loop for the necessary retries
|
||||||
for {
|
for {
|
@ -1,4 +1,4 @@
|
|||||||
package main
|
package Tunnel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
@ -7,7 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func forward(localConn net.Conn, config *ssh.ClientConfig) {
|
func forward(localConn net.Conn, config *ssh.ClientConfig, serverAddrString, remoteAddrString string) {
|
||||||
|
|
||||||
defer localConn.Close()
|
defer localConn.Close()
|
||||||
currentRetriesServer := 0
|
currentRetriesServer := 0
|
@ -1,11 +1,11 @@
|
|||||||
package main
|
package Tunnel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Another auth. method.
|
// 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 all the provided data:
|
||||||
log.Println(`User: ` + user)
|
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 ;-)
|
// 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 = make([]string, countQuestions, countQuestions)
|
||||||
answers[0] = password
|
answers[0] = callbackPassword
|
||||||
|
|
||||||
} else if countQuestions > 1 {
|
} else if countQuestions > 1 {
|
||||||
|
|
10
Tunnel/PasswordCallback.go
Normal file
10
Tunnel/PasswordCallback.go
Normal 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
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package main
|
package Tunnel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
6
Tunnel/Variables.go
Normal file
6
Tunnel/Variables.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package Tunnel
|
||||||
|
|
||||||
|
var (
|
||||||
|
currentRetriesLocal = 0 // Check how many retries are occur for creating the local end-point
|
||||||
|
callbackPassword = ``
|
||||||
|
)
|
@ -6,5 +6,4 @@ var (
|
|||||||
serverAddrString = `` // The SSH server address
|
serverAddrString = `` // The SSH server address
|
||||||
localAddrString = `` // The local end-point
|
localAddrString = `` // The local end-point
|
||||||
remoteAddrString = `` // The remote end-point (on the SSH server's side)
|
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
|
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user