Exemplo n.º 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();
    }
  }
Exemplo n.º 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);
 }
Exemplo n.º 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();
   }
 }
Exemplo n.º 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();
   }
 }
Exemplo n.º 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();
   }
 }
Exemplo n.º 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);
   }
 }
Exemplo n.º 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);
    }
  }
Exemplo n.º 8
0
 @Override
 public boolean isRunning() {
   return reader.isAlive() && !close.isSet();
 }
Exemplo n.º 9
0
 @Override
 public void join(int timeout, TimeUnit unit) throws TransportException {
   close.await(timeout, unit);
 }
Exemplo n.º 10
0
 @Override
 public void join() throws TransportException {
   close.await();
 }
Exemplo n.º 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);
 }
Exemplo n.º 12
0
 @Override
 public void notifyError(SSHException error) {
   super.notifyError(error);
   result.error(error);
 }