From fb73e0b8ca150cee46891a6c24a379e7807835e5 Mon Sep 17 00:00:00 2001 From: "Richard J. Moore" Date: Sun, 11 Jan 2015 17:04:43 +0000 Subject: [PATCH] Add support for querying the negotiated TLS version. --- OpenSSL/SSL.py | 10 ++++++++++ OpenSSL/test/test_ssl.py | 14 ++++++++++++++ setup.py | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py index 7b1cbc1b4..99a5421b0 100644 --- a/OpenSSL/SSL.py +++ b/OpenSSL/SSL.py @@ -1551,6 +1551,16 @@ def get_cipher_version(self): return version.decode("utf-8") + def get_protocol_version(self): + """ + Obtain the protocol version of the current connection. + + :returns: The TLS version of the current connection, for example + the value for TLS 1.2 would be 0x303. + :rtype: :py:class:`int` + """ + version = _lib.SSL_version(self._ssl) + return version ConnectionType = Connection diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py index 44980d53a..ab303c265 100644 --- a/OpenSSL/test/test_ssl.py +++ b/OpenSSL/test/test_ssl.py @@ -2129,6 +2129,20 @@ def test_get_cipher_bits(self): self.assertEqual(server_cipher_bits, client_cipher_bits) + def test_get_protocol_version(self): + """ + :py:obj:`Connection.get_protocol_version` returns a :py:class:`int` + giving the protocol version of the current connection. + """ + server, client = self._loopback() + server_protocol_version, client_protocol_version = \ + server.get_protocol_version(), client.get_protocol_version() + + self.assertIsInstance(server_protocol_version, int) + self.assertIsInstance(client_protocol_version, int) + + self.assertEqual(server_protocol_version, client_protocol_version) + class ConnectionGetCipherListTests(TestCase): """ diff --git a/setup.py b/setup.py index 14506309e..39028c0ea 100755 --- a/setup.py +++ b/setup.py @@ -34,7 +34,7 @@ maintainer_email = 'exarkun@twistedmatrix.com', url = 'https://github.com/pyca/pyopenssl', license = 'APL2', - install_requires=["cryptography>=0.5.4", "six>=1.5.2"], + install_requires=["cryptography>=0.7.2", "six>=1.5.2"], long_description = """\ High-level wrapper around a subset of the OpenSSL library, includes * SSL.Connection objects, wrapping the methods of Python's portable