@@ -31,6 +31,14 @@ def getWebKeyFile():
31
31
return None
32
32
33
33
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
+
34
42
from splunklib import binding
35
43
from solnlib import splunk_rest_client as rest_client
36
44
from solnlib import utils
@@ -75,21 +83,22 @@ def __init__(
75
83
host == "localhost" or host == "127.0.0.1" or host in ("::1" , "[::1]" )
76
84
)
77
85
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
81
95
82
96
if all ([is_localhost , context .get ("verify" ) is None ]):
83
97
# NOTE: this is specifically for mTLS communication
84
98
# ONLY if scheme, host, port aren't provided AND user hasn't provided server certificate
85
99
# we set verify to off (similar to 'rest.simpleRequest' implementation)
86
100
context ["verify" ] = False
87
101
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
-
93
102
self ._rest_client = rest_client .SplunkRestClient (
94
103
session_key , "-" , scheme = scheme , host = host , port = port , ** context
95
104
)
0 commit comments