@@ -760,7 +760,7 @@ def add_sign(xml, key, cert, debug=False, sign_algorithm=OneLogin_Saml2_Constant
760760
761761 @staticmethod
762762 @return_false_on_exception
763- def validate_sign (xml , cert = None , fingerprint = None , fingerprintalg = 'sha1' , validatecert = False , debug = False , xpath = None ):
763+ def validate_sign (xml , cert = None , fingerprint = None , fingerprintalg = 'sha1' , validatecert = False , debug = False , xpath = None , multicerts = None ):
764764 """
765765 Validates a signature (Message or Assertion).
766766
@@ -785,6 +785,9 @@ def validate_sign(xml, cert=None, fingerprint=None, fingerprintalg='sha1', valid
785785 :param xpath: The xpath of the signed element
786786 :type: string
787787
788+ :param multicerts: Multiple public certs
789+ :type: list
790+
788791 :param raise_exceptions: Whether to return false on failure or raise an exception
789792 :type raise_exceptions: Boolean
790793 """
@@ -805,8 +808,21 @@ def validate_sign(xml, cert=None, fingerprint=None, fingerprintalg='sha1', valid
805808
806809 if len (signature_nodes ) == 1 :
807810 signature_node = signature_nodes [0 ]
808- # Raises expection if invalid
809- return OneLogin_Saml2_Utils .validate_node_sign (signature_node , elem , cert , fingerprint , fingerprintalg , validatecert , debug , raise_exceptions = True )
811+
812+ if not multicerts :
813+ return OneLogin_Saml2_Utils .validate_node_sign (signature_node , elem , cert , fingerprint , fingerprintalg , validatecert , debug , raise_exceptions = True )
814+ else :
815+ # If multiple certs are provided, I may ignore cert and
816+ # fingerprint provided by the method and just check the
817+ # certs multicerts
818+ fingerprint = fingerprintalg = None
819+ for cert in multicerts :
820+ if OneLogin_Saml2_Utils .validate_node_sign (signature_node , elem , cert , fingerprint , fingerprintalg , validatecert , False , raise_exceptions = False ):
821+ return True
822+ raise OneLogin_Saml2_ValidationError (
823+ 'Signature validation failed. SAML Response rejected.' ,
824+ OneLogin_Saml2_ValidationError .INVALID_SIGNATURE
825+ )
810826 else :
811827 raise OneLogin_Saml2_ValidationError (
812828 'Expected exactly one signature node; got {}.' .format (len (signature_nodes )),
0 commit comments