Package ch.ethz.ssh2.packets

Examples of ch.ethz.ssh2.packets.TypesWriter


   */
  public void rmdir(String dirName) throws IOException
  {
    int req_id = generateNextRequestID();

    TypesWriter tw = new TypesWriter();
    tw.writeString(dirName, charsetName);

    sendMessage(Packet.SSH_FXP_RMDIR, req_id, tw.getBytes());

    expectStatusOKMessage(req_id);
  }
View Full Code Here


   */
  public void mv(String oldPath, String newPath) throws IOException
  {
    int req_id = generateNextRequestID();

    TypesWriter tw = new TypesWriter();
    tw.writeString(oldPath, charsetName);
    tw.writeString(newPath, charsetName);

    sendMessage(Packet.SSH_FXP_RENAME, req_id, tw.getBytes());

    expectStatusOKMessage(req_id);
  }
View Full Code Here

    return openFile(fileName, 0x00000018 | 0x00000003, attr); // SSH_FXF_CREAT | SSH_FXF_TRUNC | SSH_FXF_READ | SSH_FXF_WRITE
  }

  private byte[] createAttrs(SFTPv3FileAttributes attr)
  {
    TypesWriter tw = new TypesWriter();

    int attrFlags = 0;

    if (attr == null)
    {
      tw.writeUINT32(0);
    }
    else
    {
      if (attr.size != null)
        attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_SIZE;

      if ((attr.uid != null) && (attr.gid != null))
        attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_V3_UIDGID;

      if (attr.permissions != null)
        attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_PERMISSIONS;

      if ((attr.atime != null) && (attr.mtime != null))
        attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_V3_ACMODTIME;

      tw.writeUINT32(attrFlags);

      if (attr.size != null)
        tw.writeUINT64(attr.size.longValue());

      if ((attr.uid != null) && (attr.gid != null))
      {
        tw.writeUINT32(attr.uid.intValue());
        tw.writeUINT32(attr.gid.intValue());
      }

      if (attr.permissions != null)
        tw.writeUINT32(attr.permissions.intValue());

      if ((attr.atime != null) && (attr.mtime != null))
      {
        tw.writeUINT32(attr.atime.intValue());
        tw.writeUINT32(attr.mtime.intValue());
      }
    }

    return tw.getBytes();
  }
View Full Code Here

  private SFTPv3FileHandle openFile(String fileName, int flags, SFTPv3FileAttributes attr) throws IOException
  {
    int req_id = generateNextRequestID();

    TypesWriter tw = new TypesWriter();
    tw.writeString(fileName, charsetName);
    tw.writeUINT32(flags);
    tw.writeBytes(createAttrs(attr));

    if (debug != null)
    {
      debug.println("Sending SSH_FXP_OPEN...");
      debug.flush();
    }

    sendMessage(Packet.SSH_FXP_OPEN, req_id, tw.getBytes());

    byte[] resp = receiveMessage(34000);

    TypesReader tr = new TypesReader(resp);
View Full Code Here

    if ((len > 32768) || (len <= 0))
      throw new IllegalArgumentException("invalid len argument");

    int req_id = generateNextRequestID();

    TypesWriter tw = new TypesWriter();
    tw.writeString(handle.fileHandle, 0, handle.fileHandle.length);
    tw.writeUINT64(fileOffset);
    tw.writeUINT32(len);

    if (debug != null)
    {
      debug.println("Sending SSH_FXP_READ...");
      debug.flush();
    }

    sendMessage(Packet.SSH_FXP_READ, req_id, tw.getBytes());

    byte[] resp = receiveMessage(34000);

    TypesReader tr = new TypesReader(resp);
View Full Code Here

        if (writeRequestLen > 32768)
          writeRequestLen = 32768;

        int req_id = generateNextRequestID();

        TypesWriter tw = new TypesWriter();
        tw.writeString(handle.fileHandle, 0, handle.fileHandle.length);
        tw.writeUINT64(fileOffset);
        tw.writeString(src, srcoff, writeRequestLen);

        if (debug != null)
        {
          debug.println("Sending SSH_FXP_WRITE...");
          debug.flush();
        }

        sendMessage(Packet.SSH_FXP_WRITE, req_id, tw.getBytes());

        fileOffset += writeRequestLen;

        srcoff += writeRequestLen;
        len -= writeRequestLen;
View Full Code Here

    return tw.getBytes();
  }

  public static byte[] encodeSSHDSASignature(DSASignature ds)
  {
    TypesWriter tw = new TypesWriter();

    tw.writeString("ssh-dss");

    byte[] r = ds.getR().toByteArray();
    byte[] s = ds.getS().toByteArray();

    byte[] a40 = new byte[40];

    /* Patch (unsigned) r and s into the target array. */

    int r_copylen = (r.length < 20) ? r.length : 20;
    int s_copylen = (s.length < 20) ? s.length : 20;

    System.arraycopy(r, r.length - r_copylen, a40, 20 - r_copylen, r_copylen);
    System.arraycopy(s, s.length - s_copylen, a40, 40 - s_copylen, s_copylen);

    tw.writeString(a40, 0, 40);

    return tw.getBytes();
  }
