Package com.trilead.ssh2.packets

Examples of com.trilead.ssh2.packets.TypesReader


    log.debug("Sending SSH_FXP_OPENDIR...");
    sendMessage(Packet.SSH_FXP_OPENDIR, req_id, tw.getBytes());

    byte[] resp = receiveMessage(34000);

    TypesReader tr = new TypesReader(resp);

    int t = tr.readByte();
    listener.read(Packet.forName(t));

    int rep_id = tr.readUINT32();
    if (rep_id != req_id)
    {
      throw new RequestMismatchException();
    }

    if (t == Packet.SSH_FXP_HANDLE)
    {
      log.debug("Got SSH_FXP_HANDLE.");
      return new SFTPv3FileHandle(this, tr.readByteString());
    }

    if (t != Packet.SSH_FXP_STATUS)
    {
      throw new PacketTypeException(t);
    }

    int errorCode = tr.readUINT32();
    String errorMessage = tr.readString();
    listener.read(errorMessage);
    throw new SFTPException(errorMessage, errorCode);
  }
View Full Code Here


    sendMessage(Packet.SSH_FXP_INIT, 0, tw.getBytes());

    /* Receive SSH_FXP_VERSION */

    log.debug("Waiting for SSH_FXP_VERSION...");
    TypesReader tr = new TypesReader(receiveMessage(34000)); /* Should be enough for any reasonable server */

    int t = tr.readByte();
    listener.read(Packet.forName(t));

    if (t != Packet.SSH_FXP_VERSION)
    {
      throw new IOException("The server did not send a SSH_FXP_VERSION packet (got " + t + ")");
    }

    protocol_version = tr.readUINT32();

    log.debug("SSH_FXP_VERSION: protocol_version = " + protocol_version);
    if (protocol_version != 3)
    {
      throw new IOException("Server version " + protocol_version + " is currently not supported");
    }

    /* Read and save extensions (if any) for later use */

    while (tr.remain() != 0)
    {
      String name = tr.readString();
      listener.read(name);
      byte[] value = tr.readByteString();
      log.debug("SSH_FXP_VERSION: extension: " + name + " = '" + expandString(value, 0, value.length) + "'");
    }
  }
View Full Code Here

    log.debug("Sending SSH_FXP_OPEN...");
    sendMessage(Packet.SSH_FXP_OPEN, req_id, tw.getBytes());

    byte[] resp = receiveMessage(34000);

    TypesReader tr = new TypesReader(resp);

    int t = tr.readByte();
    listener.read(Packet.forName(t));

    int rep_id = tr.readUINT32();
    if (rep_id != req_id)
    {
      throw new RequestMismatchException();
    }

    if (t == Packet.SSH_FXP_HANDLE)
    {
      log.debug("Got SSH_FXP_HANDLE.");
      return new SFTPv3FileHandle(this, tr.readByteString());
    }

    if (t != Packet.SSH_FXP_STATUS)
    {
      throw new PacketTypeException(t);
    }

    int errorCode = tr.readUINT32();
    String errorMessage = tr.readString();
    listener.read(errorMessage);
    throw new SFTPException(errorMessage, errorCode);
  }
