SSH主机密钥证书,远程查找有效期?

我有一个使用SSH证书来validationSSH主机密钥的环境。 我正在谈论通过运行ssh-keygen -s /path/to/ca -h ...创build的证书种类。 这些证书也是以有效期间创build的,说明它们何时到期。 这些证书现在已经被使用了足够长的时间,所以我需要开始监视它们,当它们开始接近过期的时候,它们会被抬起头来。

任何方式,我可以做一个远程连接,没有login,并以某种方式获取有效期间显示alt。 获得证书下载? 运行ssh -vvv不会显示我需要的信息。 ssh-keyscan也不会显示证书。 也许有些图书馆我没有仔细看过?

最坏的情况我总是可以编写一个监控插件,它在本地运行并分析ssh-keygen -L -f的输出。 不过,远程扫描真的感觉像是更好的方法。

这是可能的,但是它缺less工具支持。 我发现了一个足够好的SSH协议的库,可以让我编写一个工具来提取主机证书valid_before时间,而不需要完整的sshlogin。 这是Go语言。 我希望它有帮助。

 package main import "golang.org/x/crypto/ssh" import "fmt" import "os" import "time" func ignoreCertChain(auth ssh.PublicKey) bool { return true // Pretend all certificates are trusted. } var sawACert bool func examineCert(cert *ssh.Certificate) bool { expires := cert.ValidBefore var humanReadable string if expires >= ssh.CertTimeInfinity { humanReadable = "infinity" } else if expires < (1 << 63) { humanReadable = time.Unix(int64(expires), 0).Format(time.RFC3339) } else { humanReadable = "the distant future" } fmt.Println("Cert expires at time", expires, "(" + humanReadable + ")") sawACert = true return true // Reject the cert, to force early connection close. } func main() { serverHostPort := os.Args[1] checker := &ssh.CertChecker{ IsAuthority: ignoreCertChain, IsRevoked: examineCert, } config := &ssh.ClientConfig{ User: "test-sshcertscan-not-a-real-login-attempt", Auth: []ssh.AuthMethod{ ssh.Password(""), }, HostKeyCallback: checker.CheckHostKey, } sawACert = false client, err := ssh.Dial("tcp", serverHostPort, config); if err != nil && !sawACert { panic(fmt.Sprint("Cannot connect to ", serverHostPort, ", error: ", err.Error())) } else if client != nil { defer client.Close() } } 

(快速使用说明:安装Go ,将上面的代码保存在sshcertscan.go中,运行go build sshcertscan.go ,然后使用./sshcertscan examplehost:22它指向examplehost端口22上的ssh服务器。

不幸的是,我不知道任何开源工具。 看来nmap将能够以NSE脚本以某种方式检索它(但需要一些调整 – 检查/ usr / share / nmap /脚本)。

SSH的Tectia SSH服务器包含一个名为ssh-fetchkey的工具,它将检索证书,然后您可以使用ssh-certview查看详细信息。

恐怕答案是“那是不可能的”。 至less不是以任何方式,我发现,使用openssh客户端或pyram的paramiko SSH库。 我会build议一个本地检查,如你所描述的,加上一个更简单的远程检查,validationSSHD使用的密钥是你刚刚检查过的证书的生命期。