34 from requests.adapters
import HTTPAdapter
35 from urllib3.poolmanager
import PoolManager
40 """ SSL/TLS Definitions namespace
42 SSL/TLS protocol versions definitions
52 if sys.version_info[:3] >= (2, 7, 9):
54 ssl module in Python 2.7.9 or later supports TLS versions 1.1 and 1.2
57 print "\n--> Using python's ssl module with support to TLS v1_1 and 1_2"
58 SSLDef.TLSv1 = ssl.PROTOCOL_TLSv1
59 SSLDef.TLSv1_1 = ssl.PROTOCOL_TLSv1_1
60 SSLDef.TLSv1_2 = ssl.PROTOCOL_TLSv1_2
61 SSLDef.SSLv2 = ssl.PROTOCOL_SSLv2
62 SSLDef.SSLv3 = ssl.PROTOCOL_SSLv3
63 SSLDef.SSLv2_3 = ssl.PROTOCOL_SSLv23
65 """ Else import pyopenssl and load tls1_1 and tls_1_2 if available.
66 Need to build pyOpenSSL on top of OpenSSL 1.0.1 to
67 get TLSv1.1 and 1.2 support
70 from OpenSSL
import SSL
71 """ Tell urllib3 to switch the ssl backend to PyOpenSSL """
72 import urllib3.contrib.pyopenssl
73 urllib3.contrib.pyopenssl.inject_into_urllib3()
75 Disable Insecure Request Warning caused due to
76 missing https cert verification
78 requests.packages.urllib3.disable_warnings()
80 SSLDef.TLSv1 = SSL.TLSv1_METHOD
81 SSLDef.TLSv1_1 = SSL.TLSv1_1_METHOD
82 SSLDef.TLSv1_2 = SSL.TLSv1_2_METHOD
83 SSLDef.SSLv2 = SSL.SSLv2_METHOD
84 SSLDef.SSLv3 = SSL.SSLv3_METHOD
85 SSLDef.SSLv2_3 = SSL.SSLv23_METHOD
87 print "\n--> Using pyopenssl module instead of python's ssl library" + \
88 " with support to tlsv1_2"
90 except ImportError
as e:
93 print "\n--> Falling back to python's ssl library without tlsv1_2 support"
94 SSLDef.TLSv1 = ssl.PROTOCOL_TLSv1
95 SSLDef.TLSv1_1 = ssl.PROTOCOL_TLSv1
96 SSLDef.TLSv1_2 = ssl.PROTOCOL_TLSv1
97 SSLDef.SSLv2 = ssl.PROTOCOL_SSLv2
98 SSLDef.SSLv3 = ssl.PROTOCOL_SSLv3
99 SSLDef.SSLv2_3 = ssl.PROTOCOL_SSLv23
102 except AttributeError
as e:
103 print "--> pyOpenSSL does not allow support for tls1_1 and tls1_2." + \
104 " PyOpenSSL needs to be build against openssl-1.0.1 to get " + \
105 " TLSv1.1 and 1.2 support"
106 print "--> Falling back to TLSv1"
108 SSLDef.TLSv1 = SSL.TLSv1_METHOD
109 SSLDef.TLSv1_1 = SSL.TLSv1_METHOD
110 SSLDef.TLSv1_2 = SSL.TLSv1_METHOD
111 SSLDef.SSLv2 = SSL.SSLv2_METHOD
112 SSLDef.SSLv3 = SSL.SSLv3_METHOD
113 SSLDef.SSLv2_3 = SSL.SSLv23_METHOD
118 """ SSL Default transport Adapter """
121 super(SSLAdapter, self).
__init__(**kwargs)
132 """ TLS Default transport Adapter """
134 super(TLSAdapter, self).
__init__(ssl_version=
None, **kwargs)
138 """ TLSv1 Default transport Adapter """
140 super(TLS1Adapter, self).
__init__(ssl_version=SSLDef.TLSv1, **kwargs)
144 """ TLSv1.1 Default transport Adapter """
146 super(TLS11Adapter, self).
__init__(ssl_version=SSLDef.TLSv1_1, **kwargs)
150 """ TLSv1.2 Default transport Adapter """
152 super(TLS12Adapter, self).
__init__(ssl_version=SSLDef.TLSv1_2, **kwargs)
156 """ SSLv2 Default transport Adapter """
158 super(SSL2Adapter, self).
__init__(ssl_version=SSLDef.SSLv2,
162 """ SSLv3 Default transport Adapter """
164 super(SSL3Adapter, self).
__init__(ssl_version=SSLDef.SSLv3,
168 """ SSLv2_3 Default transport Adapter """
170 super(SSL23Adapter, self).
__init__(ssl_version=SSLDef.SSLv2_3,