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


Python ssl.PROTOCOL_TLSv1方法代码示例

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


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

示例1: __init__

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1 [as 别名]
def __init__(self, ip_addresses, cassandra_config):
        self._ip_addresses = ip_addresses
        self._auth_provider = None
        self._ssl_context = None
        self._cassandra_config = cassandra_config

        if cassandra_config.cql_username is not None and cassandra_config.cql_password is not None:
            auth_provider = PlainTextAuthProvider(username=cassandra_config.cql_username,
                                                  password=cassandra_config.cql_password)
            self._auth_provider = auth_provider

        if cassandra_config.certfile is not None and cassandra_config.usercert is not None and \
           cassandra_config.userkey is not None:
            ssl_context = SSLContext(PROTOCOL_TLSv1)
            ssl_context.load_verify_locations(cassandra_config.certfile)
            ssl_context.verify_mode = CERT_REQUIRED
            ssl_context.load_cert_chain(
                certfile=cassandra_config.usercert,
                keyfile=cassandra_config.userkey)
            self._ssl_context = ssl_context

        load_balancing_policy = WhiteListRoundRobinPolicy(ip_addresses)
        self._execution_profiles = {
            'local': ExecutionProfile(load_balancing_policy=load_balancing_policy)
        } 
开发者ID:thelastpickle,项目名称:cassandra-medusa,代码行数:27,代码来源:cassandra_utils.py

示例2: make_HTTPS_handler

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1 [as 别名]
def make_HTTPS_handler(params, **kwargs):
    opts_no_check_certificate = params.get('nocheckcertificate', False)
    if hasattr(ssl, 'create_default_context'):  # Python >= 3.4 or 2.7.9
        context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
        if opts_no_check_certificate:
            context.check_hostname = False
            context.verify_mode = ssl.CERT_NONE
        try:
            return YoutubeDLHTTPSHandler(params, context=context, **kwargs)
        except TypeError:
            # Python 2.7.8
            # (create_default_context present but HTTPSHandler has no context=)
            pass

    if sys.version_info < (3, 2):
        return YoutubeDLHTTPSHandler(params, **kwargs)
    else:  # Python < 3.4
        context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
        context.verify_mode = (ssl.CERT_NONE
                               if opts_no_check_certificate
                               else ssl.CERT_REQUIRED)
        context.set_default_verify_paths()
        return YoutubeDLHTTPSHandler(params, context=context, **kwargs) 
开发者ID:tvalacarta,项目名称:tvalacarta,代码行数:25,代码来源:utils.py

示例3: _create_http_connection

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1 [as 别名]
def _create_http_connection(ydl_handler, http_class, is_https, *args, **kwargs):
    # Working around python 2 bug (see http://bugs.python.org/issue17849) by limiting
    # expected HTTP responses to meet HTTP/1.0 or later (see also
    # https://github.com/rg3/youtube-dl/issues/6727)
    if sys.version_info < (3, 0):
        kwargs[b'strict'] = True
    hc = http_class(*args, **kwargs)
    source_address = ydl_handler._params.get('source_address')
    if source_address is not None:
        sa = (source_address, 0)
        if hasattr(hc, 'source_address'):  # Python 2.7+
            hc.source_address = sa
        else:  # Python 2.6
            def _hc_connect(self, *args, **kwargs):
                sock = compat_socket_create_connection(
                    (self.host, self.port), self.timeout, sa)
                if is_https:
                    self.sock = ssl.wrap_socket(
                        sock, self.key_file, self.cert_file,
                        ssl_version=ssl.PROTOCOL_TLSv1)
                else:
                    self.sock = sock
            hc.connect = functools.partial(_hc_connect, hc)

    return hc 
开发者ID:yasoob,项目名称:youtube-dl-GUI,代码行数:27,代码来源:utils.py

