com.jcraft.jsch_0.1.46.v201205102330

16:34:30.553 INFO  jd.cli.Main - Decompiling com.jcraft.jsch_0.1.46.v201205102330.jar
package com.jcraft.jsch;

public class Buffer
{
  final byte[] tmp = new byte[4];
  byte[] buffer;
  int index;
  int s;
  
  public Buffer(int size)
  {
    buffer = new byte[size];
    index = 0;
    s = 0;
  }
  
  public Buffer(byte[] buffer)
  {
    this.buffer = buffer;
    index = 0;
    s = 0;
  }
  
  public Buffer()
  {
    this(20480);
  }
  
  public void putByte(byte foo)
  {
    buffer[(index++)] = foo;
  }
  
  public void putByte(byte[] foo)
  {
    putByte(foo, 0, foo.length);
  }
  
  public void putByte(byte[] foo, int begin, int length)
  {
    System.arraycopy(foo, begin, buffer, index, length);
    index += length;
  }
  
  public void putString(byte[] foo)
  {
    putString(foo, 0, foo.length);
  }
  
  public void putString(byte[] foo, int begin, int length)
  {
    putInt(length);
    putByte(foo, begin, length);
  }
  
  public void putInt(int val)
  {
    tmp[0] = ((byte)(val >>> 24));
    tmp[1] = ((byte)(val >>> 16));
    tmp[2] = ((byte)(val >>> 8));
    tmp[3] = ((byte)val);
    System.arraycopy(tmp, 0, buffer, index, 4);
    index += 4;
  }
  
  public void putLong(long val)
  {
    tmp[0] = ((byte)(int)(val >>> 56));
    tmp[1] = ((byte)(int)(val >>> 48));
    tmp[2] = ((byte)(int)(val >>> 40));
    tmp[3] = ((byte)(int)(val >>> 32));
    System.arraycopy(tmp, 0, buffer, index, 4);
    tmp[0] = ((byte)(int)(val >>> 24));
    tmp[1] = ((byte)(int)(val >>> 16));
    tmp[2] = ((byte)(int)(val >>> 8));
    tmp[3] = ((byte)(int)val);
    System.arraycopy(tmp, 0, buffer, index + 4, 4);
    index += 8;
  }
  
  void skip(int n)
  {
    index += n;
  }
  
  void putPad(int n)
  {
    while (n > 0)
    {
      buffer[(index++)] = 0;
      n--;
    }
  }
  
  public void putMPInt(byte[] foo)
  {
    int i = foo.length;
    if ((foo[0] & 0x80) != 0)
    {
      i++;
      putInt(i);
      putByte((byte)0);
    }
    else
    {
      putInt(i);
    }
    putByte(foo);
  }
  
  public int getLength()
  {
    return index - s;
  }
  
  public int getOffSet()
  {
    return s;
  }
  
  public void setOffSet(int s)
  {
    this.s = s;
  }
  
  public long getLong()
  {
    long foo = getInt() & 0xFFFFFFFF;
    foo = foo << 32 | getInt() & 0xFFFFFFFF;
    return foo;
  }
  
  public int getInt()
  {
    int foo = getShort();
    foo = foo << 16 & 0xFFFF0000 | getShort() & 0xFFFF;
    return foo;
  }
  
  public long getUInt()
  {
    long foo = 0L;
    long bar = 0L;
    foo = getByte();
    foo = foo << 8 & 0xFF00 | getByte() & 0xFF;
    bar = getByte();
    bar = bar << 8 & 0xFF00 | getByte() & 0xFF;
    foo = foo << 16 & 0xFFFFFFFFFFFF0000 | bar & 0xFFFF;
    return foo;
  }
  
  int getShort()
  {
    int foo = getByte();
    foo = foo << 8 & 0xFF00 | getByte() & 0xFF;
    return foo;
  }
  
  public int getByte()
  {
    return buffer[(s++)] & 0xFF;
  }
  
  public void getByte(byte[] foo)
  {
    getByte(foo, 0, foo.length);
  }
  
  void getByte(byte[] foo, int start, int len)
  {
    System.arraycopy(buffer, s, foo, start, len);
    s += len;
  }
  
  public int getByte(int len)
  {
    int foo = s;
    s += len;
    return foo;
  }
  
  public byte[] getMPInt()
  {
    int i = getInt();
    if ((i < 0) || (i > 8192)) {
      i = 8192;
    }
    byte[] foo = new byte[i];
    getByte(foo, 0, i);
    return foo;
  }
  
  public byte[] getMPIntBits()
  {
    int bits = getInt();
    int bytes = (bits + 7) / 8;
    byte[] foo = new byte[bytes];
    getByte(foo, 0, bytes);
    if ((foo[0] & 0x80) != 0)
    {
      byte[] bar = new byte[foo.length + 1];
      bar[0] = 0;
      System.arraycopy(foo, 0, bar, 1, foo.length);
      foo = bar;
    }
    return foo;
  }
  
  public byte[] getString()
  {
    int i = getInt();
    if ((i < 0) || (i > 262144)) {
      i = 262144;
    }
    byte[] foo = new byte[i];
    getByte(foo, 0, i);
    return foo;
  }
  
  byte[] getString(int[] start, int[] len)
  {
    int i = getInt();
    start[0] = getByte(i);
    len[0] = i;
    return buffer;
  }
  
