Skip to content

Commit 9f3a51b

Browse files
committed
SPL-264208 MSB-3468 Update python library to support mTLS when web private key is encrypted
1 parent 4415aed commit 9f3a51b

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

solnlib/server_info.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
3442
from splunklib import binding
3543
from solnlib import splunk_rest_client as rest_client
3644
from solnlib import utils
@@ -75,18 +83,24 @@ 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 (
89+
web_cert_file
90+
and web_key_file
91+
and not is_cert_or_key_encrypted(web_key_file)
92+
):
93+
context["cert_file"] = web_cert_file
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()
102+
elif web_cert_file is not None:
103+
context["cert_file"] = web_cert_file
90104
if all([is_localhost, context.get("verify") is None]):
91105
context["verify"] = False
92106

0 commit comments

Comments
 (0)