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


Python ssl.SSLWantReadError方法代碼示例

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


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

示例1: do_tls_handshake

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSLWantReadError [as 別名]
def do_tls_handshake(self):
    client_hello = await self.reader.read(4096)
    self._tlsInBuff.write(client_hello)
    try:
      self._tlsObj.do_handshake()
    except ssl.SSLWantReadError:
      server_hello = self._tlsOutBuff.read()
      self.writer.write(server_hello)
      await self.writer.drain()

    client_fin = await self.reader.read(4096)
    self._tlsInBuff.write(client_fin)
    try:
      self._tlsObj.do_handshake()
    except ssl.SSLWantReadError:
      raise TLSHandshakeError("Expected more data in Clinet FIN")

    server_fin = self._tlsOutBuff.read()
    self.writer.write(server_fin)
    await self.writer.drain() 
開發者ID:johnnykv,項目名稱:heralding,代碼行數:22,代碼來源:tls.py

示例2: read_tls

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSLWantReadError [as 別名]
def read_tls(self, size):
    data = b""
    # Check if we have any leftover data in the buffer
    try:
      data += self._tlsObj.read(size)
    except ssl.SSLWantReadError:
      pass

    # iterate until we have all needed plaintext
    while len(data) < size:
      if self.reader.at_eof():
        break
      try:
        # read ciphertext
        _rData = await self.reader.read(1)
        # put ciphertext into SSL machine
        self._tlsInBuff.write(_rData)
        # try to fill plaintext buffer
        data += self._tlsObj.read(size)
      except ssl.SSLWantReadError:
        pass

    return data 
開發者ID:johnnykv,項目名稱:heralding,代碼行數:25,代碼來源:tls.py

示例3: serve_ready

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSLWantReadError [as 別名]
def serve_ready(self):
		server = self.server()  # server is a weakref
		if not server:
			return False

		try:
			self.socket.do_handshake()
		except ssl.SSLWantReadError:
			return False
		except (socket.error, OSError, ValueError):
			self.socket.close()
			server.request_embryos.remove(self)
			return False

		self.socket.settimeout(None)
		server.request_embryos.remove(self)
		server.request_queue.put((self.socket, self.address))
		server.handle_request()
		return True 
開發者ID:zeroSteiner,項目名稱:AdvancedHTTPServer,代碼行數:21,代碼來源:advancedhttpserver.py

示例4: upgradetotls

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSLWantReadError [as 別名]
def upgradetotls(self):
        """
        upgrade to a tls wrapped connection
        :return: None
        """

        # TODO: newer TLS version?
        # noinspection PyUnresolvedReferences
        context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
        # TODO: PLATFORM STAGECERTIFICATEFILE is not the correct name for this value, move to handler or set a different
        #   variable in TRANSPORT with the same initial value?
        certkeyfile = sanatizefilename(self.handler.platform.options['STAGECERTIFICATEFILE']['Value'])
        context.load_cert_chain(certfile=certkeyfile, keyfile=certkeyfile)
        self.conn = context.wrap_bio(self.recvdataqueue.memorybio, self.senddataqueue.memorybio, server_side=True)
        print_message("Waiting for connection and TLS handshake...")
        while True:
            try:
                self.conn.do_handshake()
                break
            except (ssl.SSLWantReadError, ssl.SSLSyscallError):
                pass
        print_message("Upgrade to TLS done") 
開發者ID:SySS-Research,項目名稱:outis,代碼行數:24,代碼來源:dns.py

示例5: __read

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSLWantReadError [as 別名]
def __read(self):
        while 1:
            try:
                rdata = self.__socket.recv(4096)
            except BlockingIOError:
                break
            except ssl.SSLWantReadError:
                break
            if self.__ssl_on and not self.__ssl_ok:
                if self.__alpn_on:
                    protocol = self.__socket.selected_alpn_protocol()
                    if protocol == "h2": self.__is_http2 = True
                self.__ssl_ok = True

            if rdata:
                # if not self.__fd: self.__fd = open("test.txt", "wb")
                # self.__fd.write(rdata)
                self.__reader._putvalue(rdata)
            else:
                raise HttpErr("the connection has been closed")
        return 
