sshj
sshj copied to clipboard
Restricted Shell: Broken transport; encountered EOF
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 <null
[reader] DEBUG net.schmizz.concurrent.Promise - Awaiting <SOME
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <null
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <SOME
[main] DEBUG net.schmizz.concurrent.Promise - Setting <null
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <SOME
[main] DEBUG net.schmizz.concurrent.Promise - Setting <null
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <true
[main] DEBUG net.schmizz.concurrent.Promise - Setting <null
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <SOME
[main] INFO n.s.sshj.transport.TransportImpl - Disconnected - BY_APPLICATION
[main] DEBUG net.schmizz.concurrent.Promise - Setting <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 <null
[reader] DEBUG net.schmizz.concurrent.Promise - Awaiting <SOME
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <null
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <SOME
[main] DEBUG net.schmizz.concurrent.Promise - Setting <null
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <SOME
[main] DEBUG net.schmizz.concurrent.Promise - Setting <null
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <true
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<chan#0 / open>>
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <<chan#0 / open>> to SOME
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<chan#0 / chanreq for pty-req>>
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <<chan#0 / chanreq for pty-req>> to SOME
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<chan#0 / chanreq for shell>>
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <<chan#0 / chanreq for shell>> 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 <<chan#0 / close>>
CLI> help
clear disk-error - Clear the error information stored in disks.
[reader] DEBUG net.schmizz.concurrent.Promise - Setting <<chan#0 / close>> to SOME
[stdout] DEBUG net.schmizz.concurrent.Promise - Setting <<copyDone>> to SOME
[stderr] DEBUG net.schmizz.concurrent.Promise - Setting <<copyDone>> 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.
I got this issue with AIX as my target host. using sshj-0.21.1 fixed my issue
Got the same error, is there any workaround then downgrading? Using 0.31 from Maven. After successful upload, getting this Error Message. Target System is a Windows Server Running an SFTP Service.
Update: I think i got it to work, was using File instead of FileSystemFile