Пример #1
0
  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();
    }
  }
Пример #2
0
 private boolean tryWith(AuthMethod meth) throws UserAuthException, TransportException {
   currentMethod = meth;
   result.clear();
   meth.init(this);
   meth.request();
   return result.get(timeout, TimeUnit.SECONDS);
 }
Пример #3
0
 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();
   }
 }
Пример #4
0
 @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();
   }
 }
Пример #5
0
 @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();
   }
 }
Пример #6
0
 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);
   }
 }
Пример #7
0
  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);
    }
  }
Пример #8
0
 @Override
 public boolean isRunning() {
   return reader.isAlive() && !close.isSet();
 }
Пример #9
0
 @Override
 public void join(int timeout, TimeUnit unit) throws TransportException {
   close.await(timeout, unit);
 }
Пример #10
0
 @Override
 public void join() throws TransportException {
   close.await();
 }
Пример #11
0
 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);
 }
Пример #12
0
 @Override
 public void notifyError(SSHException error) {
   super.notifyError(error);
   result.error(error);
 }