当前位置: 首页>>代码示例>>Python>>正文


Python ssl.PROTOCOL_TLSv1_2方法代码示例

本文整理汇总了Python中ssl.PROTOCOL_TLSv1_2方法的典型用法代码示例。如果您正苦于以下问题:Python ssl.PROTOCOL_TLSv1_2方法的具体用法?Python ssl.PROTOCOL_TLSv1_2怎么用?Python ssl.PROTOCOL_TLSv1_2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ssl的用法示例。


在下文中一共展示了ssl.PROTOCOL_TLSv1_2方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1_2 [as 别名]
def run(self):
        global httpd, ui_player
        print('starting server...')
        server_address = ('', self.port)
        server_start = False
        try:
            httpd = ThreadedHTTPServer(server_address, testHTTPServer_RequestHandler)
            if self.https_allow and self.cert_file:
                if os.path.exists(self.cert_file):
                    httpd.socket = ssl.wrap_socket(
                        httpd.socket, certfile=self.cert_file, 
                        ssl_version=ssl.PROTOCOL_TLSv1_2)
            server_start = True
        except Exception as err:
            print(err, '----->error')
            txt = 'Your local IP changed..or port is blocked\n..Trying to find new IP'
            send_notification(txt)
            self.ip = get_lan_ip()
            txt = 'Your New Address is '+self.ip + '\n Please restart the player'
            send_notification(txt)
        if server_start:
            print('running server...at..'+self.ip+':'+str(self.port))
            httpd.serve_forever()
        else:
            print('server..not..started..') 
开发者ID:kanishka-linux,项目名称:kawaii-player,代码行数:27,代码来源:stream.py

示例2: setUp

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1_2 [as 别名]
def setUp(self):
        super().setUp()
        self.loop = asyncio.new_event_loop()

        # Make sure we are setting which loop we are using explicitly
        asyncio.set_event_loop(None)

        self.gnatsd = Gnatsd(port=4224, tls=True)
        start_gnatsd(self.gnatsd)

        self.ssl_ctx = ssl.create_default_context(
            purpose=ssl.Purpose.SERVER_AUTH
        )
        # self.ssl_ctx.protocol = ssl.PROTOCOL_TLSv1_2
        self.ssl_ctx.load_verify_locations('tests/certs/ca.pem')
        self.ssl_ctx.load_cert_chain(
            certfile='tests/certs/client-cert.pem',
            keyfile='tests/certs/client-key.pem'
        ) 
开发者ID:nats-io,项目名称:nats.py,代码行数:21,代码来源:utils.py

示例3: __init__

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1_2 [as 别名]
def __init__(self, destination, loop):
        self.destination = destination
        self.loop = loop
        self._start = asyncio.Event()
        self._stop = asyncio.Event()
        self._terminate = asyncio.Event()
        self.running = asyncio.Event()
        self.stopped = asyncio.Event()
        self.terminated = asyncio.Event()
        if hasattr(ssl, 'PROTOCOL_TLS_SERVER'):
            # python 3.6+
            protocol = ssl.PROTOCOL_TLS_SERVER
        elif hasattr(ssl, 'PROTOCOL_TLS'):
            # python 3.5.3+
            protocol = ssl.PROTOCOL_TLS
        else:
            # python 3.5.2
            protocol = ssl.PROTOCOL_TLSv1_2
        self.ssl_context = ssl.SSLContext(protocol)
        crt_file = Path(__file__).with_name('cert.pem')
        key_file = Path(__file__).with_name('key.pem')
        self.ssl_context.load_cert_chain(str(crt_file), str(key_file))
        self.status = None
        self.port = None
        self._task = self.loop.create_task(self.run()) 
开发者ID:juju,项目名称:python-libjuju,代码行数:27,代码来源:test_connection.py

