Package com.trilead.ssh2.packets

Examples of com.trilead.ssh2.packets.TypesWriter


        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

    /* Either I am too stupid to understand the SFTP draft
     * or the OpenSSH guys changed the semantics of src and target.
     */

    TypesWriter tw = new TypesWriter();
    tw.writeString(target, charsetName);
    tw.writeString(src, charsetName);

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

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

    expectStatusOKMessage(req_id);
  }
View Full Code Here

   */
  public String canonicalPath(String path) throws IOException
  {
    int req_id = generateNextRequestID();

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

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

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

    byte[] resp = receiveMessage(34000);

    if (debug != null)
    {
View Full Code Here

    while (true)
    {
      int req_id = generateNextRequestID();

      TypesWriter tw = new TypesWriter();
      tw.writeString(handle, 0, handle.length);

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

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

      byte[] resp = receiveMessage(34000);

      if (debug != null)
      {
View Full Code Here

  private final byte[] openDirectory(String path) throws IOException
  {
    int req_id = generateNextRequestID();

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

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

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

    byte[] resp = receiveMessage(34000);

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

    final int client_version = 3;

    if (debug != null)
      debug.println("Sending SSH_FXP_INIT (" + client_version + ")...");

    TypesWriter tw = new TypesWriter();
    tw.writeUINT32(client_version);
    sendMessage(Packet.SSH_FXP_INIT, 0, tw.getBytes());

    /* Receive SSH_FXP_VERSION */

    if (debug != null)
      debug.println("Waiting for SSH_FXP_VERSION...");
View Full Code Here

TOP

Related Classes of com.trilead.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.