@@ -465,6 +465,8 @@ class Context:
465
465
:type scheme: "https" or "http"
466
466
:param verify: Enable (True) or disable (False) SSL verification for https connections.
467
467
:type verify: ``Boolean``
468
+ :param self_signed_certificate: Specifies if self signed certificate is used
469
+ :type self_signed_certificate: ``Boolean``
468
470
:param sharing: The sharing mode for the namespace (the default is "user").
469
471
:type sharing: "global", "system", "app", or "user"
470
472
:param owner: The owner context of the namespace (optional, the default is "None").
@@ -526,6 +528,7 @@ def __init__(self, handler=None, **kwargs):
526
528
self .bearerToken = kwargs .get ("splunkToken" , "" )
527
529
self .autologin = kwargs .get ("autologin" , False )
528
530
self .additional_headers = kwargs .get ("headers" , [])
531
+ self ._self_signed_certificate = kwargs .get ("self_signed_certificate" , True )
529
532
530
533
# Store any cookies in the self.http._cookies dict
531
534
if "cookie" in kwargs and kwargs ['cookie' ] not in [None , _NoAuthenticationToken ]:
@@ -604,7 +607,11 @@ def connect(self):
604
607
"""
605
608
sock = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
606
609
if self .scheme == "https" :
607
- sock = ssl .wrap_socket (sock )
610
+ context = ssl .create_default_context ()
611
+ context .options |= ssl .OP_NO_TLSv1 | ssl .OP_NO_TLSv1_1
612
+ context .check_hostname = not self ._self_signed_certificate
613
+ context .verify_mode = ssl .CERT_NONE if self ._self_signed_certificate else ssl .CERT_REQUIRED
614
+ sock = context .wrap_socket (sock , server_hostname = self .host )
608
615
sock .connect ((socket .gethostbyname (self .host ), self .port ))
609
616
return sock
610
617
0 commit comments