Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@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