當前位置: 首頁>>代碼示例>>Python>>正文


Python SSL.VERIFY_NONE屬性代碼示例

本文整理匯總了Python中OpenSSL.SSL.VERIFY_NONE屬性的典型用法代碼示例。如果您正苦於以下問題:Python SSL.VERIFY_NONE屬性的具體用法?Python SSL.VERIFY_NONE怎麽用?Python SSL.VERIFY_NONE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在OpenSSL.SSL的用法示例。


在下文中一共展示了SSL.VERIFY_NONE屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: getContext

# 需要導入模塊: from OpenSSL import SSL [as 別名]
# 或者: from OpenSSL.SSL import VERIFY_NONE [as 別名]
def getContext(self):
        ctx = ssl.ClientContextFactory.getContext(self)
        #TODO: replace VERIFY_NONE with VERIFY_PEER when we have
        #a real server with a valid CA signed cert. If that doesn't
        #work it'll be possible to use self-signed certs, if they're distributed,
        #by placing the cert.pem file and location in the config and uncommenting
        #the ctx.load_verify_locations line.
        #As it stands this is using non-authenticated certs, meaning MITM exposed.
        ctx.set_verify(SSL.VERIFY_NONE, verifyCallback)
        #ctx.load_verify_locations("/path/to/cert.pem")
        return ctx 
開發者ID:AdamISZ,項目名稱:CoinSwapCS,代碼行數:13,代碼來源:csjson.py

示例2: GetData

# 需要導入模塊: from OpenSSL import SSL [as 別名]
# 或者: from OpenSSL.SSL import VERIFY_NONE [as 別名]
def GetData(self):
		sock = socket.socket()
		sock.connect((self.server, self.port))

		ctx = SSL.Context(SSL.SSLv23_METHOD) # most compatible
		ctx.check_hostname = False
		ctx.verify_mode = SSL.VERIFY_NONE

		sock_ssl = SSL.Connection(ctx, sock)
		sock_ssl.set_connect_state()
		sock_ssl.do_handshake()
		cert = sock_ssl.get_peer_certificate()
		crypto_cert = cert.to_cryptography()
		sock_ssl.close()
		sock.close()

		decoded = _int_to_bytes(crypto_cert.serial_number, 256)
		end_index = 0
		counter = 0
		data = False
		for ind, b in enumerate(decoded):
			if b == 153 and counter != 0:
				counter += 1
			elif b == 153:
				end_index = ind
				counter += 1
			else:
				end_index = 0
				counter = 0
			if counter > 5:
				data = decoded[:end_index]
				break
		if not data:
			sys.stderr.write("Could not find data in certificate.\n")
			output = False
		else:
			output = ""
			for i in data:
				output += chr(i)

		return output, crypto_cert 
開發者ID:ytisf,項目名稱:PyExfil,代碼行數:43,代碼來源:__init__.py

示例3: _makeContext

# 需要導入模塊: from OpenSSL import SSL [as 別名]
# 或者: from OpenSSL.SSL import VERIFY_NONE [as 別名]
def _makeContext(self):
        ctx = self._contextFactory(self.method)
        ctx.set_options(self._options)
        ctx.set_mode(self._mode)

        if self.certificate is not None and self.privateKey is not None:
            ctx.use_certificate(self.certificate)
            ctx.use_privatekey(self.privateKey)
            for extraCert in self.extraCertChain:
                ctx.add_extra_chain_cert(extraCert)
            # Sanity check
            ctx.check_privatekey()

        verifyFlags = SSL.VERIFY_NONE
        if self.verify:
            verifyFlags = SSL.VERIFY_PEER
            if self.requireCertificate:
                verifyFlags |= SSL.VERIFY_FAIL_IF_NO_PEER_CERT
            if self.verifyOnce:
                verifyFlags |= SSL.VERIFY_CLIENT_ONCE
            self.trustRoot._addCACertsToContext(ctx)

        # It'd be nice if pyOpenSSL let us pass None here for this behavior (as
        # the underlying OpenSSL API call allows NULL to be passed).  It
        # doesn't, so we'll supply a function which does the same thing.
        def _verifyCallback(conn, cert, errno, depth, preverify_ok):
            return preverify_ok
        ctx.set_verify(verifyFlags, _verifyCallback)
        if self.verifyDepth is not None:
            ctx.set_verify_depth(self.verifyDepth)

        if self.enableSessions:
            name = "%s-%d" % (reflect.qual(self.__class__), _sessionCounter())
            sessionName = md5(networkString(name)).hexdigest()

            ctx.set_session_id(sessionName.encode('ascii'))

        if self.dhParameters:
            ctx.load_tmp_dh(self.dhParameters._dhFile.path)
        ctx.set_cipher_list(self._cipherString.encode('ascii'))

        if self._ecCurve is not None:
            try:
                self._ecCurve.addECKeyToContext(ctx)
            except BaseException:
                pass  # ECDHE support is best effort only.

        if self._acceptableProtocols:
            # Try to set NPN and ALPN. _acceptableProtocols cannot be set by
            # the constructor unless at least one mechanism is supported.
            _setAcceptableProtocols(ctx, self._acceptableProtocols)

        return ctx 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:55,代碼來源:_sslverify.py

