@@ -, +, @@ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of the authors may not be used to endorse or promote products derived from this software without specific prior written permission. static private final String version="JSCH-0.1.18"; // http://ietf.org/internet-drafts/draft-ietf-secsh-assignednumbers-01.txt static final int SSH_MSG_DISCONNECT= 1; static final int SSH_MSG_IGNORE= 2; static final int SSH_MSG_UNIMPLEMENTED= 3; static final int SSH_MSG_DEBUG= 4; static final int SSH_MSG_SERVICE_REQUEST= 5; static final int SSH_MSG_SERVICE_ACCEPT= 6; static final int SSH_MSG_KEXINIT= 20; static final int SSH_MSG_NEWKEYS= 21; static final int SSH_MSG_KEXDH_INIT= 30; static final int SSH_MSG_KEXDH_REPLY= 31; static final int SSH_MSG_USERAUTH_REQUEST= 50; static final int SSH_MSG_USERAUTH_FAILURE= 51; static final int SSH_MSG_USERAUTH_SUCCESS= 52; static final int SSH_MSG_USERAUTH_BANNER= 53; static final int SSH_MSG_USERAUTH_INFO_REQUEST= 60; static final int SSH_MSG_USERAUTH_INFO_RESPONSE= 61; static final int SSH_MSG_USERAUTH_PK_OK= 60; static final int SSH_MSG_GLOBAL_REQUEST= 80; static final int SSH_MSG_REQUEST_SUCCESS= 81; static final int SSH_MSG_REQUEST_FAILURE= 82; static final int SSH_MSG_CHANNEL_OPEN= 90; 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_MSG_CHANNEL_DATA= 94; static final int SSH_MSG_CHANNEL_EXTENDED_DATA= 95; static final int SSH_MSG_CHANNEL_EOF= 96; static final int SSH_MSG_CHANNEL_CLOSE= 97; static final int SSH_MSG_CHANNEL_REQUEST= 98; static final int SSH_MSG_CHANNEL_SUCCESS= 99; static final int SSH_MSG_CHANNEL_FAILURE= 100; private byte[] V_S; // server version private byte[] V_C=("SSH-2.0-"+version).getBytes(); // client version private byte[] I_C; // the payload of the client's SSH_MSG_KEXINIT private byte[] I_S; // the payload of the server's SSH_MSG_KEXINIT private byte[] K_S; // the host key private byte[] session_id; private byte[] IVc2s; private byte[] IVs2c; private byte[] Ec2s; private byte[] Es2c; private byte[] MACc2s; private byte[] MACs2c; private int seqi=0; private int seqo=0; private Cipher s2ccipher; private Cipher c2scipher; private MAC s2cmac; private MAC c2smac; private byte[] mac_buf; private Compression deflater; private Compression inflater; private IO io; private Socket socket; private int timeout=0; private boolean isConnected=false; InputStream in=null; OutputStream out=null; static Random random; Buffer buf; Packet packet; SocketFactory socket_factory=null; private java.util.Hashtable config=null; private Proxy proxy=null; private UserInfo userinfo; String host="127.0.0.1"; int port=22; String username=null; String password=null; JSch jsch; Session(JSch jsch) throws JSchException{ super(); this.jsch=jsch; buf=new Buffer(); packet=new Packet(buf); io=new IO(); } public void connect() throws JSchException{ connect(timeout); } public void connect(int connectTimeout) throws JSchException{ if(random==null){ try{ random=(Random)(c.newInstance()); } catch(Exception e){ System.err.println("connect: random "+e); } } Packet.setRandom(random); try { int i, j; int pad=0; if(proxy==null){ } if(proxy==null){ InputStream in; OutputStream out; String message="socket is not established"; socket=socket_factory.createSocket(host, port); socket.setTcpNoDelay(true); io.setInputStream(in); io.setOutputStream(out); } else{ proxy.connect(this, host, port); io.setInputStream(proxy.getInputStream()); io.setOutputStream(proxy.getOutputStream()); } isConnected=true; i=0; while(iEs2c.length){ buf.reset(); buf.putMPInt(K); buf.putByte(H); buf.putByte(Es2c); hash.update(buf.buffer, 0, buf.index); byte[] foo=hash.digest(); byte[] bar=new byte[Es2c.length+foo.length]; } s2ccipher.init(Cipher.DECRYPT_MODE, Es2c, IVs2c); c=Class.forName(getConfig(guess[KeyExchange.PROPOSAL_MAC_ALGS_STOC])); s2cmac=(MAC)(c.newInstance()); s2cmac.init(MACs2c); mac_buf=new byte[s2cmac.getBlockSize()]; c=Class.forName(getConfig(guess[KeyExchange.PROPOSAL_ENC_ALGS_CTOS])); c2scipher=(Cipher)(c.newInstance()); while(c2scipher.getBlockSize()>Ec2s.length){ buf.reset(); buf.putMPInt(K); buf.putByte(H); buf.putByte(Ec2s); hash.update(buf.buffer, 0, buf.index); byte[] foo=hash.digest(); byte[] bar=new byte[Ec2s.length+foo.length]; } c2scipher.init(Cipher.ENCRYPT_MODE, Ec2s, IVc2s); c=Class.forName(getConfig(guess[KeyExchange.PROPOSAL_MAC_ALGS_CTOS])); c2smac=(MAC)(c.newInstance()); c2smac.init(MACc2s); if(!guess[KeyExchange.PROPOSAL_COMP_ALGS_CTOS].equals("none")){ } else{ } if(!guess[KeyExchange.PROPOSAL_COMP_ALGS_STOC].equals("none")){ } else{ } } catch(Exception e){ System.err.println("updatekeys: "+e); } } public /*synchronized*/ void write(Packet packet, Channel c, int length) throws Exception{ while(true){ if(c.rwsize>=length){ c.rwsize-=length; break; } if(c.close || !isConnected()){ } if(c.rwsize>0){ } try{Thread.sleep(10);} catch(java.lang.InterruptedException e){}; } write(packet); } public synchronized void write(Packet packet) throws Exception{ encode(packet); if(io!=null){ io.put(packet); seqo++; } } Runnable thread; public void run(){ thread=this; byte[] foo; Buffer buf=new Buffer(); Packet packet=new Packet(buf); int i=0; Channel channel; int[] start=new int[1]; int[] length=new int[1]; KeyExchange kex=null; try{ while(thread!=null){ buf=read(buf); switch(msgType){ buf.getInt(); buf.getByte(); buf.getByte(); i=buf.getInt(); try{channel.disconnect();}catch(Exception ee){} if(channel.lwsize