View Full Code Here

        break;
      }

      // Receive a single answer
      byte[] resp = receiveMessage(34000);
      TypesReader tr = new TypesReader(resp);

      int t = tr.readByte();
      listener.read(Packet.forName(t));

      // Search the pending queue
      OutstandingReadRequest req = pendingReadQueue.remove(tr.readUINT32());
      if (null == req)
      {
        throw new RequestMismatchException();
      }
      // Evaluate the answer
      if (t == Packet.SSH_FXP_STATUS)
      {
        /* In any case, stop sending more packets */

        int code = tr.readUINT32();
        String msg = tr.readString();
        listener.read(msg);

        if (log.isDebugEnabled())
        {
          String[] desc = ErrorCodes.getDescription(code);
          log.debug("Got SSH_FXP_STATUS (" + req.req_id + ") (" + ((desc != null) ? desc[0] : "UNKNOWN") + ")");
        }
        // Flag to read all pending requests but don't send any more.
        errorOccured = true;
        if (pendingReadQueue.isEmpty())
        {
          if (ErrorCodes.SSH_FX_EOF == code)
          {
            return -1;
          }
          throw new SFTPException(msg, code);
        }
      }
      else if (t == Packet.SSH_FXP_DATA)
      {
        // OK, collect data
        int readLen = tr.readUINT32();

        if ((readLen < 0) || (readLen > req.len))
        {
          throw new IOException("The server sent an invalid length field in a SSH_FXP_DATA packet.");
        }

        if (log.isDebugEnabled())
        {
          log.debug("Got SSH_FXP_DATA (" + req.req_id + ") " + req.serverOffset + "/" + readLen
              + " (requested: " + req.len + ")");
        }

        // Read bytes into buffer
        tr.readBytes(req.buffer, req.dstOffset, readLen);

        if (readLen < req.len)
        {
          /* Send this request packet again to request the remaing data in this slot. */
          req.req_id = generateNextRequestID();
View Full Code Here

  private void readStatus() throws IOException
  {
    byte[] resp = receiveMessage(34000);

    TypesReader tr = new TypesReader(resp);
    int t = tr.readByte();
    listener.read(Packet.forName(t));

    // Search the pending queue
    OutstandingStatusRequest status = pendingStatusQueue.remove(tr.readUINT32());
    if (null == status)
    {
      throw new RequestMismatchException();
    }

    // Evaluate the answer
    if (t == Packet.SSH_FXP_STATUS)
    {
      // In any case, stop sending more packets
      int code = tr.readUINT32();
      if (log.isDebugEnabled())
      {
        String[] desc = ErrorCodes.getDescription(code);
        log.debug("Got SSH_FXP_STATUS (" + status.req_id + ") (" + ((desc != null) ? desc[0] : "UNKNOWN") + ")");
      }
      if (code == ErrorCodes.SSH_FX_OK)
      {
        return;
      }
      String msg = tr.readString();
      listener.read(msg);
      throw new SFTPException(msg, code);
    }
    throw new PacketTypeException(t);
  }
View Full Code Here

  private void readPendingReadStatus() throws IOException
  {
    byte[] resp = receiveMessage(34000);

    TypesReader tr = new TypesReader(resp);
    int t = tr.readByte();
    listener.read(Packet.forName(t));

    // Search the pending queue
        OutstandingReadRequest status = pendingReadQueue.remove(tr.readUINT32());
        if (null == status)
    {
      throw new RequestMismatchException();
    }

    // Evaluate the answer
    if (t == Packet.SSH_FXP_STATUS)
    {
      // In any case, stop sending more packets
      int code = tr.readUINT32();
      if (log.isDebugEnabled())
      {
        String[] desc = ErrorCodes.getDescription(code);
        log.debug("Got SSH_FXP_STATUS (" + status.req_id + ") (" + ((desc != null) ? desc[0] : "UNKNOWN") + ")");
      }
      if (code == ErrorCodes.SSH_FX_OK)
      {
        return;
      }
            if (code == ErrorCodes.SSH_FX_EOF)
            {
                return;
            }
      String msg = tr.readString();
      listener.read(msg);
      throw new SFTPException(msg, code);
    }
    throw new PacketTypeException(t);
  }
View Full Code Here

      return;
    }

    ServerAuthenticationCallback cb = state.cb_auth;

    TypesReader tr = new TypesReader(msg, 0, msglen);
    int packet_type = tr.readByte();

    if (packet_type == Packets.SSH_MSG_USERAUTH_REQUEST)
    {
      String username = tr.readString("UTF-8");
      String service = tr.readString();
      String method = tr.readString();

      if (!"ssh-connection".equals(service))
      {
        sendresult(AuthenticationResult.FAILURE);
        return;
      }

      if ("none".equals(method))
      {
        if (cb != null)
        {
          sendresult(cb.authenticateWithNone(state.conn, username));
          return;
        }
      }

      if ("password".equals(method))
      {
        boolean flag_change_pass = tr.readBoolean();

        if (flag_change_pass)
        {
          sendresult(AuthenticationResult.FAILURE);
          return;
        }

        String password = tr.readString("UTF-8");

        if (cb != null)
        {
          sendresult(cb.authenticateWithPassword(state.conn, username, password));
          return;
View Full Code Here

{
  private static final Logger log = Logger.getLogger(DSASHA1Verify.class);

  public static DSAPublicKey decodeSSHDSAPublicKey(byte[] key) throws IOException
  {
    TypesReader tr = new TypesReader(key);

    String key_format = tr.readString();

    if (key_format.equals("ssh-dss") == false)
      throw new IllegalArgumentException("This is not a ssh-dss public key!");

    BigInteger p = tr.readMPINT();
    BigInteger q = tr.readMPINT();
    BigInteger g = tr.readMPINT();
    BigInteger y = tr.readMPINT();

    if (tr.remain() != 0)
      throw new IOException("Padding in DSA public key!");

    return new DSAPublicKey(p, q, g, y);
  }
View Full Code Here

    {
      rsArray = sig;
    }
    else
    {
      TypesReader tr = new TypesReader(sig);

      String sig_format = tr.readString();

      if (sig_format.equals("ssh-dss") == false)
        throw new IOException("Peer sent wrong signature format");

      rsArray = tr.readByteString();

      if (rsArray.length != 40)
        throw new IOException("Peer sent corrupt signature");

      if (tr.remain() != 0)
        throw new IOException("Padding in DSA signature!");
    }

    /* Remember, s and r are unsigned ints. */

 
View Full Code Here

{
  private static final Logger log = Logger.getLogger(RSASHA1Verify.class);

  public static RSAPublicKey decodeSSHRSAPublicKey(byte[] key) throws IOException
  {
    TypesReader tr = new TypesReader(key);

    String key_format = tr.readString();

    if (key_format.equals("ssh-rsa") == false)
      throw new IllegalArgumentException("This is not a ssh-rsa public key");

    BigInteger e = tr.readMPINT();
    BigInteger n = tr.readMPINT();

    if (tr.remain() != 0)
      throw new IOException("Padding in RSA public key!");

    return new RSAPublicKey(e, n);
  }
View Full Code Here

TOP

Related Classes of com.trilead.ssh2.packets.TypesReader

Copyright © 2018 www.massapicom. 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.