sshutil

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

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

Functions

func Fingerprint

func Fingerprint(in []byte, opts ...FingerprintOption) (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.

Types

type Agent

type Agent struct {
	agent.ExtendedAgent
	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) RemoveAllKeys added in v0.18.1

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

RemoveAllKeys removes from the agent all the keys matching the given options.

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 WithCertsOnly added in v0.18.1

func WithCertsOnly() AgentOption

WithCertsOnly filters only those keys accompanied by a certificate.

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
	Signature             Signature
	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 FingerprintOption added in v0.18.1

type FingerprintOption func(*fingerprintOptions)

FingerprintOption customizes the fingerprint generation.

func WithFingerprintOptions added in v0.18.1

func WithFingerprintOptions(opts ...fingerprint.Option) FingerprintOption

WithFingerprintOptions sets the fingerprint options.

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 WithCertificate

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

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

func WithSigner

func WithSigner(signer ssh.Signer) ShellOption

WithSigner adds the given signer as an ssh.AuthMethod.

type Signature added in v0.22.0

type Signature struct {
	Type  string
	Value []byte
	Rest  []byte `json:",omitempty"`
}

Jump to

Keyboard shortcuts

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