Documentation ¶
Overview ¶
Package knownhosts supports programmatic parsing, querying and manipulation of SSH known_hosts files.
Index ¶
- Variables
- func HashAddr(salt string, addr string) (string, error)
- func IsErrKeyChanged(err error) bool
- type KnownHost
- type KnownHosts
- func (khs *KnownHosts) Add(addrs ...string) (bool, error)
- func (khs *KnownHosts) FindByAddr(keyType string, addr string) *KnownHost
- func (khs *KnownHosts) FindByKey(keyType string, publicKey string) *KnownHost
- func (khs *KnownHosts) Len() int
- func (khs *KnownHosts) Parse() error
- func (khs *KnownHosts) String() string
- func (khs *KnownHosts) Sync() error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func IsErrKeyChanged ¶
IsErrKeyChanged returns true if the error message begins with the ErrKeyChanged message string.
Types ¶
type KnownHost ¶
func (KnownHost) HasAddress ¶
HasAddress returns true if the specified addr or addr:port is contained.
type KnownHosts ¶
func New ¶
func New(f string) (*KnownHosts, error)
New creates a new instance of KnownHosts. If f is empty, then DefaultKnownHostsPath will be used.
func (*KnownHosts) Add ¶
func (khs *KnownHosts) Add(addrs ...string) (bool, error)
Add resolves and adds a new set of known hosts, then renders to disk. There are obvious security considerations and implications here, since automatically adding to known_hosts can be MITM'd.
Returns bool indicating if any state was changed, and any encountered error.
Automatically merges records for different addresses sharing the same key.
Example ¶
filePath, err := WriteSampleFile() if err != nil { panic(err) } khs, err := New(filePath) if err != nil { panic(err) } if _, err := khs.Add("gitlab.com"); err != nil { panic(err) } if err := khs.Sync(); err != nil { panic(err) } bs, _ := ioutil.ReadFile(filePath) fmt.Println(string(bs))
Output:
func (*KnownHosts) FindByAddr ¶
func (khs *KnownHosts) FindByAddr(keyType string, addr string) *KnownHost
FindByAddr returns nil if no corresponding addr:port entry is found.
Example ¶
filePath, err := WriteSampleFile() if err != nil { panic(err) } khs, err := New(filePath) if err != nil { panic(err) } fmt.Printf("%# v\n", khs.FindByAddr("ssh-rsa", "github.com"))
Output:
func (*KnownHosts) FindByKey ¶
func (khs *KnownHosts) FindByKey(keyType string, publicKey string) *KnownHost
FindByKey returns nil if no corresponding key type and value entry is found.
Example ¶
filePath, err := WriteSampleFile() if err != nil { panic(err) } khs, err := New(filePath) if err != nil { panic(err) } fmt.Printf("%# v\n", khs.FindByKey("ssh-rsa", "AAAA...KUr2oK9EJ5e81"))
Output:
func (*KnownHosts) Len ¶
func (khs *KnownHosts) Len() int
func (*KnownHosts) Parse ¶
func (khs *KnownHosts) Parse() error
Parse refreshes and parses the known hosts data from disk.
func (*KnownHosts) String ¶
func (khs *KnownHosts) String() string
String transforms the current state known hosts into a string representation.
func (*KnownHosts) Sync ¶
func (khs *KnownHosts) Sync() error
Sync renders the current state to disk.