開發者ID:fdslight,項目名稱:fdslight,代碼行數:23,代碼來源:httpclient.py

示例6: do_ssl_handshake

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSLWantReadError [as 別名]
def do_ssl_handshake(self):
        try:
            self.socket.do_handshake()
            self.__ssl_handshake_ok = True

            # 如果開啟SNI那麽匹配證書
            if self.__enable_https_sni:
                cert = self.socket.getpeercert()
                ssl.match_hostname(cert, self.__https_sni_host)

            logging.print_general("TLS_handshake_ok", self.__server_address)
            self.add_evt_read(self.fileno)
            self.send_handshake()
        except ssl.SSLWantReadError:
            self.add_evt_read(self.fileno)
        except ssl.SSLWantWriteError:
            self.add_evt_write(self.fileno)
        except:
            logging.print_error()
            self.delete_handler(self.fileno) 
開發者ID:fdslight,項目名稱:fdslight,代碼行數:22,代碼來源:tunnelc.py

示例7: process

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSLWantReadError [as 別名]
def process(self, spin):
        # When ssl.SSLEOFError happens it shouldnt spawn CLOSE
        # because there may exist data to be read.
        # If it spawns CLOSE the socket is closed and no data
        # can be read from.
        try:
            size = spin.send(self.data)  
        except ssl.SSLWantReadError:
            spin.drive(SSL_SEND_ERR, spin, excpt)
        except ssl.SSLWantWriteError:
            spin.drive(SSL_SEND_ERR, spin, excpt)
        except ssl.SSLEOFError as excpt:
            pass
        except ssl.SSLError as excpt:
            spin.drive(CLOSE, excpt)
        except socket.error as excpt:
            self.process_error(spin, excpt)
        else:
            self.data = self.data[size:] 
開發者ID:untwisted,項目名稱:untwisted,代碼行數:21,代碼來源:dump_ssl.py

示例8: do_handshake

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSLWantReadError [as 別名]
def do_handshake(self, spin):
        """
        """

        try:
            spin.do_handshake()
        except ssl.CertificateError as excpt:
            spin.drive(SSL_CERTIFICATE_ERR, excpt)
        except ssl.SSLWantReadError:
            pass
        except ssl.SSLWantWriteError:
            pass
        except socket.error as excpt:
            # When it happens then it should spawn SSL_CONNECT_ERR.
            spin.drive(SSL_CONNECT_ERR, excpt)
        except ssl.SSLError as excpt:
            spin.drive(SSL_CONNECT_ERR, excpt)
        else:
            spin.drive(SSL_CONNECT)
            raise Erase 
開發者ID:untwisted,項目名稱:untwisted,代碼行數:22,代碼來源:client_ssl.py

示例9: update

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSLWantReadError [as 別名]
def update(self):
        """Main method which should be called."""
        self.logger.debug('Update')
        with self.get_inactivity_monitor():
            try:
                self.restart_event.clear()
                self.buffer = Buffer()
                self.connect()
                self.identify()
                while not self.stop_event.is_set() and not self.restart_event.is_set():
                    try:
                        data = self.soc.recv(4096)
                        if not data:
                            break
                        self.process_data(data)
                    except (socket.timeout, ssl.SSLWantReadError) as e:
                        pass
            finally:
                if self.soc:
                    self.soc.close() 
開發者ID:boreq,項目名稱:botnet,代碼行數:22,代碼來源:irc.py

示例10: update

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSLWantReadError [as 別名]
def update(self):
        """Main method which should be called."""
        self.logger.debug('Update')
        try:
            self.restart_event.clear()
            self.flush_state()
            self.connect()
            self.identify()
            while not self.stop_event.is_set() and not self.restart_event.is_set():
                try:
                    data = self.soc.recv(4096)
                    if not data:
                        break
                    self.process_data(data)
                except CriticalProtocolError:
                    raise
                except (socket.timeout, ssl.SSLWantReadError) as e:
                    pass
            time.sleep(10)
        finally:
            if self.soc:
                self.soc.close() 
