pyOpenSSL0.13---'socket' object has no attribute 'get_peer_cert_chain'

Asked by h&m

I want to get certificate chain ,but a problem happend ,the problem is that 'socket' object has no attribute 'get_peer_cert_chain'.
I use pyOpenSSL0.13 and python3.3
the sample code named test.py:

import socket
from OpenSSL import SSL
context = SSL.Context(SSL.SSLv23_METHOD)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection = SSL.Connection(context,s)
connection.connect(('www.google.com',443))
connection.setblocking(1)
try:
    connection.do_handshake()
except OpenSSL.SSL.WantReadError:
    print("Timeout")
    quit()
print(connection.get_peer_certificate().get_issuer().commonName)------>1
print(connection.get_peer_cert_chain())------------------------------------------->2

#python test.py
    print(connection.get_peer_cert_chain())
AttributeError: 'socket' object has no attribute 'get_peer_cert_chain'

step 1:success
step 2: failure

Did I ignore something?

Question information

Language:
English Edit question
Status:
Answered
For:
pyOpenSSL Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
M.-A. Lemburg (mal-egenix) said :
#1

On 09.04.2013 07:46, h&m wrote:
> print(connection.get_peer_certificate().get_issuer().commonName)------>1
> print(connection.get_peer_cert_chain())------------------------------------------->2
>
> #python test.py
> print(connection.get_peer_cert_chain())
> AttributeError: 'socket' object has no attribute 'get_peer_cert_chain'
>
>
> step 1:success
> step 2: failure
>
> Did I ignore something?

Your code is probably picking up an older version of pyOpenSSL.

Works for me:

tmp/test-get-peer-cert-chain> python test.py
Google Internet Authority
[<X509 object at 0x7ff6f123d1b0>, <X509 object at 0x7ff6f123d1d0>]

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source (#1, Apr 08 2013)
>>> Python Projects, Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
2013-04-02: Released mxODBC Zope DA 2.1.1 ... http://egenix.com/go41
2013-04-10: Python Meeting Duesseldorf ... 2 days to go

::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::

   eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/

Revision history for this message
h&m (houman-march) said :
#2

I test two cases:
1.python 3.3 + pyOpenSSL0.13 ------->Error
2.python 2.7 + pyOpenSSL0.13 ------->OK

Maybe it is a bug.

Revision history for this message
h&m (houman-march) said :
#3

Thank you ,Marc-Andre Lemburg

Can you help with this problem?

Provide an answer of your own, or ask h&m for more information if necessary.

To post a message you must log in.