sshport

package
v0.0.0-...-3e76ffc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SSHConnectionHandler

type SSHConnectionHandler struct {
	// contains filtered or unexported fields
}

SSHConnectionHandler is a helper struct for creating net.Listener that can be forwarded with ssh. It should be used in the following manner:

func sshTcpIpTest(logger logger.Logger, ctx context.Context) {
	var tcpipHandler = NewSSHConnectionHandler(logger, ctx)
	var sshServer = &ssh.Server{
		LocalPortForwardingCallback: func(ctx ssh.Context, destinationHost string, destinationPort uint32) bool {
			return true
		},
	}
	// Add it as tcpip handler in the ssh connection
	sshServer.ChannelHandlers = map[string]ssh.ChannelHandler{
		"session":      ssh.DefaultSessionHandler,
		"direct-tcpip": tcpipHandler.HandleTCPIP,
	}
	// We now create a simple http server that the user "peter" can forward from port 8080
	listener := tcpipHandler.CreateListener(8080, "peter")
	server := http.Server{}
	go server.Serve(listener)
}

func NewSSHConnectionHandler

func NewSSHConnectionHandler(logger logger.Logger, ctx context.Context) SSHConnectionHandler

NewSSHConnectionHandler creates a new SSHConnectionHandler in the given ctx and logs with the given logger.

func (*SSHConnectionHandler) CreateListener

func (s *SSHConnectionHandler) CreateListener(port uint32, user string) net.Listener

CreateListener creates a new net.Listener for the given user at the specific port. So only this user can forward this net.Listener with ssh. If user is empty, this listener is active for all users.

func (*SSHConnectionHandler) HandleTCPIP

func (s *SSHConnectionHandler) HandleTCPIP(srv *gssh.Server, conn *ssh.ServerConn, newChan ssh.NewChannel, ctx gssh.Context)

HandleTCPIP implements a direct-tcpip ssh.ChannelHandler for forward a tcp/ip connection through ssh. This code is highly copied from https://github.com/gliderlabs/ssh/blob/30ec06db4e743ac9f827a69c8b8cfb84064a6dc7/tcpip.go#L28=

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL