繁体   English   中英

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

[英]Python and m2crypto load certificate and private key from string

你能帮我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' )

谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM