Skip to content

Commit 6e18c92

Browse files
committed
knownhost to support reader
1 parent 06a226f commit 6e18c92

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

ssh/knownhosts/reader.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package knownhosts
2+
3+
import (
4+
"io"
5+
6+
"golang.org/x/crypto/ssh"
7+
)
8+
9+
func NewFromReader(r io.Reader) (ssh.HostKeyCallback, error) {
10+
db := newHostKeyDB()
11+
if err := db.Read(r, ""); err != nil {
12+
return nil, err
13+
}
14+
15+
var certChecker ssh.CertChecker
16+
certChecker.IsHostAuthority = db.IsHostAuthority
17+
certChecker.IsRevoked = db.IsRevoked
18+
certChecker.HostKeyFallback = db.check
19+
20+
return certChecker.CheckHostKey, nil
21+
}

ssh/knownhosts/reader_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package knownhosts
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
"testing"
7+
)
8+
9+
func TestNewFromReader(t *testing.T) {
10+
str := fmt.Sprintf("server*.domain %s", edKeyStr)
11+
12+
_, err := NewFromReader(strings.NewReader(str))
13+
if err != nil {
14+
t.Fatalf("cannot read from string: %v", err)
15+
}
16+
17+
}

0 commit comments

Comments
 (0)