2

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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

I was getting an error: module 'ssl' has no attribute 'PROTOCOL_SSLv3'. So now I have installed pyOpenSSL and using it instead of ssl, which has this protocol. I am now getting a timeout error, after doing a sslSocket.send(post_data.encode('utf-8')). This does not return: buf = sslSocket.recv(4096)
One tip in using socket.recv is to check how many bytes is received on receiver side and look for some characters such as \0 or \r\n to check your message is complete. The reason it gets timeout, because waiting for some data which is never will be sent to recv side. Good luck

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.