當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。