ssh

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 32 Imported by: 4

Documentation

Overview

ssh package is that describes the whole process of connecting to ssh with lssh.

TODO(blacknon): 以下の機能について、汎用ライブラリとして外出しする

  • 認証系(AuthMap系?)
  • 鍵認証
  • パスワード認証
  • 証明書認証
  • PKCS11認証
  • ssh-agent認証
  • プロキシ系
  • http/httpsプロキシ
  • socks5プロキシ
  • ssh多段プロキシ
  • フォワード系
  • PortForward
  • X11Forward
  • シェルへの接続周り(local bashrcについては組み込まない)

Index

Constants

View Source
const (
	// AUTHKEY_AGENT  = "agent"
	AUTHKEY_KEY    = "key"
	AUTHKEY_CERT   = "cert"
	AUTHKEY_PKCS11 = "pkcs11"
)

Variables

This section is empty.

Functions

func GetProxyList added in v0.5.0

func GetProxyList(server string, config conf.Config) (proxyList []string, proxyType map[string]string, err error)

GetProxyList return proxy list and map by proxy type.

Types

type AuthKey added in v0.5.5

type AuthKey struct {
	// auth type:
	//   - key
	//   - cert
	//   - pkcs11
	Type string

	// auth type value:
	//   - key(path)
	//     ex.) ~/.ssh/id_rsa
	//   - cert(path)
	//     ex.) ~/.ssh/id_rsa.crt
	//   - pkcs11(libpath)
	//     ex.) /usr/local/lib/opensc-pkcs11.so
	Value string
}

Auth map key

type Connect added in v0.5.0

type Connect struct {
	// Name of server to connect.
	// It plays an important role in obtaining connection information from Configure.
	Server string

	// conf/Config Structure.
	Conf   conf.Config
	Client *ssh.Client

	// connect login shell flag
	IsTerm bool

	// parallel connect flag
	IsParallel bool

	// use local bashrc flag
	IsLocalRc bool

	// local bashrc data
	LocalRcData string

	// local bashrc decode command
	LocalRcDecodeCmd string

	// port forward setting.`host:port`
	ForwardLocal  string
	ForwardRemote string

	// x11 forward setting.
	X11 bool

	// AuthMap
	AuthMap map[AuthKey][]ssh.Signer
	// contains filtered or unexported fields
}

Connect structure to store contents about ssh connection.

func (*Connect) CheckClientAlive added in v0.5.5

func (c *Connect) CheckClientAlive() error

CheckClientAlive Check alive ssh.Client.

func (*Connect) ConTerm added in v0.5.0

func (c *Connect) ConTerm(session *ssh.Session) (err error)

ConTerm connect to a shell using a terminal.

func (*Connect) CreateClient added in v0.5.3

func (c *Connect) CreateClient() (err error)

CreateClient create ssh.Client and store in Connect.Client

func (*Connect) CreateSession added in v0.5.0

func (c *Connect) CreateSession() (session *ssh.Session, err error)

CreateSession return *ssh.Session

func (*Connect) CreateSshAgent added in v0.5.3

func (c *Connect) CreateSshAgent() (err error)

CreateSshAgent create sshAgent and into Connecct.sshAgent

func (*Connect) PortForwarder added in v0.5.2

func (c *Connect) PortForwarder()

PortForwarder port forwarding based on the value of Connect

func (*Connect) RunCmd added in v0.5.0

func (c *Connect) RunCmd(session *ssh.Session, command []string) (err error)

RunCmd execute command via ssh from specified session.

func (*Connect) RunCmdWithOutput added in v0.5.1

func (c *Connect) RunCmdWithOutput(session *ssh.Session, command []string, outputChan chan []byte)

RunCmdWithOutput execute a command via ssh from the specified session and send its output to outputchan.

func (*Connect) SendKeepAlive added in v0.5.5

func (c *Connect) SendKeepAlive(session *ssh.Session)

SendKeepAlive send KeepAlive packet from specified Session.

func (*Connect) X11Forwarder added in v0.5.6

func (c *Connect) X11Forwarder(session *ssh.Session)

type CopyConInfo added in v0.5.0

type CopyConInfo struct {
	IsRemote bool
	Path     []string
	Server   []string
}

