obfssh

package module
v0.0.0-...-e372dc1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2019 License: LGPL-3.0 Imports: 23 Imported by: 0

README

obfssh

obfssh is wrapper for golang.org/x/crypto/ssh protocol, add support for listen or connect ssh via TLS

server usage example

import "github.com/fangdingjun/obfssh"
import "golang.org/x/crypto/ssh"


config := &ssh.ServerConfig{
	// add ssh server configure here
	// for example auth method, cipher, MAC
	...
}

var l net.Listener
var err error
if useTLS {
    cert, err := tls.LoadX509KeyPair(certFile, keyFile)
    l, err = tls.Listen("tcp", ":2022", &tls.Config{
        Certificates: []tls.Certificate{cert},
    }
}else{
    l, err = net.Listen(":2022")
}

defer l.Close()

for {
    c, err := l.Accept()
    go func(c net.Conn){
        defer c.Close()
        sc, err := obfssh.NewServer(c, config, &obfssh.Conf{})
        sc.Run()
    }(c)
}

client usage example

import "github.com/fangdingjun/obfssh"
import "golang.org/x/crypto/ssh"

addr := "localhost:2022"

config := ssh.ClientConfig{
	// add ssh client config here
	// for example auth method
	...
}

var c net.Conn
var err error 
if useTLS {
    c, err = tls.Dial("tcp", addr, &tls.Config{
        ServerName: "localhost",
        InsecureSkipVerify: true,
    }
}else{
    c, err = net.Dial("tcp", addr)
}

// create connection
client, err := obfssh.NewClient(c, config, addr, &obfssh.Conf{})

// local to remote port forward
client.AddLocalForward(":2234:10.0.0.1:3221")

// remote to local port forward
client.AddRemoteForward(":2234:10.2.0.1:3221")

// dynamic port forward
client.AddDynamicForward(":4321")

// wait to be done
client.Run()

limitions

now, the server side only implements the port forward function, start shell or execute a command is not suppurted

License

GPLv3, see LICENSE file details

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PipeAndClose

func PipeAndClose(c io.ReadWriteCloser, s io.ReadWriteCloser)

PipeAndClose pipe the data between c and s, close both when done

Types

type Client

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

Client is ssh client connection

func NewClient

func NewClient(c net.Conn, config *ssh.ClientConfig, addr string, conf *Conf) (*Client, error)

NewClient create a new ssh Client

addr is server address

conf is the client configure

func (*Client) AddDynamicForward

func (cc *Client) AddDynamicForward(local string) error

AddDynamicForward add a dynamic port forward

func (*Client) AddDynamicHTTPForward

func (cc *Client) AddDynamicHTTPForward(addr string) error

AddDynamicHTTPForward add a http dynamic forward through

secure channel

func (*Client) AddLocalForward

func (cc *Client) AddLocalForward(local, remote string) error

AddLocalForward add a local to remote port forward

func (*Client) AddRemoteForward

func (cc *Client) AddRemoteForward(local, remote string) error

AddRemoteForward add a remote to local port forward

func (*Client) Client

func (cc *Client) Client() *ssh.Client

Client return *ssh.Client

func (*Client) Close

func (cc *Client) Close()

Close close the ssh connection and free all the port forward resources

func (*Client) Run

func (cc *Client) Run() error

Run wait ssh connection to finish

func (*Client) RunCmd

func (cc *Client) RunCmd(cmd string) ([]byte, error)

RunCmd run a single command on server

func (*Client) Shell

func (cc *Client) Shell() error

Shell start a login shell on server

type Conf

type Conf struct {

	// Timeout is the socket timeout on read/write
	Timeout time.Duration

	// KeepAliveInterval  the keep alive interval
	KeepAliveInterval time.Duration

	// KeepAliveMax the max times of keep alive error
	KeepAliveMax int
}

Conf keeps the configure of server or client

type Server

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

Server is server connection

func NewServer

func NewServer(c net.Conn, config *ssh.ServerConfig, conf *Conf) (*Server, error)

NewServer create a new struct for Server

c is net.Conn

config is &ssh.ServerConfig

conf is the server configure

func (*Server) Run

func (sc *Server) Run()

Run waits for server connection finish

type TimedOutConn

type TimedOutConn struct {
	net.Conn
	Timeout time.Duration
}

TimedOutConn is a net.Conn with read/write timeout set

func (*TimedOutConn) Read

func (tc *TimedOutConn) Read(b []byte) (int, error)

func (*TimedOutConn) Write

func (tc *TimedOutConn) Write(b []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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