Skip to content

Commit 35ca774

Browse files
authored
Fix ssl verify to require certs when true (#233)
- Correct logic to always look for cert files when verify=True - Pass key_file and cert_file to handler from HttpLib - Changed default value of verify to False for backward compat
1 parent ef33349 commit 35ca774

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

splunklib/binding.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,8 @@ class Context(object):
467467
c = binding.Context(cookie="splunkd_8089=...")
468468
"""
469469
def __init__(self, handler=None, **kwargs):
470-
self.http = HttpLib(handler, kwargs.get("verify", True))
470+
self.http = HttpLib(handler, kwargs.get("verify", False), key_file=kwargs.get("key_file"),
471+
cert_file=kwargs.get("cert_file")) # Default to False for backward compat
471472
self.token = kwargs.get("token", _NoAuthenticationToken)
472473
if self.token is None: # In case someone explicitly passes token=None
473474
self.token = _NoAuthenticationToken
@@ -1120,8 +1121,11 @@ class HttpLib(object):
11201121
11211122
If using the default handler, SSL verification can be disabled by passing verify=False.
11221123
"""
1123-
def __init__(self, custom_handler=None, verify=True):
1124-
self.handler = handler(verify=verify) if custom_handler is None else custom_handler
1124+
def __init__(self, custom_handler=None, verify=False, key_file=None, cert_file=None):
1125+
if custom_handler is None:
1126+
self.handler = handler(verify=verify, key_file=key_file, cert_file=cert_file)
1127+
else:
1128+
self.handler = custom_handler
11251129
self._cookies = {}
11261130

11271131
def delete(self, url, headers=None, **kwargs):
@@ -1329,7 +1333,7 @@ def readinto(self, byte_array):
13291333
return bytes_read
13301334

13311335

1332-
def handler(key_file=None, cert_file=None, timeout=None, verify=True):
1336+
def handler(key_file=None, cert_file=None, timeout=None, verify=False):
13331337
"""This class returns an instance of the default HTTP request handler using
13341338
the values you provide.
13351339
@@ -1353,7 +1357,7 @@ def connect(scheme, host, port):
13531357
if cert_file is not None: kwargs['cert_file'] = cert_file
13541358

13551359
# If running Python 2.7.9+, disable SSL certificate validation
1356-
if (sys.version_info >= (2,7,9) and key_file is None and cert_file is None) or not verify:
1360+
if (sys.version_info >= (2,7,9) and key_file is None and cert_file is None) and not verify:
13571361
kwargs['context'] = ssl._create_unverified_context()
13581362
return six.moves.http_client.HTTPSConnection(host, port, **kwargs)
13591363
raise ValueError("unsupported scheme: %s" % scheme)

0 commit comments

Comments
 (0)