sshtest

package module
v0.0.0-...-5c1cfc5 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2020 License: MIT Imports: 12 Imported by: 0

README

go-sshtest

This code must helps you to test your ssh client.

Documentation

Index

Examples

Constants

View Source
const (
	ServerVersion = "SSH-2.0-ServerMock 1.0"
)

Variables

This section is empty.

Functions

func DebugOff

func DebugOff()

func DebugOn

func DebugOn()

func NewRSAKey

func NewRSAKey(bitSize int) *rsa.PrivateKey

func NewSSHKeyPair

func NewSSHKeyPair(bitSize int) (private *rsa.PrivateKey, public ssh.PublicKey)

NewSSHKeyPair generate new key pair

Example
// prepare keys
privateKey, publicKey := sshtest.NewSSHKeyPair(2048)

// auth in your client with agent
myAgent := agent.NewKeyring()
_ = myAgent.Add(agent.AddedKey{PrivateKey: privateKey})
_ = &ssh.ClientConfig{
	Auth: []ssh.AuthMethod{
		ssh.PublicKeysCallback(func() (signers []ssh.Signer, err error) {
			return myAgent.Signers()
		}),
	},
}

// auth in your client with signer from key
signer, _ := ssh.NewSignerFromKey(privateKey)
_ = &ssh.ClientConfig{
	Auth: []ssh.AuthMethod{
		ssh.PublicKeysCallback(func() (signers []ssh.Signer, err error) {
			return []ssh.Signer{signer}, nil
		}),
	},
}

// publicKeyCallback in your server
_ = &ssh.ServerConfig{
	PublicKeyCallback: func(c ssh.ConnMetadata, pubKey ssh.PublicKey) (*ssh.Permissions, error) {
		if string(publicKey.Marshal()) == string(pubKey.Marshal()) {
			return &ssh.Permissions{
				// Record the public key used for authentication.
				Extensions: map[string]string{
					"pubkey-fp": ssh.FingerprintSHA256(pubKey),
				},
			}, nil

		}
		return nil, fmt.Errorf("unknown public key for %q", c.User())
	},
}
Output:

Types

type Channel

type Channel struct {
	ssh.Channel
	Type string
	// contains filtered or unexported fields
}

func NewChannel

func NewChannel(channel ssh.NewChannel, mockData *MockData) *Channel

func (*Channel) Requests

func (s *Channel) Requests() []interface{}

type ChannelStat

type ChannelStat struct {
}

type Connection

type Connection struct {
	net.Conn
	ClientConn *ssh.ServerConn
	// contains filtered or unexported fields
}

func NewConnection

func NewConnection(conn net.Conn, mockData *MockData) *Connection

func (*Connection) ServedChannels

func (s *Connection) ServedChannels() []*Channel

type ConnectionStat

type ConnectionStat struct {
}

type MockData

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

func NewMockData

func NewMockData() *MockData

func (*MockData) MockExecResult

func (m *MockData) MockExecResult(command, result string, timeout time.Duration, exitStatus uint32)

type Server

type Server struct {
	// ssh server config
	*ssh.ServerConfig

	*MockData

	// timeout before force disconnect all clients when server is stopping
	StopTimeout time.Duration
	// contains filtered or unexported fields
}

func NewMockedServer

func NewMockedServer() (server *Server)

func NewServer

func NewServer(listenAddr string, serverKey ssh.Signer) (server *Server)

func (*Server) AddAuthorizedKey

func (s *Server) AddAuthorizedKey(key ssh.PublicKey)

func (*Server) ServedConnections

func (s *Server) ServedConnections() []*Connection

func (*Server) Start

func (s *Server) Start() (address string, port uint16, err error)

func (*Server) Stop

func (s *Server) Stop()

func (*Server) Wait

func (s *Server) Wait()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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