I am new to Python. I have installed signxml package and I am doing xml signature process.
Link to python package :
My xml file is getting generated. However XML signature code is little different. I was able to match most of the part but I donot have idea how to match following one.
Can any one please help me for that.
Different part is following tag
<Signature>Above part should be like this one
<Signature xmlns="">When i searched into signxml core file i found following note.
To specify the location of an enveloped signature within **data**, insert a
``<ds:Signature></ds:Signature>`` element in **data** (where
"ds" is the "" namespace). This element will
be replaced by the generated signature, and excised when generating the digest.How to make change to get this changed. Following is my python code
from lxml import etree
import xml.etree.ElementTree as ET
from signxml import XMLSigner, XMLVerifier
import signxml
el = ET.parse('example.xml')
root = el.getroot()
#cert = open("key/public.pem").read()
key = open("key/private.pem").read()
signed_root = XMLSigner(method=signxml.methods.enveloped,signature_algorithm='rsa-sha512',digest_algorithm="sha512").sign(root, key=key)
tree = ET.ElementTree(signed_root)
#dv = tree.findall(".//DigestValue");
#print(dv);
tree.write("new_signed_file.xml")What above code doing is. It takes one xml file and do digital signature process and generates new file.
Can anyone please guide me where and what change should i do for this requirements ?
1 Answer
I am assuming you are using python signxml
Go to python setup and open this file Python\Lib\site-packages\signxml\ __init__.py
Open __init__.py file and do following changes.
Find following code
def _unpack(self, data, reference_uris): sig_root = Element(ds_tag("Signature"), nsmap=self.namespaces)Change with following code.
def _unpack(self, data, reference_uris): #sig_root = Element(ds_tag("Signature"), nsmap=self.namespaces) sig_root = Element(ds_tag("Signature"), xmlns="")After doing this change re-compile your python signxml package.
Re-generate new xml signature file.