Package ch.ethz.ssh2.packets

Examples of ch.ethz.ssh2.packets.TypesWriter


  public 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));

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

    byte[] resp = receiveMessage(34000);

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


    byte[] buffer;
  }

  private void sendReadRequest(int id, SFTPv3FileHandle handle, long offset, int len) throws IOException
  {
    TypesWriter tw = new TypesWriter();
    tw.writeString(handle.fileHandle, 0, handle.fileHandle.length);
    tw.writeUINT64(offset);
    tw.writeUINT32(len);

    log.debug("Sending SSH_FXP_READ (" + id + ") " + offset + "/" + len);
    sendMessage(Packet.SSH_FXP_READ, id, tw.getBytes());
  }
View Full Code Here

            // Send the next write request
            OutstandingStatusRequest req = new OutstandingStatusRequest();
            req.req_id = generateNextRequestID();

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

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

            pendingStatusQueue.put(req.req_id, req);

            // Only read next status if parallelism reached
            while (pendingStatusQueue.size() >= parallelism)
View Full Code Here

    byte[] pubKeyBlob = identity.getPublicKeyBlob();
    if(pubKeyBlob == null) {
      return false;
    }

    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(identity.getAlgName());
    tw.writeString(pubKeyBlob, 0, pubKeyBlob.length);

    byte[] msg = tw.getBytes();
    byte[] response = identity.sign(msg);

    PacketUserauthRequestPublicKey ua = new PacketUserauthRequestPublicKey(
        "ssh-connection", user, identity.getAlgName(), pubKeyBlob, response);
    tm.sendMessage(ua.getPayload());
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

    return new DSAPublicKey(p, q, g, y);
  }

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

    tw.writeString("ssh-dss");
    tw.writeMPInt(pk.getP());
    tw.writeMPInt(pk.getQ());
    tw.writeMPInt(pk.getG());
    tw.writeMPInt(pk.getY());

    return tw.getBytes();
  }
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

  private void closeHandle(byte[] handle) throws IOException
  {
    int req_id = generateNextRequestID();

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

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

    expectStatusOKMessage(req_id);
  }
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.