SSHJ trying to start a session results in SSH_MSG_UNIMPLEMENTED

3.7k views Asked by At

I'm on a Windows machine, and I need to write some Java code that connects to a remote Solaris machine by using SSH and can then execute commands on it and get their output, but I'm having some trouble authenticating. (I'm using SSHJ 0.8.1)

Here's the code for connecting and starting a session:

public void init(String address, int portNumber, String hostKeyVerifier) throws IOException {
      client = new SSHClient();
      client.getConnection().setTimeout(300);
      client.addHostKeyVerifier(hostKeyVerifier); 
      client.connect(address, portNumber); 
      client.authPassword("user", "password");
      session = client.startSession();
   }

I'd expect this to result in a working connection, since trying to connect to instances of Apache Karaf with the same code (albeit with a different host key verifier, address, port and credentials) works. Instead, this is the output I get:

16:27:58.029 [main] INFO  n.schmizz.sshj.common.SecurityUtils - BouncyCastle not registered, using the default JCE provider
16:27:58.159 [main] INFO  n.s.sshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0_8_1_SNAPSHOT
16:27:58.159 [main] INFO  n.s.sshj.transport.TransportImpl - Server identity string: SSH-2.0-Sun_SSH_2.2
16:27:58.159 [main] DEBUG net.schmizz.concurrent.Promise - Setting <<kex done>> to `null`
16:27:58.159 [main] DEBUG n.s.sshj.transport.KeyExchanger - Sending SSH_MSG_KEXINIT
16:27:58.169 [main] DEBUG net.schmizz.concurrent.Promise - Setting <<kexinit sent>> to `SOME`
16:27:58.169 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<kex done>>
16:27:58.189 [reader] DEBUG n.s.sshj.transport.KeyExchanger - Received SSH_MSG_KEXINIT
16:27:58.189 [reader] DEBUG n.s.sshj.transport.KeyExchanger - Negotiated algorithms: [ kex=diffie-hellman-group1-sha1; sig=ssh-rsa; c2sCipher=aes128-ctr; s2cCipher=aes128-ctr; c2sMAC=hmac-sha1; s2cMAC=hmac-sha1; c2sComp=none; s2cComp=none ]
16:27:58.209 [reader] DEBUG net.schmizz.sshj.transport.kex.DHG1 - Sending SSH_MSG_KEXDH_INIT
16:27:58.239 [reader] DEBUG n.s.sshj.transport.KeyExchanger - Received kex followup data
16:27:58.239 [reader] DEBUG net.schmizz.sshj.transport.kex.DHG1 - Received SSH_MSG_KEXDH_REPLY
16:27:58.249 [reader] DEBUG n.s.sshj.transport.KeyExchanger - Trying to verify host key with net.schmizz.sshj.SSHClient$1@135bdd3
16:27:58.249 [reader] DEBUG n.s.sshj.transport.KeyExchanger - Sending SSH_MSG_NEWKEYS
16:27:58.249 [reader] DEBUG n.s.sshj.transport.KeyExchanger - Received SSH_MSG_NEWKEYS
16:27:58.249 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<kexinit sent>> to `null`
16:27:58.249 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<kex done>> to `SOME`
16:27:58.249 [main] DEBUG net.schmizz.sshj.SSHClient - Key exchange took 0.09 seconds
16:27:58.249 [main] DEBUG net.schmizz.concurrent.Promise - Setting <<service accept>> to `null`
16:27:58.249 [main] DEBUG n.s.sshj.transport.TransportImpl - Sending SSH_MSG_SERVICE_REQUEST for ssh-userauth
16:27:58.249 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<service accept>>
16:27:58.309 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<service accept>> to `SOME`
16:27:58.309 [main] DEBUG n.s.sshj.transport.TransportImpl - Setting active service to ssh-userauth
16:27:58.309 [main] DEBUG n.schmizz.sshj.userauth.UserAuthImpl - Trying `password` auth...
16:27:58.309 [main] DEBUG net.schmizz.concurrent.Promise - Setting <<authenticated>> to `null`
16:27:58.309 [main] DEBUG n.s.s.userauth.method.AuthPassword - Requesting password for [AccountResource] [email protected]
16:27:58.309 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<authenticated>>
16:28:28.320 [main] DEBUG n.schmizz.sshj.userauth.UserAuthImpl - `password` auth failed
16:28:28.320 [main] DEBUG n.schmizz.sshj.userauth.UserAuthImpl - Saving for later - net.schmizz.sshj.userauth.UserAuthException: Timeout expired
16:28:28.320 [main] DEBUG n.schmizz.sshj.userauth.UserAuthImpl - Trying `keyboard-interactive` auth...
16:28:28.321 [main] DEBUG net.schmizz.concurrent.Promise - Setting <<authenticated>> to `null`
16:28:28.321 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<authenticated>>
16:28:43.363 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<authenticated>> to `SOME`
16:28:43.363 [main] DEBUG n.schmizz.sshj.userauth.UserAuthImpl - `keyboard-interactive` auth successful
16:28:43.365 [main] DEBUG n.s.sshj.transport.TransportImpl - Setting active service to ssh-connection
16:28:43.366 [main] DEBUG n.s.sshj.connection.ConnectionImpl - Attaching `session` channel (#0)
16:28:43.366 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<chan#0 / open>>
16:29:28.387 [reader] DEBUG n.s.sshj.transport.TransportImpl - Received SSH_MSG_UNIMPLEMENTED #5
16:29:28.397 [reader] ERROR n.s.sshj.transport.TransportImpl - Dying because - net.schmizz.sshj.common.SSHException: [PROTOCOL_ERROR] Unexpected: SSH_MSG_UNIMPLEMENTED
16:29:28.397 [reader] INFO  n.s.sshj.transport.TransportImpl - Disconnected - PROTOCOL_ERROR
16:29:28.398 [reader] DEBUG n.s.sshj.transport.KeyExchanger - Got notified of net.schmizz.sshj.common.SSHException: [PROTOCOL_ERROR] Unexpected: SSH_MSG_UNIMPLEMENTED
16:29:28.398 [reader] DEBUG n.s.sshj.connection.ConnectionImpl - Notified of net.schmizz.sshj.common.SSHException: [PROTOCOL_ERROR] Unexpected: SSH_MSG_UNIMPLEMENTED
16:29:28.398 [reader] DEBUG n.s.s.c.c.direct.SessionChannel - Channel #0 got notified of net.schmizz.sshj.common.SSHException: [PROTOCOL_ERROR] Unexpected: SSH_MSG_UNIMPLEMENTED
16:29:28.398 [reader] DEBUG n.s.sshj.connection.ConnectionImpl - Forgetting `session` channel (#0)
16:29:28.398 [main] ERROR net.schmizz.concurrent.Promise - <<chan#0 / open>> woke to: net.schmizz.sshj.connection.ConnectionException: Unexpected: SSH_MSG_UNIMPLEMENTED
16:29:28.398 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<chan#0 / close>> to `SOME`
16:29:28.398 [reader] DEBUG n.s.sshj.transport.TransportImpl - Setting active service to null-service
16:29:28.398 [reader] DEBUG n.s.sshj.transport.TransportImpl - Sending SSH_MSG_DISCONNECT: reason=[PROTOCOL_ERROR], msg=[Unexpected: SSH_MSG_UNIMPLEMENTED]
16:29:28.398 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<transport close>> to `SOME`
16:29:28.398 [reader] DEBUG net.schmizz.sshj.transport.Reader - Stopping

Also, this is the stack trace I get in Eclipse:

net.schmizz.sshj.connection.ConnectionException: Unexpected: SSH_MSG_UNIMPLEMENTED
    at net.schmizz.sshj.connection.ConnectionException$1.chain(ConnectionException.java:32)
    at net.schmizz.sshj.connection.ConnectionException$1.chain(ConnectionException.java:26)
    at net.schmizz.concurrent.Promise.deliverError(Promise.java:95)
    at net.schmizz.concurrent.Event.deliverError(Event.java:72)
    at net.schmizz.concurrent.ErrorDeliveryUtil.alertEvents(ErrorDeliveryUtil.java:34)
    at net.schmizz.sshj.connection.channel.AbstractChannel.notifyError(AbstractChannel.java:241)
    at net.schmizz.sshj.connection.channel.direct.SessionChannel.notifyError(SessionChannel.java:249)
    at net.schmizz.sshj.common.ErrorNotifiable$Util.alertAll(ErrorNotifiable.java:35)
    at net.schmizz.sshj.connection.ConnectionImpl.notifyError(ConnectionImpl.java:250)
    at net.schmizz.sshj.transport.TransportImpl.die(TransportImpl.java:578)
    at net.schmizz.sshj.transport.Reader.run(Reader.java:79)
Caused by: net.schmizz.sshj.common.SSHException: [PROTOCOL_ERROR] Unexpected: SSH_MSG_UNIMPLEMENTED
    at net.schmizz.sshj.AbstractService.notifyUnimplemented(AbstractService.java:66)
    at net.schmizz.sshj.transport.TransportImpl.gotUnimplemented(TransportImpl.java:555)
    at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:490)
    at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:127)
    at net.schmizz.sshj.transport.Decoder.received(Decoder.java:195)
    at net.schmizz.sshj.transport.Reader.run(Reader.java:72)

PuTTY is capable of connecting to that same address and port, using the same credentials, with no issues, though it does take some time. What should I do to get a working connection with Java here?

0

There are 0 answers