示例4: test_configures_tls_context

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1_2 [as 别名]
def test_configures_tls_context(self, mocker):
        mock_mqtt_client = mocker.patch.object(mqtt, "Client").return_value
        mock_ssl_context_constructor = mocker.patch.object(ssl, "SSLContext")
        mock_ssl_context = mock_ssl_context_constructor.return_value

        MQTTTransport(client_id=fake_device_id, hostname=fake_hostname, username=fake_username)

        # Verify correctness of TLS/SSL Context
        assert mock_ssl_context_constructor.call_count == 1
        assert mock_ssl_context_constructor.call_args == mocker.call(protocol=ssl.PROTOCOL_TLSv1_2)
        assert mock_ssl_context.check_hostname is True
        assert mock_ssl_context.verify_mode == ssl.CERT_REQUIRED

        # Verify context has been set
        assert mock_mqtt_client.tls_set_context.call_count == 1
        assert mock_mqtt_client.tls_set_context.call_args == mocker.call(context=mock_ssl_context) 
开发者ID:Azure,项目名称:azure-iot-sdk-python,代码行数:18,代码来源:test_mqtt_transport.py

示例5: convert_version2method

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1_2 [as 别名]
def convert_version2method(protocol_version):
    """
    Convert internal protocol version ID to Python SSL method.

    :param Integer protocol_version: Version ID
    :return: OpenSSL method or None if not found
    :rtype: OpenSSL method or None
    """
    if protocol_version == flextls.registry.version.SSLv2:
        return ssl.PROTOCOL_SSLv2
    if protocol_version == flextls.registry.version.SSLv3:
        return ssl.PROTOCOL_SSLv3
    if protocol_version == flextls.registry.version.TLSv10:
        return ssl.PROTOCOL_TLSv1
    if protocol_version == flextls.registry.version.TLSv11:
        return ssl.PROTOCOL_TLSv1_1
    if protocol_version == flextls.registry.version.TLSv12:
        return ssl.PROTOCOL_TLSv1_2

    return None 
开发者ID:DinoTools,项目名称:pysslscan,代码行数:22,代码来源:int_ssl.py

示例6: _create_ssl_context

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1_2 [as 别名]
def _create_ssl_context(self):
        """
        This method creates the SSLContext object used by Paho to authenticate the connection.
        """
        logger.info("creating a SSL context")
        ssl_context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLSv1_2)

        if self._ca_cert:
            ssl_context.load_verify_locations(cadata=self._ca_cert)
        else:
            ssl_context.load_default_certs()
        ssl_context.verify_mode = ssl.CERT_REQUIRED
        ssl_context.check_hostname = True

        if self._x509_cert is not None:
            logger.info("configuring SSL context with client-side certificate and key")
            ssl_context.load_cert_chain(
                self._x509_cert.certificate_file,
                self._x509_cert.key_file,
                self._x509_cert.pass_phrase,
            )

        return ssl_context 
开发者ID:Azure,项目名称:azure-iot-sdk-python-preview,代码行数:25,代码来源:mqtt_transport.py

示例7: connect

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1_2 [as 别名]
def connect(self):
        if self._socket:
            raise Exception('Already connected')

        self._socket = ssl.wrap_socket(
            socket.socket(socket.AF_INET, socket.SOCK_STREAM), ssl_version=ssl.PROTOCOL_TLSv1_2
        )
        logger.debug('Connecting socket to %s relay...', self._router)
        try:
            self._socket.settimeout(15.0)
            self._socket.connect((self._router.ip, self._router.tor_port))

            handshake = TorHandshake(self, self._protocol)
            handshake.initiate()
        except Exception as e:
            logger.error(e)
            raise TorSocketConnectError(e) 
开发者ID:torpyorg,项目名称:torpy,代码行数:19,代码来源:cell_socket.py

示例8: initTLSContext

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1_2 [as 别名]
def initTLSContext(self, ca_file, node_crt_file, node_key_file,
                       protocol=ssl.PROTOCOL_TLSv1_2,
                       verify_mode=ssl.CERT_REQUIRED):
        try:
            context = ssl.SSLContext(protocol)
            context.check_hostname = False
            context.load_verify_locations(ca_file)

            context.load_cert_chain(node_crt_file, node_key_file)
            # print(context.get_ca_certs())
            context.set_ecdh_curve(self.ECDH_curve)
            context.verify_mode = verify_mode
            self.context = context
        except Exception as e:
            raise ChannelException(("init ssl context failed,"
                                    " please check the certificatsreason: {}").
                                   format(e)) 
