ssh

package
v0.0.0-...-93fed14 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: BSD-3-Clause Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSSHPort = 44338

DefaultSSHPort is the default SSH port of the NetBird's embedded SSH server

View Source
const RSAKeySize = 2048

RSAKeySize is a size of newly generated RSA key

View Source
const TerminalBackoffDelay = 500 * time.Millisecond

TerminalBackoffDelay is the delay between terminal session readiness checks

View Source
const TerminalTimeout = 10 * time.Second

TerminalTimeout is the timeout for terminal session to be ready

Variables

This section is empty.

Functions

func EncodePrivateKeyToPEM

func EncodePrivateKeyToPEM(privateKey crypto.Signer) ([]byte, error)

EncodePrivateKeyToPEM encodes Private Key from RSA to PEM format

func GeneratePrivateKey

func GeneratePrivateKey(keyType KeyType) ([]byte, error)

GeneratePrivateKey creates RSA Private Key of specified byte size

func GeneratePublicKey

func GeneratePublicKey(key []byte) ([]byte, error)

GeneratePublicKey returns the public part of the private key

Types

type Client

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

Client wraps crypto/ssh Client to simplify usage

func Dial

func Dial(network, addr string, config *ssh.ClientConfig) (*Client, error)

Dial connects to the remote SSH server.

func DialWithKey

func DialWithKey(addr, user string, privateKey []byte) (*Client, error)

DialWithKey connects to the remote SSH server with a provided private key file (PEM).

func (*Client) Close

func (c *Client) Close() error

Close closes the wrapped SSH Client

func (*Client) OpenTerminal

func (c *Client) OpenTerminal() error

OpenTerminal starts an interactive terminal session with the remote SSH server

type DefaultServer

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

DefaultServer is the embedded NetBird SSH server

func (*DefaultServer) AddAuthorizedKey

func (srv *DefaultServer) AddAuthorizedKey(peer, newKey string) error

AddAuthorizedKey add a given peer key to server authorized keys

func (*DefaultServer) RemoveAuthorizedKey

func (srv *DefaultServer) RemoveAuthorizedKey(peer string)

RemoveAuthorizedKey removes SSH key of a given peer from the authorized keys

func (*DefaultServer) Start

func (srv *DefaultServer) Start() error

Start starts SSH server. Blocking

func (*DefaultServer) Stop

func (srv *DefaultServer) Stop() error

Stop stops SSH server.

type KeyType

type KeyType string

KeyType is a type of SSH key

const ECDSA KeyType = "ecdsa"

ECDSA is key of type ecdsa

const ED25519 KeyType = "ed25519"

ED25519 is key of type ed25519

const RSA KeyType = "rsa"

RSA is key of type rsa

type MockServer

type MockServer struct {
	Ctx                     context.Context
	StopFunc                func() error
	StartFunc               func() error
	AddAuthorizedKeyFunc    func(peer, newKey string) error
	RemoveAuthorizedKeyFunc func(peer string)
}

MockServer mocks ssh.Server

func (*MockServer) AddAuthorizedKey

func (srv *MockServer) AddAuthorizedKey(peer, newKey string) error

AddAuthorizedKey add a given peer key to server authorized keys

func (*MockServer) RemoveAuthorizedKey

func (srv *MockServer) RemoveAuthorizedKey(peer string)

RemoveAuthorizedKey removes SSH key of a given peer from the authorized keys

func (*MockServer) Start

func (srv *MockServer) Start() error

Start starts SSH server. Blocking

func (*MockServer) Stop

func (srv *MockServer) Stop() error

Stop stops SSH server.

type Server

type Server interface {
	// Stop stops SSH server.
	Stop() error
	// Start starts SSH server. Blocking
	Start() error
	// RemoveAuthorizedKey removes SSH key of a given peer from the authorized keys
	RemoveAuthorizedKey(peer string)
	// AddAuthorizedKey add a given peer key to server authorized keys
	AddAuthorizedKey(peer, newKey string) error
}

Server is an interface of SSH server

func DefaultSSHServer

func DefaultSSHServer(hostKeyPEM []byte, addr string) (Server, error)

DefaultSSHServer is a function that creates DefaultServer

Jump to

Keyboard shortcuts

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