開發者ID:boreq,項目名稱:botnet,代碼行數:24,代碼來源:mumble.py

示例11: handle_in

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSLWantReadError [as 別名]
def handle_in(self):
        self._sync_tls_in()

        try:
            data = self.tls.read()
        except ssl.SSLWantReadError:
            return

        if data.startswith(b'\x00\x00\x00\x00'):
            self.read_control_message(data)
        elif data.startswith(b'PUSH_REPLY'):
            self.c.on_push(data)
        elif data.startswith(b'AUTH_FAILED'):
            raise AuthFailed()
        else:
            self.log.warn("Unknown control packet: %r", data) 
開發者ID:0xa,項目名稱:pyopenvpn,代碼行數:18,代碼來源:control_channel.py

示例12: recv

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSLWantReadError [as 別名]
def recv(self, timeout: Optional[float] = None) -> bytes:
    """
    Receives a message from the relay.

    :param timeout: maxiumum number of seconds to await a response, this
      blocks indefinitely if **None**

    :returns: bytes for the message received

    :raises:
      * :class:`stem.ProtocolError` the content from the socket is malformed
      * :class:`stem.SocketClosed` if the socket closes before we receive a complete message
    """

    def wrapped_recv(s: ssl.SSLSocket, sf: BinaryIO) -> bytes:
      if timeout is None:
        return s.recv(1024)
      else:
        s.setblocking(False)
        s.settimeout(timeout)

        try:
          return s.recv(1024)
        except (socket.timeout, ssl.SSLError, ssl.SSLWantReadError):
          return None
        finally:
          s.setblocking(True)

    return self._recv(wrapped_recv) 
開發者ID:torproject,項目名稱:stem,代碼行數:31,代碼來源:socket.py

示例13: recv_blocked

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSLWantReadError [as 別名]
def recv_blocked(self, buflen=8*1024, timeout=None, *args, **kwargs):
        force_first_loop_iteration = True
        end = time.time()+timeout if timeout else 0
        while force_first_loop_iteration or (not timeout or time.time()<end):
            # force one recv otherwise we might not even try to read if timeout is too narrow
            try:
                return self.recv(buflen=buflen, *args, **kwargs)
            except ssl.SSLWantReadError:
                pass
            force_first_loop_iteration = False 
開發者ID:tintinweb,項目名稱:striptls,代碼行數:12,代碼來源:striptls.py

示例14: receive

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSLWantReadError [as 別名]
def receive(self, leng=1024):
        """
        receive data from connected host
        :param leng: length of data to collect
        :return: data
        """

        if not self.server:
            print_error("Connection not open")
            return

        data = None

        # if wrapped by a TLS connection, read from there
        if self.conn:
            while data is None:
                # if there is no data in either queue, block until there is
                while self.conn.pending() <= 0 and not self.recvdataqueue.has_data():
                    time.sleep(0.1)
                print_debug(DEBUG_MODULE, "conn.pending = {}, recvdataqueue = {}"
                            .format(self.conn.pending(), self.recvdataqueue.length()))

                try:
                    data = self.conn.read(leng)
                    break
                except (ssl.SSLWantReadError, ssl.SSLSyscallError):
                    pass

        # else, read from the dataqueue normally
        else:
            # if there is no data, block until there is
            while not self.recvdataqueue.has_data():
                pass
            data = self.recvdataqueue.read(leng)

        # finish even if less data than requested, higher level must handle this
        return data 
開發者ID:SySS-Research,項目名稱:outis,代碼行數:39,代碼來源:dns.py

示例15: recv

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSLWantReadError [as 別名]
def recv(self, num=4096):
		try:
			return self.s.recv(num)
		except (BlockingIOError, ssl.SSLWantReadError):
			pass
		except OSError as e:
			logger.warning("Socket was closed unexpectedly")
			return b"" 
開發者ID:Kinnay,項目名稱:NintendoClients,代碼行數:10,代碼來源:socket.py


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