jquast / telnetlib3

Python Telnet server and client Protocol library using asyncio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cannot recv WILL ECHO on server end

twmr opened this issue · comments

I'm currently debugging an issue when a telnet connection is established form a (external) java client to our python telnet server. For this I've tried to reproduce this issue by compiling a minimal java telnet client (https://commons.apache.org/proper/commons-net/examples/telnet/TelnetClientExample.java) and testing it on our server. In the logs of our server I can see an exception when a connection to the server is established:

[11 May 2023 16:01:23.182] telnetlib3.server_base|     INFO | Connection from <Peer 127.0.0.1 41170>
[11 May 2023 16:01:23.182] telnetlib3.stream_writer|    DEBUG | pending_option[DO + TTYPE] = True
[11 May 2023 16:01:23.182] telnetlib3.stream_writer|    DEBUG | send IAC DO TTYPE
[11 May 2023 16:01:23.182] telnetlib3.stream_writer|    DEBUG | recv IAC WILL ECHO
[11 May 2023 16:01:23.182] telnetlib3.stream_writer|    DEBUG | WILL ECHO unsolicited
[11 May 2023 16:01:23.182] telnetlib3.stream_writer|    DEBUG | handle_will(ECHO)
[11 May 2023 16:01:23.183] telnetlib3.server_base|     WARN |   File "/home/thomashisch/miniconda3/envs/py311_2/lib/python3.11/site-packages/telnetlib3/server_base.py", line 179, in data_received
[11 May 2023 16:01:23.183] telnetlib3.server_base|     WARN |     recv_inband = self.writer.feed_byte(bytes([byte]))
[11 May 2023 16:01:23.183] telnetlib3.server_base|     WARN |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[11 May 2023 16:01:23.183] telnetlib3.server_base|     WARN |   File "/home/thomashisch/miniconda3/envs/py311_2/lib/python3.11/site-packages/telnetlib3/stream_writer.py", line 453, in feed_byte
[11 May 2023 16:01:23.183] telnetlib3.server_base|     WARN |     self.handle_will(opt)
[11 May 2023 16:01:23.183] telnetlib3.server_base|     WARN |   File "/home/thomashisch/miniconda3/envs/py311_2/lib/python3.11/site-packages/telnetlib3/stream_writer.py", line 1503, in handle_will
[11 May 2023 16:01:23.183] telnetlib3.server_base|     WARN |     raise ValueError("cannot recv WILL ECHO on server end")
[11 May 2023 16:01:23.183] telnetlib3.server_base|     WARN | ValueError: cannot recv WILL ECHO on server end

In this ticket I want to report that the exception is unexpected, because we don't get this exception with other telnet clients.

With a GNU telnet command from (Ubuntu host) the following is output:

[11 May 2023 16:13:06.323] telnetlib3.server_base|     INFO | Connection from <Peer 127.0.0.1 46088>
[11 May 2023 16:13:06.324] telnetlib3.stream_writer|    DEBUG | pending_option[DO + TTYPE] = True
[11 May 2023 16:13:06.324] telnetlib3.stream_writer|    DEBUG | send IAC DO TTYPE
[11 May 2023 16:13:06.324] telnetlib3.stream_writer|    DEBUG | recv IAC WILL TTYPE
[11 May 2023 16:13:06.324] telnetlib3.stream_writer|    DEBUG | handle_will(TTYPE)
[11 May 2023 16:13:06.325] telnetlib3.stream_writer|    DEBUG | remote_option[TTYPE] = True
[11 May 2023 16:13:06.325] telnetlib3.stream_writer|    DEBUG | send IAC SB TTYPE SEND IAC SE
[11 May 2023 16:13:06.325] telnetlib3.stream_writer|    DEBUG | pending_option[SB + TTYPE] = True
[11 May 2023 16:13:06.325] telnetlib3.stream_writer|    DEBUG | pending_option[DO + TTYPE] = False
[11 May 2023 16:13:06.325] telnetlib3.server_base|    DEBUG | begin advanced negotiation
[11 May 2023 16:13:06.325] telnetlib3.stream_writer|    DEBUG | pending_option[WILL + SGA] = True
[11 May 2023 16:13:06.325] telnetlib3.stream_writer|    DEBUG | send IAC WILL SGA
[11 May 2023 16:13:06.325] telnetlib3.stream_writer|    DEBUG | pending_option[WILL + ECHO] = True
[11 May 2023 16:13:06.325] telnetlib3.stream_writer|    DEBUG | send IAC WILL ECHO
[11 May 2023 16:13:06.326] telnetlib3.stream_writer|    DEBUG | pending_option[WILL + BINARY] = True
[11 May 2023 16:13:06.326] telnetlib3.stream_writer|    DEBUG | send IAC WILL BINARY
[11 May 2023 16:13:06.326] telnetlib3.stream_writer|    DEBUG | pending_option[DO + NEW_ENVIRON] = True
[11 May 2023 16:13:06.326] telnetlib3.stream_writer|    DEBUG | send IAC DO NEW_ENVIRON
[11 May 2023 16:13:06.326] telnetlib3.stream_writer|    DEBUG | pending_option[DO + NAWS] = True
[11 May 2023 16:13:06.326] telnetlib3.stream_writer|    DEBUG | send IAC DO NAWS
[11 May 2023 16:13:06.326] telnetlib3.stream_writer|    DEBUG | pending_option[DO + CHARSET] = True
[11 May 2023 16:13:06.326] telnetlib3.stream_writer|    DEBUG | send IAC DO CHARSET
[11 May 2023 16:13:06.326] telnetlib3.stream_writer|    DEBUG | sub-negotiation cmd TTYPE SE completion byte
[11 May 2023 16:13:06.326] telnetlib3.stream_writer|    DEBUG | pending_option[SB + TTYPE] = False
[11 May 2023 16:13:06.326] telnetlib3.stream_writer|    DEBUG | recv TTYPE IS: b'XTERM-256COLOR'
[11 May 2023 16:13:06.326] telnetlib3.stream_writer|    DEBUG | recv IAC SB TTYPE IS 'XTERM-256COLOR'
[11 May 2023 16:13:06.326] telnetlib3.server|    DEBUG | ttype cycle cont at ttype1: XTERM-256COLOR.
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | send IAC SB TTYPE SEND IAC SE
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | pending_option[SB + TTYPE] = True
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | recv IAC DO SGA
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | handle_do(SGA)
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | skip WILL SGA; pending_option = True
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | local_option[SGA] = True
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | pending_option[WILL + SGA] = False
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | recv IAC DO ECHO
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | handle_do(ECHO)
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | skip WILL ECHO; pending_option = True
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | local_option[ECHO] = True
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | pending_option[WILL + ECHO] = False
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | recv IAC DO BINARY
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | handle_do(BINARY)
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | skip WILL BINARY; pending_option = True
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | local_option[BINARY] = True
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | pending_option[WILL + BINARY] = False
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | recv IAC WILL NEW_ENVIRON
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | handle_will(NEW_ENVIRON)
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | remote_option[NEW_ENVIRON] = True
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | request_environ: b"\xff\xfa'\x01\x00LANG\x00TERM\x00COLUMNS\x00LINES\x00DISPLAY\x00COLORTERM\x00\x03\xff\xf0"
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | pending_option[SB + NEW_ENVIRON] = True
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | pending_option[DO + NEW_ENVIRON] = False
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | recv IAC WILL NAWS
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | handle_will(NAWS)
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | skip DO NAWS; pending_option = True
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | remote_option[NAWS] = True
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | pending_option[SB + NAWS] = True
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | pending_option[DO + NAWS] = False
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | sub-negotiation cmd NAWS SE completion byte
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | pending_option[SB + NAWS] = False
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | recv IAC SB NAWS (cols=211, rows=50) IAC SE
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | recv IAC WONT CHARSET
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | handle_wont(CHARSET)
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | remote_option[CHARSET] = False
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | pending_option[DO + CHARSET] = False
[11 May 2023 16:13:06.327] telnetlib3.server|    DEBUG | BINARY in: direction request.
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | pending_option[DO + BINARY] = True
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | send IAC DO BINARY
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | sub-negotiation cmd TTYPE SE completion byte
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | pending_option[SB + TTYPE] = False
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | recv TTYPE IS: b'XTERM-256COLOR'
[11 May 2023 16:13:06.327] telnetlib3.stream_writer|    DEBUG | recv IAC SB TTYPE IS 'XTERM-256COLOR'
[11 May 2023 16:13:06.327] telnetlib3.server|    DEBUG | ttype cycle stop at ttype2: XTERM-256COLOR, looped.
[11 May 2023 16:13:06.328] telnetlib3.stream_writer|    DEBUG | sub-negotiation cmd NEW_ENVIRON SE completion byte
[11 May 2023 16:13:06.328] telnetlib3.stream_writer|    DEBUG | pending_option[SB + NEW_ENVIRON] = False
[11 May 2023 16:13:06.328] telnetlib3.stream_writer|    DEBUG | recv NEW_ENVIRON IS: b'\x03LANG\x01en_US.UTF-8\x03TERM\x01XTERM-256COLOR\x03COLUMNS\x03LINES\x00DISPLAY\x01PF3885SS:1\x03COLORTERM\x01truecolor\x00DISPLAY\x01PF3885SS:1\x00DISPLAY\x01PF3885SS:1'
[11 May 2023 16:13:06.328] telnetlib3.stream_writer|    DEBUG | NEW_ENVIRON IS unsolicited
[11 May 2023 16:13:06.328] telnetlib3.server|    DEBUG | on_environ received: {'LANG': 'en_US.UTF-8', 'TERM': 'XTERM-256COLOR', 'DISPLAY': 'PF3885SS:1', 'COLORTERM': 'truecolor'}
[11 May 2023 16:13:06.328] telnetlib3.stream_writer|    DEBUG | recv IAC WILL BINARY
[11 May 2023 16:13:06.328] telnetlib3.stream_writer|    DEBUG | handle_will(BINARY)
[11 May 2023 16:13:06.328] telnetlib3.stream_writer|    DEBUG | skip DO BINARY; pending_option = True
[11 May 2023 16:13:06.328] telnetlib3.stream_writer|    DEBUG | remote_option[BINARY] = True
[11 May 2023 16:13:06.328] telnetlib3.stream_writer|    DEBUG | pending_option[DO + BINARY] = False
[11 May 2023 16:13:06.328] telnetlib3.server|    DEBUG | encoding complete: 'UTF-8'
[11 May 2023 16:13:06.328] telnetlib3.server_base|    DEBUG | negotiation complete after 0.01s.

if you think that the telnet client example is wrong, because it sends the WILL ECHO command, I can report report this upstream.