if ((sshSessionStateCode & ClientSession.AUTHED) == 0) {
try {
sshClientSession.authPublicKey(user, key);
} catch (IOException e) {
throw new SshException("I/O error while authenticating " + this, e);
} catch (IllegalStateException e) {
throw new SshException("Error authenticating " + this, e);
}
sshSessionStateCode = sshClientSession.waitFor(ClientSession.CLOSED | ClientSession.AUTHED
| ClientSession.WAIT_AUTH, authenticationTimeout.getTotalMilliseconds());
}
if ((sshSessionStateCode & ClientSession.WAIT_AUTH) != 0) {
throw new SshException("SSH authentication failed (trying " + connectionInfo + ")");
}
if ((sshSessionStateCode & ClientSession.CLOSED) != 0) {
this.sshClientSession = null;
state = SshConnectionState.Closed;
throw new SshException("SSH connection closed while trying to login");
}
// if (serverKeyVerifier != null) {
// byte[] serverKey = getServerKey(sshClientSession);
// SocketAddress remoteAddress = new InetSocketAddress(connectionInfo.getHost(), connectionInfo.getPort());
// if (!serverKeyVerifier.verifyServerKey(remoteAddress, serverKey)) {
// sshClientSession.close(true);
// throw new SshException("SSH key verification failed");
// }
// }
if ((sshSessionStateCode & ClientSession.AUTHED) != 0) {
state = SshConnectionState.Authenticated;
return true;
}
if (sshSessionStateCode == ClientSession.TIMEOUT) {
throw new SshException("Timeout while waiting for session");
}
throw new SshException("Unexpected state; not authenticated; not closed");
}