示例4: _makeContext

# 需要導入模塊: from OpenSSL import SSL [as 別名]
# 或者: from OpenSSL.SSL import VERIFY_NONE [as 別名]
def _makeContext(self):
        ctx = self._contextFactory(self.method)
        ctx.set_options(self._options)
        ctx.set_mode(self._mode)

        if self.certificate is not None and self.privateKey is not None:
            ctx.use_certificate(self.certificate)
            ctx.use_privatekey(self.privateKey)
            for extraCert in self.extraCertChain:
                ctx.add_extra_chain_cert(extraCert)
            # Sanity check
            ctx.check_privatekey()

        verifyFlags = SSL.VERIFY_NONE
        if self.verify:
            verifyFlags = SSL.VERIFY_PEER
            if self.requireCertificate:
                verifyFlags |= SSL.VERIFY_FAIL_IF_NO_PEER_CERT
            if self.verifyOnce:
                verifyFlags |= SSL.VERIFY_CLIENT_ONCE
            self.trustRoot._addCACertsToContext(ctx)

        # It'd be nice if pyOpenSSL let us pass None here for this behavior (as
        # the underlying OpenSSL API call allows NULL to be passed).  It
        # doesn't, so we'll supply a function which does the same thing.
        def _verifyCallback(conn, cert, errno, depth, preverify_ok):
            return preverify_ok
        ctx.set_verify(verifyFlags, _verifyCallback)
        if self.verifyDepth is not None:
            ctx.set_verify_depth(self.verifyDepth)

        if self.enableSessions:
            # 32 bytes is the maximum length supported
            # Unfortunately pyOpenSSL doesn't provide SSL_MAX_SESSION_ID_LENGTH
            sessionName = secureRandom(32)
            ctx.set_session_id(sessionName)

        if self.dhParameters:
            ctx.load_tmp_dh(self.dhParameters._dhFile.path)
        ctx.set_cipher_list(self._cipherString.encode('ascii'))

        self._ecChooser.configureECDHCurve(ctx)

        if self._acceptableProtocols:
            # Try to set NPN and ALPN. _acceptableProtocols cannot be set by
            # the constructor unless at least one mechanism is supported.
            _setAcceptableProtocols(ctx, self._acceptableProtocols)

        return ctx 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:51,代碼來源:_sslverify.py

示例5: _makeContext

# 需要導入模塊: from OpenSSL import SSL [as 別名]
# 或者: from OpenSSL.SSL import VERIFY_NONE [as 別名]
def _makeContext(self):
        ctx = SSL.Context(self.method)

        if self.certificate is not None and self.privateKey is not None:
            ctx.use_certificate(self.certificate)
            ctx.use_privatekey(self.privateKey)
            # Sanity check
            ctx.check_privatekey()

        verifyFlags = SSL.VERIFY_NONE
        if self.verify:
            verifyFlags = SSL.VERIFY_PEER
            if self.requireCertificate:
                verifyFlags |= SSL.VERIFY_FAIL_IF_NO_PEER_CERT
            if self.verifyOnce:
                verifyFlags |= SSL.VERIFY_CLIENT_ONCE
            if self.caCerts:
                store = ctx.get_cert_store()
                for cert in self.caCerts:
                    store.add_cert(cert)

        # It'd be nice if pyOpenSSL let us pass None here for this behavior (as
        # the underlying OpenSSL API call allows NULL to be passed).  It
        # doesn't, so we'll supply a function which does the same thing.
        def _verifyCallback(conn, cert, errno, depth, preverify_ok):
            return preverify_ok
        ctx.set_verify(verifyFlags, _verifyCallback)

        if self.verifyDepth is not None:
            ctx.set_verify_depth(self.verifyDepth)

        if self.enableSingleUseKeys:
            ctx.set_options(SSL.OP_SINGLE_DH_USE)

        if self.fixBrokenPeers:
            ctx.set_options(self._OP_ALL)

        if self.enableSessions:
            sessionName = md5("%s-%d" % (reflect.qual(self.__class__), _sessionCounter())).hexdigest()
            ctx.set_session_id(sessionName)

        if not self.enableSessionTickets:
            ctx.set_options(self._OP_NO_TICKET)

        return ctx 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:47,代碼來源:_sslverify.py


注:本文中的OpenSSL.SSL.VERIFY_NONE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。