本文整理汇总了Python中ssl.CERT_NONE属性的典型用法代码示例。如果您正苦于以下问题:Python ssl.CERT_NONE属性的具体用法?Python ssl.CERT_NONE怎么用?Python ssl.CERT_NONE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类ssl
的用法示例。
在下文中一共展示了ssl.CERT_NONE属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: jenkins
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import CERT_NONE [as 别名]
def jenkins(url, port):
try:
cli_port = False
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
try:
output = urllib2.urlopen('https://'+url+':'+port+"/jenkins/", context=ctx, timeout=8).info()
cli_port = int(output['X-Jenkins-CLI-Port'])
except urllib2.HTTPError, e:
if e.getcode() == 404:
try:
output = urllib2.urlopen('https://'+url+':'+port, context=ctx, timeout=8).info()
cli_port = int(output['X-Jenkins-CLI-Port'])
except:
pass
except:
pass
示例2: start_server
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import CERT_NONE [as 别名]
def start_server(port):
# Start the server
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_socket.bind(('', port))
server_socket.listen(128) # Maximum connections Mac OSX can handle.
status_messages.append(MESSAGE_INFO + "Successfully started the server on port {0}.".format(str(port)))
status_messages.append(MESSAGE_INFO + "Waiting for clients...")
while True:
client_connection, client_address = ssl.wrap_socket(server_socket, cert_reqs=ssl.CERT_NONE, server_side=True, keyfile="server.key", certfile="server.crt").accept()
status_messages.append(MESSAGE_INFO + "New client connected!")
connections.append(client_connection)
示例3: resolve_cert_reqs
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import CERT_NONE [as 别名]
def resolve_cert_reqs(candidate):
"""
Resolves the argument to a numeric constant, which can be passed to
the wrap_socket function/method from the ssl module.
Defaults to :data:`ssl.CERT_NONE`.
If given a string it is assumed to be the name of the constant in the
:mod:`ssl` module or its abbrevation.
(So you can specify `REQUIRED` instead of `CERT_REQUIRED`.
If it's neither `None` nor a string we assume it is already the numeric
constant which can directly be passed to wrap_socket.
"""
if candidate is None:
return CERT_NONE
if isinstance(candidate, str):
res = getattr(ssl, candidate, None)
if res is None:
res = getattr(ssl, 'CERT_' + candidate)
return res
return candidate
示例4: resolve_cert_reqs
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import CERT_NONE [as 别名]
def resolve_cert_reqs(candidate):
"""
Resolves the argument to a numeric constant, which can be passed to
the wrap_socket function/method from the ssl module.
Defaults to :data:`ssl.CERT_NONE`.
If given a string it is assumed to be the name of the constant in the
:mod:`ssl` module or its abbreviation.
(So you can specify `REQUIRED` instead of `CERT_REQUIRED`.
If it's neither `None` nor a string we assume it is already the numeric
constant which can directly be passed to wrap_socket.
"""
if candidate is None:
return CERT_NONE
if isinstance(candidate, str):
res = getattr(ssl, candidate, None)
if res is None:
res = getattr(ssl, 'CERT_' + candidate)
return res
return candidate
示例5: __init__
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import CERT_NONE [as 别名]
def __init__(self, host, port=None, key_file=None, cert_file=None,
strict=_strict_sentinel, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
source_address=None, **_3to2kwargs):
if 'check_hostname' in _3to2kwargs: check_hostname = _3to2kwargs['check_hostname']; del _3to2kwargs['check_hostname']
else: check_hostname = None
if 'context' in _3to2kwargs: context = _3to2kwargs['context']; del _3to2kwargs['context']
else: context = None
super(HTTPSConnection, self).__init__(host, port, strict, timeout,
source_address)
self.key_file = key_file
self.cert_file = cert_file
if context is None:
# Some reasonable defaults
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
context.options |= ssl.OP_NO_SSLv2
will_verify = context.verify_mode != ssl.CERT_NONE
if check_hostname is None:
check_hostname = will_verify
elif check_hostname and not will_verify:
raise ValueError("check_hostname needs a SSL context with "
"either CERT_OPTIONAL or CERT_REQUIRED")
if key_file or cert_file:
context.load_cert_chain(cert_file, key_file)
self._context = context
self._check_hostname = check_hostname
示例6: resolve_cert_reqs
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import CERT_NONE [as 别名]
def resolve_cert_reqs(candidate):
"""
Resolves the argument to a numeric constant, which can be passed to
the wrap_socket function/method from the ssl module.
Defaults to :data:`ssl.CERT_NONE`.
If given a string it is assumed to be the name of the constant in the
:mod:`ssl` module or its abbreviation.
(So you can specify `REQUIRED` instead of `CERT_REQUIRED`.
If it's neither `None` nor a string we assume it is already the numeric
constant which can directly be passed to wrap_socket.
"""
if candidate is None:
return CERT_REQUIRED
if isinstance(candidate, str):
res = getattr(ssl, candidate, None)
if res is None:
res = getattr(ssl, "CERT_" + candidate)
return res
return candidate
示例7: test_start_tls_smtp
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import CERT_NONE [as 别名]
def test_start_tls_smtp(self):
# This flow is simplified from RFC 3207 section 5.
# We don't really need all of this, but it helps to make sure
# that after realistic back-and-forth traffic the buffers end up
# in a sane state.
yield self.server_send_line(b"220 mail.example.com ready\r\n")
yield self.client_send_line(b"EHLO mail.example.com\r\n")
yield self.server_send_line(b"250-mail.example.com welcome\r\n")
yield self.server_send_line(b"250 STARTTLS\r\n")
yield self.client_send_line(b"STARTTLS\r\n")
yield self.server_send_line(b"220 Go ahead\r\n")
client_future = self.client_start_tls(dict(cert_reqs=ssl.CERT_NONE))
server_future = self.server_start_tls(_server_ssl_options())
self.client_stream = yield client_future
self.server_stream = yield server_future
self.assertTrue(isinstance(self.client_stream, SSLIOStream))
self.assertTrue(isinstance(self.server_stream, SSLIOStream))
yield self.client_send_line(b"EHLO mail.example.com\r\n")
yield self.server_send_line(b"250 mail.example.com welcome\r\n")
示例8: connect_to_server
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import CERT_NONE [as 别名]
def connect_to_server(self, server_cls):
server = client = None
try:
sock, port = bind_unused_port()
server = server_cls(ssl_options=_server_ssl_options())
server.add_socket(sock)
client = SSLIOStream(socket.socket(),
ssl_options=dict(cert_reqs=ssl.CERT_NONE))
yield client.connect(('127.0.0.1', port))
self.assertIsNotNone(client.socket.cipher())
finally:
if server is not None:
server.stop()
if client is not None:
client.close()
示例9: _create_ssl_ctx
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import CERT_NONE [as 别名]
def _create_ssl_ctx(self, sslp):
if isinstance(sslp, ssl.SSLContext):
return sslp
ca = sslp.get('ca')
capath = sslp.get('capath')
hasnoca = ca is None and capath is None
ctx = ssl.create_default_context(cafile=ca, capath=capath)
ctx.check_hostname = not hasnoca and sslp.get('check_hostname', True)
ctx.verify_mode = ssl.CERT_NONE if hasnoca else ssl.CERT_REQUIRED
if 'cert' in sslp:
ctx.load_cert_chain(sslp['cert'], keyfile=sslp.get('key'))
if 'cipher' in sslp:
ctx.set_ciphers(sslp['cipher'])
ctx.options |= ssl.OP_NO_SSLv2
ctx.options |= ssl.OP_NO_SSLv3
return ctx
示例10: myFunction
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import CERT_NONE [as 别名]
def myFunction():
# We create this context so that we can crawl
# https sites
myssl = ssl.create_default_context();
myssl.check_hostname=False
myssl.verify_mode=ssl.CERT_NONE
with Timer() as t:
req = Request('https://tutorialedge.net', headers={'User-Agent': 'Mozilla/5.0'})
response = urlopen(req, context=myssl)
print("Elapsed Time: {} seconds".format(t.elapsed))
示例11: __init__
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import CERT_NONE [as 别名]
def __init__(self, protocol_version):
self.protocol = protocol_version
# Use default values from a real SSLContext
self.check_hostname = False
self.verify_mode = ssl.CERT_NONE
self.ca_certs = None
self.options = 0
self.certfile = None
self.keyfile = None
self.ciphers = None
示例12: jboss
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import CERT_NONE [as 别名]
def jboss(url, port, retry=False):
try:
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
output = urllib2.urlopen(
'https://' +
url +
':' +
port +
"/invoker/JMXInvokerServlet",
context=ctx,
timeout=8).read()
except:
try:
output = urllib2.urlopen(
'http://' +
url +
':' +
port +
"/invoker/JMXInvokerServlet",
timeout=8).read()
except:
# OK. I give up.
return False
if "\xac\xed\x00\x05" in output:
mutex.acquire()
print " - (possibly) Vulnerable JBOSS: " + url + " (" + port + ")"
saveToFile('[+] JBoss: ' + ':' + port + '\n')
mutex.release()
return True
return False
示例13: connect
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import CERT_NONE [as 别名]
def connect(self):
"""Connect to vCenter server"""
try:
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
if self.config['no_ssl_verify']:
requests.packages.urllib3.disable_warnings()
context.verify_mode = ssl.CERT_NONE
self.si = SmartConnectNoSSL(
host=self.config['server'],
user=self.config['username'],
pwd=self.config['password'],
port=int(self.config['port']),
certFile=None,
keyFile=None,
)
else:
self.si = SmartConnect(
host=self.config['server'],
user=self.config['username'],
pwd=self.config['password'],
port=int(self.config['port']),
sslContext=context,
certFile=None,
keyFile=None,
)
except Exception as e:
print('Unable to connect to vsphere server.')
print(e)
sys.exit(1)
# add a clean up routine
atexit.register(Disconnect, self.si)
self.content = self.si.RetrieveContent()