#69 J2SSH hangs when key exchanging fails (fix provided)

Current CVS
open
nobody
J2SSH (50)
5
2014-07-22
2006-08-03
yongh
No

The j2ssh application hangs when something of key
exchanging fails, for example, the host key signature
is invalid.

The cause of the hanging is the method
onStartTransportProtocol() in class
TransportProtocolClient.

protected void onStartTransportProtocol() throws
IOException {
while ((state.getValue() !=
TransportProtocolState.CONNECTED) &&
(state.getValue() !=
TransportProtocolState.DISCONNECTED)) {
try {
state.waitForStateUpdate();
} catch (InterruptedException ex) {
throw new IOException("The operation
was interrupted");
}
}

....

}

The state of key exchanging is
PERFORMING_KEYEXCHANGE, when something go wrong, the
connection to SSH server is going to stop and the
state will never be updated any more. So the J2SSH
application will hang in the method
onStartTransportProtocol() and can't exit from the
while loop.

The fix is to update the state to DISCONNECTED when
something of key exchanging fail. I fixed the bug by
adding following in the sendDisconnect(int reason,
String description) method just before stop() method.

state.setValue(TransportProtocolState.DISCONNECTED);
state.setDisconnectReason(description);

Discussion