Package ch.ethz.ssh2.crypto.cipher

Examples of ch.ethz.ssh2.crypto.cipher.BlockCipher


  {
    checkHandleValidAndOpen(handle);

    int req_id = generateNextRequestID();

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

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

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

    byte[] resp = receiveMessage(34000);

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


  private SFTPv3FileAttributes statBoth(String path, int statMethod) throws IOException
  {
    int req_id = generateNextRequestID();

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

    if (debug != null)
    {
      debug.println("Sending SSH_FXP_STAT/SSH_FXP_LSTAT...");
      debug.flush();
    }

    sendMessage(statMethod, req_id, tw.getBytes());

    byte[] resp = receiveMessage(34000);

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

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

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

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

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

    byte[] resp = receiveMessage(34000);

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

   */
  public void setstat(String path, SFTPv3FileAttributes attr) throws IOException
  {
    int req_id = generateNextRequestID();

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

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

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

    expectStatusOKMessage(req_id);
  }
View Full Code Here

  {
    checkHandleValidAndOpen(handle);

    int req_id = generateNextRequestID();

    TypesWriter tw = new TypesWriter();
    tw.writeString(handle.fileHandle, 0, handle.fileHandle.length);
    tw.writeBytes(createAttrs(attr));

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

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

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

    /* Tell the other side that we start using the new material */

    PacketNewKeys ign = new PacketNewKeys();
    tm.sendKexMessage(ign.getPayload());

    BlockCipher cbc;
    MAC mac;

    try
    {
      cbc = BlockCipherFactory.createCipher(kxs.np.enc_algo_client_to_server, true, km.enc_key_client_to_server,
View Full Code Here

    if (msg[0] == Packets.SSH_MSG_NEWKEYS)
    {
      if (km == null)
        throw new IOException("Peer sent SSH_MSG_NEWKEYS, but I have no key material ready!");

      BlockCipher cbc;
      MAC mac;

      try
      {
        cbc = BlockCipherFactory.createCipher(kxs.np.enc_algo_server_to_client, false,
View Full Code Here

      throw new IOException("Broken PEM, DEK-Info is incomplete!");

    String algo = ps.dekInfo[0];
    byte[] salt = hexToByteArray(ps.dekInfo[1]);

    BlockCipher bc = null;

    if (algo.equals("DES-EDE3-CBC"))
    {
      DESede des3 = new DESede();
      des3.init(false, generateKeyFromPasswordSaltWithMD5(pw, salt, 24));
      bc = new CBCMode(des3, salt, false);
    }
    else if (algo.equals("DES-CBC"))
    {
      DES des = new DES();
      des.init(false, generateKeyFromPasswordSaltWithMD5(pw, salt, 8));
      bc = new CBCMode(des, salt, false);
    }
    else if (algo.equals("AES-128-CBC"))
    {
      AES aes = new AES();
      aes.init(false, generateKeyFromPasswordSaltWithMD5(pw, salt, 16));
      bc = new CBCMode(aes, salt, false);
    }
    else if (algo.equals("AES-192-CBC"))
    {
      AES aes = new AES();
      aes.init(false, generateKeyFromPasswordSaltWithMD5(pw, salt, 24));
      bc = new CBCMode(aes, salt, false);
    }
    else if (algo.equals("AES-256-CBC"))
    {
      AES aes = new AES();
      aes.init(false, generateKeyFromPasswordSaltWithMD5(pw, salt, 32));
      bc = new CBCMode(aes, salt, false);
    }
    else
    {
      throw new IOException("Cannot decrypt PEM structure, unknown cipher " + algo);
    }

    if ((ps.data.length % bc.getBlockSize()) != 0)
      throw new IOException("Invalid PEM structure, size of encrypted block is not a multiple of "
          + bc.getBlockSize());

    /* Now decrypt the content */

    byte[] dz = new byte[ps.data.length];

    for (int i = 0; i < ps.data.length / bc.getBlockSize(); i++)
    {
      bc.transformBlock(ps.data, i * bc.getBlockSize(), dz, i * bc.getBlockSize());
    }

    /* Now check and remove RFC 1423/PKCS #7 padding */

    dz = removePadding(dz, bc.getBlockSize());

    ps.data = dz;
    ps.dekInfo = null;
    ps.procType = null;
  }
View Full Code Here

TOP

Related Classes of ch.ethz.ssh2.crypto.cipher.BlockCipher

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.