【问题标题】:openssl hangs and does not exitopenssl 挂起且不退出
【发布时间】:2012-03-16 01:07:00
【问题描述】:

我正在尝试使用 openssl 获取证书,但它似乎一直挂起。我进行了大量研究,但似乎并非所有可用选项都适用于 Windows。

openssl s_client -showcerts -connect google.com:443 > cert.txt

我试过这个:

openssl s_client -connect xyz:443 < quit.txt > cert.txt

其中quit.txt 包含“退出\n” 来自http://bytes.com/topic/php/answers/8802-automate-openssl-s_client-command-batch-php-script

那没有用。我也看了Openssl s_clinet -connect scripting. Force quit help

我也试过-prexit

我也对此进行了研究,但无法正常工作: https://serverfault.com/questions/139728/how-to-download-ssl-certificate-from-a-website

我做得很好!我设法做了一些我认为不可能的事情,像这个错误这样简单的事情设法阻止了我暂时 :(

【问题讨论】:

  • 编辑了基本的拼写和语法,试图让它看起来像你在提出问题时付出了一些努力。将新版本重新定位到 ServerFault,在那里您更有可能得到答案。
  • 查看stackoverflow.com/questions/16823068/… -- WScript 中的 SendKeys("\n") 可以让 OpenSSL 在 EOF 无法退出的地方退出。

标签: cmd openssl quit


【解决方案1】:

在 Windows 上,只需在您的 openssl 命令之前输入 winpty 即可。因此,例如,您可以像这样创建一个证书:

winpty openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days XXX

【讨论】:

  • 非常感谢!!!!我花了多少时间试图弄清楚为什么这么小的命令行不能在我的 Windows 上运行......!!!
  • 在 Windows 7 上的 Git Bash 中为我工作!
  • @temporary_user_name 完全正确 - 由于使用了 mintty in Git Bash for Windows,会出现此问题。
  • 谢谢,终于可以生成 .pfx 了 :)
  • 对于openssl中的另一个命令,我发现它正坐在那里等我输入密码,但我看不到提示。
【解决方案2】:

看起来一些用于 Windows 的 OpenSSL 发行版需要额外的按键,独立于标准输入。 Quit.txt 正确地通过管道传输到 openssl 的 STDIN(服务器接收 QUIT 命令),但在您按下任意键之前什么都不会发生。

Cygwin's 版本的 OpenSSL 不存在此问题。不幸的是,Cygwin 的基本安装需要大约 100 MB 的磁盘空间,但您可以尝试仅提取 openssl.exe 和所需的库。

此方法有效:

echo QUIT | c:\cygwin\bin\openssl.exe s_client -showcerts -connect google.com:443 > cert.txt

【讨论】:

  • 感谢您的 MBu。它工作这是我需要复制 cygcrypto-0.9.8.dll cyggcc_s-1.dll cygssl-0.9.8.dll cygwin1.dll cygz.dll find-serial.bat libeay32.dll openssl.exe ssleay32 的文件列表。 dll
  • 不仅在 Windows 上,而且在 Linux 上,通过管道输入命令的 echo QUIT 解决了停止输出问题。
  • 这解决了我在我们的网络上尝试扫描过期证书时的超时问题。我必须添加一个 sleep 以使其更稳定 (sleep 2; echo QUIT;)|openssl ...
【解决方案3】:

如果在 windows 上运行在 mingw64 下,你可以使用 winpty 程序正确包装终端

例如在 bash 下创建别名 别名 openssl='winpty openssl.exe'

然后 openssl s_client -connect 等等

应该按预期工作

【讨论】:

  • 或者在 openssl 之前输入 winpty。这对我有用。谢谢。
【解决方案4】:

由于我不完全理解的原因,在我的情况下,将 QUIT 或 quit\n 回显到输入中不起作用。我在 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

【讨论】:

    猜你喜欢
    • 2016-03-04
    • 2011-04-15
    • 2018-04-27
    • 1970-01-01
    • 1970-01-01
    • 2014-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多