v0.0.0-...-1a11905 Latest Latest

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

Go to latest
Published: Aug 25, 2020 License: Apache-2.0 Imports: 27 Imported by: 0




This section is empty.


View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is the error returned if a something is not found.


func Fingerprint

func Fingerprint(in []byte) (string, error)

Fingerprint returns the key size, fingerprint, comment and algorithm of a public key.

func NewCertSigner

func NewCertSigner(cert *ssh.Certificate, priv interface{}) (ssh.Signer, error)

NewCertSigner creates a new signer with the given certificate and private key.

func ParseCertificate

func ParseCertificate(in []byte) (*ssh.Certificate, error)

ParseCertificate returns a certificate from the marshaled bytes.

func ProxyCommand

func ProxyCommand(cmd, user, host, port string) string

ProxyCommand replaces %%, %h, %p, and %r in the given command.

%%  A literal `%`.
%h  The remote hostname.
%p  The remote port.
%r  The remote username.

func PublicKey

func PublicKey(key ssh.PublicKey) (crypto.PublicKey, error)

PublicKey returns the Go's crypto.PublicKey of an ssh.PublicKey.


type Agent

type Agent struct {
	Conn net.Conn

Agent represents a client to an ssh.Agent.

func DialAgent

func DialAgent() (*Agent, error)

DialAgent returns an ssh.Agent client. It uses the SSH_AUTH_SOCK to connect to the agent.

func (*Agent) AddCertificate

func (a *Agent) AddCertificate(subject string, cert *ssh.Certificate, priv interface{}) error

AddCertificate adds the given certificate to the agent.

func (*Agent) AuthMethod

func (a *Agent) AuthMethod() ssh.AuthMethod

AuthMethod returns the ssh.Agent as an ssh.AuthMethod.

func (*Agent) Close

func (a *Agent) Close() error

Close closes the connection to the agent.

func (*Agent) GetKey

func (a *Agent) GetKey(comment string, opts ...AgentOption) (*agent.Key, error)

GetKey retrieves a key from the agent by the given comment.

func (*Agent) GetSigner

func (a *Agent) GetSigner(comment string, opts ...AgentOption) (ssh.Signer, error)

GetSigner returns a signer that has a key with the given comment.

func (*Agent) HasKeys

func (a *Agent) HasKeys(opts ...AgentOption) (bool, error)

HasKeys returns if a key filtered with the given options exists.

func (*Agent) ListCertificates

func (a *Agent) ListCertificates(opts ...AgentOption) ([]*ssh.Certificate, error)

ListCertificates returns the list of certificates in the agent.

func (*Agent) ListKeys

func (a *Agent) ListKeys(opts ...AgentOption) ([]*agent.Key, error)

ListKeys returns the list of keys in the agent.

func (*Agent) RemoveKeys

func (a *Agent) RemoveKeys(comment string, opts ...AgentOption) (bool, error)

RemoveKeys removes the keys with the given comment from the agent.

type AgentOption

type AgentOption func(o *options)

AgentOption is the type used for variadic options in Agent methods.

func WithRemoveExpiredCerts

func WithRemoveExpiredCerts(t time.Time) AgentOption

WithRemoveExpiredCerts will remove the expired certificates automatically.

func WithSignatureKey

func WithSignatureKey(keys []ssh.PublicKey) AgentOption

WithSignatureKey filters certificate not signed by the given signing keys.

type CertificateInspect

type CertificateInspect struct {
	Type                  string
	KeyName               string
	KeyID                 string
	KeyAlgo               string
	KeyFingerprint        string
	SigningKeyAlgo        string
	SigningKeyFingerprint string
	Serial                uint64
	ValidAfter            time.Time
	ValidBefore           time.Time
	Principals            []string
	CriticalOptions       map[string]string
	Extensions            map[string]string

CertificateInspect contains details of an ssh.Certificate in human readable format.

func InspectCertificate

func InspectCertificate(cert *ssh.Certificate) (*CertificateInspect, error)

InspectCertificate returns a CertificateInspect with the properties of the given ssh.Certificate.

func (*CertificateInspect) Validity

func (c *CertificateInspect) Validity() string

Validity returns a human version of the validity of the certificate. It returns the dates using the local time zone to behave as ssh-keygen.

type Shell

type Shell struct {
	// contains filtered or unexported fields

Shell implements a remote shell to an SSH server using x/crypto/ssh

func NewShell

func NewShell(user, address string, opts ...ShellOption) (*Shell, error)

NewShell initializes a new shell to the given address.

func (*Shell) Close

func (s *Shell) Close() error

Close finalizes the connection.

func (*Shell) LocalForward

func (s *Shell) LocalForward(bindNetwork, bindAddress, hostNetwork, hostAddress string) error

LocalForward creates a local listener in the bindAddress forwarding the packages to the remote hostAddress.

func (*Shell) RemoteForward

func (s *Shell) RemoteForward(bindNetwork, bindAddress, hostNetwork, hostAddress string) error

RemoteForward creates a remote listener in the bindAddress and forwards the packages to the local hostAddress.

func (*Shell) RemoteShell

func (s *Shell) RemoteShell() error

RemoteShell starts a login shell on the remote host.

func (*Shell) Run

func (s *Shell) Run(cmd string) error

Run runs cmd on the remote host.

type ShellOption

type ShellOption func(s *Shell) error

ShellOption is the type used to add new options to the shell.

func WithAddUser

func WithAddUser(user string, cert *ssh.Certificate, priv interface{}) ShellOption

WithAddUser uses the given provisioner certificate to add an user in the server.

func WithAuthMethod

func WithAuthMethod(am ssh.AuthMethod) ShellOption

WithAuthMethod adds a new ssh.AuthMethod to the shell.

func WithBastion

func WithBastion(user, address, command string) ShellOption

WithBastion forward the connection through the given bastion address.

func WithCertificate

func WithCertificate(cert *ssh.Certificate, priv interface{}) ShellOption

WithCertificate adds a signer with the given certificate as an ssh.AuthMethod.

func WithProxyCommand

func WithProxyCommand(command string) ShellOption

WithProxyCommand forwards the connection through the given command

func WithSigner

func WithSigner(signer ssh.Signer) ShellOption

WithSigner adds the given signer as an ssh.AuthMethod.

Jump to

Keyboard shortcuts

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