Skip to content

Commit dd81512

Browse files
timofey-barminc00kiemon5ter
authored andcommitted
Add support for xmlsec1 1.3
1 parent 94ffddf commit dd81512

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/saml2/sigver.py

+19-7
Original file line numberDiff line numberDiff line change
@@ -471,18 +471,25 @@ def import_rsa_key_from_file(filename):
471471
return key
472472

473473

474-
def parse_xmlsec_output(output):
474+
def parse_xmlsec_verify_output(xmlsec_vsn, output):
475475
"""Parse the output from xmlsec to try to find out if the
476476
command was successfull or not.
477477
478478
:param output: The output from Popen
479479
:return: A boolean; True if the command was a success otherwise False
480480
"""
481-
for line in output.splitlines():
482-
if line == "OK":
483-
return True
484-
elif line == "FAIL":
485-
raise XmlsecError(output)
481+
if xmlsec_vsn < (1, 3):
482+
for line in output.splitlines():
483+
if line == "OK":
484+
return True
485+
elif line == "FAIL":
486+
raise XmlsecError(output)
487+
else:
488+
for line in output.splitlines():
489+
if line == 'Verification status: OK':
490+
return True
491+
elif line == 'Verification status: FAILED':
492+
raise XmlsecError(output)
486493
raise XmlsecError(output)
487494

488495

@@ -629,6 +636,9 @@ def __init__(self, xmlsec_binary, delete_tmpfiles=True, **kwargs):
629636
raise ValueError("xmlsec_binary should be of type string")
630637
self.xmlsec = xmlsec_binary
631638
self.delete_tmpfiles = delete_tmpfiles
639+
vsn = self.version()
640+
[maj_num_str, min_num_str] = vsn.split('.')[0:2]
641+
self.vsn = (int(maj_num_str), int(min_num_str))
632642
try:
633643
self.non_xml_crypto = RSACrypto(kwargs["rsa_key"])
634644
except KeyError:
@@ -824,7 +834,7 @@ def validate_signature(self, signedtext, cert_file, cert_type, node_name, node_i
824834
except XmlsecError as e:
825835
raise SignatureError(com_list) from e
826836

827-
return parse_xmlsec_output(stderr)
837+
return parse_xmlsec_verify_output(self.vsn, stderr)
828838

829839
def _run_xmlsec(self, com_list, extra_args):
830840
"""
@@ -836,6 +846,8 @@ def _run_xmlsec(self, com_list, extra_args):
836846
"""
837847
with NamedTemporaryFile(suffix=".xml") as ntf:
838848
com_list.extend(["--output", ntf.name])
849+
if self.vsn >= (1, 3):
850+
com_list.extend(['--lax-key-search'])
839851
com_list += extra_args
840852

841853
logger.debug("xmlsec command: %s", " ".join(com_list))

0 commit comments

Comments
 (0)