我正在尝试使用 openssl 来获取证书,但它似乎一直挂着。我做了很多研究,但似乎并非所有可用选项都适用于 Windows。
openssl s_client -showcerts -connect google.com:443 > cert.txt
我试过这个:
openssl s_client -connect xyz:443 < quit.txt > cert.txt
其中
quit.txt
包含“退出
”
来自 http://bytes.com/topic/php/answers/8802-automate-openssl-s_client-command-batch-php-script
那没有用。我还查看了 Openssl s_clinet -connect 脚本。强制退出帮助
我也尝试过
-prexit
我也研究过这个,但无法让它工作: https://serverfault.com/questions/139728/how-to-download-ssl-certificate-from-a-website
我做得很好!我设法做了一些我认为不可能的事情,像这个错误这样简单的事情成功地阻止了我暂时:(
在 Windows 上,只需在 openssl 命令之前输入
winpty
即可。因此,例如,您可以创建一个如下所示的证书:
winpty openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days XXX
看起来一些 Windows 的 OpenSSL 发行版需要额外的按键,独立于标准输入。 Quit.txt 正确地通过管道传输到 openssl 的 STDIN(服务器接收 QUIT 命令),但在您按任意键之前不会发生任何事情。
此问题在 OpenSSL 的 Cygwin 版本中不存在。不幸的是,Cygwin 的基本安装需要大约 100 MB 的磁盘空间,但您可以尝试仅提取 openssl.exe 和所需的库。
这个方法有效:
echo QUIT | c:\cygwin\bin\openssl.exe s_client -showcerts -connect google.com:443 > cert.txt
如果在 Windows 上的 mingw64 下运行,您可以使用 winpty 程序正确包装终端
例如在 bash 下创建别名 别名 openssl='winpty openssl.exe'
然后 openssl s_client -connect 等等
应该按预期工作
出于我不完全理解的原因,回显退出或退出 输入在我的情况下不起作用。我在 Windows 8.1 上使用 MINGW64 和 OpenSSL 1.0.2d,并且使用 openssl 从 bash 脚本内的服务器获取证书。然而,只需在后台运行 openssl 命令并稍等一下对我来说就有用了:
#!/bin/bash
openssl s_client -connect my.server.com:443 -showcerts > output.txt 2>/dev/null &
sleep 2
使用
s_client
的 openssl
选项时,需要发送到服务器的数据。在 *nix 上,前置 echo |
会发送 CR,以便 openssl
不会挂起,例如:
echo | openssl s_client -servername www.microsoft.com -connect www.microsoft.com:443 2>/dev/null | openssl x509 -noout -subject -issuer -dates
如果您只是运行 openssl 命令,当它似乎挂起时,只需继续按 Enter 键,它最终会继续显示提示。每当你遇到另一个挂起的情况时,只要继续按 Enter 键,最终就会完成工作。