By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,750 Members | 1,060 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,750 IT Pros & Developers. It's quick & easy.

automate openssl s_client command in batch or PHP script

P: n/a
Hello,

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

openssl s_client www.somewebsite.com:443 > 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 www.somewebsite.com:443 > 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{enter}"). 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
hang.

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,

Niko
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Niko wrote:
Hello,

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

openssl s_client www.somewebsite.com:443 > 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 www.somewebsite.com:443 > cert.txt")

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


You got many options. The simplest would be:

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

Where quit.txt contains "quit\n"
/Bent
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.