Added support for client SSL certificates for https
Thanks almer-fuel for the inital patch!
This commit is contained in:
@@ -19,9 +19,12 @@ class RequestsHttpConnection(Connection):
|
|||||||
:arg verify_certs: whether to verify SSL certificates
|
:arg verify_certs: whether to verify SSL certificates
|
||||||
:arg ca_certs: optional path to CA bundle. By default standard requests'
|
:arg ca_certs: optional path to CA bundle. By default standard requests'
|
||||||
bundle will be used.
|
bundle will be used.
|
||||||
|
:arg client_cert: path to the file containing the private key and the
|
||||||
|
certificate
|
||||||
"""
|
"""
|
||||||
def __init__(self, host='localhost', port=9200, http_auth=None,
|
def __init__(self, host='localhost', port=9200, http_auth=None,
|
||||||
use_ssl=False, verify_certs=False, ca_certs=None, **kwargs):
|
use_ssl=False, verify_certs=False, ca_certs=None, client_cert=None,
|
||||||
|
**kwargs):
|
||||||
if not REQUESTS_AVAILABLE:
|
if not REQUESTS_AVAILABLE:
|
||||||
raise ImproperlyConfigured("Please install requests to use RequestsHttpConnection.")
|
raise ImproperlyConfigured("Please install requests to use RequestsHttpConnection.")
|
||||||
|
|
||||||
@@ -37,6 +40,7 @@ class RequestsHttpConnection(Connection):
|
|||||||
host, port, self.url_prefix
|
host, port, self.url_prefix
|
||||||
)
|
)
|
||||||
self.session.verify = verify_certs
|
self.session.verify = verify_certs
|
||||||
|
self.session.cert = client_cert
|
||||||
if ca_certs:
|
if ca_certs:
|
||||||
if not verify_certs:
|
if not verify_certs:
|
||||||
raise ImproperlyConfigured("You cannot pass CA certificates when verify SSL is off.")
|
raise ImproperlyConfigured("You cannot pass CA certificates when verify SSL is off.")
|
||||||
|
|||||||
@@ -17,12 +17,14 @@ class Urllib3HttpConnection(Connection):
|
|||||||
:arg ca_certs: optional path to CA bundle. See
|
:arg ca_certs: optional path to CA bundle. See
|
||||||
http://urllib3.readthedocs.org/en/latest/security.html#using-certifi-with-urllib3
|
http://urllib3.readthedocs.org/en/latest/security.html#using-certifi-with-urllib3
|
||||||
for instructions how to get default set
|
for instructions how to get default set
|
||||||
|
:arg client_cert: path to the file containing the private key and the
|
||||||
|
certificate
|
||||||
:arg maxsize: the maximum number of connections which will be kept open to
|
:arg maxsize: the maximum number of connections which will be kept open to
|
||||||
this host.
|
this host.
|
||||||
"""
|
"""
|
||||||
def __init__(self, host='localhost', port=9200, http_auth=None,
|
def __init__(self, host='localhost', port=9200, http_auth=None,
|
||||||
use_ssl=False, verify_certs=False, ca_certs=None, maxsize=10,
|
use_ssl=False, verify_certs=False, ca_certs=None, client_cert=None,
|
||||||
**kwargs):
|
maxsize=10, **kwargs):
|
||||||
|
|
||||||
super(Urllib3HttpConnection, self).__init__(host=host, port=port, **kwargs)
|
super(Urllib3HttpConnection, self).__init__(host=host, port=port, **kwargs)
|
||||||
self.headers = {}
|
self.headers = {}
|
||||||
@@ -39,6 +41,7 @@ class Urllib3HttpConnection(Connection):
|
|||||||
if verify_certs:
|
if verify_certs:
|
||||||
kw['cert_reqs'] = 'CERT_REQUIRED'
|
kw['cert_reqs'] = 'CERT_REQUIRED'
|
||||||
kw['ca_certs'] = ca_certs
|
kw['ca_certs'] = ca_certs
|
||||||
|
kw['cert_file'] = client_cert
|
||||||
elif ca_certs:
|
elif ca_certs:
|
||||||
raise ImproperlyConfigured("You cannot pass CA certificates when verify SSL is off.")
|
raise ImproperlyConfigured("You cannot pass CA certificates when verify SSL is off.")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user