automate openssl s_client command in batch or PHP script

This is a discussion on automate openssl s_client command in batch or PHP script within the PHP Language forums, part of the PHP Programming Forums category; Hello, I want to retrieve the details of an SSL certificate of HTTPS websites, using openSSL, running on Windows 2003. ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-24-2004
Niko
 
Posts: n/a
Default automate openssl s_client command in batch or PHP script

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
Reply With Quote
  #2 (permalink)  
Old 10-24-2004
Bent Stigsen
 
Posts: n/a
Default Re: automate openssl s_client command in batch or PHP script

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:12 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0