English 中文(简体)
与露天相比,m2加密错误行为
原标题:wrong behaviour of m2crypto compared to openssl

我必须巩固并可能重新布置一只手脚印,以证实新电文是有效的(即与公司私人钥匙加密并签署了一套公用钥匙)。

这个布沙板将被小的申请所取代,可能的话,在M2Crypto的帮助下,写到Tald。

直到现在,加密部分实际上运行良好,但我对签字的核查有问题。

我需要撰写假冒代码,以取代这一单方双线。

 openssl smime -verify -in to_verify.txt -CAfile signer_pubkey.pem -out verified.txt

核实内容。 txt是“普通”多部分/签名第7页,可以附在签名上或没有签名。

先前的指挥部门在核查成功时撤离0次,并从烟幕中提取内容。

如今,在平线上,从m2加密实例中取回:

import os
from M2Crypto import BIO, Rand, SMIME, X509
cert_dir =  /home/niphlod/certs 
doc_dir =  /home/niphlod/datastore 

signer = os.path.join(cert_dir,  signer_pubkey.pem )
letter = os.path.join(doc_dir, out_decrypt.txt )

# Instantiate an SMIME object.
s = SMIME.SMIME()

# Load the signer s cert. 
x509 = X509.load_cert(signer)
sk = X509.X509_Stack()
sk.push(x509)
s.set_x509_stack(sk)

# Load the signer s CA cert. They re all self-signed, hence the following
st = X509.X509_Store()
st.load_info(signer)
s.set_x509_store(st)

# Load the data, verify it.
p7, data = SMIME.smime_load_pkcs7(letter)
v = s.verify(p7)
print v
print data
print data.read()

......令人惊讶的是,我感到惊讶。

Traceback (most recent call last):
  File "m2crypto_verify.py", line 28, in <module>
    v = s.verify(p7)
  File "/usr/lib/pymodules/python2.6/M2Crypto/SMIME.py", line 215, in verify
    blob = m2.pkcs7_verify0(p7, self.x509_stack._ptr(), self.x509_store._ptr(), flags)
M2Crypto.SMIME.PKCS7_Error: no content

开放式正读、提取和核实这些档案正确,但 m2加密如何报告没有内容?

BUMP: 没有人对此感兴趣?

问题回答

I ve利用M2Cryp纽约总部 v0.17改变行文,围绕一个类似的问题开展工作:

 v= s.verify(p7)

纽约总部

 v = s.verify(p7,data)

回答是正确的。

    v = s.verify(p7,data)

核实方法需要比较已签字电文的两部分(即与加密的正文)。

这一职能涉及以下几个论点:M2Crypto doc。 http://www.openssl PKCS7_verification methodsdocument in OpenSSL s doc。 不幸的是,M2Crypto s tutorial含有错误的缺省值(至少在我的环境下为0.20.1)。

这是用于与M2Crypto进行S/Mime核查的Im机制。

# Load the data
#
try:
  p7, data = SMIME.smime_load_pkcs7( letter )
except SMIME.SMIME_Error, e:
  print  Error: could not load {file} because {error} .format(file=letter,error=e)
  sys.exit()

# Verify the data
#
try:
  if data is not None:
    v = s.verify(p7, data)
  else:
    v = s.verify(p7)
  if v:
    print  Client signature verified 
except SMIME.SMIME_Error, e:
  print  Error: message verification failed %s  % e




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签