[Tutor] Sending a disconnect after openssl s_client command?

Kayvan Sarikhani ksarikhani at gmail.com
Mon Apr 20 23:24:18 CEST 2009


On Mon, Apr 20, 2009 at 1:17 PM, Martin Walsh <mwalsh at mwalsh.org> wrote:

> from subprocess import Popen, PIPE
>
> openssl_cmd = 'openssl s_client -ssl2 -connect somewebsitename:443'
> openssl = Popen(
>  openssl_cmd, shell=True, stdout=PIPE, stderr=PIPE, stdin=PIPE
> )
> stdout, stderr = openssl.communicate('GET /')
>
> Alternatively, if you're using python 2.6 and above, it looks like you
> can do something similar with a few lines of code, and the ssl module
> from the standard lib ...
>
> # untested!
> import ssl
> try:
>    cert = ssl.get_server_certificate(
>        ('somewebsitename', 443), ssl.PROTOCOL_SSLv2
>    )
> except ssl.SSLError, ex:
>    # site may not support sslv2
>    ...
>
> HTH,
> Marty


Thanks Marty; this does indeed help...it just also means I need to really
learn how subprocess works. ;) I wish I could claim to be using 2.6, but
unfortunately the most current version at work is Python 2.5.2...most boxes
here are even below, and I can't convince them to upgrade. Ah, well.

Thanks again though!

K
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090420/e46e7b73/attachment-0001.htm>


More information about the Tutor mailing list