开发者ID:FISCO-BCOS,项目名称:python-sdk,代码行数:19,代码来源:channelhandler.py

示例9: tls_set

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1_2 [as 别名]
def tls_set(self, ca_certs, certfile=None, keyfile=None, cert_reqs=ssl.CERT_REQUIRED, 
            tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None):
        start_time = time.time()
        try:
            super(MQTTClient,self).tls_set(ca_certs,
            certfile,
                keyfile,
                cert_reqs, 
                tls_version,
                ciphers)
        except Exception as e:
            fire_locust_failure(
                request_type=REQUEST_TYPE,
                name='tls_set',
                response_time=time_delta(start_time, time.time()),
                exception=e)

    #retry is not used at the time since this implementation only supports QoS 0 
开发者ID:concurrencylabs,项目名称:mqtt-locust,代码行数:20,代码来源:mqtt_locust.py

示例10: loop

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1_2 [as 别名]
def loop(self):
        """Main server loop for accepting connections. Better call it on its own thread"""
        while True:
            try:
                (csock, (ipaddr, port)) = self.connection["sock"].accept()
                self._log("L", "New connection from %s:%s" % (str(ipaddr),
                                                              str(port)))
            except sock_error:
                raise sock_error
            try:
                csock = ssl.wrap_socket(csock, server_side=True, certfile="server.crt",
                                        keyfile="server.key",
                                        ssl_version=ssl.PROTOCOL_TLSv1_2)
            except AttributeError: # All PROTOCOL consts are merged on TLS in Python2.7.13
                csock = ssl.wrap_socket(csock, server_side=True, certfile="server.crt",
                                        keyfile="server.key",
                                        ssl_version=ssl.PROTOCOL_TLS)
            self.clients["hosts"][str(self.clients["serial"])] = Host(csock, ipaddr, port,
                                                                      self.clients["serial"])
            self.clients["serial"] += 1 
开发者ID:panagiks,项目名称:RSPET,代码行数:22,代码来源:rspet_server.py

示例11: get_ssl_params

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1_2 [as 别名]
def get_ssl_params(server_params: dict,
                   https: Optional[bool],
                   ssl_key: Optional[str],
                   ssl_cert: Optional[str]) -> SSLConfig:
    https = https or server_params['https']
    if https:
        ssh_key_path = Path(ssl_key or server_params['https_key_path']).resolve()
        if not ssh_key_path.is_file():
            e = FileNotFoundError('Ssh key file not found: please provide correct path in --key param or '
                                  'https_key_path param in server configuration file')
            log.error(e)
            raise e

        ssh_cert_path = Path(ssl_cert or server_params['https_cert_path']).resolve()
        if not ssh_cert_path.is_file():
            e = FileNotFoundError('Ssh certificate file not found: please provide correct path in --cert param or '
                                  'https_cert_path param in server configuration file')
            log.error(e)
            raise e

        ssl_config = SSLConfig(version=PROTOCOL_TLSv1_2, keyfile=str(ssh_key_path), certfile=str(ssh_cert_path))
    else:
        ssl_config = SSLConfig(None, None, None)

    return ssl_config 
开发者ID:deepmipt,项目名称:DeepPavlov,代码行数:27,代码来源:server.py

示例12: get_ssl_version

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1_2 [as 别名]
def get_ssl_version(sock):
        # Seth behaves differently depeding on the TLS protocol
        # https://bugs.python.org/issue31453
        # This is an ugly hack (as if the rest of this wasn't...)
    versions = [
        ssl.PROTOCOL_TLSv1,
        ssl.PROTOCOL_TLSv1_1,
        ssl.PROTOCOL_TLSv1_2,
        ]
    firstbytes = sock.recv(16, socket.MSG_PEEK)
    try:
        return versions[firstbytes[10]-1]
    except IndexError:
        print("Unexpected SSL version: %s" % hexlify(firstbytes))
        return versions[-1]


