@staticmethod<EOL><INDENT>@return_false_on_exception<EOL>def validate_node_sign(signature_node, elem, cert=None, fingerprint=None, fingerprintalg='<STR_LIT>', validatecert=False, debug=False):<DEDENT>
if (cert is None or cert == '<STR_LIT>') and fingerprint:<EOL><INDENT>x509_certificate_nodes = OneLogin_Saml2_XML.query(signature_node, '<STR_LIT>')<EOL>if len(x509_certificate_nodes) > <NUM_LIT:0>:<EOL><INDENT>x509_certificate_node = x509_certificate_nodes[<NUM_LIT:0>]<EOL>x509_cert_value = OneLogin_Saml2_XML.element_text(x509_certificate_node)<EOL>x509_cert_value_formatted = OneLogin_Saml2_Utils.format_cert(x509_cert_value)<EOL>x509_fingerprint_value = OneLogin_Saml2_Utils.calculate_x509_fingerprint(x509_cert_value_formatted, fingerprintalg)<EOL>if fingerprint == x509_fingerprint_value:<EOL><INDENT>cert = x509_cert_value_formatted<EOL><DEDENT><DEDENT><DEDENT>if cert is None or cert == '<STR_LIT>':<EOL><INDENT>raise OneLogin_Saml2_Error(<EOL>'<STR_LIT>',<EOL>OneLogin_Saml2_Error.CERT_NOT_FOUND<EOL>)<EOL><DEDENT>reference_elem = OneLogin_Saml2_XML.query(signature_node, '<STR_LIT>')<EOL>if len(reference_elem) > <NUM_LIT:0>:<EOL><INDENT>if reference_elem[<NUM_LIT:0>].get('<STR_LIT>') == '<STR_LIT>':<EOL><INDENT>reference_elem[<NUM_LIT:0>].set('<STR_LIT>', '<STR_LIT>' % signature_node.getparent().get('<STR_LIT>'))<EOL><DEDENT><DEDENT>if validatecert:<EOL><INDENT>manager = xmlsec.KeysManager()<EOL>manager.load_cert_from_memory(cert, xmlsec.KeyFormat.CERT_PEM, xmlsec.KeyDataType.TRUSTED)<EOL>dsig_ctx = xmlsec.SignatureContext(manager)<EOL><DEDENT>else:<EOL><INDENT>dsig_ctx = xmlsec.SignatureContext()<EOL>dsig_ctx.key = xmlsec.Key.from_memory(cert, xmlsec.KeyFormat.CERT_PEM, None)<EOL><DEDENT>dsig_ctx.set_enabled_key_data([xmlsec.KeyData.X509])<EOL>try:<EOL><INDENT>dsig_ctx.verify(signature_node)<EOL><DEDENT>except Exception as err:<EOL><INDENT>raise OneLogin_Saml2_ValidationError(<EOL>'<STR_LIT>',<EOL>OneLogin_Saml2_ValidationError.INVALID_SIGNATURE,<EOL>str(err)<EOL>)<EOL><DEDENT>return True<EOL>
Validates a signature node.

:param signature_node: The signature node
:type: Node

:param xml: The element we should validate
:type: Document

:param cert: The public cert
:type: string

:param fingerprint: The fingerprint of the public cert
:type: string

:param fingerprintalg: The algorithm used to build the fingerprint
:type: string

:param validatecert: If true, will verify the signature and if the cert is valid.
:type: bool

:param debug: Activate the xmlsec debug
:type: bool

:param raise_exceptions: Whether to return false on failure or raise an exception
:type raise_exceptions: Boolean