automate openssl s_client command in batch or PHP script

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I want to retrieve the details of an SSL certificate of HTTPS
websites, using openSSL, running on Windows 2003. This works fine as

openssl s_client > cert.txt

In order to close the openSSL connection to the HTTPS website, I have
to manually type "quit" + enter.

Now I want to use this line in a PHP script (running on Windows 2003
with IIS6), so I do not have the possibility to type "quit" + enter.
If I  use following code, the PHP script will hang:

shell_exec("openssl s_client > cert.txt")

Is there a possibility to automate openSSL s_client, so it can be used
from a script or batch ?

I have tried to invoke the above openSSL command from VBS, and use
sendkeys("quit"). This works fine if ran from a DOS window, but
not if the VBS script in turn is invoked by a PHP webpage. In this
case, the PHP page will wait for the VBS script to end, and because
the VBS script is invoked from a PHP webpage and not in a DOS window,
the sendkeys function doesn't work. So PHP will wait infinitely and

Can openSSL s_client be automated, or can one of the PHP functions
shell_exec, or exec or popen be used without the script hanging
infinitely ?

Thanks for your help,


Re: automate openssl s_client command in batch or PHP script

Niko wrote:
Quoted text here. Click to load it

You got many options. The simplest would be:

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

Where quit.txt contains "quit\n"


Site Timeline