Python dm.xmlsec“签名验证失败”

时间:2014-05-27 12:31:53

标签: python openssl x509certificate signature

我想用公钥验证Windows Mobile InApp Receipt我有证书(.cer),我有.pem文件,我得到公钥

这是我的代码:

import dm.xmlsec.binding as xmlsec
xmlsec.initialize()
from os.path import dirname, basename
from lxml import etree
from lxml.etree import tostring
def verify_file(xml_file, key_file):
     """verify signature in *xml_file* with key in *key_file*.

     *xml_file* contains the signed XML document.
     It can be a file, a filename string or an HTTP/FTP url.

     *key_file* contains the PEM public key. It must be a filename.

     An exception is raised when the verification fails.
     """
     from lxml.etree import parse
     doc = etree.parse(xml_file)
     node = doc.find(".//{%s}Signature" % xmlsec.DSigNs)
     dsigCtx = xmlsec.DSigCtx()
     # Note: we do not provide read access to `dsigCtx.signKey`.
     #  Therefore, unlike the `xmlsec` example, we must set the key name
     #  before we assign it to `dsigCtx`

     signKey = xmlsec.Key.load(key_file, xmlsec.KeyDataFormatPem, None)
     signKey.name = basename(key_file)
     # Note: the assignment below effectively copies the key
     dsigCtx.signKey = signKey
     dsigCtx.verify(node)

from StringIO import StringIO
if __name__ =="__main__" :
     verify_file('path/of/ReceiptSHA256.xml', 'path/of/pubkey.pem')


但每次运行dsigCtx.verify(node)时问题都会给我错误:

File "_xmlsec.pyx", line 369, in dm.xmlsec.binding._xmlsec.DSigCtx.verify (src/_xmlsec.c:5182) 
dm.xmlsec.binding._xmlsec.VerificationError: ('signature verification failed', 2) 

当我调试它然后我发现实际dsigCtx.verify(node)给我错误
tuple: ('verifying failed with return value', -1)

我有有效证书,.pem文件,公钥和收据但它仍然给我错误

请在此问候中帮助我,

0 个答案:

没有答案