urllib getting SSL certificate info

Ghirai ghirai at ghirai.com
Tue Aug 19 23:32:42 CEST 2008


On Wednesday 20 August 2008 00:05:47 Jean-Paul Calderone wrote:

> I don't know about M2Crypto.  Here's some sample code for PyOpenSSL:
>
>   from socket import socket
>   from OpenSSL.SSL import Connection, Context, SSLv3_METHOD
>   s = socket()
>   s.connect(('google.com', 443))
>   c = Connection(Context(SSLv3_METHOD), s)
>   c.set_connect_state()
>   c.send('GET / HTTP/1.1\r\n\r\n')
>   cert = c.get_peer_certificate()
>   print cert.get_issuer().get_components()
>   print cert.get_subject().get_components()
>
> When I run this, I get:
>
>   [('C', 'ZA'), ('O', 'Thawte Consulting (Pty) Ltd.'), ('CN', 'Thawte SGC
> CA')] [('C', 'US'), ('ST', 'California'), ('L', 'Mountain View'), ('O',
> 'Google Inc'), ('CN', 'www.google.com')]
>
>

Thanks, i'll go with PyOpenSSL, it seems easier, and has decent docs :)

-- 
Regards,
Ghirai.



More information about the Python-list mailing list