Find SSL Version after Handshake in OpenSSL

encryption, openssl, pyopenssl, ssl

Solution

i want to check the version on handshake

The relevant functions to check the version both client and server use for the remaining session in pyOpenSSL are get_protocol_version_name or get_protocol_version:

connection.do_handshake()
#wants to check version here
print(connection.get_protocol_version_name())

Note that these functions are only available since pyOpenSSL 0.16.0

Please not also that you cannot specify a list of TLS methods when creating the context but only a single method which essentially specifies the minimal TLS version supported by the client. Thus

context = OpenSSL.SSL.Context(SSL.TLSv1_METHOD)

allows the client to use TLS 1.0 and better. If you instead use `SSL.TLSv1_2_METHOD` the client would be restricted to TLS 1.2 and better and thus could not establish a SSL connection with a server supporting only TLS 1.0.

Problem

I want to find out the protocols supported by a target but the problem is that their are quite a number websites which are not supporting a particular version but when i performed handshake it was successful becz target surpassed the version that i gave and perform handshake on the supported version [ it happened on only 1 website] example : i passed a version :TLSVersion.TLS_1_2 but the handshake is performed using TLSv1_0 becz it is not supporting TLSVersion.TLS_1_2 Because of the above issue i want to check the version on handshake and i dont want to use scapy.ssl_tls ``` version = [SSL.SSLv23_METHOD, SSL.TLSv1_METHOD, SSL.TLSv1_1_METHOD, SSL.TLSv1_2_METHOD] context = OpenSSL.SSL.Context(version) soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) soc.settimeout(CONNECTION_TIMEOUT) connection = OpenSSL.SSL.Connection(context,soc) connection.connect((host,port)) connection.do_handshake() #wants to check version here ```

Original source