@@ -471,18 +471,25 @@ def import_rsa_key_from_file(filename):
471
471
return key
472
472
473
473
474
- def parse_xmlsec_output ( output ):
474
+ def parse_xmlsec_verify_output ( xmlsec_vsn , output ):
475
475
"""Parse the output from xmlsec to try to find out if the
476
476
command was successfull or not.
477
477
478
478
:param output: The output from Popen
479
479
:return: A boolean; True if the command was a success otherwise False
480
480
"""
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 )
486
493
raise XmlsecError (output )
487
494
488
495
@@ -629,6 +636,9 @@ def __init__(self, xmlsec_binary, delete_tmpfiles=True, **kwargs):
629
636
raise ValueError ("xmlsec_binary should be of type string" )
630
637
self .xmlsec = xmlsec_binary
631
638
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 ))
632
642
try :
633
643
self .non_xml_crypto = RSACrypto (kwargs ["rsa_key" ])
634
644
except KeyError :
@@ -824,7 +834,7 @@ def validate_signature(self, signedtext, cert_file, cert_type, node_name, node_i
824
834
except XmlsecError as e :
825
835
raise SignatureError (com_list ) from e
826
836
827
- return parse_xmlsec_output ( stderr )
837
+ return parse_xmlsec_verify_output ( self . vsn , stderr )
828
838
829
839
def _run_xmlsec (self , com_list , extra_args ):
830
840
"""
@@ -836,6 +846,8 @@ def _run_xmlsec(self, com_list, extra_args):
836
846
"""
837
847
with NamedTemporaryFile (suffix = ".xml" ) as ntf :
838
848
com_list .extend (["--output" , ntf .name ])
849
+ if self .vsn >= (1 , 3 ):
850
+ com_list .extend (['--lax-key-search' ])
839
851
com_list += extra_args
840
852
841
853
logger .debug ("xmlsec command: %s" , " " .join (com_list ))
0 commit comments