From 301c81d6027b5846866e92fbf94a7e398ea3faff Mon Sep 17 00:00:00 2001
From: Ubuntu <ubuntu@lxc.openstacklocal>
Date: Fri, 13 Nov 2015 15:19:03 +0000
Subject: [PATCH] Detect ssl version
Signed-off-by: Chuck Short <zulcss@ubuntu.com>
---
pylxd/connection.py | 8 +++++++-
pylxd/tests/test_connection.py | 9 +++++++--
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/pylxd/connection.py b/pylxd/connection.py
index e01350c..7d7c8ff 100644
--- a/pylxd/connection.py
+++ b/pylxd/connection.py
@@ -51,10 +51,16 @@ class HTTPSConnection(http_client.HTTPConnection):
self.sock = sock
self._tunnel()
+ # ssl tls version
+ if hasattr(ssl, 'PROTOCOL_TLSv1_2'):
+ DEFAULT_TLS_VERSION = ssl.PROTOCOL_TLSv1_2
+ else:
+ DEFAULT_TLS_VERSION = ssl.PROTOCOL_TLSv1
+
(cert_file, key_file) = self._get_ssl_certs()
self.sock = ssl.wrap_socket(sock, certfile=cert_file,
keyfile=key_file,
- ssl_version=ssl.PROTOCOL_TLSv1_2)
+ ssl_version=DEFAULT_TLS_VERSION)
@staticmethod
def _get_ssl_certs():
diff --git a/pylxd/tests/test_connection.py b/pylxd/tests/test_connection.py
index 2c7f4fa..ee7caef 100644
--- a/pylxd/tests/test_connection.py
+++ b/pylxd/tests/test_connection.py
@@ -25,6 +25,11 @@ from pylxd import connection
from pylxd import exceptions
from pylxd.tests import annotated_data
+if hasattr(ssl, 'PROTOCOL_TLSv1_2'):
+ DEFAULT_TLS_VERSION = ssl.PROTOCOL_TLSv1_2
+else:
+ DEFAULT_TLS_VERSION = ssl.PROTOCOL_TLSv1
+
@ddt
class LXDInitConnectionTest(unittest.TestCase):
@@ -53,7 +58,7 @@ class LXDInitConnectionTest(unittest.TestCase):
ms.return_value,
certfile='/home/foo/.config/lxc/client.crt',
keyfile='/home/foo/.config/lxc/client.key',
- ssl_version=ssl.PROTOCOL_TLSv1_2,
+ ssl_version=DEFAULT_TLS_VERSION
)
@mock.patch('os.environ', {'HOME': '/home/foo'})
@@ -71,7 +76,7 @@ class LXDInitConnectionTest(unittest.TestCase):
ms.return_value,
certfile='/home/foo/.config/lxc/client.crt',
keyfile='/home/foo/.config/lxc/client.key',
- ssl_version=ssl.PROTOCOL_TLSv1_2)
+ ssl_version=DEFAULT_TLS_VERSION)
@mock.patch('pylxd.connection.HTTPSConnection')
@mock.patch('pylxd.connection.UnixHTTPConnection')
--
1.9.1