本文整理汇总了Golang中golang.org/x/crypto/ssh.ClientConfig.HostKeyCallback方法的典型用法代码示例。如果您正苦于以下问题:Golang ClientConfig.HostKeyCallback方法的具体用法?Golang ClientConfig.HostKeyCallback怎么用?Golang ClientConfig.HostKeyCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/crypto/ssh.ClientConfig
的用法示例。
在下文中一共展示了ClientConfig.HostKeyCallback方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sshClientConfig
func sshClientConfig(user string, checker *HostKeyChecker, addr string) (*gossh.ClientConfig, error) {
agentClient, err := SSHAgentClient()
if err != nil {
return nil, err
}
signers, err := agentClient.Signers()
if err != nil {
return nil, err
}
cfg := gossh.ClientConfig{
User: user,
Auth: []gossh.AuthMethod{
gossh.PublicKeys(signers...),
},
}
if checker != nil {
cfg.HostKeyCallback = checker.Check
cfg.HostKeyAlgorithms = checker.GetHostKeyAlgorithms(addr)
}
return &cfg, nil
}
示例2:
fakeReceptor.RouteToHandler("GET", "/v1/actual_lrps/"+processGuid+"/index/0",
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v1/actual_lrps/"+processGuid+"/index/0"),
ghttp.RespondWithJSONEncoded(http.StatusOK, actualLRP),
),
)
Expect(process).NotTo(BeNil())
})
Context("when the client attempts to verify the host key", func() {
var handshakeHostKey ssh.PublicKey
BeforeEach(func() {
clientConfig.HostKeyCallback = func(hostname string, remote net.Addr, key ssh.PublicKey) error {
handshakeHostKey = key
return errors.New("fail")
}
})
It("receives the correct host key", func() {
_, err := ssh.Dial("tcp", address, clientConfig)
Expect(err).To(HaveOccurred())
proxyHostKey, err := ssh.ParsePrivateKey([]byte(hostKeyPem))
Expect(err).NotTo(HaveOccurred())
proxyPublicHostKey := proxyHostKey.PublicKey()
Expect(proxyPublicHostKey.Marshal()).To(Equal(handshakeHostKey.Marshal()))
})
})