Documentation ¶
Index ¶
- func HostKeyAlgorithms(cb ssh.HostKeyCallback, hostWithPort string) []string
- func IsHostKeyChanged(err error) bool
- func IsHostUnknown(err error) bool
- func Line(addresses []string, key ssh.PublicKey) string
- func Normalize(address string) string
- func WriteKnownHost(w io.Writer, hostname string, remote net.Addr, key ssh.PublicKey) error
- type HostKeyCallback
- type HostKeyDB
- type PublicKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HostKeyAlgorithms ¶
func HostKeyAlgorithms(cb ssh.HostKeyCallback, hostWithPort string) []string
HostKeyAlgorithms is a convenience function for performing host key algorithm lookups on an ssh.HostKeyCallback directly. It is intended for use in code paths that stay with the New method of golang.org/x/crypto/ssh/knownhosts rather than this package's New or NewDB methods. The returned values will not include ssh.CertAlgo* values. If any known_hosts lines had @cert-authority prefixes, their original key algo will be returned instead. For proper CA support, use HostKeyDB.HostKeyAlgorithms.
func IsHostKeyChanged ¶
IsHostKeyChanged returns a boolean indicating whether the error indicates the host key has changed. It is intended to be called on the error returned from invoking a host key callback, to check whether an SSH host is known.
func IsHostUnknown ¶
IsHostUnknown returns a boolean indicating whether the error represents an unknown host. It is intended to be called on the error returned from invoking a host key callback to check whether an SSH host is known.
func Line ¶
Line returns a line to append to the known_hosts files. This implementation uses the local patched implementation of Normalize in order to solve https://github.com/golang/go/issues/53463.
func Normalize ¶
Normalize normalizes an address into the form used in known_hosts. This implementation includes a fix for https://github.com/golang/go/issues/53463 and will omit brackets around ipv6 addresses on standard port 22.
func WriteKnownHost ¶
WriteKnownHost writes a known_hosts line to writer for the supplied hostname, remote, and key. This is useful when writing a custom hostkey callback which wraps a callback obtained from this package to provide additional known_hosts management functionality. The hostname, remote, and key typically correspond to the callback's args. This function does not support writing @cert-authority lines.
Types ¶
type HostKeyCallback ¶
type HostKeyCallback ssh.HostKeyCallback
HostKeyCallback wraps ssh.HostKeyCallback with an additional method to perform host key algorithm lookups from the known_hosts entries. It is otherwise identical to ssh.HostKeyCallback, and does not introduce any file- parsing behavior beyond what is in golang.org/x/crypto/ssh/knownhosts.
Note that its HostKeys and HostKeyAlgorithms methods do not provide any special treatment for @cert-authority lines, which will look like normal non-CA host keys. For proper CA support, e.g. when building a general-purpose SSH client, use HostKeyDB instead.
HostKeyCallback should generally only be used in situations in which @cert-authority lines are unlikely (for example, Git-related use-cases, since Git forges generally don't use them), or in situations where the extra file- parsing is undesirable, for reasons of code trust / security or perhaps performance impact.
func New ¶
func New(files ...string) (HostKeyCallback, error)
New creates a HostKeyCallback from the given OpenSSH known_hosts file(s). The returned value may be used in ssh.ClientConfig.HostKeyCallback by casting it to ssh.HostKeyCallback, or using its HostKeyCallback method. Otherwise, it operates the same as the New function in golang.org/x/crypto/ssh/knownhosts. When supplying multiple files, their order does not matter.
func (HostKeyCallback) HostKeyAlgorithms ¶
func (hkcb HostKeyCallback) HostKeyAlgorithms(hostWithPort string) (algos []string)
HostKeyAlgorithms returns a slice of host key algorithms for the supplied host:port found in the known_hosts file(s), or an empty slice if the host is not already known. The result may be used in ssh.ClientConfig's HostKeyAlgorithms field, either as-is or after filtering (if you wish to ignore or prefer particular algorithms). For hosts that have multiple known_hosts entries (for different key types), the result will be sorted by known_hosts filename and line number. The returned values will not include ssh.CertAlgo* values. If any known_hosts lines had @cert-authority prefixes, their original key algo will be returned instead. For proper CA support, use HostKeyDB.HostKeyAlgorithms.
func (HostKeyCallback) HostKeyCallback ¶
func (hkcb HostKeyCallback) HostKeyCallback() ssh.HostKeyCallback
HostKeyCallback simply casts the receiver back to ssh.HostKeyCallback, for use in ssh.ClientConfig.HostKeyCallback.
func (HostKeyCallback) HostKeys ¶
func (hkcb HostKeyCallback) HostKeys(hostWithPort string) []ssh.PublicKey
HostKeys returns a slice of known host public keys for the supplied host:port found in the known_hosts file(s), or an empty slice if the host is not already known. For hosts that have multiple known_hosts entries (for different key types), the result will be sorted by known_hosts filename and line number. In the returned values, there is no way to distinguish between CA keys (known_hosts lines beginning with @cert-authority) and regular keys. To do so, use HostKeyDB.HostKeys instead.
type HostKeyDB ¶
type HostKeyDB struct {
// contains filtered or unexported fields
}
HostKeyDB wraps logic in golang.org/x/crypto/ssh/knownhosts with additional behaviors, such as the ability to perform host key/algorithm lookups from the known_hosts entries. It fully supports @cert-authority lines as well, and can return ssh.CertAlgo* values when looking up algorithms. To create a HostKeyDB, use NewDB.
func NewDB ¶
NewDB creates a HostKeyDB from the given OpenSSH known_hosts file(s). It reads and parses the provided files one additional time (beyond logic in golang.org/x/crypto/ssh/knownhosts) in order to handle CA lines properly. When supplying multiple files, their order does not matter.
func (*HostKeyDB) HostKeyAlgorithms ¶
HostKeyAlgorithms returns a slice of host key algorithms for the supplied host:port found in the known_hosts file(s), or an empty slice if the host is not already known. The result may be used in ssh.ClientConfig's HostKeyAlgorithms field, either as-is or after filtering (if you wish to ignore or prefer particular algorithms). For hosts that have multiple known_hosts entries (of different key types), the result will be sorted by known_hosts filename and line number. For @cert-authority lines, the returned algorithm will be the correct ssh.CertAlgo* value.
func (*HostKeyDB) HostKeyCallback ¶
func (hkdb *HostKeyDB) HostKeyCallback() ssh.HostKeyCallback
HostKeyCallback returns an ssh.HostKeyCallback for use in ssh.ClientConfig.HostKeyCallback.
func (*HostKeyDB) HostKeys ¶
HostKeys returns a slice of known host public keys for the supplied host:port found in the known_hosts file(s), or an empty slice if the host is not already known. For hosts that have multiple known_hosts entries (for different key types), the result will be sorted by known_hosts filename and line number.