示例4: test_context

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1 [as 别名]
def test_context(self):
        self.client.quit()
        ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
        self.assertRaises(ValueError, ftplib.FTP_TLS, keyfile=CERTFILE,
                          context=ctx)
        self.assertRaises(ValueError, ftplib.FTP_TLS, certfile=CERTFILE,
                          context=ctx)
        self.assertRaises(ValueError, ftplib.FTP_TLS, certfile=CERTFILE,
                          keyfile=CERTFILE, context=ctx)

        self.client = ftplib.FTP_TLS(context=ctx, timeout=TIMEOUT)
        self.client.connect(self.server.host, self.server.port)
        self.assertNotIsInstance(self.client.sock, ssl.SSLSocket)
        self.client.auth()
        self.assertIs(self.client.sock.context, ctx)
        self.assertIsInstance(self.client.sock, ssl.SSLSocket)

        self.client.prot_p()
        with self.client.transfercmd('list') as sock:
            self.assertIs(sock.context, ctx)
            self.assertIsInstance(sock, ssl.SSLSocket) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_ftplib.py

示例5: convert_version2method

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1 [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_socket

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1 [as 别名]
def create_socket():
    logger.info('Creating SSL socket')
    s_ = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s = ssl.wrap_socket(
        sock=s_,
        keyfile=None,
        certfile=None,
        server_side=False,
        cert_reqs=ssl.CERT_REQUIRED,
        ssl_version=getattr(
            ssl,
            'PROTOCOL_TLSv1_2',
            ssl.PROTOCOL_TLSv1
        ),
        ca_certs=certifi.where(),
        do_handshake_on_connect=True,
        suppress_ragged_eofs=True,
    )
    try:
        logger.info('Connecting to {}:{}'.format(ENDPOINT, PORT))
        s.connect((ENDPOINT, PORT))
        return s
    except socket.error, exc:
        logger.error('Exception socket.error : {}'.format(exc))
        raise SystemExit 
开发者ID:rapid7,项目名称:le_lambda,代码行数:27,代码来源:le_lambda.py

示例7: __init__

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1 [as 别名]
def __init__(self, url, user_agent, cookies_string=False, custom_header=False, insecure_ssl='false', proxy=False):
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
        self.__url = url
        self.__headers = dict()
        self.__headers['User-Agent'] = self.__default_user_agent if user_agent == 'default' else user_agent
        if cookies_string:
            self.__headers['Cookie'] = cookies_string
        if custom_header:
            self.__parse_custom_header(custom_header)
        self.__verify = 'CERT_REQUIRED' if insecure_ssl == 'false' else 'CERT_NONE'
        if proxy:
            proxy_type = proxy.split('://')[0]
            if proxy_type == 'http' or proxy_type == 'https':
                self.__request_obj = urllib3.ProxyManager(proxy, ssl_version=ssl.PROTOCOL_TLSv1,
                                                          timeout=self.__request_timeout, cert_reqs=self.__verify)
            else:
                self.__request_obj = SOCKSProxyManager(proxy, ssl_version=ssl.PROTOCOL_TLSv1,
                                                       timeout=self.__request_timeout, cert_reqs=self.__verify)
        else:
            self.__request_obj = urllib3.PoolManager(ssl_version=ssl.PROTOCOL_TLSv1, timeout=self.__request_timeout,
                                                     cert_reqs=self.__verify)
        # print (vars(self)) 
开发者ID:antonioCoco,项目名称:SharPyShell,代码行数:24,代码来源:Request.py

示例8: connect

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1 [as 别名]
def connect(self):
        # check configuration
        if not (hasattr(settings, 'LDAP_SERVERS') and hasattr(settings, 'LDAP_BIND_ADMIN') and
                hasattr(settings, 'LDAP_BIND_ADMIN_PASS') and hasattr(settings, 'LDAP_AD_DOMAIN')
                and hasattr(settings, 'LDAP_CERT_FILE')
                ):
            raise ImproperlyConfigured()

        # first: build server pool from settings
        tls = Tls(validate=ssl.CERT_OPTIONAL, version=ssl.PROTOCOL_TLSv1, ca_certs_file=settings.LDAP_CERT_FILE)

        if self.pool is None:
            self.pool = ServerPool(None, pool_strategy=FIRST, active=True)
            for srv in settings.LDAP_SERVERS:
                # Only add servers that supports SSL, impossible to make changes without
                if srv['use_ssl']:
                    server = Server(srv['host'], srv['port'], srv['use_ssl'], tls=tls)
                    self.pool.add(server)

        # then, try to connect with user/pass from settings
        self.con = Connection(self.pool, auto_bind=True, authentication=SIMPLE,
                              user=settings.LDAP_BIND_ADMIN, password=settings.LDAP_BIND_ADMIN_PASS) 
开发者ID:Lucterios2,项目名称:django_auth_ldap3_ad,代码行数:24,代码来源:ad_users.py

示例9: create_socket

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1 [as 别名]
def create_socket():
    logger.info('Creating SSL socket')
    s_ = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s = ssl.wrap_socket(
        sock=s_,
        keyfile=None,
        certfile=None,
        server_side=False,
        cert_reqs=ssl.CERT_REQUIRED,
        ssl_version=getattr(
            ssl,
            'PROTOCOL_TLSv1_2',
            ssl.PROTOCOL_TLSv1
        ),
        ca_certs=certifi.where(),
        do_handshake_on_connect=True,
        suppress_ragged_eofs=True,
    )
    try:
        logger.info('Connecting to {}:{}'.format(ENDPOINT, PORT))
        s.connect((ENDPOINT, PORT))
        return s
    except socket.error, exc:
        logger.error('Exception socket.error : {}'.format(exc)) 
开发者ID:LogentriesCommunity,项目名称:le-aws-cloudwatch,代码行数:26,代码来源:le_cloudwatch.py

示例10: server_loop

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1 [as 别名]
def server_loop(self):
        if CONF.ctl_privkey is not None and CONF.ctl_cert is not None:
            if CONF.ca_certs is not None:
                server = StreamServer((CONF.ofp_listen_host,
                                       CONF.ofp_ssl_listen_port),
                                      datapath_connection_factory,
                                      keyfile=CONF.ctl_privkey,
                                      certfile=CONF.ctl_cert,
                                      cert_reqs=ssl.CERT_REQUIRED,
                                      ca_certs=CONF.ca_certs,
                                      ssl_version=ssl.PROTOCOL_TLSv1)
            else:
                server = StreamServer((CONF.ofp_listen_host,
                                       CONF.ofp_ssl_listen_port),
                                      datapath_connection_factory,
                                      keyfile=CONF.ctl_privkey,
                                      certfile=CONF.ctl_cert,
                                      ssl_version=ssl.PROTOCOL_TLSv1)
        else:
            server = StreamServer((CONF.ofp_listen_host,
                                   CONF.ofp_tcp_listen_port),
                                  datapath_connection_factory)

        # LOG.debug('loop')
        server.serve_forever() 
开发者ID:OpenState-SDN,项目名称:ryu,代码行数:27,代码来源:controller.py

示例11: loadUcsConfig

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1 [as 别名]
def loadUcsConfig():
	from ConfigParser import SafeConfigParser

	configFile = os.path.join(os.path.dirname(__file__),"UcsConfig.cfg")
	parser = SafeConfigParser()
	parser.read(configFile)

	sslProtocol = parser.get('ssl_connection', 'ssl_protocol').strip('"')
	isVerifyCertificate = parser.getboolean('ssl_connection', 'verify_certificate')

	if not sys.version_info < (2, 6):
		from functools import partial
		import ssl

		sslProtocolDict = {'TLSv1': ssl.PROTOCOL_TLSv1}

		ssl.wrap_socket = partial(ssl.wrap_socket, ssl_version=sslProtocolDict[sslProtocol])

		if not sys.version_info < (2, 7, 9) and not isVerifyCertificate:
			ssl._create_default_https_context = ssl._create_unverified_context 
开发者ID:CiscoUcs,项目名称:UcsPythonSDK,代码行数:22,代码来源:UcsBase.py

示例12: _make_tls_connection

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1 [as 别名]
def _make_tls_connection(self):
        """Initiate TLS connection.

        [initiating entity only]
        """
        logger.debug("Preparing TLS connection")
        if self.settings["tls_verify_peer"]:
            cert_reqs = ssl.CERT_REQUIRED
        else:
            cert_reqs = ssl.CERT_NONE
        self.stream.transport.starttls(
                    keyfile = self.settings["tls_key_file"],
                    certfile = self.settings["tls_cert_file"],
                    server_side = not self.stream.initiator,
                    cert_reqs = cert_reqs,
                    ssl_version = ssl.PROTOCOL_TLSv1,
                    ca_certs = self.settings["tls_cacert_file"],
                    do_handshake_on_connect = False,
                    ) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:21,代码来源:streamtls.py

示例13: sslwrap

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1 [as 别名]
def sslwrap(func):
    @wraps(func)
    def bar(*args, **kw):
        kw['ssl_version'] = ssl.PROTOCOL_TLSv1
        return func(*args, **kw)
    return bar 
开发者ID:rapid7,项目名称:nexpose-client-python,代码行数:8,代码来源:sslfix.py

示例14: connect

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1 [as 别名]
def connect(self):
        """Connect to the server"""
        
        # Connect the SSL tunnel
        self.Log.debug("connecting to %s on port %i.", self.host, self.port)
        std_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.control_socket = ssl.wrap_socket(std_sock, certfile=self.client_certif, ssl_version=ssl.PROTOCOL_TLSv1)

        self.control_socket.connect((self.host, self.port))
        
        self.control_socket.setblocking(0)
        
        # Perform the Mumble authentication
        version = mumble_pb2.Version()
        version.version = (PYMUMBLE_PROTOCOL_VERSION[0] << 16) + (PYMUMBLE_PROTOCOL_VERSION[1] << 8) + PYMUMBLE_PROTOCOL_VERSION[2]
        version.release = self.application
        version.os = PYMUMBLE_OS_STRING
        version.os_version = PYMUMBLE_OS_VERSION_STRING
        self.Log.debug("sending: version: %s", version)
        self.send_message(PYMUMBLE_MSG_TYPES_VERSION, version)
        
        authenticate = mumble_pb2.Authenticate()
        authenticate.username = self.user
        authenticate.password = self.password
        authenticate.celt_versions.extend(SUPPORTED_BITSTREAMS.keys())
#        authenticate.celt_versions.extend([-2147483637])  # for debugging - only celt 0.7
        authenticate.opus = True
        self.Log.debug("sending: authenticate: %s", authenticate)
        self.send_message(PYMUMBLE_MSG_TYPES_AUTHENTICATE, authenticate)
        
        self.connected = PYMUMBLE_CONN_STATE_AUTHENTICATING 
开发者ID:Robert904,项目名称:pymumble,代码行数:33,代码来源:mumble.py

示例15: __init__

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_TLSv1 [as 别名]
def __init__(self, client_cert=None, ca_cert=None, verify=None,
                 ssl_version=None, assert_hostname=None,
                 assert_fingerprint=None):

        self.assert_hostname = assert_hostname
        self.assert_fingerprint = assert_fingerprint

        # TLS v1.0 seems to be the safest default; SSLv23 fails in mysterious
        # ways

        self.ssl_version = ssl_version or ssl.PROTOCOL_TLSv1

        # "tls" and "tls_verify" must have both or neither cert/key files
        # In either case, Alert the user when both are expected, but any are
        # missing.

        if client_cert:
            try:
                tls_cert, tls_key = client_cert
            except ValueError:
                raise errors.TLSParameterError(
                    'client_config must be a tuple of'
                    ' (client certificate, key file)'
                )

            if not (tls_cert and tls_key) or (not os.path.isfile(tls_cert) or
               not os.path.isfile(tls_key)):
                raise errors.TLSParameterError(
                    'Path to a certificate and key files must be provided'
                    ' through the client_config param'
                )
            self.cert = (tls_cert, tls_key)

        # If verify is set, make sure the cert exists
        self.verify = verify
        self.ca_cert = ca_cert
        if self.verify and self.ca_cert and not os.path.isfile(self.ca_cert):
            raise errors.TLSParameterError(
                'Invalid CA certificate provided for `tls_ca_cert`.'
            ) 
开发者ID:yeasy,项目名称:hyperledger-py,代码行数:42,代码来源:tls.py


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