#  def launch_rdp_client():
#      time.sleep(1)
#      p = subprocess.Popen(
#          ["xfreerdp",
#           "/v:%s:%d" % (args.bind_ip, consts.RELAY_PORT),
#           "/u:%s\\%s" % (domain, user),
#          ],
#      ) 
开发者ID:SySS-Research,项目名称:Seth,代码行数:27,代码来源:main.py

示例13: test_compatibility_no_supported_ssl_version

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1_2 [as 别名]
def test_compatibility_no_supported_ssl_version(self):
        """This tests mimics the behavior of a Python build without
        support for TLS v1, v1_1 or v1_2.
        """
        restore_tls_v1_2 = sys.modules['ssl'].PROTOCOL_TLSv1_2
        restore_tls_v1_1 = sys.modules['ssl'].PROTOCOL_TLSv1_1
        restore_tls_v1 = sys.modules['ssl'].PROTOCOL_TLSv1
        try:
            del sys.modules['ssl'].PROTOCOL_TLSv1_2
            del sys.modules['ssl'].PROTOCOL_TLSv1_1
            del sys.modules['ssl'].PROTOCOL_TLSv1
            imp.reload(compatibility)
            self.assertIsNone(compatibility.DEFAULT_SSL_VERSION)
            self.assertFalse(compatibility.SSL_SUPPORTED)
            self.assertFalse(compatibility.SSL_CERT_MAP)
            self.assertFalse(compatibility.SSL_VERSIONS)
        finally:
            sys.modules['ssl'].PROTOCOL_TLSv1_2 = restore_tls_v1_2
            sys.modules['ssl'].PROTOCOL_TLSv1_1 = restore_tls_v1_1
            sys.modules['ssl'].PROTOCOL_TLSv1 = restore_tls_v1
            imp.reload(compatibility) 
开发者ID:eandersson,项目名称:amqpstorm,代码行数:23,代码来源:compatiblity_tests.py

示例14: test_compatibility_only_tls_v1_supported

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1_2 [as 别名]
def test_compatibility_only_tls_v1_supported(self):
        """This tests mimics the behavior of Python 2.7.8 or earlier that
        only supported TLS v1 and SSLv23.
        """
        restore_tls_v1_2 = sys.modules['ssl'].PROTOCOL_TLSv1_2
        restore_tls_v1 = sys.modules['ssl'].PROTOCOL_TLSv1_1
        try:
            del sys.modules['ssl'].PROTOCOL_TLSv1_2
            del sys.modules['ssl'].PROTOCOL_TLSv1_1
            imp.reload(compatibility)
            self.assertEqual(compatibility.get_default_ssl_version(),
                             ssl.PROTOCOL_TLSv1)
        finally:
            sys.modules['ssl'].PROTOCOL_TLSv1_2 = restore_tls_v1_2
            sys.modules['ssl'].PROTOCOL_TLSv1_1 = restore_tls_v1
            imp.reload(compatibility) 
开发者ID:eandersson,项目名称:amqpstorm,代码行数:18,代码来源:compatiblity_tests.py

示例15: new_client

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1_2 [as 别名]
def new_client(self, s1):
		try:
			ssl_sock = sslpsk.wrap_socket(s1,
				server_side = True,
				ssl_version=ssl.PROTOCOL_TLSv1_2,
				ciphers='PSK-AES128-CBC-SHA256',
				psk=lambda identity: gen_psk(identity, self.hint),
				hint=self.hint)

			s2 = client(self.host, self.port)
			self.sessions.append((ssl_sock, s2))
		except ssl.SSLError as e:
			print("could not establish sslpsk socket:", e)
			if "NO_SHARED_CIPHER" in e.reason or "WRONG_VERSION_NUMBER" in e.reason or "WRONG_SSL_VERSION" in e.reason:
				print("don't panic this is probably just your phone!")
		except Exception as e:
			print(e) 
开发者ID:ct-Open-Source,项目名称:tuya-convert,代码行数:19,代码来源:psk-frontend.py


注:本文中的ssl.PROTOCOL_TLSv1_2方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。