Skip to content

Commit cbc50c9

Browse files
author
Kevin D Smith
committed
Merge branch 'master' of github.com:sassoftware/python-swat
2 parents 4c3a894 + e21d193 commit cbc50c9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

swat/cas/rest/connection.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import re
3030
import requests
3131
import six
32+
import ssl
3233
import sys
3334
from six.moves import urllib
3435
from .message import REST_CASMessage
@@ -159,6 +160,15 @@ def _normalize_list(items):
159160
return newitems
160161

161162

163+
class SSLContextAdapter(requests.adapters.HTTPAdapter):
164+
"""HTTPAdapter that uses the default SSL context on the machine."""
165+
166+
def init_poolmanager(self, connections, maxsize, block=requests.adapters.DEFAULT_POOLBLOCK, **pool_kwargs):
167+
context = ssl.create_default_context()
168+
pool_kwargs['ssl_context'] = context
169+
return super(SSLContextAdapter, self).init_poolmanager(connections, maxsize, block, **pool_kwargs)
170+
171+
162172
class REST_CASConnection(object):
163173
'''
164174
Create a REST CAS connection
@@ -260,6 +270,8 @@ def __init__(self, hostname, port, username, password, soptions, error):
260270
self._req_sess.verify = os.path.expanduser(os.environ['SSLCALISTLOC'])
261271
elif 'CAS_CLIENT_SSL_CA_LIST' in os.environ:
262272
self._req_sess.verify = os.path.expanduser(os.environ['CAS_CLIENT_SSL_CA_LIST'])
273+
elif 'REQUESTS_CA_BUNDLE' not in os.environ:
274+
self._req_sess.mount('https://', SSLContextAdapter())
263275

264276
if os.environ.get('SSLREQCERT', 'y').lower().startswith('n'):
265277
self._req_sess.verify = False

0 commit comments

Comments
 (0)