English 中文(简体)
m2 加密习俗验证
原标题:m2crypto custom certificate verification

I need to build an encrypted connection between two peers, and I need to authenticate both. Both peers already share a fingerprint (SHA256 hash) of the other peer public key. I m not using X509 or OpenPGP keys/certs as they are too big and bulky for my needs and they don t fit in the security model.

I m 试图通过滥用其X509模式与M2Crypto(宗教图书馆)建立联系:

  • 鉴于母体是私人钥匙,形成了一种几乎自动的ert。

  • 与其他同侪建立联系,提供我的证明

  • • 核实其他同侪 c;

Is the following code secure? is it correct? is there a way do do it better (maybe with other libraries)? My doubts are about OpenSSL not actually using the certificate public key for authentication as I m not requesting any verification of the certificates.

我只需要使用被废弃编码编码的机车钥匙所储存的加密流,欢迎任何免费的假日软件解决方案。 我更喜欢M2Crypto,因为我知道它更好,并且已经在同一个项目中使用它的一些法典。

我的守则(调整客户同侪,服务器应当类似):

other_fingerprints = [] #list of fingerprints, (binary data)
mysocket = ... #any socket object

CERTFILE, KEYFILE = "testcert","testkey" # private key wrapped in the cert

from M2Crypto import *
ctx = SSL.Context( sslv3 )
ctx.set_verify(SSL.verify_none, depth=1)
ctx.load_cert(CERTFILE, KEYFILE)
c = SSL.Connection(ctx, mysocket)
c.connect_ssl()
peercert = c.get_peer_cert()
keyobj = peercert.get_pubkey()
keydata = keyobj.as_der()
md = EVP.MessageDigest( sha256 )
md.update(keydata)
h = md.digest()
if h not in other_fingerprints:
    raise(IOError) #other party not auth ed
# from now on the connection is secure, right?
c.send("Hello secret world!")
print c.recv(4096)
c.close()

事先感谢你的答复和建议。

最佳回答

你的做法似乎应当发挥作用,但已经有一个可以使用的 built印检查器。 见以下网址:。 在建立开放式特别轨道的关键时,怎么办?

问题回答

问题在于:使用适当的X509证书,验证/核实不对称。 “这是否安全?”——因为你不得不问。

你的解决办法可能奏效,但你要求就“这一安全性?”提出建议。 告诉我,你或许应该从盒子中直接使用。





相关问题
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 ]="...

热门标签