Python和m2crypto从字符串加载证书和私钥

时间:2015-01-28 12:57:15

标签: python m2crypto

你能帮我解决m2crypto吗?

以下代码是返回'HTTP / 1.1 403 Forbidden'服务器。 证书和私钥未加载到代码中:

from M2Crypto import Rand, SSL, httpslib, threading , BIO , X509 , RSA
ctx = SSL.Context('sslv23')
store = ctx.get_cert_store()
bio = BIO.MemoryBuffer()
bio.write( str( open( 'certi.pem', 'r' ).read() ) )
store.add_x509( X509.load_cert_bio(bio) )

# or
# store.add_x509( X509.load_cert_string( str(open( 'certi.pem', 'r' ).read()) ) )

ctx.set_verify( SSL.verify_none, depth=1 )    
ctx.set_info_callback()
h = httpslib.HTTPSConnection( ‘Server’, 443, ssl_context=ctx )
h.set_debuglevel(1)
h.request( 'mysoap' )

当我这样做时,它有效:

from M2Crypto import Rand, SSL, httpslib, threading , BIO , X509 , RSA
ctx = SSL.Context('sslv23')
ctx.load_cert_chain( str( 'certi.pem' ) ) 
ctx.set_verify( SSL.verify_none, depth=1 )    
ctx.set_info_callback()
h = httpslib.HTTPSConnection( ‘Server’, 443, ssl_context=ctx )
h.set_debuglevel(1)
h.request( 'mysoap' )

感谢的

0 个答案:

没有答案
相关问题