Skip to content

Commit fb18ca0

Browse files
author
Shakeel Mohamed
committed
If Python 2.7.9+ skip SSL cert verification
1 parent 7b6228e commit fb18ca0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

splunklib/binding.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import ssl
3131
import urllib
3232
import io
33+
import sys
3334

3435
from datetime import datetime
3536
from functools import wraps
@@ -1204,6 +1205,10 @@ def connect(scheme, host, port):
12041205
if scheme == "https":
12051206
if key_file is not None: kwargs['key_file'] = key_file
12061207
if cert_file is not None: kwargs['cert_file'] = cert_file
1208+
1209+
# If running Python 2.7.9+, disable SSL certificate validation
1210+
if sys.version_info >= (2,7,9) and key_file is None and cert_file is None:
1211+
kwargs['context'] = ssl._create_unverified_context()
12071212
return httplib.HTTPSConnection(host, port, **kwargs)
12081213
raise ValueError("unsupported scheme: %s" % scheme)
12091214

tests/test_binding.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import testlib
2525
import unittest
2626
import socket
27+
import sys
28+
import ssl
2729

2830
import splunklib.binding as binding
2931
from splunklib.binding import HTTPError, AuthenticationError, UrlEncoded
@@ -430,7 +432,11 @@ def urllib2_handler(url, message, **kwargs):
430432
headers = dict(message.get('headers', []))
431433
req = urllib2.Request(url, data, headers)
432434
try:
433-
response = urllib2.urlopen(req)
435+
# If running Python 2.7.9+, disable SSL certificate validation
436+
if sys.version_info >= (2, 7, 9):
437+
response = urllib2.urlopen(req, context=ssl._create_unverified_context())
438+
else:
439+
response = urllib2.urlopen(req)
434440
except urllib2.HTTPError, response:
435441
pass # Propagate HTTP errors via the returned response message
436442
return {

0 commit comments

Comments
 (0)