@@ -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 (output , version = None ):
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 version is None or version < (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
@@ -593,9 +600,18 @@ def verify_redirect_signature(saml_msg, crypto, cert=None, sigkey=None):
593
600
594
601
595
602
class CryptoBackend :
603
+ @property
596
604
def version (self ):
597
605
raise NotImplementedError ()
598
606
607
+ @property
608
+ def version_nums (self ):
609
+ try :
610
+ vns = tuple (int (t ) for t in self .version )
611
+ except ValueError :
612
+ vns = (0 , 0 , 0 )
613
+ return vns
614
+
599
615
def encrypt (self , text , recv_key , template , key_type ):
600
616
raise NotImplementedError ()
601
617
@@ -634,6 +650,7 @@ def __init__(self, xmlsec_binary, delete_tmpfiles=True, **kwargs):
634
650
except KeyError :
635
651
pass
636
652
653
+ @property
637
654
def version (self ):
638
655
com_list = [self .xmlsec , "--version" ]
639
656
pof = Popen (com_list , stderr = PIPE , stdout = PIPE )
@@ -642,7 +659,7 @@ def version(self):
642
659
try :
643
660
return content .split (" " )[1 ]
644
661
except IndexError :
645
- return ""
662
+ return "0.0.0 "
646
663
647
664
def encrypt (self , text , recv_key , template , session_key_type , xpath = "" ):
648
665
"""
@@ -824,7 +841,7 @@ def validate_signature(self, signedtext, cert_file, cert_type, node_name, node_i
824
841
except XmlsecError as e :
825
842
raise SignatureError (com_list ) from e
826
843
827
- return parse_xmlsec_output (stderr )
844
+ return parse_xmlsec_verify_output (stderr , self . version_nums )
828
845
829
846
def _run_xmlsec (self , com_list , extra_args ):
830
847
"""
@@ -836,6 +853,8 @@ def _run_xmlsec(self, com_list, extra_args):
836
853
"""
837
854
with NamedTemporaryFile (suffix = ".xml" ) as ntf :
838
855
com_list .extend (["--output" , ntf .name ])
856
+ if self .version_nums >= (1 , 3 ):
857
+ com_list .extend (['--lax-key-search' ])
839
858
com_list += extra_args
840
859
841
860
logger .debug ("xmlsec command: %s" , " " .join (com_list ))
@@ -870,10 +889,13 @@ class CryptoBackendXMLSecurity(CryptoBackend):
870
889
def __init__ (self ):
871
890
CryptoBackend .__init__ (self )
872
891
892
+ @property
873
893
def version (self ):
874
- # XXX if XMLSecurity.__init__ included a __version__, that would be
875
- # better than static 0.0 here.
876
- return "XMLSecurity 0.0"
894
+ try :
895
+ import xmlsec
896
+ return xmlsec .__version__
897
+ except (ImportError , AttributeError ):
898
+ return "0.0.0"
877
899
878
900
def sign_statement (self , statement , node_name , key_file , node_id ):
879
901
"""
0 commit comments