type ExecHistory added in v0.5.5

type ExecHistory struct {
	Cmd        string
	OutputData *bytes.Buffer
	StdoutData *bytes.Buffer
	StderrData *bytes.Buffer
}

type History added in v0.5.5

type History struct {
	Timestamp string
	Command   string
}

History struct

type Output added in v0.5.5

type Output struct {
	// Template variable value.
	//     - ${COUNT}  ... Count value(int)
	//     - ${SERVER} ... Server Name
	//     - ${ADDR}   ... Address
	//     - ${USER}   ... User Name
	//     - ${PORT}   ... Port
	//     - ${DATE}   ... Date(YYYY/mm/dd)
	//     - ${YEAR}   ... Year(YYYY)
	//     - ${MONTH}  ... Month(mm)
	//     - ${DAY}    ... Day(dd)
	//     - ${TIME}   ... Time(HH:MM:SS)
	//     - ${HOUR}   ... Hour(HH)
	//     - ${MINUTE} ... Minute(MM)
	//     - ${SECOND} ... Second(SS)
	Templete string

	Count      int
	ServerList []string
	Conf       conf.ServerConfig
	AutoColor  bool
	// contains filtered or unexported fields
}

Output struct. command execute and lssh-shell mode output data.

func (*Output) Create added in v0.5.5

func (o *Output) Create(server string)

Create template, set variable value.

func (*Output) GetPrompt added in v0.5.5

func (o *Output) GetPrompt() (p string)

GetPrompt update variable value

type P11 added in v0.5.3

type P11 struct {
	Pkcs11Provider string
	Ctx            *pkcs11.Ctx
	Label          string
	SlotID         uint
	KeyID          map[int][]byte
	PIN            string
	SessionHandle  pkcs11.SessionHandle
	Signers        []ssh.Signer
}

P11 struct for pkcs11 processing.

func (*P11) CreateCtx added in v0.5.3

func (p *P11) CreateCtx(pkcs11Provider string) (err error)

CreateCtx create and into P11.Ctx

func (*P11) Get added in v0.5.5

func (p *P11) Get() (cryptoSigners []crypto.Signer, err error)

Get return []crypto.Signer, do a series of processing.

func (*P11) GetCryptoSigner added in v0.5.3

func (p *P11) GetCryptoSigner() (signers []crypto.Signer, err error)

GetCryptoSigner return []crypto.Signer

func (*P11) GetKeyID added in v0.5.3

func (p *P11) GetKeyID() (err error)

GetKeyID acquire KeyID via PKCS11 and store it in P11 structure.

func (*P11) GetPIN added in v0.5.3

func (p *P11) GetPIN() (err error)

GetPin prompt for PIN if P11.Pin is blank

func (*P11) GetTokenLabel added in v0.5.3

func (p *P11) GetTokenLabel() (err error)

GetTokenLabel get pkcs11 token label. and into P11.Label. Only one token is supported.

func (*P11) RecreateCtx added in v0.5.3

func (p *P11) RecreateCtx(pkcs11Provider string) (err error)

RecreateCtx exchange PKCS11.Ctx with PIN accessible ctx

type Parser added in v0.5.6

type Parser struct {
}

type Proxy added in v0.5.0

type Proxy struct {
	Name string
	Type string
}

type Run added in v0.5.0

type Run struct {
	ServerList        []string
	Conf              conf.Config
	IsTerm            bool
	IsParallel        bool
	IsShell           bool
	IsX11             bool
	PortForwardLocal  string
	PortForwardRemote string
	ExecCmd           []string
	StdinData         []byte
	InputData         []byte        // @TODO: Delete???
	OutputData        *bytes.Buffer // use terminal log
	AuthMap           map[AuthKey][]ssh.Signer
}

func (*Run) Start added in v0.5.0

func (r *Run) Start()

Start ssh connect

type RunScp added in v0.5.0

type RunScp struct {
	From       CopyConInfo
	To         CopyConInfo
	CopyData   *bytes.Buffer
	Permission bool
	Config     conf.Config
}

func (*RunScp) Start added in v0.5.0

func (r *RunScp) Start()

Start scp, switching process.

Jump to

Keyboard shortcuts

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