0
votes

Traceback (most recent call last): File "ssl-common.py", line 14, in s = ctx.wrap_socket(s, server_hostname=dst[0]) File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 363, in wrap_socket _context=self) File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 611, in init self.do_handshake() File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 840, in do_handshake self._sslobj.do_handshake() socket.error: [Errno 54] Connection reset by peer

I am getting the above errors when I try to run the below script on my Mac. I have reinstalled openssl through homebrew, as well as through pip

import socket
import ssl
import OpenSSL.crypto as crypto

dst = ('1.2.3.4',443)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ret = s.connect_ex(dst)
if ret == 0 :
    ctx = ssl.create_default_context()
    ctx.check_hostname = False
    ctx.verify_mode = ssl.CERT_NONE
    s = ctx.wrap_socket(s, server_hostname=dst[0])

    # get certificate
    cert_bin = s.getpeercert(True)
    x509 = crypto.load_certificate(crypto.FILETYPE_ASN1,cert_bin)
    print(x509.get_subject().CN)
else :
    print "socket.connect_ex returned ", ret
1

1 Answers

0
votes
[Errno 54] Connection reset by peer

It seems like a problem on where you want to connect. Check your connectivity by pinging and etc.

Please do check this out: What does "connection reset by peer" mean?