本文整理汇总了Python中twisted.internet.ssl.ClientContextFactory.getContext方法的典型用法代码示例。如果您正苦于以下问题:Python ClientContextFactory.getContext方法的具体用法?Python ClientContextFactory.getContext怎么用?Python ClientContextFactory.getContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.ssl.ClientContextFactory
的用法示例。
在下文中一共展示了ClientContextFactory.getContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MyWebClientContextFactory
# 需要导入模块: from twisted.internet.ssl import ClientContextFactory [as 别名]
# 或者: from twisted.internet.ssl.ClientContextFactory import getContext [as 别名]
class MyWebClientContextFactory(object):
def __init__(self):
self._options = ClientContextFactory()
def getContext(self, hostname, port):
return self._options.getContext()
示例2: getContext
# 需要导入模块: from twisted.internet.ssl import ClientContextFactory [as 别名]
# 或者: from twisted.internet.ssl.ClientContextFactory import getContext [as 别名]
def getContext(self, hostname, port):
ctx = ClientContextFactory.getContext(self)
ctx.set_options(SSL.OP_NO_SSLv2)
if self._verify:
ctx.load_verify_locations(None, self._verify_location)
ctx.set_verify(SSL.VERIFY_PEER|SSL.VERIFY_FAIL_IF_NO_PEER_CERT, self._verifyCert)
return ctx
示例3: getContext
# 需要导入模块: from twisted.internet.ssl import ClientContextFactory [as 别名]
# 或者: from twisted.internet.ssl.ClientContextFactory import getContext [as 别名]
def getContext(self):
ctx = ClientContextFactory.getContext(self)
# Enable all workarounds to SSL bugs as documented by
# http://www.openssl.org/docs/ssl/SSL_CTX_set_options.html
ctx.set_options(OP_ALL)
if self.hostname:
ScrapyClientTLSOptions(self.hostname, ctx)
return ctx
示例4: getContext
# 需要导入模块: from twisted.internet.ssl import ClientContextFactory [as 别名]
# 或者: from twisted.internet.ssl.ClientContextFactory import getContext [as 别名]
def getContext(self, hostname=None, port=None):
ctx = ClientContextFactory.getContext(self)
# Enable all workarounds to SSL bugs as documented by
# http://www.openssl.org/docs/ssl/SSL_CTX_set_options.html
ctx.set_options(SSL.OP_ALL)
if hostname:
ClientTLSOptions(hostname, ctx)
return ctx
示例5: _get_noverify_context
# 需要导入模块: from twisted.internet.ssl import ClientContextFactory [as 别名]
# 或者: from twisted.internet.ssl.ClientContextFactory import getContext [as 别名]
def _get_noverify_context(self):
"""
Use ClientContextFactory directly and set the method if necessary.
This will perform no host verification at all.
"""
from twisted.internet.ssl import ClientContextFactory
context_factory = ClientContextFactory()
if self.ssl_method is not None:
context_factory.method = self.ssl_method
return context_factory.getContext()
示例6: getContext
# 需要导入模块: from twisted.internet.ssl import ClientContextFactory [as 别名]
# 或者: from twisted.internet.ssl.ClientContextFactory import getContext [as 别名]
def getContext(self):
"""Create an SSL context.
This is a sample implementation that loads a certificate from a file
called 'client.pem'."""
ctx = ClientContextFactory.getContext(self)
ctx.use_certificate_file(self.certificateFileName)
ctx.use_privatekey_file(self.privateKeyFileName)
ctx.load_client_ca(self.certificateChainFile)
ctx.load_verify_locations(self.certificateChainFile)
ctx.set_verify(VERIFY_PEER|VERIFY_FAIL_IF_NO_PEER_CERT,
self._verify)
ctx.set_verify_depth(10)
return ctx
示例7: getContext
# 需要导入模块: from twisted.internet.ssl import ClientContextFactory [as 别名]
# 或者: from twisted.internet.ssl.ClientContextFactory import getContext [as 别名]
def getContext(self, hostname, port):
self.method = SSL.SSLv23_METHOD
ctx = ClientContextFactory.getContext(self)
if 'cert' in self.ssl_opts and 'key' in self.ssl_opts:
ctx.use_certificate_file(os.path.expanduser(self.ssl_opts['cert']))
ctx.use_privatekey_file(os.path.expanduser(self.ssl_opts['key']))
if 'verify' in self.ssl_opts and to_bool(self.ssl_opts['verify']):
ctx.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT,
self.verifyCallback)
if 'ca' in self.ssl_opts:
ctx.load_verify_locations(os.path.expanduser(self.ssl_opts['CAFile']))
return ctx
示例8: getContext
# 需要导入模块: from twisted.internet.ssl import ClientContextFactory [as 别名]
# 或者: from twisted.internet.ssl.ClientContextFactory import getContext [as 别名]
def getContext(self):
self.method = SSL.SSLv23_METHOD
ctx = ClientContextFactory.getContext(self)
return ctx
示例9: getContext
# 需要导入模块: from twisted.internet.ssl import ClientContextFactory [as 别名]
# 或者: from twisted.internet.ssl.ClientContextFactory import getContext [as 别名]
def getContext(self, host, port):
ctx = ClientContextFactory.getContext(self)
ctx.set_verify_depth(0)
ctx.set_verify(OpenSSL.SSL.VERIFY_PEER | OpenSSL.SSL.VERIFY_FAIL_IF_NO_PEER_CERT, self.verifyHostname)
return ctx
示例10: getContext
# 需要导入模块: from twisted.internet.ssl import ClientContextFactory [as 别名]
# 或者: from twisted.internet.ssl.ClientContextFactory import getContext [as 别名]
def getContext(self, *_):
return ClientContextFactory.getContext(self)
示例11: getContext
# 需要导入模块: from twisted.internet.ssl import ClientContextFactory [as 别名]
# 或者: from twisted.internet.ssl.ClientContextFactory import getContext [as 别名]
def getContext(self, hostname, port):
# FIXME: no attempt to verify certificates!
return ClientContextFactory.getContext(self)
示例12: getContext
# 需要导入模块: from twisted.internet.ssl import ClientContextFactory [as 别名]
# 或者: from twisted.internet.ssl.ClientContextFactory import getContext [as 别名]
def getContext(self, hostname, port):
"""
This is overridden to disable certificate checking so that this
tool can be used in any environment
"""
return ClientContextFactory.getContext(self)
示例13: getContext
# 需要导入模块: from twisted.internet.ssl import ClientContextFactory [as 别名]
# 或者: from twisted.internet.ssl.ClientContextFactory import getContext [as 别名]
def getContext(self, hostname, port):
print ">>> getContext", hostname, port
ctx = ClientContextFactory.getContext(self)
ctx.set_verify(SSL.VERIFY_NONE, self.verifyHost)
return ctx
示例14: getContext
# 需要导入模块: from twisted.internet.ssl import ClientContextFactory [as 别名]
# 或者: from twisted.internet.ssl.ClientContextFactory import getContext [as 别名]
def getContext(self):
ctx = ClientContextFactory.getContext(self)
# Enable all workarounds to SSL bugs as documented by
# http://www.openssl.org/docs/ssl/SSL_CTX_set_options.html
ctx.set_options(SSL.OP_ALL)
return ctx
示例15: getContext
# 需要导入模块: from twisted.internet.ssl import ClientContextFactory [as 别名]
# 或者: from twisted.internet.ssl.ClientContextFactory import getContext [as 别名]
def getContext(self):
"""Get the parent context but disable SSLv3."""
ctx = ClientContextFactory.getContext(self)
ctx.set_options(OP_NO_SSLv3)
return ctx