support host key for dabases

This commit is contained in:
Boshi Lian 2019-01-07 02:07:18 -08:00
parent c0ae381d48
commit 3e597d6f04

View file

@ -27,6 +27,18 @@ func (p *plugin) findUpstream(conn ssh.ConnMetadata) (net.Conn, *ssh.AuthPipe, e
return nil, nil, err
}
hostKeyCallback := ssh.InsecureIgnoreHostKey()
if !d.Upstream.Server.IgnoreHostKey {
key, err := ssh.ParsePublicKey([]byte(d.Upstream.Server.HostKey.Key.Data))
if err != nil {
return nil, nil, err
}
hostKeyCallback = ssh.FixedHostKey(key)
}
pipe := ssh.AuthPipe{
User: d.Upstream.Username,
@ -56,7 +68,7 @@ func (p *plugin) findUpstream(conn ssh.ConnMetadata) (net.Conn, *ssh.AuthPipe, e
return ssh.AuthPipeTypeNone, nil, nil
},
UpstreamHostKeyCallback: ssh.InsecureIgnoreHostKey(),
UpstreamHostKeyCallback: hostKeyCallback,
}
return c, &pipe, nil
}