How to use the signxml.methods.detached function in signxml

To help you get started, we’ve selected a few signxml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github VOLTTRON / volttron / services / core / OpenADRVenAgent / openadrven / agent.py View on Github external
    @staticmethod
    def calculate_signature(signed_object_xml):
        """
            Calculate a digital signature for the SignedObject to be sent to the VTN.

        @param signed_object_xml: (xml string) A SignedObject.
        @return: (lxml) A Signature and a SignedObject.
        """
        signed_object_lxml = etree_.fromstring(signed_object_xml)
        signed_object_lxml.set('Id', 'signedObject')
        # Use XMLSigner to create a Signature.
        # Use "detached method": the signature lives alonside the signed object in the XML element tree.
        # Use c14n "exclusive canonicalization": the signature is independent of namespace inclusion/exclusion.
        signer = signxml.XMLSigner(method=signxml.methods.detached,
                                   c14n_algorithm='http://www.w3.org/2001/10/xml-exc-c14n#')
        signature_lxml = signer.sign(signed_object_lxml,
                                     key=open(KEY_FILENAME, 'rb').read(),
                                     cert=open(CERT_FILENAME, 'rb').read(),
                                     key_name='123')
        # This generated Signature lacks the ReplayProtect property described in OpenADR profile spec section 10.6.3.
        return signature_lxml, signed_object_lxml

signxml

Python XML Signature and XAdES library

Apache-2.0
Latest version published 2 months ago

Package Health Score

77 / 100
Full package analysis

Similar packages