diff --git a/ChangeLog b/ChangeLog index cd84be7c1..b5b392272 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,8 @@ 2015-05-27 Jim Shaver * OpenSSL/SSL.py, : Add ``get_protocol_version()`` and - ``get_protocol_version_name()`` to Connection - Based on work from Rich Moore + ``get_protocol_version_name()`` to ``Connection``. + Based on work from Rich Moore. 2015-05-02 Jim Shaver diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py index af1931f33..ec032418d 100644 --- a/OpenSSL/SSL.py +++ b/OpenSSL/SSL.py @@ -1889,12 +1889,24 @@ def get_protocol_version_name(self): :returns: The TLS version of the current connection, for example the value for TLS 1.2 would be ``b'TLSv1.2'``. - :rtype: :py:class:`unicode` + :rtype: :py:class:`bytes` """ version = _ffi.string(_lib.SSL_get_version(self._ssl)) return version + 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 would be 0x769. + :rtype: :py:class:`int` + """ + version = _lib.SSL_version(self._ssl) + return version + + @_requires_npn def get_next_proto_negotiated(self): """ @@ -1950,17 +1962,6 @@ def get_alpn_proto_negotiated(self): return _ffi.buffer(data[0], data_len[0])[:] - 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 01a76c1e2..91f115cf6 100644 --- a/OpenSSL/test/test_ssl.py +++ b/OpenSSL/test/test_ssl.py @@ -2775,6 +2775,7 @@ def test_get_protocol_version(self): self.assertEqual(server_protocol_version, client_protocol_version) + class ConnectionGetCipherListTests(TestCase): """ Tests for :py:obj:`Connection.get_cipher_list`. diff --git a/doc/api/ssl.rst b/doc/api/ssl.rst index 38f0d331b..3315580a2 100644 --- a/doc/api/ssl.rst +++ b/doc/api/ssl.rst @@ -601,9 +601,8 @@ Connection objects have the following methods: .. py:method:: Connection.get_protocol_version() Retrieve the version of the SSL or TLS protocol used by the Connection. - For example, it will return ``0x303`` for connections made over TLS - version 1.2, or ``Unknown`` for connections that were not successfully - established. + For example, it will return ``0x769`` for connections made over TLS + version 1. .. py:method:: Connection.get_protocol_version_name()