reuse VerifyHostKeyFromKnownHosts (#143)
This commit is contained in:
parent
841350fadb
commit
e7b276d6a5
4 changed files with 26 additions and 50 deletions
|
|
@ -7,6 +7,8 @@ import (
|
|||
"strconv"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"golang.org/x/crypto/ssh/knownhosts"
|
||||
)
|
||||
|
||||
func AuthMethodTypeToName(a AuthMethod) string {
|
||||
|
|
@ -132,3 +134,22 @@ func CreateNextPluginAuth(meta map[string]string) *Upstream_NextPlugin {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
func VerifyHostKeyFromKnownHosts(knownhostsData io.Reader, hostname, netaddr string, key []byte) error {
|
||||
hostKeyCallback, err := knownhosts.NewFromReader(knownhostsData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pub, err := ssh.ParsePublicKey(key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
addr, err := net.ResolveTCPAddr("tcp", netaddr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return hostKeyCallback(hostname, addr, pub)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue