@@ -31,6 +31,14 @@ def getWebKeyFile():
3131 return None
3232
3333
34+ try :
35+ from splunk .rest import is_cert_or_key_encrypted
36+ except (ModuleNotFoundError , ImportError ):
37+
38+ def is_cert_or_key_encrypted (cert_filename ):
39+ return False
40+
41+
3442from splunklib import binding
3543from solnlib import splunk_rest_client as rest_client
3644from solnlib import utils
@@ -75,21 +83,22 @@ def __init__(
7583 host == "localhost" or host == "127.0.0.1" or host in ("::1" , "[::1]" )
7684 )
7785
78- if getWebCertFile () and getWebKeyFile ():
79- context ["cert_file" ] = getWebCertFile ()
80- context ["key_file" ] = getWebKeyFile ()
86+ web_key_file = getWebKeyFile ()
87+ web_cert_file = getWebCertFile ()
88+ if web_cert_file and (
89+ web_key_file is None or not is_cert_or_key_encrypted (web_key_file )
90+ ):
91+ context ["cert_file" ] = web_cert_file
92+
93+ if web_key_file is not None :
94+ context ["key_file" ] = web_key_file
8195
8296 if all ([is_localhost , context .get ("verify" ) is None ]):
8397 # NOTE: this is specifically for mTLS communication
8498 # ONLY if scheme, host, port aren't provided AND user hasn't provided server certificate
8599 # we set verify to off (similar to 'rest.simpleRequest' implementation)
86100 context ["verify" ] = False
87101
88- elif getWebCertFile () is not None :
89- context ["cert_file" ] = getWebCertFile ()
90- if all ([is_localhost , context .get ("verify" ) is None ]):
91- context ["verify" ] = False
92-
93102 self ._rest_client = rest_client .SplunkRestClient (
94103 session_key , "-" , scheme = scheme , host = host , port = port , ** context
95104 )
0 commit comments