View Full Code Here

    return new RSAPublicKey(e, n);
  }

  public static byte[] encodeSSHRSAPublicKey(RSAPublicKey pk) throws IOException
  {
    TypesWriter tw = new TypesWriter();

    tw.writeString("ssh-rsa");
    tw.writeMPInt(pk.getE());
    tw.writeMPInt(pk.getN());

    return tw.getBytes();
  }
View Full Code Here

    return new RSASignature(new BigInteger(1, s));
  }

  public static byte[] encodeSSHRSASignature(RSASignature sig) throws IOException
  {
    TypesWriter tw = new TypesWriter();

    tw.writeString("ssh-rsa");

    /* 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)."
     */

    byte[] s = sig.getS().toByteArray();

    /* Remove first zero sign byte, if present */

    if ((s.length > 1) && (s[0] == 0x00))
      tw.writeString(s, 1, s.length - 1);
    else
      tw.writeString(s, 0, s.length);

    return tw.getBytes();
  }
View Full Code Here

      {
        DSAPrivateKey pk = (DSAPrivateKey) key;

        byte[] pk_enc = DSASHA1Verify.encodeSSHDSAPublicKey(pk.getPublicKey());

        TypesWriter tw = new TypesWriter();

        byte[] H = tm.getSessionIdentifier();

        tw.writeString(H, 0, H.length);
        tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST);
        tw.writeString(user);
        tw.writeString("ssh-connection");
        tw.writeString("publickey");
        tw.writeBoolean(true);
        tw.writeString("ssh-dss");
        tw.writeString(pk_enc, 0, pk_enc.length);

        byte[] msg = tw.getBytes();

        DSASignature ds = DSASHA1Verify.generateSignature(msg, pk, rnd);

        byte[] ds_enc = DSASHA1Verify.encodeSSHDSASignature(ds);

        PacketUserauthRequestPublicKey ua = new PacketUserauthRequestPublicKey("ssh-connection", user,
            "ssh-dss", pk_enc, ds_enc);
        tm.sendMessage(ua.getPayload());
      }
      else if (key instanceof RSAPrivateKey)
      {
        RSAPrivateKey pk = (RSAPrivateKey) key;

        byte[] pk_enc = RSASHA1Verify.encodeSSHRSAPublicKey(pk.getPublicKey());

        TypesWriter tw = new TypesWriter();
        {
          byte[] H = tm.getSessionIdentifier();

          tw.writeString(H, 0, H.length);
          tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST);
          tw.writeString(user);
          tw.writeString("ssh-connection");
          tw.writeString("publickey");
          tw.writeBoolean(true);
          tw.writeString("ssh-rsa");
          tw.writeString(pk_enc, 0, pk_enc.length);
        }
       
        byte[] msg = tw.getBytes();

        RSASignature ds = RSASHA1Verify.generateSignature(msg, pk);

        byte[] rsa_sig_enc = RSASHA1Verify.encodeSSHRSASignature(ds);
View Full Code Here

TOP

Related Classes of ch.ethz.ssh2.packets.TypesWriter

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.