我尝试使用pyxmlsec/xmlsec/libxml2对XML文件进行签名,但失败了(sigCtx->signValueNode == NULL:error=100:assertion)。
当我从命令行运行时,它工作得很流畅:
xmlsec1 sign --output signed.xml --pkcs12 c.pfx --pwd mypwd tobesigned.xml我的Python代码:
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!
...完整错误跟踪:
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: 有什么建议吗?
谢谢!
发布于 2012-11-11 07:42:41
xmlsec是使用-DXMLSEC_NO_SIZE_T选项编译的,而pyxmlsec是使用-UXMLSEC_NO_SIZE_T编译的。
编辑setup.py并在t = tuple(flag[2:].split('='))之后添加以下行
if len(t) == 1: t = tuple([t[0],""])打补丁后效果很好。
确保清理、重建和重新安装!
https://stackoverflow.com/questions/13071246
复制相似问题