Open edsonbernar opened 3 years ago
@edsonbernar what line breaks do you mean exactly? The string representation of the XML tree is generated by lxml's etree.tostring()
function, this isn't part of xmlsec
.
Hi, The code 'return etree.tostring(xml_element, encoding=str)' is just my output. Signing takes place before that.
If you add the code below before 'ctx.sign(signature_node)' then the signature is generated in the correct pattern.
signature_node = etree.tostring(
signature_node, encoding=str).replace('\n','')
signature_node = etree.fromstring(signature_node)
parent.append(signature_node)
ctx.sign(signature_node)
It seems to me that 'xmlsec.template.create()' introduces line breaks throughout the signature node. At least that's what I notice when I open the signed xml in an editor. Using another library to sign (signxml), the signature node does not come out with line breaks.
If you mean the line breaks in the base64-encoded signature value, then you can control the maximal line size via xmlsec.base64_default_line_size
, e.g.
import xmlsec
xmlsec.base64_default_line_size(size=4096)
...
Otherwise, please provide a reproducible example that illustrates what you mean exactly.
I already use 'xmlsec.base64_default_line_size' to avoid line breaks in the certificate. I will try to make the xml signature with the 'Signature' element already existing in the xml, without using 'xmlsec.template.create' to create and then add.
I tested it and the result was the same. Because of the breaks the 'SignatureValue' is different from other libraries (.Net, Python Signxml) The 'DigestValue' is calculated the same in all. Anyway thanks for the help.
Hi, Is it possible to avoid line breaks in the signature tag that is generated? Some servers refuse these characters.
Code