-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathreader.go
More file actions
27 lines (22 loc) · 867 Bytes
/
reader.go
File metadata and controls
27 lines (22 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package knownhosts
import (
"io"
"golang.org/x/crypto/ssh"
)
// NewFromReader creates a host key callback from the given OpenSSH host io.Reader
// which is in SSH_KNOWN_HOSTS_FILE_FORMAT. The returned callback is for use in
// ssh.ClientConfig.HostKeyCallback. By preference, the key check
// operates on the hostname if available, i.e. if a server changes its
// IP address, the host key check will still succeed, even though a
// record of the new IP address is not available.
func NewFromReader(readers ...io.Reader) (ssh.HostKeyCallback, error) {
db := newHostKeyDB()
if err := db.Read(io.MultiReader(readers...), ""); err != nil {
return nil, err
}
var certChecker ssh.CertChecker
certChecker.IsHostAuthority = db.IsHostAuthority
certChecker.IsRevoked = db.IsRevoked
certChecker.HostKeyFallback = db.check
return certChecker.CheckHostKey, nil
}