How to use the asyncssh.misc.ProtocolError function in asyncssh

To help you get started, we’ve selected a few asyncssh examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ronf / asyncssh / asyncssh / kex_dh.py View on Github external
def _process_group(self, _pkttype, _pktid, packet):
        """Process a DH gex group message"""

        if self._conn.is_server():
            raise ProtocolError('Unexpected kex group msg')

        p = packet.get_mpint()
        g = packet.get_mpint()
        packet.check_end()

        self._init_group(g, p)
        self._gex_data += MPInt(p) + MPInt(g)
        self._perform_init()
github ronf / asyncssh / asyncssh / kex_dh.py View on Github external
mic = packet.get_string()
        token_present = packet.get_boolean()
        token = packet.get_string() if token_present else None
        packet.check_end()

        if token:
            if self._gss.complete:
                raise ProtocolError('Non-empty token after complete')

            self._process_token(token)

            if self._token:
                raise ProtocolError('Non-empty token after complete')

        if not self._gss.complete:
            raise ProtocolError('GSS exchange failed to complete')

        self._check_secure()
        self._verify_reply(self._gss, self._host_key_data, mic)
        self._conn.enable_gss_kex_auth()
github ronf / asyncssh / asyncssh / channel.py View on Github external
def _flush_recv_buf(self, exc=None):
        """Flush as much data in the recv buffer as the application allows"""

        while self._recv_buf and not self._recv_paused:
            self._deliver_data(*self._recv_buf.pop(0))

        if not self._recv_buf:
            if self._encoding and not exc and \
                    self._recv_state in ('eof_pending', 'close_pending'):
                try:
                    self._decoder.decode(b'', True)
                except UnicodeDecodeError as unicode_exc:
                    raise ProtocolError(str(unicode_exc)) from None

            if self._recv_state == 'eof_pending':
                self._recv_state = 'eof'

                if (not self._session.eof_received() and
                        self._send_state == 'open'):
                    self.write_eof()
            elif self._recv_state == 'close_pending':
                self._recv_state = 'closed'
                self._loop.call_soon(self._cleanup, exc)
github ronf / asyncssh / asyncssh / channel.py View on Github external
Data sent after the channel has been closed by the session
           is dropped.

        """

        if not data:
            return

        if self._send_state in {'close_pending', 'closed'}:
            return

        datalen = len(data)

        if datalen > self._recv_window:
            raise ProtocolError('Window exceeded')

        if datatype:
            typename = ' from %s' % _data_type_names[datatype]
        else:
            typename = ''

        self.logger.debug2('Received %d data byte%s%s', datalen,
                           's' if datalen > 1 else '', typename)

        if self._recv_paused:
            self._recv_buf.append((data, datatype))
        else:
            self._deliver_data(data, datatype)
github ronf / asyncssh / asyncssh / kex_dh.py View on Github external
def _compute_server_shared(self):
        """Compute server shared key"""

        if not 1 <= self._e < self._p:
            raise ProtocolError('Kex DH e out of range')

        y = randrange(2, self._q)
        self._f = pow(self._g, y, self._p)

        k = pow(self._e, y, self._p)

        if k < 1: # pragma: no cover, shouldn't be possible with valid p
            raise ProtocolError('Kex DH k out of range')

        return k
github ronf / asyncssh / asyncssh / kex_dh.py View on Github external
def _send_continue(self):
        """Send a GSS continue message"""

        if not self._token:
            raise ProtocolError('Empty GSS token in continue')

        self.send_packet(MSG_KEXGSS_CONTINUE, String(self._token))
github ronf / asyncssh / asyncssh / kex_dh.py View on Github external
def _parse_client_key(self, packet):
        """Parse a DH client key"""

        if not self._p:
            raise ProtocolError('Kex DH p not specified')

        self._e = packet.get_mpint()
github ronf / asyncssh / asyncssh / channel.py View on Github external
def _process_close(self, _pkttype, _pktid, packet):
        """Process an incoming channel close"""

        if self._recv_state not in {'open', 'eof_pending', 'eof'}:
            raise ProtocolError('Channel not open')

        packet.check_end()

        self.logger.info('Received channel close')

        self._close_send()

        self._recv_state = 'close_pending'
        self._flush_recv_buf()
github ronf / asyncssh / asyncssh / auth.py View on Github external
def _process_password_change(self, _pkttype, _pktid, packet):
        """Process a password change request"""

        prompt = packet.get_string()
        lang = packet.get_string()

        try:
            prompt = prompt.decode('utf-8')
            lang = lang.decode('ascii')
        except UnicodeDecodeError:
            raise ProtocolError('Invalid password change request') from None

        self.auth_failed()
        self.create_task(self._change_password(prompt, lang))

        return True