Home > Mobile >  Python Socket Client SSL Connection
Python Socket Client SSL Connection

Time:11-10

I have implemented the following to connect to a remote server:

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(10)
context = SSLContext(ssl.PROTOCOL_TLSv1_2)
context.verify_mode = ssl.CERT_NONE
sslSocket = context.wrap_socket(s, server_hostname=hostname)
sslSocket.connect((hostname, port))

I am getting an error:

[SSL: WRONG_SSL_VERSION] wrong ssl version (_ssl.c:2820)

When I connect via openssl via the command line this is the response I am getting from the server:

New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-RSA-AES128-GCM-SHA256

What am I missing in my call to get the error with SSL version?

CodePudding user response:

You have to change protocol version in line: 'ssl.PROTOCOL_TLSv1_2' To another such as : ssl.PROTOCOL_SSLV3 I am not sure for grammar. Search it in documents. This: PROTOCOL_SSLv23

  • Related