Package ch.ethz.ssh2.packets

Examples of ch.ethz.ssh2.packets.TypesReader


{
  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


    return tw.getBytes();
  }

  public static RSASignature decodeSSHRSASignature(byte[] sig) throws IOException
  {
    TypesReader tr = new TypesReader(sig);

    String sig_format = tr.readString();

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

    /* S is NOT an MPINT. "The value for 'rsa_signature_blob' is encoded as a string
     * containing s (which is an integer, without lengths or padding, unsigned and in
     * network byte order)." See also below.
     */

    byte[] s = tr.readByteString();

    if (s.length == 0)
      throw new IOException("Error in RSA signature, S is empty.");

    if (log.isEnabled())
    {
      log.log(80, "Decoding ssh-rsa signature string (length: " + s.length + ")");
    }

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

    return new RSASignature(new BigInteger(1, s));
  }
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

    {
      debug.println("Got REPLY.");
      debug.flush();
    }

    TypesReader tr = new TypesReader(resp);

    int t = tr.readByte();

    int rep_id = tr.readUINT32();
    if (rep_id != req_id)
      throw new IOException("The server sent an invalid id field.");

    if (t == Packet.SSH_FXP_ATTRS)
    {
      return readAttrs(tr);
    }

    if (t != Packet.SSH_FXP_STATUS)
      throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");

    int errorCode = tr.readUINT32();

    throw new SFTPException(tr.readString(), errorCode);
  }
View Full Code Here

    {
      debug.println("Got REPLY.");
      debug.flush();
    }

    TypesReader tr = new TypesReader(resp);

    int t = tr.readByte();

    int rep_id = tr.readUINT32();
    if (rep_id != req_id)
      throw new IOException("The server sent an invalid id field.");

    if (t == Packet.SSH_FXP_ATTRS)
    {
      return readAttrs(tr);
    }

    if (t != Packet.SSH_FXP_STATUS)
      throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");

    int errorCode = tr.readUINT32();

    throw new SFTPException(tr.readString(), errorCode);
  }
View Full Code Here

    {
      debug.println("Got REPLY.");
      debug.flush();
    }

    TypesReader tr = new TypesReader(resp);

    int t = tr.readByte();

    int rep_id = tr.readUINT32();
    if (rep_id != req_id)
      throw new IOException("The server sent an invalid id field.");

    if (t == Packet.SSH_FXP_NAME)
    {
      int count = tr.readUINT32();

      if (count != 1)
        throw new IOException("The server sent an invalid SSH_FXP_NAME packet.");

      return tr.readString(charsetName);
    }

    if (t != Packet.SSH_FXP_STATUS)
      throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");

    int errorCode = tr.readUINT32();

    throw new SFTPException(tr.readString(), errorCode);
  }
View Full Code Here

    {
      debug.println("Got REPLY.");
      debug.flush();
    }

    TypesReader tr = new TypesReader(resp);

    int t = tr.readByte();

    int rep_id = tr.readUINT32();
    if (rep_id != id)
      throw new IOException("The server sent an invalid id field.");

    if (t != Packet.SSH_FXP_STATUS)
      throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");

    int errorCode = tr.readUINT32();

    if (errorCode == ErrorCodes.SSH_FX_OK)
      return;

    throw new SFTPException(tr.readString(), errorCode);
  }
View Full Code Here

    {
      debug.println("Got REPLY.");
      debug.flush();
    }

    TypesReader tr = new TypesReader(resp);

    int t = tr.readByte();

    int rep_id = tr.readUINT32();
    if (rep_id != req_id)
      throw new IOException("The server sent an invalid id field.");

    if (t == Packet.SSH_FXP_NAME)
    {
      int count = tr.readUINT32();

      if (count != 1)
        throw new IOException("The server sent an invalid SSH_FXP_NAME packet.");

      return tr.readString(charsetName);
    }

    if (t != Packet.SSH_FXP_STATUS)
      throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");

    int errorCode = tr.readUINT32();

    throw new SFTPException(tr.readString(), errorCode);
  }
View Full Code Here

      {
        debug.println("Got REPLY.");
        debug.flush();
      }

      TypesReader tr = new TypesReader(resp);

      int t = tr.readByte();

      int rep_id = tr.readUINT32();
      if (rep_id != req_id)
        throw new IOException("The server sent an invalid id field.");

      if (t == Packet.SSH_FXP_NAME)
      {
        int count = tr.readUINT32();

        if (debug != null)
          debug.println("Parsing " + count + " name entries...");

        while (count > 0)
        {
          SFTPv3DirectoryEntry dirEnt = new SFTPv3DirectoryEntry();

          dirEnt.filename = tr.readString(charsetName);
          dirEnt.longEntry = tr.readString(charsetName);

          dirEnt.attributes = readAttrs(tr);
          files.addElement(dirEnt);

          if (debug != null)
            debug.println("File: '" + dirEnt.filename + "'");
          count--;
        }
        continue;
      }

      if (t != Packet.SSH_FXP_STATUS)
        throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");

      int errorCode = tr.readUINT32();

      if (errorCode == ErrorCodes.SSH_FX_EOF)
        return files;

      throw new SFTPException(tr.readString(), errorCode);
    }
  }
View Full Code Here

TOP

Related Classes of ch.ethz.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.