}
@Override
protected Boolean doAuth(Buffer buffer, boolean init) throws Exception {
if (!"ssh-connection".equals(service)) {
throw new SshException(SshConstants.SSH2_DISCONNECT_PROTOCOL_ERROR, "Unsupported service '" + service + "'");
}
if (init) {
// Prompt for password
buffer = session.createBuffer(SshConstants.Message.SSH_MSG_USERAUTH_INFO_REQUEST, 0);
buffer.putString("Password authentication");
buffer.putString("");
buffer.putString("en-US");
buffer.putInt(1);
buffer.putString("Password: ");
buffer.putBoolean(false);
session.writePacket(buffer);
return null;
} else {
SshConstants.Message cmd = buffer.getCommand();
if (cmd != SshConstants.Message.SSH_MSG_USERAUTH_INFO_RESPONSE) {
throw new SshException("Received unexepected message: " + cmd);
}
int num = buffer.getInt();
if (num != 1) {
throw new SshException("Expected 1 response from user but received " + num);
}
String password = buffer.getString();
return checkPassword(session, username, password);
}
}