Examples of SshException


Examples of org.apache.sshd.common.SshException

                    // Read packet length
                    decoderLength = decoderBuffer.getInt();
                    // Check packet length validity
                    if (decoderLength < 5 || decoderLength > (256 * 1024)) {
                        log.info("Error decoding packet (invalid length) {}", decoderBuffer.printHex());
                        throw new SshException(SshConstants.SSH2_DISCONNECT_PROTOCOL_ERROR,
                                               "Invalid packet length: " + decoderLength);
                    }
                    // Ok, that's good, we can go to the next step
                    decoderState = 1;
                } else {
                    // need more data
                    break;
                }
            // We have received the beginning of the packet
            } else if (decoderState == 1) {
                // The read position should always be 4 at this point
                assert decoderBuffer.rpos() == 4;
                int macSize = inMac != null ? inMac.getBlockSize() : 0;
                // Check if the packet has been fully received
                if (decoderBuffer.available() >= decoderLength + macSize) {
                    byte[] data = decoderBuffer.array();
                    // Decrypt the remaining of the packet
                    if (inCipher != null){
                        inCipher.update(data, inCipherSize, decoderLength + 4 - inCipherSize);
                    }
                    // Check the mac of the packet
                    if (inMac != null) {
                        // Update mac with packet id
                        inMac.updateUInt(seqi);
                        // Update mac with packet data
                        inMac.update(data, 0, decoderLength + 4);
                        // Compute mac result
                        inMac.doFinal(inMacResult, 0);
                        // Check the computed result with the received mac (just after the packet data)
                        if (!BufferUtils.equals(inMacResult, 0, data, decoderLength + 4, macSize)) {
                            throw new SshException(SshConstants.SSH2_DISCONNECT_MAC_ERROR, "MAC Error");
                        }
                    }
                    // Increment incoming packet sequence number
                    seqi = (seqi + 1) & 0xffffffffL;
                    // Get padding
View Full Code Here

Examples of org.jclouds.ssh.SshException

   SshException propagate(Exception e, String message) {
      message += ": " + e.getMessage();
      if (e.getMessage() != null && e.getMessage().indexOf("Auth fail") != -1)
         throw new AuthorizationException("(" + toString() + ") " + message, e);
      throw e instanceof SshException ? SshException.class.cast(e) : new SshException(
               "(" + toString() + ") " + message, e);
   }
View Full Code Here

Examples of org.platformlayer.ops.ssh.SshException

      ChannelSession clientChannel = BugFixChannelExec.createExecChannel(sshClientSession, command,
          useAgentForwarding);
      return clientChannel;
    } catch (Exception e) {
      ExceptionUtils.handleInterrupted(e);
      throw new SshException("Error creating channel", e);
    }
  }
View Full Code Here

Examples of org.platformlayer.ops.ssh.SshException

      System.out.println("New SSH connection to " + connectionInfo.getHost());

      ConnectFuture connect = client.connect(connectionInfo.getSocketAddress());
      if (!connect.await(connectTimeout.getTotalMilliseconds())) {
        connect.cancel();
        throw new SshException("Timeout while waiting for SSH connection to " + connectionInfo.getHost());
      }

      this.sshClientSession = connect.getSession();

      if (this.sshClientSession == null) {
        throw new IllegalStateException();
      }

      this.state = SshConnectionState.Connected;
    } catch (Exception e) {
      ExceptionUtils.handleInterrupted(e);
      throw new SshException("Error connecting to SSH server @" + connectionInfo.getSocketAddress(), e);
    }
  }
View Full Code Here

Examples of org.platformlayer.ops.ssh.SshException

    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");
  }
View Full Code Here

Examples of org.platformlayer.ops.ssh.SshException

        if (isAuthenticated == false) {
          // This happens when we upload the wrong public_key...
          // double check if you hit this!
          // This also happens if we're running a command that isn't
          // valid
          throw new SshException("Authentication failed.  Tried to connect to " + getUser() + "@"
              + sshConnection.getConnectionInfo().getHost());
        } else {
          log.debug("SSH authentication succeeded");
        }
      }
View Full Code Here

Examples of org.platformlayer.ops.ssh.SshException

      ProcessExecution processExecution = new ProcessExecution(command, exitCode, stdoutBinary.toByteArray(),
          stderrBinary.toByteArray());
      return processExecution;
    } catch (RuntimeSshException e) {
      throw new SshException("Unexpected SSH error", e);
    }
  }
View Full Code Here

Examples of org.platformlayer.ops.ssh.SshException

      sshChannel.setErr(stderr);
      try {
        sshChannel.open().await(DEFAULT_SSH_CONNECT_TIMEOUT.getTotalMilliseconds());
      } catch (Exception e) {
        ExceptionUtils.handleInterrupted(e);
        throw new SshException("Ssh error opening channel", e);
      }

      if (listener != null) {
        throw new UnsupportedOperationException();
        // listener.startedProcess(sshChannel.getStdin());
      }

      if (timeout == null) {
        timeout = TimeSpan.ZERO;
      }

      // Wait for everything to finish
      int flags = sshChannel.waitFor(ClientChannel.EOF | ClientChannel.CLOSED, timeout.getTotalMilliseconds());
      if ((flags & ClientChannel.TIMEOUT) != 0) {
        closeAndRemoveFromPool();
        throw new SshException("Timeout while waiting for SSH task to complete.  Timeout was " + timeout);
      }

      flags = sshChannel.waitFor(ClientChannel.EXIT_STATUS, 30000);
      if ((flags & ClientChannel.TIMEOUT) != 0) {
        closeAndRemoveFromPool();
        throw new SshException("Timeout while waiting for exit code.  Timeout was " + timeout);
      }

      Integer exitCode = getExitStatus(sshChannel);

      if (exitCode == null) {
        closeAndRemoveFromPool();
        throw new SshException("No exit code returned");
      }

      return exitCode;
    } finally {
      if (sshChannel != null) {
View Full Code Here

Examples of org.platformlayer.ops.ssh.SshException

    try {
      TimeSpan timeout = TimeSpan.FIVE_MINUTES;
      scp.put(fileData, dataLength, filename, remoteDir, mode, timeout, sudo);
    } catch (IOException ioException) {
      throw new SshException("Cannot doing scp on file", ioException);
    } catch (RuntimeSshException e) {
      throw new SshException("Error doing scp on file", e);
    }

  }
View Full Code Here

Examples of org.platformlayer.ops.ssh.SshException

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      TimeSpan timeout = TimeSpan.FIVE_MINUTES;
      scp.get(remoteFile, baos, timeout, sudo);
      return baos.toByteArray();
    } catch (IOException ioException) {
      throw new SshException("Cannot read file", ioException);
    } catch (SshException sshException) {
      String message = sshException.getMessage();
      if (message != null && message.endsWith(": No such file or directory")) {
        return null;
      }
      throw sshException;
    } catch (RuntimeSshException e) {
      throw new SshException("Error reading file", e);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.