  public void reset()
  {
    index = 0;
    s = 0;
  }
  
  public void shift()
  {
    if (s == 0) {
      return;
    }
    System.arraycopy(buffer, s, buffer, 0, index - s);
    index -= s;
    s = 0;
  }
  
  void rewind()
  {
    s = 0;
  }
  
  byte getCommand()
  {
    return buffer[5];
  }
  
  void checkFreeSize(int n)
  {
    if (buffer.length < index + n)
    {
      byte[] tmp = new byte[buffer.length * 2];
      System.arraycopy(buffer, 0, tmp, 0, index);
      buffer = tmp;
    }
  }
}

/* Location:
 * Qualified Name:     com.jcraft.jsch.Buffer
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jcraft.jsch;

import java.io.IOException;
import java.io.OutputStream;

class Channel$1
  extends OutputStream
{
  private int dataLen = 0;
  private Buffer buffer = null;
  private Packet packet = null;
  private boolean closed = false;
  
  Channel$1(Channel paramChannel1, Channel paramChannel2) {}
  
  private synchronized void init()
    throws IOException
  {
    buffer = new Buffer(this$0.rmpsize);
    packet = new Packet(buffer);
    
    byte[] _buf = buffer.buffer;
    if (_buf.length - 14 - 84 <= 0)
    {
      buffer = null;
      packet = null;
      throw new IOException("failed to initialize the channel.");
    }
  }
  
  byte[] b = new byte[1];
  private final Channel this$0;
  
  public void write(int w)
    throws IOException
  {
    b[0] = ((byte)w);
    write(b, 0, 1);
  }
  
  public void write(byte[] buf, int s, int l)
    throws IOException
  {
    if (packet == null) {
      init();
    }
    if (closed) {
      throw new IOException("Already closed");
    }
    byte[] _buf = buffer.buffer;
    int _bufl = _buf.length;
    while (l > 0)
    {
      int _l = l;
      if (l > _bufl - (14 + dataLen) - 84) {
        _l = _bufl - (14 + dataLen) - 84;
      }
      if (_l <= 0)
      {
        flush();
      }
      else
      {
        System.arraycopy(buf, s, _buf, 14 + dataLen, _l);
        dataLen += _l;
        s += _l;
        l -= _l;
      }
    }
  }
  
  public void flush()
    throws IOException
  {
    if (closed) {
      throw new IOException("Already closed");
    }
    if (dataLen == 0) {
      return;
    }
    packet.reset();
    buffer.putByte((byte)94);
    buffer.putInt(this$0.recipient);
    buffer.putInt(dataLen);
    buffer.skip(dataLen);
    try
    {
      int foo = dataLen;
      dataLen = 0;
      synchronized (val$channel)
      {
        if (!val$channel.close) {
          this$0.getSession().write(packet, val$channel, foo);
        }
      }
    }
    catch (Exception e)
    {
      close();
      throw new IOException(e.toString());
    }
  }
  
  public void close()
    throws IOException
  {
    if (packet == null) {
      try
      {
        init();
      }
      catch (IOException e)
      {
        return;
      }
    }
    if (closed) {
      return;
    }
    if (dataLen > 0) {
      flush();
    }
    val$channel.eof();
    closed = true;
  }
}

/* Location:
 * Qualified Name:     com.jcraft.jsch.Channel.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jcraft.jsch;

import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

class Channel$MyPipedInputStream
  extends PipedInputStream
{
  private final Channel this$0;
  
  Channel$MyPipedInputStream(Channel paramChannel)
    throws IOException
  {}
  
  Channel$MyPipedInputStream(Channel paramChannel, int size)
    throws IOException
  {
    buffer = new byte[size];
  }
  
  Channel$MyPipedInputStream(Channel paramChannel, PipedOutputStream out)
    throws IOException
  {
    super(out);
  }
  
  Channel$MyPipedInputStream(Channel paramChannel, PipedOutputStream out, int size)
    throws IOException
  {
    super(out);
    buffer = new byte[size];
  }
  
  public synchronized void updateReadSide()
    throws IOException
  {
    if (available() != 0) {
      return;
    }
    in = 0;
    out = 0;
    buffer[(in++)] = 0;
    read();
  }
}

/* Location:
 * Qualified Name:     com.jcraft.jsch.Channel.MyPipedInputStream
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jcraft.jsch;

import java.io.IOException;
import java.io.PipedOutputStream;

class Channel$PassiveInputStream
  extends Channel.MyPipedInputStream
{
  PipedOutputStream out;
  private final Channel this$0;
  
  Channel$PassiveInputStream(Channel paramChannel, PipedOutputStream out, int size)
    throws IOException
  {
    super(paramChannel, out, size);
    this.out = out;
  }
  
  Channel$PassiveInputStream(Channel paramChannel, PipedOutputStream out)
    throws IOException
  {
    super(paramChannel, out);
    this.out = out;
  }
  
  public void close()
    throws IOException
  {
    if (out != null) {
      out.close();
    }
    out = null;
  }
}

/* Location:
 * Qualified Name:     com.jcraft.jsch.Channel.PassiveInputStream
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jcraft.jsch;

import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

class Channel$PassiveOutputStream
  extends PipedOutputStream
{
  private final Channel this$0;
  
  Channel$PassiveOutputStream(Channel paramChannel, PipedInputStream in)
    throws IOException
  {
    super(in);
  }
}

/* Location:
 * Qualified Name:     com.jcraft.jsch.Channel.PassiveOutputStream
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jcraft.jsch;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.util.Vector;

public abstract class Channel
  implements Runnable
{
  static final int SSH_MSG_CHANNEL_OPEN_CONFIRMATION = 91;
  static final int SSH_MSG_CHANNEL_OPEN_FAILURE = 92;
  static final int SSH_MSG_CHANNEL_WINDOW_ADJUST = 93;
  static final int SSH_OPEN_ADMINISTRATIVELY_PROHIBITED = 1;
  static final int SSH_OPEN_CONNECT_FAILED = 2;
  static final int SSH_OPEN_UNKNOWN_CHANNEL_TYPE = 3;
  static final int SSH_OPEN_RESOURCE_SHORTAGE = 4;
  static int index = 0;
  private static Vector pool = new Vector();
  int id;
  
  static Channel getChannel(String type)
  {
    if (type.equals("session")) {
      return new ChannelSession();
    }
    if (type.equals("shell")) {
      return new ChannelShell();
    }
    if (type.equals("exec")) {
      return new ChannelExec();
    }
    if (type.equals("x11")) {
      return new ChannelX11();
    }
    if (type.equals("auth-agent@openssh.com")) {
      return new ChannelAgentForwarding();
    }
    if (type.equals("direct-tcpip")) {
      return new ChannelDirectTCPIP();
    }
    if (type.equals("forwarded-tcpip")) {
      return new ChannelForwardedTCPIP();
    }
    if (type.equals("sftp")) {
      return new ChannelSftp();
    }
    if (type.equals("subsystem")) {
      return new ChannelSubsystem();
    }
    return null;
  }
  
  static Channel getChannel(int id, Session session)
  {
    synchronized (pool)
    {
      for (int i = 0; i < pool.size(); i++)
      {
        Channel c = (Channel)pool.elementAt(i);
        if ((id == id) && (session == session)) {
          return c;
        }
      }
    }
    return null;
  }
  
  static void del(Channel c)
  {
    synchronized (pool)
    {
      pool.removeElement(c);
    }
  }
  
  volatile int recipient = -1;
  protected byte[] type = Util.str2byte("foo");
  volatile int lwsize_max = 1048576;
  volatile int lwsize = lwsize_max;
  volatile int lmpsize = 16384;
  volatile long rwsize = 0L;
  volatile int rmpsize = 0;
  IO io = null;
  Thread thread = null;
  volatile boolean eof_local = false;
  volatile boolean eof_remote = false;
  volatile boolean close = false;
  volatile boolean connected = false;
  volatile boolean open_confirmation = false;
  volatile int exitstatus = -1;
  volatile int reply = 0;
  volatile int connectTimeout = 0;
  private Session session;
  int notifyme = 0;
  
  Channel()
  {
    synchronized (pool)
    {
      id = (index++);
      pool.addElement(this);
    }
  }
  
  synchronized void setRecipient(int foo)
  {
    recipient = foo;
    if (notifyme > 0) {
      notifyAll();
    }
  }
  
  int getRecipient()
  {
    return recipient;
  }
  
  void init()
    throws JSchException
  {}
  
  public void connect()
    throws JSchException
  {
    connect(0);
  }
  
  public void connect(int connectTimeout)
    throws JSchException
  {
    this.connectTimeout = connectTimeout;
    try
    {
      sendChannelOpen();
      start();
    }
    catch (Exception e)
    {
      connected = false;
      disconnect();
      if ((e instanceof JSchException)) {
        throw ((JSchException)e);
      }
      throw new JSchException(e.toString(), e);
    }
  }
  
  public void setXForwarding(boolean foo) {}
  
  public void start()
    throws JSchException
  {}
  
  public boolean isEOF()
  {
    return eof_remote;
  }
  
  void getData(Buffer buf)
  {
    setRecipient(buf.getInt());
    setRemoteWindowSize(buf.getUInt());
    setRemotePacketSize(buf.getInt());
  }
  
  public void setInputStream(InputStream in)
  {
    io.setInputStream(in, false);
  }
  
  public void setInputStream(InputStream in, boolean dontclose)
  {
    io.setInputStream(in, dontclose);
  }
  
  public void setOutputStream(OutputStream out)
  {
    io.setOutputStream(out, false);
  }
  
  public void setOutputStream(OutputStream out, boolean dontclose)
  {
    io.setOutputStream(out, dontclose);
  }
  
  public void setExtOutputStream(OutputStream out)
  {
    io.setExtOutputStream(out, false);
  }
  
  public void setExtOutputStream(OutputStream out, boolean dontclose)
  {
    io.setExtOutputStream(out, dontclose);
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    PipedInputStream in = new MyPipedInputStream(32768);
    
    io.setOutputStream(new PassiveOutputStream(in), false);
    return in;
  }
  
  public InputStream getExtInputStream()
    throws IOException
  {
    PipedInputStream in = new MyPipedInputStream(32768);
    
    io.setExtOutputStream(new PassiveOutputStream(in), false);
    return in;
  }
  
  public OutputStream getOutputStream()
    throws IOException
  {
    final Channel channel = this;
    OutputStream out = new OutputStream()
    {
      private int dataLen = 0;
      private Buffer buffer = null;
      private Packet packet = null;
      private boolean closed = false;
      
      private synchronized void init()
        throws IOException
      {
        buffer = new Buffer(rmpsize);
        packet = new Packet(buffer);
        
        byte[] _buf = buffer.buffer;
        if (_buf.length - 14 - 84 <= 0)
        {
          buffer = null;
          packet = null;
          throw new IOException("failed to initialize the channel.");
        }
      }
      
      byte[] b = new byte[1];
      
      public void write(int w)
        throws IOException
      {
        b[0] = ((byte)w);
        write(b, 0, 1);
      }
      
      public void write(byte[] buf, int s, int l)
        throws IOException
      {
        if (packet == null) {
          init();
        }
        if (closed) {
          throw new IOException("Already closed");
        }
        byte[] _buf = buffer.buffer;
        int _bufl = _buf.length;
        while (l > 0)
        {
          int _l = l;
          if (l > _bufl - (14 + dataLen) - 84) {
            _l = _bufl - (14 + dataLen) - 84;
          }
          if (_l <= 0)
          {
            flush();
          }
          else
          {
            System.arraycopy(buf, s, _buf, 14 + dataLen, _l);
            dataLen += _l;
            s += _l;
            l -= _l;
          }
        }
      }
      
      public void flush()
        throws IOException
      {
        if (closed) {
          throw new IOException("Already closed");
        }
        if (dataLen == 0) {
          return;
        }
        packet.reset();
        buffer.putByte((byte)94);
        buffer.putInt(recipient);
        buffer.putInt(dataLen);
        buffer.skip(dataLen);
        try
        {
          int foo = dataLen;
          dataLen = 0;
          synchronized (channel)
          {
            if (!channelclose) {
              getSession().write(packet, channel, foo);
            }
          }
        }
        catch (Exception e)
        {
          close();
          throw new IOException(e.toString());
        }
      }
      
      public void close()
        throws IOException
      {
        if (packet == null) {
          try
          {
            init();
          }
          catch (IOException e)
          {
            return;
          }
        }
        if (closed) {
          return;
        }
        if (dataLen > 0) {
          flush();
        }
        channel.eof();
        closed = true;
      }
    };
    return out;
  }
  
  class MyPipedInputStream
    extends PipedInputStream
  {
    MyPipedInputStream()
      throws IOException
    {}
    
    MyPipedInputStream(int size)
      throws IOException
    {
      buffer = new byte[size];
    }
    
    MyPipedInputStream(PipedOutputStream out)
      throws IOException
    {
      super();
    }
    
    MyPipedInputStream(PipedOutputStream out, int size)
      throws IOException
    {
      super();
      buffer = new byte[size];
    }
    
    public synchronized void updateReadSide()
      throws IOException
    {
      if (available() != 0) {
        return;
      }
      in = 0;
      out = 0;
      buffer[(in++)] = 0;
      read();
    }
  }
  
  void setLocalWindowSizeMax(int foo)
  {
    lwsize_max = foo;
  }
  
  void setLocalWindowSize(int foo)
  {
    lwsize = foo;
  }
  
  void setLocalPacketSize(int foo)
  {
    lmpsize = foo;
  }
  
  synchronized void setRemoteWindowSize(long foo)
  {
    rwsize = foo;
  }
  
  synchronized void addRemoteWindowSize(int foo)
  {
    rwsize += foo;
    if (notifyme > 0) {
      notifyAll();
    }
  }
  
  void setRemotePacketSize(int foo)
  {
    rmpsize = foo;
  }
  
  public void run() {}
  
  void write(byte[] foo)
    throws IOException
  {
    write(foo, 0, foo.length);
  }
  
  void write(byte[] foo, int s, int l)
    throws IOException
  {
    try
    {
      io.put(foo, s, l);
    }
    catch (NullPointerException e) {}
  }
  
  void write_ext(byte[] foo, int s, int l)
    throws IOException
  {
    try
    {
      io.put_ext(foo, s, l);
    }
    catch (NullPointerException e) {}
  }
  
  void eof_remote()
  {
    eof_remote = true;
    try
    {
      io.out_close();
    }
    catch (NullPointerException e) {}
  }
  
  void eof()
  {
    if (eof_local) {
      return;
    }
    eof_local = true;
    try
    {
      Buffer buf = new Buffer(100);
      Packet packet = new Packet(buf);
      packet.reset();
      buf.putByte((byte)96);
      buf.putInt(getRecipient());
      synchronized (this)
      {
        if (!close) {
          getSession().write(packet);
        }
      }
    }
    catch (Exception e) {}
  }
  
  void close()
  {
    if (close) {
      return;
    }
    close = true;
    eof_local = (eof_remote = 1);
    try
    {
      Buffer buf = new Buffer(100);
      Packet packet = new Packet(buf);
      packet.reset();
      buf.putByte((byte)97);
      buf.putInt(getRecipient());
      synchronized (this)
      {
        getSession().write(packet);
      }
    }
    catch (Exception e) {}
  }
  
  public boolean isClosed()
  {
    return close;
  }
  
  static void disconnect(Session session)
  {
    Channel[] channels = null;
    int count = 0;
    synchronized (pool)
    {
      channels = new Channel[pool.size()];
      for (int i = 0; i < pool.size(); i++) {
        try
        {
          Channel c = (Channel)pool.elementAt(i);
          if (session == session) {
            channels[(count++)] = c;
          }
        }
        catch (Exception e) {}
      }
    }
    for (int i = 0; i < count; i++) {
      channels[i].disconnect();
    }
  }
  
  public void disconnect()
  {
    try
    {
      synchronized (this)
      {
        if (!connected) {
          return;
        }
        connected = false;
      }
      close();
      
      eof_remote = (eof_local = 1);
      
      thread = null;
      try
      {
        if (io != null) {
          io.close();
        }
      }
      catch (Exception e) {}
    }
    finally
    {
      del(this);
    }
  }
  
  public boolean isConnected()
  {
    Session _session = session;
    if (_session != null) {
      return (_session.isConnected()) && (connected);
    }
    return false;
  }
  
  public void sendSignal(String signal)
    throws Exception
  {
    RequestSignal request = new RequestSignal();
    request.setSignal(signal);
    request.request(getSession(), this);
  }
  
  class PassiveInputStream
    extends Channel.MyPipedInputStream
  {
    PipedOutputStream out;
    
    PassiveInputStream(PipedOutputStream out, int size)
      throws IOException
    {
      super(out, size);
      this.out = out;
    }
    
    PassiveInputStream(PipedOutputStream out)
      throws IOException
    {
      super(out);
      this.out = out;
    }
    
    public void close()
      throws IOException
    {
      if (out != null) {
        out.close();
      }
      out = null;
    }
  }
  
  class PassiveOutputStream
    extends PipedOutputStream
  {
    PassiveOutputStream(PipedInputStream in)
      throws IOException
    {
      super();
    }
  }
  
  void setExitStatus(int status)
  {
    exitstatus = status;
  }
  
  public int getExitStatus()
  {
    return exitstatus;
  }
  
  void setSession(Session session)
  {
    this.session = session;
  }
  
  public Session getSession()
    throws JSchException
  {
    Session _session = session;
    if (_session == null) {
      throw new JSchException("session is not available");
    }
    return _session;
  }
  
  public int getId()
  {
    return id;
  }
  
  protected void sendOpenConfirmation()
    throws Exception
  {
    Buffer buf = new Buffer(100);
    Packet packet = new Packet(buf);
    packet.reset();
    buf.putByte((byte)91);
    buf.putInt(getRecipient());
    buf.putInt(id);
    buf.putInt(lwsize);
    buf.putInt(lmpsize);
    getSession().write(packet);
  }
  
  protected void sendOpenFailure(int reasoncode)
  {
    try
    {
      Buffer buf = new Buffer(100);
      Packet packet = new Packet(buf);
      packet.reset();
      buf.putByte((byte)92);
      buf.putInt(getRecipient());
      buf.putInt(reasoncode);
      buf.putString(Util.str2byte("open failed"));
      buf.putString(Util.empty);
      getSession().write(packet);
    }
    catch (Exception e) {}
  }
  
  protected Packet genChannelOpenPacket()
  {
    Buffer buf = new Buffer(100);
    Packet packet = new Packet(buf);
    
    packet.reset();
    buf.putByte((byte)90);
    buf.putString(type);
    buf.putInt(id);
    buf.putInt(lwsize);
    buf.putInt(lmpsize);
    return packet;
  }
  
  protected void sendChannelOpen()
    throws Exception
  {
    Session _session = getSession();
    if (!_session.isConnected()) {
      throw new JSchException("session is down");
    }
    Packet packet = genChannelOpenPacket();
    _session.write(packet);
    
    int retry = 10;
    long start = System.currentTimeMillis();
    long timeout = connectTimeout;
    if (timeout != 0L) {
      retry = 1;
    }
    synchronized (this)
    {
      while ((getRecipient() == -1) && (_session.isConnected()) && (retry > 0)) {
        if ((timeout > 0L) && 
          (System.currentTimeMillis() - start > timeout))
        {
          retry = 0;
        }
        else
        {
          try
          {
            long t = timeout == 0L ? 5000L : timeout;
            notifyme = 1;
            wait(t);
          }
          catch (InterruptedException e) {}finally
          {
            notifyme = 0;
          }
          retry--;
        }
      }
    }
    if (!_session.isConnected()) {
      throw new JSchException("session is down");
    }
    if (getRecipient() == -1) {
      throw new JSchException("channel is not opened.");
    }
    if (!open_confirmation) {
      throw new JSchException("channel is not opened.");
    }
    connected = true;
  }
}

/* Location:
 * Qualified Name:     com.jcraft.jsch.Channel
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jcraft.jsch;

import java.io.IOException;
import java.util.Vector;

class ChannelAgentForwarding
  extends Channel
{
  private static final int LOCAL_WINDOW_SIZE_MAX = 131072;
  private static final int LOCAL_MAXIMUM_PACKET_SIZE = 16384;
  private final byte SSH_AGENTC_REQUEST_RSA_IDENTITIES = 1;
  private final byte SSH_AGENT_RSA_IDENTITIES_ANSWER = 2;
  private final byte SSH_AGENTC_RSA_CHALLENGE = 3;
  private final byte SSH_AGENT_RSA_RESPONSE = 4;
  private final byte SSH_AGENT_FAILURE = 5;
  private final byte SSH_AGENT_SUCCESS = 6;
  private final byte SSH_AGENTC_ADD_RSA_IDENTITY = 7;
  private final byte SSH_AGENTC_REMOVE_RSA_IDENTITY = 8;
  private final byte SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES = 9;
  private final byte SSH2_AGENTC_REQUEST_IDENTITIES = 11;
  private final byte SSH2_AGENT_IDENTITIES_ANSWER = 12;
  private final byte SSH2_AGENTC_SIGN_REQUEST = 13;
  private final byte SSH2_AGENT_SIGN_RESPONSE = 14;
  private final byte SSH2_AGENTC_ADD_IDENTITY = 17;
  private final byte SSH2_AGENTC_REMOVE_IDENTITY = 18;
  private final byte SSH2_AGENTC_REMOVE_ALL_IDENTITIES = 19;
  private final byte SSH2_AGENT_FAILURE = 30;
  boolean init = true;
  private Buffer rbuf = null;
  private Buffer wbuf = null;
  private Packet packet = null;
  private Buffer mbuf = null;
  
  ChannelAgentForwarding()
  {
    setLocalWindowSizeMax(131072);
    setLocalWindowSize(131072);
    setLocalPacketSize(16384);
    
    type = Util.str2byte("auth-agent@openssh.com");
    rbuf = new Buffer();
    rbuf.reset();
    
    mbuf = new Buffer();
    connected = true;
  }
  
  public void run()
  {
    try
    {
      sendOpenConfirmation();
    }
    catch (Exception e)
    {
      close = true;
      disconnect();
    }
  }
  
  void write(byte[] foo, int s, int l)
    throws IOException
  {
    if (packet == null)
    {
      wbuf = new Buffer(rmpsize);
      packet = new Packet(wbuf);
    }
    rbuf.shift();
    if (rbuf.buffer.length < rbuf.index + l)
    {
      byte[] newbuf = new byte[rbuf.s + l];
      System.arraycopy(rbuf.buffer, 0, newbuf, 0, rbuf.buffer.length);
      rbuf.buffer = newbuf;
    }
    rbuf.putByte(foo, s, l);
    
    int mlen = rbuf.getInt();
    if (mlen > rbuf.getLength())
    {
      rbuf.s -= 4;
      return;
    }
    int typ = rbuf.getByte();
    
    Session _session = null;
    try
    {
      _session = getSession();
    }
    catch (JSchException e)
    {
      throw new IOException(e.toString());
    }
    IdentityRepository irepo = jsch.getIdentityRepository();
    UserInfo userinfo = _session.getUserInfo();
    
    mbuf.reset();
    if (typ == 11)
    {
      mbuf.putByte((byte)12);
      Vector identities = irepo.getIdentities();
      synchronized (identities)
      {
        int count = 0;
        for (int i = 0; i < identities.size(); i++)
        {
          Identity identity = (Identity)identities.elementAt(i);
          if (identity.getPublicKeyBlob() != null) {
            count++;
          }
        }
        mbuf.putInt(count);
        for (int i = 0; i < identities.size(); i++)
        {
          Identity identity = (Identity)identities.elementAt(i);
          byte[] pubkeyblob = identity.getPublicKeyBlob();
          if (pubkeyblob != null)
          {
            mbuf.putString(pubkeyblob);
            mbuf.putString(Util.empty);
          }
        }
      }
    }
    else if (typ == 1)
    {
      mbuf.putByte((byte)2);
      mbuf.putInt(0);
    }
    else if (typ == 13)
    {
      byte[] blob = rbuf.getString();
      byte[] data = rbuf.getString();
      int flags = rbuf.getInt();
      
      Vector identities = irepo.getIdentities();
      Identity identity = null;
      synchronized (identities)
      {
        for (int i = 0; i < identities.size(); i++)
        {
          Identity _identity = (Identity)identities.elementAt(i);
          if (_identity.getPublicKeyBlob() != null) {
            if (Util.array_equals(blob, _identity.getPublicKeyBlob())) {
              if (_identity.isEncrypted())
              {
                if (userinfo != null) {
                  while ((_identity.isEncrypted()) && 
                    (userinfo.promptPassphrase("Passphrase for " + _identity.getName())))
                  {
                    String _passphrase = userinfo.getPassphrase();
                    if (_passphrase == null) {
                      break;
                    }
                    byte[] passphrase = Util.str2byte(_passphrase);
                    try
                    {
                      if (_identity.setPassphrase(passphrase)) {
                        break;
                      }
                    }
                    catch (JSchException e)
                    {
                      break;
                    }
                  }
                }
              }
              else if (!_identity.isEncrypted())
              {
                identity = _identity;
                break;
              }
            }
          }
        }
      }
      byte[] signature = null;
      if (identity != null) {
        signature = identity.getSignature(data);
      }
      if (signature == null)
      {
        mbuf.putByte((byte)30);
      }
      else
      {
        mbuf.putByte((byte)14);
        mbuf.putString(signature);
      }
    }
    else if (typ == 18)
    {
      byte[] blob = rbuf.getString();
      irepo.remove(blob);
      mbuf.putByte((byte)6);
    }
    else if (typ == 9)
    {
      mbuf.putByte((byte)6);
    }
    else if (typ == 19)
    {
      irepo.removeAll();
      mbuf.putByte((byte)6);
    }
    else if (typ == 17)
    {
      int fooo = rbuf.getLength();
      byte[] tmp = new byte[fooo];
      rbuf.getByte(tmp);
      boolean result = irepo.add(tmp);
      mbuf.putByte((byte)(result ? 6 : 5));
    }
    else
    {
      rbuf.skip(rbuf.getLength() - 1);
      mbuf.putByte((byte)5);
    }
    byte[] response = new byte[mbuf.getLength()];
    mbuf.getByte(response);
    send(response);
  }
  
  private void send(byte[] message)
  {
    packet.reset();
    wbuf.putByte((byte)94);
    wbuf.putInt(recipient);
    wbuf.putInt(4 + message.length);
    wbuf.putString(message);
    try
    {
      getSession().write(packet, this, 4 + message.length);
    }
    catch (Exception e) {}
  }
  
  void eof_remote()
  {
    super.eof_remote();
    eof();
  }
}

/* Location:
 * Qualified Name:     com.jcraft.jsch.ChannelAgentForwarding
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jcraft.jsch;

import java.io.InputStream;
import java.io.OutputStream;

public class ChannelDirectTCPIP
  extends Channel
{
  private static final int LOCAL_WINDOW_SIZE_MAX = 131072;
  private static final int LOCAL_MAXIMUM_PACKET_SIZE = 16384;
  private static final byte[] _type = Util.str2byte("direct-tcpip");
  String host;
  int port;
  String originator_IP_address = "127.0.0.1";
  int originator_port = 0;
  
  ChannelDirectTCPIP()
  {
    type = _type;
    setLocalWindowSizeMax(131072);
    setLocalWindowSize(131072);
    setLocalPacketSize(16384);
  }
  
  void init()
  {
    io = new IO();
  }
  
  public void connect()
    throws JSchException
  {
    try
    {
      Session _session = getSession();
      if (!_session.isConnected()) {
        throw new JSchException("session is down");
      }
      if (io.in != null)
      {
        thread = new Thread(this);
        thread.setName("DirectTCPIP thread " + _session.getHost());
        if (daemon_thread) {
          thread.setDaemon(daemon_thread);
        }
        thread.start();
      }
    }
    catch (Exception e)
    {
      io.close();
      io = null;
      Channel.del(this);
      if ((e instanceof JSchException)) {
        throw ((JSchException)e);
      }
    }
  }
  
  public void run()
  {
    try
    {
      sendChannelOpen();
      
      Buffer buf = new Buffer(rmpsize);
      Packet packet = new Packet(buf);
      Session _session = getSession();
      int i = 0;
      while ((isConnected()) && (thread != null) && (io != null) && (io.in != null))
      {
        i = io.in.read(buffer, 14, buffer.length - 14 - 84);
        if (i <= 0)
        {
          eof();
          break;
        }
        packet.reset();
        buf.putByte((byte)94);
        buf.putInt(recipient);
        buf.putInt(i);
        buf.skip(i);
        synchronized (this)
        {
          if (close) {
            break;
          }
          _session.write(packet, this, i);
        }
      }
    }
    catch (Exception e) {}
    disconnect();
  }
  
  public void setInputStream(InputStream in)
  {
    io.setInputStream(in);
  }
  
  public void setOutputStream(OutputStream out)
  {
    io.setOutputStream(out);
  }
  
  public void setHost(String host)
  {
    this.host = host;
  }
  
  public void setPort(int port)
  {
    this.port = port;
  }
  
  public void setOrgIPAddress(String foo)
  {
    originator_IP_address = foo;
  }
  
  public void setOrgPort(int foo)
  {
    originator_port = foo;
  }
  
  protected Packet genChannelOpenPacket()
  {
    Buffer buf = new Buffer(150);
    Packet packet = new Packet(buf);
    
    packet.reset();
    buf.putByte((byte)90);
    buf.putString(type);
    buf.putInt(id);
    buf.putInt(lwsize);
    buf.putInt(lmpsize);
    buf.putString(Util.str2byte(host));
    buf.putInt(port);
    buf.putString(Util.str2byte(originator_IP_address));
    buf.putInt(originator_port);
    return packet;
  }
}

/* Location:
 * Qualified Name:     com.jcraft.jsch.ChannelDirectTCPIP
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jcraft.jsch;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class ChannelExec
  extends ChannelSession
{
  byte[] command = new byte[0];
  
  public void start()
    throws JSchException
  {
    Session _session = getSession();
    try
    {
      sendRequests();
      Request request = new RequestExec(command);
      request.request(_session, this);
    }
    catch (Exception e)
    {
      if ((e instanceof JSchException)) {
        throw ((JSchException)e);
      }
      if ((e instanceof Throwable)) {
        throw new JSchException("ChannelExec", e);
      }
      throw new JSchException("ChannelExec");
    }
    if (io.in != null)
    {
      thread = new Thread(this);
      thread.setName("Exec thread " + _session.getHost());
      if (daemon_thread) {
        thread.setDaemon(daemon_thread);
      }
      thread.start();
    }
  }
  
  public void setCommand(String command)
  {
    this.command = Util.str2byte(command);
  }
  
  public void setCommand(byte[] command)
  {
    this.command = command;
  }
  
  void init()
    throws JSchException
  {
    io.setInputStream(getSessionin);
    io.setOutputStream(getSessionout);
  }
  
  public void setErrStream(OutputStream out)
  {
    setExtOutputStream(out);
  }
  
  public void setErrStream(OutputStream out, boolean dontclose)
  {
    setExtOutputStream(out, dontclose);
  }
  
  public InputStream getErrStream()
    throws IOException
  {
    return getExtInputStream();
  }
}

/* Location:
 * Qualified Name:     com.jcraft.jsch.ChannelExec
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jcraft.jsch;

import java.io.InputStream;
import java.io.PipedOutputStream;
import java.net.Socket;
import java.util.Vector;

public class ChannelForwardedTCPIP
  extends Channel
{
  static Vector pool = new Vector();
  private static final int LOCAL_WINDOW_SIZE_MAX = 131072;
  private static final int LOCAL_MAXIMUM_PACKET_SIZE = 16384;
  private static final int TIMEOUT = 10000;
  SocketFactory factory = null;
  private Socket socket = null;
  private ForwardedTCPIPDaemon daemon = null;
  String target;
  int lport;
  int rport;
  
  ChannelForwardedTCPIP()
  {
    setLocalWindowSizeMax(131072);
    setLocalWindowSize(131072);
    setLocalPacketSize(16384);
    io = new IO();
    connected = true;
  }
  
  public void run()
  {
    try
    {
      if (lport == -1)
      {
        Class c = Class.forName(target);
        daemon = ((ForwardedTCPIPDaemon)c.newInstance());
        
        PipedOutputStream out = new PipedOutputStream();
        io.setInputStream(new Channel.PassiveInputStream(this, out, 32768), false);
        
        daemon.setChannel(this, getInputStream(), out);
        Object[] foo = getPort(getSession(), rport);
        daemon.setArg((Object[])foo[3]);
        
        new Thread(daemon).start();
      }
      else
      {
        socket = (factory == null ? Util.createSocket(target, lport, 10000) : factory.createSocket(target, lport));
        
        socket.setTcpNoDelay(true);
        io.setInputStream(socket.getInputStream());
        io.setOutputStream(socket.getOutputStream());
      }
      sendOpenConfirmation();
    }
    catch (Exception e)
    {
      sendOpenFailure(1);
      close = true;
      disconnect();
      return;
    }
    thread = Thread.currentThread();
    Buffer buf = new Buffer(rmpsize);
    Packet packet = new Packet(buf);
    int i = 0;
    try
    {
      Session _session = getSession();
      while ((thread != null) && (io != null) && (io.in != null))
      {
        i = io.in.read(buffer, 14, buffer.length - 14 - 84);
        if (i <= 0)
        {
          eof();
          break;
        }
        packet.reset();
        buf.putByte((byte)94);
        buf.putInt(recipient);
        buf.putInt(i);
        buf.skip(i);
        synchronized (this)
        {
          if (close) {
            break;
          }
          _session.write(packet, this, i);
        }
      }
    }
    catch (Exception e) {}
    disconnect();
  }
  
  void getData(Buffer buf)
  {
    setRecipient(buf.getInt());
    setRemoteWindowSize(buf.getUInt());
    setRemotePacketSize(buf.getInt());
    byte[] addr = buf.getString();
    int port = buf.getInt();
    byte[] orgaddr = buf.getString();
    int orgport = buf.getInt();
    
    Session _session = null;
    try
    {
      _session = getSession();
    }
    catch (JSchException e) {}
    synchronized (pool)
    {
      for (int i = 0; i < pool.size(); i++)
      {
        Object[] foo = (Object[])pool.elementAt(i);
        if ((foo[0] == _session) && 
          (((Integer)foo[1]).intValue() == port))
        {
          rport = port;
          target = ((String)foo[2]);
          if ((foo[3] == null) || ((foo[3] instanceof Object[]))) {
            lport = -1;
          } else {
            lport = ((Integer)foo[3]).intValue();
          }
          if (foo.length < 6) {
            break;
          }
          factory = ((SocketFactory)foo[5]); break;
        }
      }
      if (target != null) {}
    }
  }
  
  static Object[] getPort(Session session, int rport)
  {
    synchronized (pool)
    {
      for (int i = 0; i < pool.size(); i++)
      {
        Object[] bar = (Object[])pool.elementAt(i);
        if ((bar[0] == session) && 
          (((Integer)bar[1]).intValue() == rport)) {
          return bar;
        }
      }
      return null;
    }
  }
  
  static String[] getPortForwarding(Session session)
  {
    Vector foo = new Vector();
    synchronized (pool)
    {
      for (int i = 0; i < pool.size(); i++)
      {
        Object[] bar = (Object[])pool.elementAt(i);
        if (bar[0] == session) {
          if (bar[3] == null) {
            foo.addElement(bar[1] + ":" + bar[2] + ":");
          } else {
            foo.addElement(bar[1] + ":" + bar[2] + ":" + bar[3]);
          }
        }
      }
    }
    String[] bar = new Str
1 2 3 4 5 6 7 8 9 10 11 12

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd