Pau*_*ice 3 linux shell mono openssl ssl-certificate
如何从给定的 URL 获取根 SSL 证书以及任何中间证书到文件?理想情况下通过一些 linux shell 兼容的命令行,但如果必须的话也可以手动完成。 更新:交互式地,使用 Chrome,如果我检查证书,我可以选择导出它。如果适用的话,有一种方法可以抓住整个链条。所以现在我只是在寻找一种可编写脚本的方法。
背景:
mono nuget.exe install ./packages.config -o ./packages
将会在 ubuntu 上安装项目包,只要在机器的 Trust store 中安装了所需的证书即可。部分来说,它是这样完成的:
$ certmgr -ssl https://nugetgallery.blob.core.windows.net
此命令带有 -ssl 选项,从指定的 url 获取证书和任何中间体,并需要用户确认。我正在尝试自动化服务器构建,因此我想在不需要用户确认的情况下添加证书。
我尝试将响应通过管道传输到命令中 - 即:
$ echo "Yes" | certmgr -ssl https://nugetgallery.blob.core.windows.net
那是行不通的。我尝试将证书导出到文件,以便将它们添加到我的构建项目中,但 mono certmgr 尚未实现“放置”。
假设安装了 openssl,此命令行:
echo | openssl s_client \
    -showcerts \
    -connect nugetgallery.blob.core.windows.net:443 2>&1 |
        sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > cert.pem
生成一个包含该链中涉及的所有三个证书的文件。
感谢这个问题的答案:Using openssl to get thecertificate from a server来解决获取链的问题。以下命令会将保存的证书加载到信任存储中。
openssl crl2pkcs7 -nocrl -certfile cert.pem -out cert.p7b
certmgr -add -c -m Trust ./cert.p7b