Ubuntu Pastebin

Paste from ubuntu at Fri, 13 Nov 2015 15:22:15 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
Download as text