Restricted Shell: Broken transport; encountered EOF
- Dominant language
- Java
- Stars
- 2.7k
- Forks
- 620
- Avg merge
- 3d 23h
- Merged PRs (30d)
- 11
Description
I am trying to execute a simple "help" command on a hardware appliance with sshj. As it is common for such appliances only a restricted shell is available. The code used was taken from net/schmizz/sshj/examples/ with no modification other than using the password auth and seetting a PromiscuousVerifier().
The version used is 0.26.0 pulled from maven.
Using the net/schmizz/sshj/examples/Exec.java example results in the following error:
[main] INFO n.s.s.t.random.BouncyCastleRandom - Generating random seed from SecureRandom.
[main] INFO n.s.sshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0.26.0
[main] INFO n.s.sshj.transport.TransportImpl - Server identity string: SSH-1.99-IPSSH-6.7.0
[main] DEBUG net.schmizz.concurrent.Promise - Setting <> to `null`
[reader] DEBUG net.schmizz.concurrent.Promise - Awaiting <>
[main] DEBUG net.schmizz.concurrent.Promise - Setting <> to `SOME`
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <>
[reader] DEBUG c.hierynomus.sshj.transport.kex.DHG - Sending SSH_MSG_KEXDH_INIT
[reader] DEBUG c.hierynomus.sshj.transport.kex.DHG - Received SSH_MSG_KEXDH_REPLY
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <> to `null`
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <> to `SOME`
[main] DEBUG net.schmizz.concurrent.Promise - Setting <> to `null`
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <>
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <> to `SOME`
[main] DEBUG net.schmizz.concurrent.Promise - Setting <> to `null`
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <>
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <> to `true`
[main] DEBUG net.schmizz.concurrent.Promise - Setting <> to `null`
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <>
**[reader] ERROR n.s.sshj.transport.TransportImpl - Dying because - Broken transport; encountered EOF
net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
at net.schmizz.sshj.transport.Reader.run(Reader.java:57)**
[reader] INFO n.s.sshj.transport.TransportImpl - Disconnected - UNKNOWN
**[main] ERROR net.schmizz.concurrent.Promise - <> woke to: net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF**
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <> to `SOME`
[main] INFO n.s.sshj.transport.TransportImpl - Disconnected - BY_APPLICATION
**[main] DEBUG net.schmizz.concurrent.Promise - Setting <> to `SOME`
Exception in thread "main" net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
at net.schmizz.sshj.transport.Reader.run(Reader.java:57)**
The error seams to occur at net/schmizz/sshj/Reader.run because imp.read() returning -1.
```
while (!isInterrupted()) {
int read;
try {
**read = inp.read(recvbuf, 0, needed);**
} catch(SocketTimeoutException e) {
if (isInterrupted()) {
throw e;
}
continue;
}
if (read == -1) {
throw new TransportException("Broken transport; encountered EOF");
} else {
needed = decoder.received(recvbuf, read);
}
```
The odd thing is that when using the example code from net/schmizz/sshj/examples/RudimentaryPTY.java the restricted command prompt appears and commands can be entered:
[main] INFO n.s.s.t.random.BouncyCastleRandom - Generating random seed from SecureRandom.
[main] INFO n.s.sshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0.26.0
[main] INFO n.s.sshj.transport.TransportImpl - Server identity string: SSH-1.99-IPSSH-6.7.0
[main] DEBUG net.schmizz.concurrent.Promise - Setting <> to `null`
[reader] DEBUG net.schmizz.concurrent.Promise - Awaiting <>
[main] DEBUG net.schmizz.concurrent.Promise - Setting <> to `SOME`
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <>
[reader] DEBUG c.hierynomus.sshj.transport.kex.DHG - Sending SSH_MSG_KEXDH_INIT
[reader] DEBUG c.hierynomus.sshj.transport.kex.DHG - Received SSH_MSG_KEXDH_REPLY
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <> to `null`
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <> to `SOME`
[main] DEBUG net.schmizz.concurrent.Promise - Setting <> to `null`
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <>
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <> to `SOME`
[main] DEBUG net.schmizz.concurrent.Promise - Setting <> to `null`
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <>
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <> to `true`
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <>
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <> to `SOME`
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <>
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <> to `SOME`
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <>
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <> to `SOME`
CLI> help
Using the RudimentaryPTY.java to manually write an InputStream to the StreamCopier appears to work at first but then encounters the same error.
```
InputStream stream = new ByteArrayInputStream("help\n".getBytes());
new StreamCopier(stream, shell.getOutputStream(), LoggerFactory.DEFAULT)
.bufSize(shell.getRemoteMaxPacketSize()).copy();
```
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <>
CLI> help
clear disk-error - Clear the error information stored in disks.
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <> to `SOME`
[stdout] DEBUG net.schmizz.concurrent.Promise - Setting <> to `SOME`
[stderr] DEBUG net.schmizz.concurrent.Promise - Setting <> to `SOME`
[reader] ERROR n.s.sshj.transport.TransportImpl - Dying because - Broken transport; encountered EOF
net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
at net.schmizz.sshj.transport.Reader.run(Reader.java:57)
[reader] INFO n.s.sshj.transport.TransportImpl - Disconnected - UNKNOWN
Any help in determining the root cause of this is greatly appreciated.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.