当前位置: 首页>>代码示例>>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;未经允许,请勿转载。