public void die(Exception ex) { close.lock(); try { if (!close.isSet()) { log.error("Dying because - {}", ex); final SSHException causeOfDeath = SSHException.chainer.chain(ex); disconnectListener.notifyDisconnect( causeOfDeath.getDisconnectReason(), causeOfDeath.getMessage()); ErrorDeliveryUtil.alertEvents(causeOfDeath, close, serviceAccept); kexer.notifyError(causeOfDeath); getService().notifyError(causeOfDeath); setService(nullService); { // Perhaps can send disconnect packet to server final boolean didNotReceiveDisconnect = msg != Message.DISCONNECT; final boolean gotRequiredInfo = causeOfDeath.getDisconnectReason() != DisconnectReason.UNKNOWN; if (didNotReceiveDisconnect && gotRequiredInfo) sendDisconnect(causeOfDeath.getDisconnectReason(), causeOfDeath.getMessage()); } finishOff(); close.set(); } } finally { close.unlock(); } }
private boolean tryWith(AuthMethod meth) throws UserAuthException, TransportException { currentMethod = meth; result.clear(); meth.init(this); meth.request(); return result.get(timeout, TimeUnit.SECONDS); }
private void gotServiceAccept() throws TransportException { serviceAccept.lock(); try { if (!serviceAccept.hasWaiters()) throw new TransportException( DisconnectReason.PROTOCOL_ERROR, "Got a service accept notification when none was awaited"); serviceAccept.set(); } finally { serviceAccept.unlock(); } }
@Override public void reqService(Service service) throws TransportException { serviceAccept.lock(); try { serviceAccept.clear(); sendServiceRequest(service.getName()); serviceAccept.await(timeoutMs, TimeUnit.MILLISECONDS); setService(service); } finally { serviceAccept.unlock(); } }
@Override public void disconnect(DisconnectReason reason, String message) { close.lock(); try { if (isRunning()) { disconnectListener.notifyDisconnect(reason, message); getService().notifyError(new TransportException(reason, "Disconnected")); sendDisconnect(reason, message); finishOff(); close.set(); } } finally { close.unlock(); } }
private void gotFailure(SSHPacket buf) throws UserAuthException, TransportException { allowed.clear(); allowed.addAll(Arrays.<String>asList(buf.readString().split(","))); partialSuccess |= buf.readBoolean(); if (allowed.contains(currentMethod.getName()) && currentMethod.shouldRetry()) currentMethod.request(); else { saveException(currentMethod.getName() + " auth failed"); result.set(false); } }
private void gotUnknown(Message msg, SSHPacket buf) throws SSHException { if (currentMethod == null || result == null) { trans.sendUnimplemented(); return; } log.debug("Asking {} method to handle {} packet", currentMethod.getName(), msg); try { currentMethod.handle(msg, buf); } catch (UserAuthException e) { result.error(e); } }
@Override public boolean isRunning() { return reader.isAlive() && !close.isSet(); }
@Override public void join(int timeout, TimeUnit unit) throws TransportException { close.await(timeout, unit); }
@Override public void join() throws TransportException { close.await(); }
private void gotSuccess() { trans.setAuthenticated(); // So it can put delayed compression into force if applicable trans.setService(nextService); // We aren't in charge anymore, next service is result.set(true); }
@Override public void notifyError(SSHException error) { super.notifyError(error); result.error(error); }