I'm trying to sign a XML file using pyxmlsec/xmlsec/libxml2 but it fails (sigCtx->signValueNode == NULL:error=100:assertion
).
When I run from command line it works smoothly:
xmlsec1 sign --output signed.xml --pkcs12 c.pfx --pwd mypwd tobesigned.xml
My Python code:
libxml2.initParser()
libxml2.substituteEntitiesDefault(1)
xmlsec.init()
xmlsec.cryptoAppInit(None)
xmlsec.cryptoInit()
doc_xml = libxml2.parseMemory(xml, len(xml))
signature_node = xmlsec.findNode(
doc_xml.getRootElement(),
xmlsec.NodeSignature,
xmlsec.DSigNs,
)
signer = xmlsec.DSigCtx()
key = xmlsec.cryptoAppKeyLoad(
filename=str(self.issuer.certificate.path),
format=xmlsec.KeyDataFormatPkcs12,
pwd=str(self.issuer.certificate_password),
pwdCallback=None,
pwdCallbackCtx=None,
)
signer.signKey = key
signer.sign(signature_node) # error!
...
Full error trace:
func=xmlSecDSigCtxProcessSignatureNode:file=xmldsig.c:line=463:obj=unknown:subj=dsigCtx->signValueNode == NULL:error=100:assertion:
func=xmlSecDSigCtxSign:file=xmldsig.c:line=303:obj=unknown:subj=xmlSecDSigCtxSigantureProcessNode:error=1:xmlsec library function failed:
Any tips?
Thanks!
xmlsec was compiled with -DXMLSEC_NO_SIZE_T option and pyxmlsec with -UXMLSEC_NO_SIZE_T.
Edit setup.py and add the following line after t = tuple(flag[2:].split('='))
if len(t) == 1: t = tuple([t[0],""])
Works well after patching.
Make sure to clean, rebuild and reinstall!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With