WriteString() public method

public WriteString ( String foo ) : void
foo String
return void
Esempio n. 1
0
        public override byte[] getPublicKeyBlob()
        {
            byte[] foo = base.getPublicKeyBlob();
            if (foo != null)
            {
                return(foo);
            }

            if (P_array == null)
            {
                return(null);
            }

            Buffer buf = new Buffer(sshdss.Length + 4 +
                                    P_array.Length + 4 +
                                    Q_array.Length + 4 +
                                    G_array.Length + 4 +
                                    pub_array.Length + 4);

            buf.WriteString(sshdss);
            buf.WriteString(P_array);
            buf.WriteString(Q_array);
            buf.WriteString(G_array);
            buf.WriteString(pub_array);
            return(buf.buffer);
        }
Esempio n. 2
0
        byte[] getSignature_rsa(Session session, byte[] data)
        {
            try
            {
                Type         t   = Type.GetType(jsch.getConfig("signature.rsa"));
                SignatureRSA rsa = (SignatureRSA)Activator.CreateInstance(t);

                rsa.init();
                rsa.setPrvKey(e_array, n_array, d_array, p_array, q_array, dmp1_array, dmq1_array, iqmp_array);

                /*
                 * byte[] goo=new byte[4];
                 * goo[0]=(byte)(session.getSessionId().Length>>>24);
                 * goo[1]=(byte)(session.getSessionId().Length>>>16);
                 * goo[2]=(byte)(session.getSessionId().Length>>>8);
                 * goo[3]=(byte)(session.getSessionId().Length);
                 * rsa.update(goo);
                 * rsa.update(session.getSessionId());
                 */
                rsa.update(data);
                byte[] sig = rsa.sign();
                Buffer buf = new Buffer("ssh-rsa".Length + 4 +
                                        sig.Length + 4);
                buf.WriteString(System.Text.Encoding.Default.GetBytes("ssh-rsa"));
                buf.WriteString(sig);
                return(buf.buffer);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(null);
        }
Esempio n. 3
0
        public void request(Session session, Channel channel)
        {
            Buffer buf    = new Buffer();
            Packet packet = new Packet(buf);

            bool reply = waitForReply();

            if (reply)
            {
                channel.reply = -1;
            }

            packet.reset();
            buf.WriteByte((byte)Session.SSH_MSG_CHANNEL_REQUEST);
            buf.WriteInt(channel.getRecipient());
            buf.WriteString(Util.getBytes("subsystem"));
            buf.WriteByte((byte)(waitForReply() ? 1 : 0));
            buf.WriteString(Util.getBytes("sftp"));
            session.write(packet);

            if (reply)
            {
                while (channel.reply == -1)
                {
                    try{ System.Threading.Thread.Sleep(10); }
                    catch                    //(Exception ee)
                    {
                    }
                }
                if (channel.reply == 0)
                {
                    throw new JSchException("failed to send sftp request");
                }
            }
        }
Esempio n. 4
0
		public void request(Session session, Channel channel)
		{
			Buffer buf=new Buffer();
			Packet packet=new Packet(buf);

			bool reply=waitForReply();
			if(reply)
			{
				channel.reply=-1;
			}

			packet.reset();
			buf.WriteByte((byte)Session.SSH_MSG_CHANNEL_REQUEST);
			buf.WriteInt(channel.getRecipient());
			buf.WriteString("subsystem");
			buf.WriteByte((byte)(waitForReply() ? 1 : 0));
			buf.WriteString(subsystem);
			session.write(packet);

			if(reply)
			{
				while(channel.reply==-1)
				{
					try { System.Threading.Thread.Sleep(10); }
					catch//(System.Exception ee)
					{
					}
				}
				if(channel.reply==0)
				{
					throw new JSchException("failed to send subsystem request");
				}
			}
		}
Esempio n. 5
0
        byte[] getSignature_dss(Session session, byte[] data)
        {
            /*
             *      byte[] foo;
             *      int i;
             *      System.out.print("P ");
             *      foo=P_array;
             *      for(i=0;  i<foo.Length; i++){
             *      System.out.print(Integer.toHexString(foo[i]&0xff)+":");
             *      }
             *      System.out.println("");
             *      System.out.print("Q ");
             *      foo=Q_array;
             *      for(i=0;  i<foo.Length; i++){
             *      System.out.print(Integer.toHexString(foo[i]&0xff)+":");
             *      }
             *      System.out.println("");
             *      System.out.print("G ");
             *      foo=G_array;
             *      for(i=0;  i<foo.Length; i++){
             *      System.out.print(Integer.toHexString(foo[i]&0xff)+":");
             *      }
             *      System.out.println("");
             */

            try
            {
                Type         t   = Type.GetType(jsch.getConfig("signature.dss"));
                SignatureDSA dsa = (SignatureDSA)(Activator.CreateInstance(t));
                dsa.init();
                dsa.setPrvKey(prv_array, P_array, Q_array, G_array);

                /*
                 * byte[] goo=new byte[4];
                 * goo[0]=(byte)(session.getSessionId().Length>>>24);
                 * goo[1]=(byte)(session.getSessionId().Length>>>16);
                 * goo[2]=(byte)(session.getSessionId().Length>>>8);
                 * goo[3]=(byte)(session.getSessionId().Length);
                 * dsa.update(goo);
                 * dsa.update(session.getSessionId());
                 */
                dsa.update(data);
                byte[] sig = dsa.sign();
                Buffer buf = new Buffer("ssh-dss".Length + 4 +
                                        sig.Length + 4);
                buf.WriteString(System.Text.Encoding.Default.GetBytes("ssh-dss"));
                buf.WriteString(sig);
                return(buf.buffer);
            }
            catch (Exception e)
            {
                Console.WriteLine("e " + e);
            }
            return(null);
        }
Esempio n. 6
0
        public void request(Session session, Channel channel)
        {
            Buffer buf    = new Buffer();
            Packet packet = new Packet(buf);

            packet.reset();
            buf.WriteByte((byte)Session.SSH_MSG_CHANNEL_REQUEST);
            buf.WriteInt(channel.getRecipient());
            buf.WriteString(Util.getBytes("signal"));
            buf.WriteByte((byte)(waitForReply() ? 1 : 0));
            buf.WriteString(Util.getBytes(signal));
            session.write(packet);
        }
Esempio n. 7
0
        public void request(Session session, Channel channel)
        {
            Buffer buf=new Buffer();
            Packet packet=new Packet(buf);

            packet.reset();
            buf.WriteByte((byte) Session.SSH_MSG_CHANNEL_REQUEST);
            buf.WriteInt(channel.getRecipient());
            buf.WriteString( Util.getBytes("signal"));
            buf.WriteByte((byte)(waitForReply() ? 1 : 0));
            buf.WriteString(Util.getBytes(signal));
            session.write(packet);
        }
        internal static void delPort(Session session, int rport)
        {
            lock (pool)
            {
                Object[] foo = null;
                for (int i = 0; i < pool.Count; i++)
                {
                    Object[] bar = (Object[])(pool[i]);
                    if (bar[0] != session)
                    {
                        continue;
                    }
                    if ((int)bar[1] != rport)
                    {
                        continue;
                    }
                    foo = bar;
                    break;
                }
                if (foo == null)
                {
                    return;
                }
                pool.Remove(foo);
            }

            Buffer buf    = new Buffer(100);        // ??
            Packet packet = new Packet(buf);

            try
            {
                // byte SSH_MSG_GLOBAL_REQUEST 80
                // string "cancel-tcpip-forward"
                // boolean want_reply
                // string  address_to_bind (e.g. "127.0.0.1")
                // uint32  port number to bind
                packet.reset();
                buf.WriteByte((byte)80 /*SSH_MSG_GLOBAL_REQUEST*/);
                buf.WriteString(Encoding.UTF8.GetBytes("cancel-tcpip-forward"));
                buf.WriteByte((byte)0);
                buf.WriteString(Encoding.UTF8.GetBytes("0.0.0.0"));
                buf.WriteInt(rport);
                session.write(packet);
            }
            catch (Exception)
            {
                //    throw new JSchException(e.toString());
            }
        }
Esempio n. 9
0
        byte[] getPublicKeyBlob_rsa()
        {
            if (e_array == null)
            {
                return(null);
            }
            Buffer buf = new Buffer("ssh-rsa".Length + 4 +
                                    e_array.Length + 4 +
                                    n_array.Length + 4);

            buf.WriteString(System.Text.Encoding.Default.GetBytes("ssh-rsa"));
            buf.WriteString(e_array);
            buf.WriteString(n_array);
            return(buf.buffer);
        }
Esempio n. 10
0
        public virtual void connect()
        {
            if (!session.isConnected())
            {
                throw new JSchException("session is down");
            }
            try
            {
                Buffer buf    = new Buffer(100);
                Packet packet = new Packet(buf);
                // send
                // byte   SSH_MSG_CHANNEL_OPEN(90)
                // string channel type         //
                // uint32 sender channel       // 0
                // uint32 initial window size  // 0x100000(65536)
                // uint32 maxmum packet size   // 0x4000(16384)
                packet.reset();
                buf.WriteByte((byte)90);
                buf.WriteString(this.type);
                buf.WriteInt(this.id);
                buf.WriteInt(this.lwsize);
                buf.WriteInt(this.lmpsize);
                session.write(packet);

                int retry = 1000;
                while (this.getRecipient() == -1 &&
                       session.isConnected() &&
                       retry > 0)
                {
                    try {
                        System.Threading.Thread.Sleep(50);
                    }
                    catch (Exception)
                    {
                    }
                    retry--;
                }
                if (!session.isConnected())
                {
                    throw new JSchException("session is down");
                }
                if (retry == 0)
                {
                    throw new JSchException("channel is not opened.");
                }
                connected = true;
                start();
            }
            catch (Exception e)
            {
                connected = false;
                if (e is JSchException)
                {
                    throw (JSchException)e;
                }
            }
        }
Esempio n. 11
0
        byte[] getPublicKeyBlob_dss()
        {
            if (P_array == null)
            {
                return(null);
            }
            Buffer buf = new Buffer("ssh-dss".Length + 4 +
                                    P_array.Length + 4 +
                                    Q_array.Length + 4 +
                                    G_array.Length + 4 +
                                    pub_array.Length + 4);

            buf.WriteString(System.Text.Encoding.Default.GetBytes("ssh-dss"));
            buf.WriteString(P_array);
            buf.WriteString(Q_array);
            buf.WriteString(G_array);
            buf.WriteString(pub_array);
            return(buf.buffer);
        }
Esempio n. 12
0
        public void request(Session session, Channel channel)
        {
            Packet packet = session.packet;
            Buffer buf    = session.buf;

            // send
            // byte     SSH_MSG_CHANNEL_REQUEST(98)
            // uint32 recipient channel
            // string request type       // "exec"
            // boolean want reply        // 0
            // string command
            packet.reset();
            buf.WriteByte((byte)Session.SSH_MSG_CHANNEL_REQUEST);
            buf.WriteInt(channel.getRecipient());
            buf.WriteString("exec");
            buf.WriteByte((byte)(waitForReply() ? 1 : 0));
            buf.WriteString(command);
            session.write(packet);
        }
Esempio n. 13
0
 internal void dump(Buffer buf)
 {
     buf.WriteInt(Flags);
     if ((Flags & SSH_FILEXFER_ATTR_SIZE) != 0)
     {
         buf.WriteLong(_Size);
     }
     if ((Flags & SSH_FILEXFER_ATTR_UIDGID) != 0)
     {
         buf.WriteInt(uid); buf.WriteInt(gid);
     }
     if ((Flags & SSH_FILEXFER_ATTR_PERMISSIONS) != 0)
     {
         buf.WriteInt((int)_Permissions);
     }
     if ((Flags & SSH_FILEXFER_ATTR_ACMODTIME) != 0)
     {
         buf.WriteInt(AccessTime);
     }
     if ((Flags & SSH_FILEXFER_ATTR_ACMODTIME) != 0)
     {
         buf.WriteInt(ModificationTime);
     }
     if ((Flags & SSH_FILEXFER_ATTR_EXTENDED) != 0)
     {
         int count = extended.Length / 2;
         if (count > 0)
         {
             for (int i = 0; i < count; i++)
             {
                 buf.WriteString(Util.getBytes(extended[i * 2]));
                 buf.WriteString(Util.getBytes(extended[i * 2 + 1]));
             }
         }
     }
 }
Esempio n. 14
0
        public void request(Session session, Channel channel)
        {
            Buffer buf    = new Buffer();
            Packet packet = new Packet(buf);

            // byte      SSH_MSG_CHANNEL_REQUEST(98)
            // uint32 recipient channel
            // string request type        // "x11-req"
            // boolean want reply         // 0
            // boolean   single connection
            // string    x11 authentication protocol // "MIT-MAGIC-COOKIE-1".
            // string    x11 authentication cookie
            // uint32    x11 screen number
            packet.reset();
            buf.WriteByte((byte)Session.SSH_MSG_CHANNEL_REQUEST);
            buf.WriteInt(channel.getRecipient());
            buf.WriteString(Util.getBytes("x11-req"));
            buf.WriteByte((byte)(waitForReply() ? 1 : 0));
            buf.WriteByte((byte)0);
            buf.WriteString(Util.getBytes("MIT-MAGIC-COOKIE-1"));
            buf.WriteString(ChannelX11.getFakedCookie(session));
            buf.WriteInt(0);
            session.write(packet);
        }
Esempio n. 15
0
		public void request(Session session, Channel channel) 
		{
			Buffer buf=new Buffer();
			Packet packet=new Packet(buf);

			// byte      SSH_MSG_CHANNEL_REQUEST(98)
			// uint32 recipient channel
			// string request type        // "x11-req"
			// boolean want reply         // 0
			// boolean   single connection
			// string    x11 authentication protocol // "MIT-MAGIC-COOKIE-1".
			// string    x11 authentication cookie
			// uint32    x11 screen number
			packet.reset();
			buf.WriteByte((byte) Session.SSH_MSG_CHANNEL_REQUEST);
			buf.WriteInt(channel.getRecipient());
			buf.WriteString(Util.getBytes("x11-req"));
			buf.WriteByte((byte)(waitForReply() ? 1 : 0));
			buf.WriteByte((byte)0);
			buf.WriteString(Util.getBytes("MIT-MAGIC-COOKIE-1"));
			buf.WriteString(ChannelX11.getFakedCookie(session));
			buf.WriteInt(0);
			session.write(packet);
		}
Esempio n. 16
0
        public void request(Session session, Channel channel)
        {
            Buffer buf    = new Buffer();
            Packet packet = new Packet(buf);

            // send
            // byte     SSH_MSG_CHANNEL_REQUEST(98)
            // uint32 recipient channel
            // string request type       // "shell"
            // boolean want reply        // 0
            packet.reset();
            buf.WriteByte((byte)Session.SSH_MSG_CHANNEL_REQUEST);
            buf.WriteInt(channel.getRecipient());
            buf.WriteString(Util.getBytes("shell"));
            buf.WriteByte((byte)(waitForReply() ? 1 : 0));
            session.write(packet);
        }
Esempio n. 17
0
		public void request(Session session, Channel channel) 
		{
			Buffer buf=new Buffer();
			Packet packet=new Packet(buf);

			// send
			// byte     SSH_MSG_CHANNEL_REQUEST(98)
			// uint32 recipient channel
			// string request type       // "shell"
			// boolean want reply        // 0
			packet.reset();
			buf.WriteByte((byte) Session.SSH_MSG_CHANNEL_REQUEST);
			buf.WriteInt(channel.getRecipient());
			buf.WriteString(Util.getBytes("shell"));
			buf.WriteByte((byte)(waitForReply() ? 1 : 0));
			session.write(packet);
		}
Esempio n. 18
0
        public virtual bool start(Session session)
        {
            Packet packet = session.packet;
            Buffer buf    = session.buf;

            // send
            // byte      SSH_MSG_SERVICE_REQUEST(5)
            // string    service name "ssh-userauth"
            packet.reset();
            buf.WriteByte((byte)Session.SSH_MSG_SERVICE_REQUEST);
            buf.WriteString(Util.getBytes("ssh-userauth"));
            session.write(packet);

            // receive
            // byte      SSH_MSG_SERVICE_ACCEPT(6)
            // string    service name
            buf = session.read(buf);
            //System.out.println("read: 6 ? "+buf.buffer[5]);
            return(buf.buffer[5] == 6);
        }
        public void request(Session session, Channel channel)
        {
            Buffer buf    = new Buffer();
            Packet packet = new Packet(buf);

            //byte      SSH_MSG_CHANNEL_REQUEST
            //uint32    recipient_channel
            //string    "window-change"
            //boolean   FALSE
            //uint32    terminal width, columns
            //uint32    terminal height, rows
            //uint32    terminal width, pixels
            //uint32    terminal height, pixels
            packet.reset();
            buf.WriteByte((byte)Session.SSH_MSG_CHANNEL_REQUEST);
            buf.WriteInt(channel.getRecipient());
            buf.WriteString(Util.getBytes("window-change"));
            buf.WriteByte((byte)(waitForReply() ? 1 : 0));
            buf.WriteInt(width_columns);
            buf.WriteInt(height_rows);
            buf.WriteInt(width_pixels);
            buf.WriteInt(height_pixels);
            session.write(packet);
        }
Esempio n. 20
0
        public void request(Session session, Channel channel)
        {
            Buffer buf=new Buffer();
            Packet packet=new Packet(buf);

            //byte      SSH_MSG_CHANNEL_REQUEST
            //uint32    recipient_channel
            //string    "window-change"
            //boolean   FALSE
            //uint32    terminal width, columns
            //uint32    terminal height, rows
            //uint32    terminal width, pixels
            //uint32    terminal height, pixels
            packet.reset();
            buf.WriteByte((byte) Session.SSH_MSG_CHANNEL_REQUEST);
            buf.WriteInt(channel.getRecipient());
            buf.WriteString(Util.getBytes("window-change"));
            buf.WriteByte((byte)(waitForReply() ? 1 : 0));
            buf.WriteInt(width_columns);
            buf.WriteInt(height_rows);
            buf.WriteInt(width_pixels);
            buf.WriteInt(height_pixels);
            session.write(packet);
        }
Esempio n. 21
0
		public virtual void connect()
		{
			if(!session.isConnected())
			{
				throw new JSchException("session is down");
			}
			try
			{
				Buffer buf=new Buffer(100);
				Packet packet=new Packet(buf);
				// send
				// byte   SSH_MSG_CHANNEL_OPEN(90)
				// string channel type         //
				// uint32 sender channel       // 0
				// uint32 initial window size  // 0x100000(65536)
				// uint32 maxmum packet size   // 0x4000(16384)
				packet.reset();
				buf.WriteByte((byte)90);
				buf.WriteString(this.type);
				buf.WriteInt(this.id);
				buf.WriteInt(this.lwsize);
				buf.WriteInt(this.lmpsize);
				session.write(packet);

				int retry=1000;
				while(this.getRecipient()==-1 &&
					session.isConnected() &&
					retry>0)
				{

					try {
						System.Threading.Thread.Sleep(50);
					}
					catch(Exception)
					{
					}
					retry--;
				}
				if(!session.isConnected())
				{
					throw new JSchException("session is down");
				}
				if(retry==0)
				{
					throw new JSchException("channel is not opened.");
				}
				connected=true;
				start();
			}
			catch(Exception e)
			{
				connected=false;
				if(e is JSchException) throw (JSchException)e;
			}
		}
Esempio n. 22
0
        private void setPortForwarding(int rport)
        {
            lock(grr)
            {
                Buffer buf=new Buffer(100); // ??
                Packet packet=new Packet(buf);

                try
                {
                    // byte SSH_MSG_GLOBAL_REQUEST 80
                    // String "tcpip-forward"
                    // bool want_reply
                    // String  address_to_bind
                    // uint32  port number to bind
                    packet.reset();
                    buf.WriteByte((byte) SSH_MSG_GLOBAL_REQUEST);
                    buf.WriteString( "tcpip-forward" );
                    //      buf.putByte((byte)0);
                    buf.WriteByte((byte)1);
                    buf.WriteString("0.0.0.0");
                    buf.WriteInt(rport);
                    write(packet);
                }
                catch(Exception e)
                {
                    throw new JSchException(e.ToString());
                }

                grr.setThread(System.Threading.Thread.CurrentThread);
                try { System.Threading.Thread.Sleep(10000); }
                catch(Exception)
                {
                }
                int reply=grr.getReply();
                grr.setThread(null);
                if(reply==0)
                {
                    throw new JSchException("remote port forwarding failed for listen port "+rport);
                }
            }
        }
Esempio n. 23
0
        public void connect(int connectTimeout)
        {
            if(_isConnected)
            {
                throw new JSchException("session is already connected");
            }
            io=new IO();
            if(random==null)
            {
                try
                {
                    random = (Random)System.Activator.CreateInstance(System.Type.GetType(getConfig("random")));
                }
                catch(Exception e)
                {
                    System.Console.Error.WriteLine("connect: random "+e);
                }
            }
            Packet.setRandom(random);

            try
            {
                int i, j;
                //int pad=0;

                if(proxy==null)
                {
                    proxy=jsch.getProxy(host);
                    if(proxy!=null)
                    {
                        lock(proxy)
                        {
                            proxy.close();
                        }
                    }
                }

                if(proxy==null)
                {
                    Stream In;
                    Stream Out;
                    if(socket_factory==null)
                    {
                        socket=Util.createSocket(host, port, connectTimeout);
                        In=new NetworkStream(socket);
                        Out=new NetworkStream(socket);
                    }
                    else
                    {
                        socket=socket_factory.createSocket(host, port);
                        In=socket_factory.getInputStream(socket);
                        Out=socket_factory.getOutputStream(socket);
                    }
                    //if(timeout>0){ socket.setSoTimeout(timeout); }
                    socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true);
                    io.setInputStream(In);
                    io.setOutputStream(Out);
                }
                else
                {
                    lock (proxy)
                    {
                        proxy.connect(socket_factory, host, port, connectTimeout);
                        io.setInputStream(proxy.getInputStream());
                        io.setOutputStream(proxy.getOutputStream());
                        socket=proxy.getSocket();
                    }
                }

                if (connectTimeout > 0 && socket != null)
                {
                    socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, connectTimeout);
                    socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, connectTimeout);
                }

                _isConnected=true;

                while(true)
                {

                    i=0;
                    j=0;
                    while(i<buf.buffer.Length)
                    {
                        j=io.getByte();
                        if(j<0)break;
                        buf.buffer[i]=(byte)j; i++;
                        if(j==10)break;
                    }
                    if(j<0)
                    {
                        throw new JSchException("connection is closed by foreign host");
                    }

                    if(buf.buffer[i-1]==10)
                    {    // 0x0a
                        i--;
                        if(buf.buffer[i-1]==13)
                        {  // 0x0d
                            i--;
                        }
                    }

                    if(i>4 && (i!=buf.buffer.Length) &&
                        (buf.buffer[0]!='S'||buf.buffer[1]!='S'||
                        buf.buffer[2]!='H'||buf.buffer[3]!='-'))
                    {
                        //System.err.println(Encoding.UTF8.GetString(buf.buffer, 0, i);
                        continue;
                    }

                    if(i==buf.buffer.Length ||
                        i<7 ||                                      // SSH-1.99 or SSH-2.0
                        (buf.buffer[4]=='1' && buf.buffer[6]!='9')  // SSH-1.5
                        )
                    {
                        throw new JSchException("invalid server's version String");
                    }
                    break;
                }

                V_S = new byte[i]; System.Array.Copy(buf.buffer, 0, V_S, 0, i);
                //System.Console.WriteLine("V_S: ("+i+") ["+Encoding.UTF8.GetString(V_S)+"]");

                //io.put(V_C, 0, V_C.Length); io.put("\n".getBytes(), 0, 1);
            {
                // Some Cisco devices will miss to read '\n' if it is sent separately.
                byte[] foo=new byte[V_C.Length+1];
                System.Array.Copy(V_C, 0, foo, 0, V_C.Length);
                foo[foo.Length-1]=(byte)'\n';
                io.put(foo, 0, foo.Length);
            }

                buf=read(buf);
                //System.Console.WriteLine("read: 20 ? "+buf.buffer[5]);
                if(buf.buffer[5]!=SSH_MSG_KEXINIT)
                {
                    throw new JSchException("invalid protocol: "+buf.buffer[5]);
                }
                KeyExchange kex=receive_kexinit(buf);

                while(true)
                {
                    buf=read(buf);
                    if(kex.getState()==buf.buffer[5])
                    {
                        bool result=kex.next(buf);
                        if(!result)
                        {
                            //System.Console.WriteLine("verify: "+result);
                            in_kex=false;
                            throw new JSchException("verify: "+result);
                        }
                    }
                    else
                    {
                        in_kex=false;
                        throw new JSchException("invalid protocol(kex): "+buf.buffer[5]);
                    }
                    if(kex.getState()==KeyExchange.STATE_END)
                    {
                        break;
                    }
                }

                try{ checkHost(host, kex); }
                catch(JSchException ee)
                {
                    in_kex=false;
                    throw ee;
                }

                send_newkeys();

                // receive SSH_MSG_NEWKEYS(21)
                buf=read(buf);
                //System.Console.WriteLine("read: 21 ? "+buf.buffer[5]);
                if(buf.buffer[5]==SSH_MSG_NEWKEYS)
                {
                    receive_newkeys(buf, kex);
                }
                else
                {
                    in_kex=false;
                    throw new JSchException("invalid protocol(newkyes): "+buf.buffer[5]);
                }

                bool auth=false;
                bool auth_cancel=false;

                UserAuthNone usn=new UserAuthNone(userinfo);
                auth=usn.start(this);

                String methods=null;
                if(!auth)
                {
                    methods=usn.getMethods();
                    if(methods!=null)
                    {
                        methods=methods.ToLower();
                    }
                    else
                    {
                        // methods: publickey,password,keyboard-interactive
                        methods="publickey,password,keyboard-interactive";
                    }
                }

            //loop:
                while(true)
                {

                    //System.Console.WriteLine("methods: "+methods);

                    while (!auth && methods != null && methods.Length > 0)
                    {

                        //System.Console.WriteLine("  methods: "+methods);

                        UserAuth us=null;
                        if (methods.StartsWith("publickey"))
                        {
                            //System.Console.WriteLine("   jsch.identities.size()="+jsch.identities.size());
                            lock(jsch.identities)
                            {
                                if(jsch.identities.Count>0)
                                {
                                    us=new UserAuthPublicKey(userinfo);
                                }
                            }
                        }
                        else if (methods.StartsWith("keyboard-interactive"))
                        {
                            if(userinfo is UIKeyboardInteractive)
                            {
                                us=new UserAuthKeyboardInteractive(userinfo);
                            }
                        }
                        else if (methods.StartsWith("password"))
                        {
                            us=new UserAuthPassword(userinfo);
                        }
                        if(us!=null)
                        {
                            try
                            {
                                auth=us.start(this);
                                auth_cancel=false;
                            }
                            catch(JSchAuthCancelException)
                            {
                                //System.Console.WriteLine(ee);
                                auth_cancel=true;
                            }
                            catch(JSchPartialAuthException ee)
                            {
                                methods=ee.getMethods();
                                //System.Console.WriteLine("PartialAuth: "+methods);
                                auth_cancel=false;
                                continue;//loop;
                            }
                            catch(Exception ee)
                            {
                                System.Console.WriteLine("ee: "+ee); // SSH_MSG_DISCONNECT: 2 Too many authentication failures
                            }
                        }
                        if(!auth)
                        {
                            int comma=methods.IndexOf(",");
                            if(comma==-1) break;
                            methods=methods.Substring(comma+1);
                        }
                    }
                    break;
                }

                if (connectTimeout > 0 || timeout > 0)
                {
                    socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, timeout);
                    socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, timeout);
                }

                if(auth)
                {
                    isAuthed=true;
                    connectThread = new System.Threading.Thread(this.run);
                    connectThread.Name = "Connect thread " + host + " session";
                    connectThread.Start();
                    return;
                }
                if(auth_cancel)
                    throw new JSchException("Auth cancel");
                throw new JSchException("Auth fail");
            }
            catch(Exception e)
            {
                in_kex=false;
                if(_isConnected)
                {
                    try
                    {
                        packet.reset();
                        buf.WriteByte((byte)SSH_MSG_DISCONNECT);
                        buf.WriteInt(3);
                        buf.WriteString(e.ToString());
                        buf.WriteString("en");
                        write(packet);
                        disconnect();
                    }
                    catch(Exception)
                    {
                    }
                }
                _isConnected=false;
                //e.printStackTrace();
                //if(e is Exception) throw (Exception)e;
                if(e is JSchException) throw (JSchException)e;
                throw new JSchException("Session.connect: "+e);
            }
        }
Esempio n. 24
0
 public void sendKeepAliveMsg()
 {
     Buffer buf=new Buffer();
     Packet packet=new Packet(buf);
     packet.reset();
     buf.WriteByte((byte)SSH_MSG_GLOBAL_REQUEST);
     buf.WriteString(keepalivemsg);
     buf.WriteByte((byte)1);
     write(packet);
 }
Esempio n. 25
0
        public override byte[] getPublicKeyBlob()
        {
            byte[] foo=base.getPublicKeyBlob();
            if(foo!=null) return foo;

            if(pub_array==null) return null;

            Buffer buf=new Buffer(sshrsa.Length+4+
                pub_array.Length+4+
                n_array.Length+4);
            buf.WriteString(sshrsa);
            buf.WriteString(pub_array);
            buf.WriteString(n_array);
            return buf.buffer;
        }
Esempio n. 26
0
		byte[] getSignature_dss(Session session, byte[] data)
		{
			/*
				byte[] foo;
				int i;
				System.out.print("P ");
				foo=P_array;
				for(i=0;  i<foo.Length; i++){
				System.out.print(Integer.toHexString(foo[i]&0xff)+":");
				}
				System.out.println("");
				System.out.print("Q ");
				foo=Q_array;
				for(i=0;  i<foo.Length; i++){
				System.out.print(Integer.toHexString(foo[i]&0xff)+":");
				}
				System.out.println("");
				System.out.print("G ");
				foo=G_array;
				for(i=0;  i<foo.Length; i++){
				System.out.print(Integer.toHexString(foo[i]&0xff)+":");
				}
				System.out.println("");
			*/

			try
			{      
				Type t=Type.GetType(jsch.getConfig("signature.dss"));
				SignatureDSA dsa=(SignatureDSA)(Activator.CreateInstance(t));
				dsa.init();
				dsa.setPrvKey(prv_array, P_array, Q_array, G_array);

				/*
				byte[] goo=new byte[4];
				goo[0]=(byte)(session.getSessionId().Length>>>24);
				goo[1]=(byte)(session.getSessionId().Length>>>16);
				goo[2]=(byte)(session.getSessionId().Length>>>8);
				goo[3]=(byte)(session.getSessionId().Length);
				dsa.update(goo);
				dsa.update(session.getSessionId());
				*/
				dsa.update(data);
				byte[] sig = dsa.sign();
				Buffer buf=new Buffer("ssh-dss".Length+4+
					sig.Length+4);
				buf.WriteString( System.Text.Encoding.Default.GetBytes( "ssh-dss" ) );
				buf.WriteString(sig);
				return buf.buffer;
			}
			catch(Exception e)
			{
				Console.WriteLine("e "+e);
			}
			return null;
		}
Esempio n. 27
0
		byte[] getPublicKeyBlob_dss()
		{
			if(P_array==null) return null;
			Buffer buf=new Buffer("ssh-dss".Length+4+
				P_array.Length+4+ 
				Q_array.Length+4+ 
				G_array.Length+4+ 
				pub_array.Length+4);
			buf.WriteString(System.Text.Encoding.Default.GetBytes("ssh-dss"));
			buf.WriteString(P_array);
			buf.WriteString(Q_array);
			buf.WriteString(G_array);
			buf.WriteString(pub_array);
			return buf.buffer;
		}
Esempio n. 28
0
        public override bool start(Session session)
        {
//    super.start(session);
//System.out.println("UserAuthPassword: start");
            Packet packet   = session.packet;
            Buffer buf      = session.buf;
            String username = session.username;
            String password = session.password;
            String dest     = username + "@" + session.host;

            if (session.port != 22)
            {
                dest += (":" + session.port);
            }

            while (true)
            {
                if (password == null)
                {
                    if (userinfo == null)
                    {
                        //throw new JSchException("USERAUTH fail");
                        return(false);
                    }
                    if (!userinfo.promptPassword("Password for " + dest))
                    {
                        throw new JSchAuthCancelException("password");
                        //break;
                    }
                    password = userinfo.getPassword();
                    if (password == null)
                    {
                        throw new JSchAuthCancelException("password");
                        //break;
                    }
                }

                byte[] _username = null;
                try{ _username = Util.getBytesUTF8(username); }
                catch {//(java.io.UnsupportedEncodingException e){
                    _username = Util.getBytes(username);
                }

                byte[] _password = null;
                try{ _password = Util.getBytesUTF8(password); }
                catch {//(java.io.UnsupportedEncodingException e){
                    _password = Util.getBytes(password);
                }

                // send
                // byte      SSH_MSG_USERAUTH_REQUEST(50)
                // string    user name
                // string    service name ("ssh-connection")
                // string    "password"
                // boolen    FALSE
                // string    plaintext password (ISO-10646 UTF-8)
                packet.reset();
                buf.WriteByte((byte)Session.SSH_MSG_USERAUTH_REQUEST);
                buf.WriteString(_username);
                buf.WriteString(Util.getBytes("ssh-connection"));
                buf.WriteString(Util.getBytes("password"));
                buf.WriteByte((byte)0);
                buf.WriteString(_password);
                session.write(packet);

loop:
                while (true)
                {
                    // receive
                    // byte      SSH_MSG_USERAUTH_SUCCESS(52)
                    // string    service name
                    buf = session.read(buf);
                    //System.out.println("read: 52 ? "+    buf.buffer[5]);
                    if (buf.buffer[5] == Session.SSH_MSG_USERAUTH_SUCCESS)
                    {
                        return(true);
                    }
                    if (buf.buffer[5] == Session.SSH_MSG_USERAUTH_BANNER)
                    {
                        buf.ReadInt(); buf.ReadByte(); buf.ReadByte();
                        byte[] _message = buf.ReadString();
                        byte[] lang     = buf.ReadString();
                        String message  = null;
                        try{ message = Util.getStringUTF8(_message); }
                        catch {//(java.io.UnsupportedEncodingException e){
                            message = Util.getString(_message);
                        }
                        if (userinfo != null)
                        {
                            userinfo.showMessage(message);
                        }
                        goto loop;
                    }
                    if (buf.buffer[5] == Session.SSH_MSG_USERAUTH_FAILURE)
                    {
                        buf.ReadInt(); buf.ReadByte(); buf.ReadByte();
                        byte[] foo             = buf.ReadString();
                        int    partial_success = buf.ReadByte();
                        //System.out.println(Encoding.UTF8.GetString(foo)+
                        //		 " partial_success:"+(partial_success!=0));
                        if (partial_success != 0)
                        {
                            throw new JSchPartialAuthException(Util.getString(foo));
                        }
                        break;
                    }
                    else
                    {
//        System.out.println("USERAUTH fail ("+buf.buffer[5]+")");
//	  throw new JSchException("USERAUTH fail ("+buf.buffer[5]+")");
                        return(false);
                    }
                }
                password = null;
            }
            //throw new JSchException("USERAUTH fail");
            //return false;
        }
Esempio n. 29
0
		internal static void delPort(Session session, int rport)
		{
			lock(pool)
			{
				Object[] foo=null;
				for(int i=0; i<pool.Count; i++)
				{
					Object[] bar=(Object[])(pool[i]);
					if (bar[0] != session) continue;
					if ((int)bar[1] != rport) continue;
					foo=bar;
					break;
				}
				if(foo==null)return;
				pool.Remove(foo);	
			}

			Buffer buf=new Buffer(100); // ??
			Packet packet=new Packet(buf);

			try
			{
				// byte SSH_MSG_GLOBAL_REQUEST 80
				// string "cancel-tcpip-forward"
				// boolean want_reply
				// string  address_to_bind (e.g. "127.0.0.1")
				// uint32  port number to bind
				packet.reset();
				buf.WriteByte((byte) 80/*SSH_MSG_GLOBAL_REQUEST*/);
				buf.WriteString(Encoding.UTF8.GetBytes("cancel-tcpip-forward"));
				buf.WriteByte((byte)0);
				buf.WriteString(Encoding.UTF8.GetBytes("0.0.0.0"));
				buf.WriteInt(rport);
				session.write(packet);
			}
			catch(Exception)
			{
				//    throw new JSchException(e.toString());
			}
		}
Esempio n. 30
0
        public override bool next(Buffer _buf)
        {
            int  i, j;
            bool result = false;

            switch (state)
            {
            case SSH_MSG_KEXDH_REPLY:
                // The server responds with:
                // byte      SSH_MSG_KEXDH_REPLY(31)
                // string    server public host key and certificates (K_S)
                // mpint     f
                // string    signature of H
                j = _buf.ReadInt();
                j = _buf.ReadByte();
                j = _buf.ReadByte();
                if (j != 31)
                {
                    Console.WriteLine("type: must be 31 " + j);
                    result = false;
                    break;
                }

                K_S = _buf.ReadString();
                // K_S is server_key_blob, which includes ....
                // string ssh-dss
                // impint p of dsa
                // impint q of dsa
                // impint g of dsa
                // impint pub_key of dsa
                //System.out.print("K_S: "); //dump(K_S, 0, K_S.length);
                byte[] f        = _buf.ReadMPInt();
                byte[] sig_of_H = _buf.ReadString();

                /*
                 * for(int ii=0; ii<sig_of_H.length;ii++){
                 * System.out.print(Integer.toHexString(sig_of_H[ii]&0xff));
                 * System.out.print(": ");
                 * }
                 * Console.WriteLine("");
                 */

                dh.setF(f);
                K = dh.getK();

                //The hash H is computed as the HASH hash of the concatenation of the
                //following:
                // string    V_C, the client's version string (CR and NL excluded)
                // string    V_S, the server's version string (CR and NL excluded)
                // string    I_C, the payload of the client's SSH_MSG_KEXINIT
                // string    I_S, the payload of the server's SSH_MSG_KEXINIT
                // string    K_S, the host key
                // mpint     e, exchange value sent by the client
                // mpint     f, exchange value sent by the server
                // mpint     K, the shared secret
                // This value is called the exchange hash, and it is used to authenti-
                // cate the key exchange.
                buf.Reset();
                buf.WriteString(V_C); buf.WriteString(V_S);
                buf.WriteString(I_C); buf.WriteString(I_S);
                buf.WriteString(K_S);
                buf.WriteMPInt(e); buf.WriteMPInt(f);
                buf.WriteMPInt(K);
                byte[] foo = new byte[buf.Length];
                buf.ReadByte(foo);
                sha.update(foo, 0, foo.Length);
                H = sha.digest();
                //System.out.print("H -> "); //dump(H, 0, H.length);

                i = 0;
                j = 0;
                j = (int)((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000) |
                    ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
                String alg = Util.getString(K_S, i, j);
                i += j;

                result = false;

                if (alg.Equals("ssh-rsa"))
                {
                    byte[] tmp;
                    byte[] ee;
                    byte[] n;

                    type = RSA;

                    j = (int)((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000) |
                        ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
                    tmp = new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i += j;
                    ee  = tmp;
                    j   = (int)((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000) |
                          ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
                    tmp = new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i += j;
                    n   = tmp;

                    //	SignatureRSA sig=new SignatureRSA();
                    //	sig.init();

                    SignatureRSA sig = null;
                    try
                    {
                        Type t = Type.GetType(session.getConfig("signature.rsa"));
                        sig = (SignatureRSA)(Activator.CreateInstance(t));
                        sig.init();
                    }
                    catch (Exception eee)
                    {
                        Console.WriteLine(eee);
                    }

                    sig.setPubKey(ee, n);
                    sig.update(H);
                    result = sig.verify(sig_of_H);
                    //MainClass.dump(ee, n, sig_of_H, H);
                }
                else if (alg.Equals("ssh-dss"))
                {
                    byte[] q = null;
                    byte[] tmp;
                    byte[] p;
                    byte[] g;

                    type = DSS;

                    j = (int)((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000) |
                        ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
                    tmp = new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i += j;
                    p   = tmp;
                    j   = (int)((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000) |
                          ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
                    tmp = new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i += j;
                    q   = tmp;
                    j   = (int)((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000) |
                          ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
                    tmp = new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i += j;
                    g   = tmp;
                    j   = (int)((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000) |
                          ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
                    tmp = new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i += j;
                    f   = tmp;
                    //	SignatureDSA sig=new SignatureDSA();
                    //	sig.init();
                    SignatureDSA sig = null;
                    try
                    {
                        Type t = Type.GetType(session.getConfig("signature.dss"));
                        sig = (SignatureDSA)(Activator.CreateInstance(t));
                        sig.init();
                    }
                    catch (Exception ee)
                    {
                        Console.WriteLine(ee);
                    }
                    sig.setPubKey(f, p, q, g);
                    sig.update(H);
                    result = sig.verify(sig_of_H);
                }
                else
                {
                    Console.WriteLine("unknow alg");
                }
                state = STATE_END;
                break;
            }
            return(result);
        }
Esempio n. 31
0
        public override void connect()
        {
            try
            {
                if(!session.isConnected())
                {
                    throw new JSchException("session is down");
                }
                Buffer buf=new Buffer(150);
                Packet packet=new Packet(buf);
                // send
                // byte   SSH_MSG_CHANNEL_OPEN(90)
                // string channel type         //
                // uint32 sender channel       // 0
                // uint32 initial window size  // 0x100000(65536)
                // uint32 maxmum packet size   // 0x4000(16384)

                packet.reset();
                buf.WriteByte((byte)90);
                buf.WriteString(Util.getBytes("direct-tcpip"));
                buf.WriteInt(id);
                buf.WriteInt(lwsize);
                buf.WriteInt(lmpsize);
                buf.WriteString(Util.getBytes(host));
                buf.WriteInt(port);
                buf.WriteString(Util.getBytes(originator_IP_address));
                buf.WriteInt(originator_port);
                session.write(packet);

                int retry=1000;
                try
                {
                    while(this.getRecipient()==-1 &&
                        session.isConnected() &&
                        retry>0 &&
                        !_eof_remote)
                    {
                        //Thread.sleep(500);
                        System.Threading.Thread.Sleep(50);
                        retry--;
                    }
                }
                catch
                {
                }

                if(!session.isConnected())
                {
                    throw new JSchException("session is down");
                }
                if(retry==0 || this._eof_remote)
                {
                    throw new JSchException("channel is not opened.");
                }
                /*
                if(this.eof_remote){      // failed to open
                  disconnect();
                  return;
                }
                */

                connected=true;

                thread = new System.Threading.Thread(this.run);
                thread.Start();
            }
            catch(Exception e)
            {
                io.close();
                io=null;
                Channel.del(this);
                if (e is JSchException)
                {
                    throw (JSchException) e;
                }
            }
        }
Esempio n. 32
0
		public override byte[] getPublicKeyBlob()
		{
			byte[] foo=base.getPublicKeyBlob();
			if(foo!=null) return foo;

			if(P_array==null) return null;

			Buffer buf=new Buffer(sshdss.Length+4+
				P_array.Length+4+ 
				Q_array.Length+4+ 
				G_array.Length+4+ 
				pub_array.Length+4);
			buf.WriteString(sshdss);
			buf.WriteString(P_array);
			buf.WriteString(Q_array);
			buf.WriteString(G_array);
			buf.WriteString(pub_array);
			return buf.buffer;
		}
Esempio n. 33
0
		byte[] getPublicKeyBlob_rsa()
		{
			if(e_array==null) return null;
			Buffer buf=new Buffer("ssh-rsa".Length+4+
				e_array.Length+4+ 
				n_array.Length+4);
			buf.WriteString( System.Text.Encoding.Default.GetBytes( "ssh-rsa" ) );
			buf.WriteString(e_array);
			buf.WriteString(n_array);
			return buf.buffer;
		}
        public override bool start(Session session)
        {
//System.out.println("UserAuthKeyboardInteractive: start");
            Packet packet   = session.packet;
            Buffer buf      = session.buf;
            String username = session.username;
            String dest     = username + "@" + session.host;

            if (session.port != 22)
            {
                dest += (":" + session.port);
            }

            bool cancel = false;

            byte[] _username = null;
            try{ _username = System.Text.Encoding.UTF8.GetBytes(username); }
            catch {
                _username = Util.getBytes(username);
            }

            while (true)
            {
                // send
                // byte      SSH_MSG_USERAUTH_REQUEST(50)
                // string    user name (ISO-10646 UTF-8, as defined in [RFC-2279])
                // string    service name (US-ASCII) "ssh-userauth" ? "ssh-connection"
                // string    "keyboard-interactive" (US-ASCII)
                // string    language tag (as defined in [RFC-3066])
                // string    submethods (ISO-10646 UTF-8)
                packet.reset();
                buf.WriteByte((byte)Session.SSH_MSG_USERAUTH_REQUEST);
                buf.WriteString(_username);
                buf.WriteString(Util.getBytes("ssh-connection"));
                //buf.putString("ssh-userauth".getBytes());
                buf.WriteString(Util.getBytes("keyboard-interactive"));
                buf.WriteString(Util.getBytes(""));
                buf.WriteString(Util.getBytes(""));
                session.write(packet);

                bool firsttime = true;
loop:
                while (true)
                {
                    // receive
                    // byte      SSH_MSG_USERAUTH_SUCCESS(52)
                    // string    service name
                    try{ buf = session.read(buf); }
                    catch (JSchException e) {
                        e.GetType();
                        return(false);
                    }
                    catch (System.IO.IOException e) {
                        e.GetType();
                        return(false);
                    }
                    //System.out.println("read: 52 ? "+    buf.buffer[5]);
                    if (buf.buffer[5] == Session.SSH_MSG_USERAUTH_SUCCESS)
                    {
                        return(true);
                    }
                    if (buf.buffer[5] == Session.SSH_MSG_USERAUTH_BANNER)
                    {
                        buf.ReadInt(); buf.ReadByte(); buf.ReadByte();
                        byte[] _message = buf.ReadString();
                        byte[] lang     = buf.ReadString();
                        String message  = null;
                        try{ message = Util.getStringUTF8(_message); }
                        catch {
                            message = Util.getString(_message);
                        }
                        if (userinfo != null)
                        {
                            userinfo.showMessage(message);
                        }
                        goto loop;
                    }
                    if (buf.buffer[5] == Session.SSH_MSG_USERAUTH_FAILURE)
                    {
                        buf.ReadInt(); buf.ReadByte(); buf.ReadByte();
                        byte[] foo             = buf.ReadString();
                        int    partial_success = buf.ReadByte();
//	  System.out.println(Encoding.UTF8.GetString(foo)+
//			     " partial_success:"+(partial_success!=0));

                        if (partial_success != 0)
                        {
                            throw new JSchPartialAuthException(Util.getString(foo));
                        }

                        if (firsttime)
                        {
                            throw new JSchException("USERAUTH KI is not supported");
                            //return false;
                            //cancel=true;  // ??
                        }
                        break;
                    }
                    if (buf.buffer[5] == Session.SSH_MSG_USERAUTH_INFO_REQUEST)
                    {
                        firsttime = false;
                        buf.ReadInt(); buf.ReadByte(); buf.ReadByte();
                        String name         = Util.getString(buf.ReadString());
                        String instruction  = Util.getString(buf.ReadString());
                        String languate_tag = Util.getString(buf.ReadString());
                        int    num          = buf.ReadInt();
//System.out.println("name: "+name);
//System.out.println("instruction: "+instruction);
//System.out.println("lang: "+languate_tag);
//System.out.println("num: "+num);
                        String[] prompt = new String[num];
                        bool[]   echo   = new bool[num];
                        for (int i = 0; i < num; i++)
                        {
                            prompt[i] = Util.getString(buf.ReadString());
                            echo[i]   = (buf.ReadByte() != 0);
//System.out.println("  "+prompt[i]+","+echo[i]);
                        }

                        String[] response = null;
                        if (num > 0 ||
                            (name.Length > 0 || instruction.Length > 0)
                            )
                        {
                            UIKeyboardInteractive kbi = (UIKeyboardInteractive)userinfo;
                            if (userinfo != null)
                            {
                                response = kbi.promptKeyboardInteractive(dest,
                                                                         name,
                                                                         instruction,
                                                                         prompt,
                                                                         echo);
                            }
                        }
                        // byte      SSH_MSG_USERAUTH_INFO_RESPONSE(61)
                        // int       num-responses
                        // string    response[1] (ISO-10646 UTF-8)
                        // ...
                        // string    response[num-responses] (ISO-10646 UTF-8)
//if(response!=null)
//System.out.println("response.length="+response.length);
//else
//System.out.println("response is null");
                        packet.reset();
                        buf.WriteByte((byte)Session.SSH_MSG_USERAUTH_INFO_RESPONSE);
                        if (num > 0 &&
                            (response == null || // cancel
                             num != response.Length))
                        {
                            buf.WriteInt(0);
                            if (response == null)
                            {
                                cancel = true;
                            }
                        }
                        else
                        {
                            buf.WriteInt(num);
                            for (int i = 0; i < num; i++)
                            {
//System.out.println("response: |"+response[i]+"| <- replace here with **** if you need");
                                buf.WriteString(Util.getBytes(response[i]));
                            }
                        }
                        session.write(packet);
                        if (cancel)
                        {
                            break;
                        }
//System.out.println("continue loop");
                        goto loop;
                    }
                    //throw new JSchException("USERAUTH fail ("+buf.buffer[5]+")");
                    return(false);
                }
                if (cancel)
                {
                    throw new JSchAuthCancelException("keyboard-interactive");
                    //break;
                }
            }
            //return false;
        }
Esempio n. 35
0
		byte[] getSignature_rsa(Session session, byte[] data)
		{
			try
			{      
				Type t=Type.GetType(jsch.getConfig("signature.rsa"));
				SignatureRSA rsa=(SignatureRSA)Activator.CreateInstance(t);

				rsa.init();
				rsa.setPrvKey(e_array, n_array, d_array, p_array, q_array, dmp1_array, dmq1_array, iqmp_array);

				/*
				byte[] goo=new byte[4];
				goo[0]=(byte)(session.getSessionId().Length>>>24);
				goo[1]=(byte)(session.getSessionId().Length>>>16);
				goo[2]=(byte)(session.getSessionId().Length>>>8);
				goo[3]=(byte)(session.getSessionId().Length);
				rsa.update(goo);
				rsa.update(session.getSessionId());
				*/
				rsa.update(data);
				byte[] sig = rsa.sign();
				Buffer buf=new Buffer("ssh-rsa".Length+4+
					sig.Length+4);
				buf.WriteString( System.Text.Encoding.Default.GetBytes( "ssh-rsa" ));
				buf.WriteString(sig);
				return buf.buffer;
			}
			catch(Exception e)
			{
				Console.WriteLine(e);
			}
			return null;
		}
Esempio n. 36
0
        public override bool next(Buffer _buf)
        {
            int  i, j;
            bool result = false;

            switch (state)
            {
            case SSH_MSG_KEX_DH_GEX_GROUP:
                // byte  SSH_MSG_KEX_DH_GEX_GROUP(31)
                // mpint p, safe prime
                // mpint g, generator for subgroup in GF (p)
                _buf.ReadInt();
                _buf.ReadByte();
                j = _buf.ReadByte();
                if (j != 31)
                {
                    Console.WriteLine("type: must be 31 " + j);
                    result = false;
                }

                p = _buf.ReadMPInt();
                g = _buf.ReadMPInt();

                /*
                 * for(int iii=0; iii<p.length; iii++){
                 * System.out.println("0x"+Integer.toHexString(p[iii]&0xff)+",");
                 * }
                 * System.out.println("");
                 * for(int iii=0; iii<g.length; iii++){
                 * System.out.println("0x"+Integer.toHexString(g[iii]&0xff)+",");
                 * }
                 */
                dh.setP(p);
                dh.setG(g);

                // The client responds with:
                // byte  SSH_MSG_KEX_DH_GEX_INIT(32)
                // mpint e <- g^x mod p
                //         x is a random number (1 < x < (p-1)/2)

                e = dh.getE();

                packet.reset();
                buf.WriteByte((byte)0x20);
                buf.WriteMPInt(e);
                session.write(packet);

                state  = SSH_MSG_KEX_DH_GEX_REPLY;
                result = true;
                break;

            case SSH_MSG_KEX_DH_GEX_REPLY:
                // The server responds with:
                // byte      SSH_MSG_KEX_DH_GEX_REPLY(33)
                // string    server public host key and certificates (K_S)
                // mpint     f
                // string    signature of H
                j = _buf.ReadInt();
                j = _buf.ReadByte();
                j = _buf.ReadByte();
                if (j != 33)
                {
                    Console.WriteLine("type: must be 33 " + j);
                    result = false;
                }

                K_S = _buf.ReadString();
                // K_S is server_key_blob, which includes ....
                // string ssh-dss
                // impint p of dsa
                // impint q of dsa
                // impint g of dsa
                // impint pub_key of dsa
                //System.out.print("K_S: "); dump(K_S, 0, K_S.length);

                byte[] f        = _buf.ReadMPInt();
                byte[] sig_of_H = _buf.ReadString();

                dh.setF(f);
                K = dh.getK();

                //The hash H is computed as the HASH hash of the concatenation of the
                //following:
                // string    V_C, the client's version string (CR and NL excluded)
                // string    V_S, the server's version string (CR and NL excluded)
                // string    I_C, the payload of the client's SSH_MSG_KEXINIT
                // string    I_S, the payload of the server's SSH_MSG_KEXINIT
                // string    K_S, the host key
                // uint32    min, minimal size in bits of an acceptable group
                // uint32   n, preferred size in bits of the group the server should send
                // uint32    max, maximal size in bits of an acceptable group
                // mpint     p, safe prime
                // mpint     g, generator for subgroup
                // mpint     e, exchange value sent by the client
                // mpint     f, exchange value sent by the server
                // mpint     K, the shared secret
                // This value is called the exchange hash, and it is used to authenti-
                // cate the key exchange.

                buf.Reset();
                buf.WriteString(V_C); buf.WriteString(V_S);
                buf.WriteString(I_C); buf.WriteString(I_S);
                buf.WriteString(K_S);
                buf.WriteInt(min); buf.WriteInt(preferred); buf.WriteInt(max);
                buf.WriteMPInt(p); buf.WriteMPInt(g); buf.WriteMPInt(e); buf.WriteMPInt(f);
                buf.WriteMPInt(K);

                byte[] foo = new byte[buf.Length];
                buf.ReadByte(foo);
                sha.update(foo, 0, foo.Length);

                H = sha.digest();

                // System.out.print("H -> "); dump(H, 0, H.length);

                i = 0;
                j = 0;
                j = (int)((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000) |
                    ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
                String alg = Util.getString(K_S, i, j);
                i += j;


                if (alg.Equals("ssh-rsa"))
                {
                    byte[] tmp;
                    byte[] ee;
                    byte[] n;

                    type = RSA;

                    j = (int)((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000) |
                        ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
                    tmp = new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i += j;
                    ee  = tmp;
                    j   = (int)((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000) |
                          ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
                    tmp = new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i += j;
                    n   = tmp;

                    //	SignatureRSA sig=new SignatureRSA();
                    //	sig.init();

                    SignatureRSA sig = null;
                    try
                    {
                        Type t = Type.GetType(session.getConfig("signature.rsa"));
                        sig = (SignatureRSA)(Activator.CreateInstance(t));
                        sig.init();
                    }
                    catch (Exception eee)
                    {
                        Console.WriteLine(eee);
                    }

                    sig.setPubKey(ee, n);
                    sig.update(H);
                    result = sig.verify(sig_of_H);
                }
                else if (alg.Equals("ssh-dss"))
                {
                    byte[] q = null;
                    byte[] tmp;

                    type = DSS;

                    j = (int)((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000) |
                        ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
                    tmp = new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i += j;
                    p   = tmp;
                    j   = (int)((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000) |
                          ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
                    tmp = new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i += j;
                    q   = tmp;
                    j   = (int)((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000) |
                          ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
                    tmp = new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i += j;
                    g   = tmp;
                    j   = (int)((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000) |
                          ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
                    tmp = new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i += j;
                    f   = tmp;

                    //	SignatureDSA sig=new SignatureDSA();
                    //	sig.init();

                    SignatureDSA sig = null;
                    try
                    {
                        Type t = Type.GetType(session.getConfig("signature.dss"));
                        sig = (SignatureDSA)(Activator.CreateInstance(t));
                        sig.init();
                    }
                    catch (Exception ee)
                    {
                        Console.WriteLine(ee);
                    }

                    sig.setPubKey(f, p, q, g);
                    sig.update(H);
                    result = sig.verify(sig_of_H);
                }
                else
                {
                    Console.WriteLine("unknow alg");
                }
                state = STATE_END;
                break;
            }
            return(result);
        }
Esempio n. 37
0
 internal void dump(Buffer buf)
 {
     buf.WriteInt(Flags);
     if ((Flags & SSH_FILEXFER_ATTR_SIZE) != 0) { buf.WriteLong(_Size); }
     if ((Flags & SSH_FILEXFER_ATTR_UIDGID) != 0)
     {
         buf.WriteInt(uid); buf.WriteInt(gid);
     }
     if ((Flags & SSH_FILEXFER_ATTR_PERMISSIONS) != 0)
     {
         buf.WriteInt((int)_Permissions);
     }
     if ((Flags & SSH_FILEXFER_ATTR_ACMODTIME) != 0) { buf.WriteInt(AccessTime); }
     if ((Flags & SSH_FILEXFER_ATTR_ACMODTIME) != 0) { buf.WriteInt(ModificationTime); }
     if ((Flags & SSH_FILEXFER_ATTR_EXTENDED) != 0)
     {
         int count = extended.Length / 2;
         if (count > 0)
         {
             for (int i = 0; i < count; i++)
             {
                 buf.WriteString(Util.getBytes(extended[i * 2]));
                 buf.WriteString(Util.getBytes(extended[i * 2 + 1]));
             }
         }
     }
 }
Esempio n. 38
0
        public override void connect()
        {
            try
            {
                if (!session.isConnected())
                {
                    throw new JSchException("session is down");
                }
                Buffer buf    = new Buffer(150);
                Packet packet = new Packet(buf);
                // send
                // byte   SSH_MSG_CHANNEL_OPEN(90)
                // string channel type         //
                // uint32 sender channel       // 0
                // uint32 initial window size  // 0x100000(65536)
                // uint32 maxmum packet size   // 0x4000(16384)

                packet.reset();
                buf.WriteByte((byte)90);
                buf.WriteString(Util.getBytes("direct-tcpip"));
                buf.WriteInt(id);
                buf.WriteInt(lwsize);
                buf.WriteInt(lmpsize);
                buf.WriteString(Util.getBytes(host));
                buf.WriteInt(port);
                buf.WriteString(Util.getBytes(originator_IP_address));
                buf.WriteInt(originator_port);
                session.write(packet);

                int retry = 1000;
                try
                {
                    while (this.getRecipient() == -1 &&
                           session.isConnected() &&
                           retry > 0 &&
                           !_eof_remote)
                    {
                        //Thread.sleep(500);
                        System.Threading.Thread.Sleep(50);
                        retry--;
                    }
                }
                catch
                {
                }

                if (!session.isConnected())
                {
                    throw new JSchException("session is down");
                }
                if (retry == 0 || this._eof_remote)
                {
                    throw new JSchException("channel is not opened.");
                }

                /*
                 * if(this.eof_remote){      // failed to open
                 * disconnect();
                 * return;
                 * }
                 */

                connected = true;

                thread = new System.Threading.Thread(this.run);
                thread.Start();
            }
            catch (Exception e)
            {
                io.close();
                io = null;
                Channel.del(this);
                if (e is JSchException)
                {
                    throw (JSchException)e;
                }
            }
        }
Esempio n. 39
0
        public override bool start(Session session)
        {
            //super.start(session);

            //Vector identities=JSch.identities;
            System.Collections.ArrayList identities = session.jsch.identities;

            Packet packet = session.packet;
            Buffer buf    = session.buf;

            String passphrase = null;
            String username   = session.username;

            byte[] _username = null;
            try{ _username = Util.getBytesUTF8(username); }
            catch
            {            //(java.io.UnsupportedEncodingException e){
                _username = Util.getBytes(username);
            }

            for (int i = 0; i < identities.Count; i++)
            {
                Identity identity   = (Identity)(identities[i]);
                byte[]   pubkeyblob = identity.getPublicKeyBlob();

                //System.out.println("UserAuthPublicKey: "+identity+" "+pubkeyblob);

                if (pubkeyblob != null)
                {
                    // send
                    // byte      SSH_MSG_USERAUTH_REQUEST(50)
                    // string    user name
                    // string    service name ("ssh-connection")
                    // string    "publickey"
                    // boolen    FALSE
                    // string    plaintext password (ISO-10646 UTF-8)
                    packet.reset();
                    buf.WriteByte((byte)Session.SSH_MSG_USERAUTH_REQUEST);
                    buf.WriteString(_username);
                    buf.WriteString(Util.getBytes("ssh-connection"));
                    buf.WriteString(Util.getBytes("publickey"));
                    buf.WriteByte((byte)0);
                    buf.WriteString(Util.getBytes(identity.getAlgName()));
                    buf.WriteString(pubkeyblob);
                    session.write(packet);

loop1:
                    while (true)
                    {
                        // receive
                        // byte      SSH_MSG_USERAUTH_PK_OK(52)
                        // string    service name
                        buf = session.read(buf);
                        //System.out.println("read: 60 ? "+    buf.buffer[5]);
                        if (buf.buffer[5] == Session.SSH_MSG_USERAUTH_PK_OK)
                        {
                            break;
                        }
                        else if (buf.buffer[5] == Session.SSH_MSG_USERAUTH_FAILURE)
                        {
                            //	System.out.println("USERAUTH publickey "+session.getIdentity()+
                            //			   " is not acceptable.");
                            break;
                        }
                        else if (buf.buffer[5] == Session.SSH_MSG_USERAUTH_BANNER)
                        {
                            buf.ReadInt(); buf.ReadByte(); buf.ReadByte();
                            byte[] _message = buf.ReadString();
                            byte[] lang     = buf.ReadString();
                            String message  = null;
                            try{ message = Util.getStringUTF8(_message); }
                            catch
                            {                            //(java.io.UnsupportedEncodingException e){
                                message = Util.getString(_message);
                            }
                            if (userinfo != null)
                            {
                                userinfo.showMessage(message);
                            }
                            goto loop1;
                        }
                        else
                        {
                            //System.out.println("USERAUTH fail ("+buf.buffer[5]+")");
                            //throw new JSchException("USERAUTH fail ("+buf.buffer[5]+")");
                            break;
                        }
                    }
                    if (buf.buffer[5] != Session.SSH_MSG_USERAUTH_PK_OK)
                    {
                        continue;
                    }
                }

                //System.out.println("UserAuthPublicKey: identity.isEncrypted()="+identity.isEncrypted());

                int count = 5;
                while (true)
                {
                    if ((identity.isEncrypted() && passphrase == null))
                    {
                        if (userinfo == null)
                        {
                            throw new JSchException("USERAUTH fail");
                        }
                        if (identity.isEncrypted() &&
                            !userinfo.promptPassphrase("Passphrase for " + identity.getName()))
                        {
                            throw new JSchAuthCancelException("publickey");
                            //throw new JSchException("USERAUTH cancel");
                            //break;
                        }
                        passphrase = userinfo.getPassphrase();
                    }

                    if (!identity.isEncrypted() || passphrase != null)
                    {
                        //System.out.println("UserAuthPublicKey: @1 "+passphrase);
                        if (identity.setPassphrase(passphrase))
                        {
                            break;
                        }
                    }
                    passphrase = null;
                    count--;
                    if (count == 0)
                    {
                        break;
                    }
                }

                //System.out.println("UserAuthPublicKey: identity.isEncrypted()="+identity.isEncrypted());

                if (identity.isEncrypted())
                {
                    continue;
                }
                if (pubkeyblob == null)
                {
                    pubkeyblob = identity.getPublicKeyBlob();
                }

                //System.out.println("UserAuthPublicKey: pubkeyblob="+pubkeyblob);

                if (pubkeyblob == null)
                {
                    continue;
                }

                // send
                // byte      SSH_MSG_USERAUTH_REQUEST(50)
                // string    user name
                // string    service name ("ssh-connection")
                // string    "publickey"
                // boolen    TRUE
                // string    plaintext password (ISO-10646 UTF-8)
                packet.reset();
                buf.WriteByte((byte)Session.SSH_MSG_USERAUTH_REQUEST);
                buf.WriteString(_username);
                buf.WriteString(Util.getBytes("ssh-connection"));
                buf.WriteString(Util.getBytes("publickey"));
                buf.WriteByte((byte)1);
                buf.WriteString(Util.getBytes(identity.getAlgName()));
                buf.WriteString(pubkeyblob);

                //      byte[] tmp=new byte[buf.index-5];
                //      System.arraycopy(buf.buffer, 5, tmp, 0, tmp.length);
                //      buf.putString(signature);

                byte[] sid    = session.getSessionId();
                uint   sidlen = (uint)sid.Length;
                byte[] tmp    = new byte[4 + sidlen + buf.index - 5];
                tmp[0] = (byte)(sidlen >> 24);
                tmp[1] = (byte)(sidlen >> 16);
                tmp[2] = (byte)(sidlen >> 8);
                tmp[3] = (byte)(sidlen);
                Array.Copy(sid, 0, tmp, 4, sidlen);
                Array.Copy(buf.buffer, 5, tmp, 4 + sidlen, buf.index - 5);

                byte[] signature = identity.getSignature(session, tmp);
                if (signature == null)
                {                  // for example, too long key length.
                    break;
                }
                buf.WriteString(signature);

                session.write(packet);

loop2:
                while (true)
                {
                    // receive
                    // byte      SSH_MSG_USERAUTH_SUCCESS(52)
                    // string    service name
                    buf = session.read(buf);
                    //System.out.println("read: 52 ? "+    buf.buffer[5]);
                    if (buf.buffer[5] == Session.SSH_MSG_USERAUTH_SUCCESS)
                    {
                        return(true);
                    }
                    else if (buf.buffer[5] == Session.SSH_MSG_USERAUTH_BANNER)
                    {
                        buf.ReadInt(); buf.ReadByte(); buf.ReadByte();
                        byte[] _message = buf.ReadString();
                        byte[] lang     = buf.ReadString();
                        String message  = null;
                        try{ message = Util.getStringUTF8(_message); }
                        catch
                        {                        //(java.io.UnsupportedEncodingException e){
                            message = Util.getString(_message);
                        }
                        if (userinfo != null)
                        {
                            userinfo.showMessage(message);
                        }
                        goto loop2;
                    }
                    else if (buf.buffer[5] == Session.SSH_MSG_USERAUTH_FAILURE)
                    {
                        buf.ReadInt(); buf.ReadByte(); buf.ReadByte();
                        byte[] foo             = buf.ReadString();
                        int    partial_success = buf.ReadByte();
                        //System.out.println(Encoding.UTF8.GetString(foo)+
                        //                   " partial_success:"+(partial_success!=0));
                        if (partial_success != 0)
                        {
                            throw new JSchPartialAuthException(Util.getString(foo));
                        }
                        break;
                    }
                    //System.out.println("USERAUTH fail ("+buf.buffer[5]+")");
                    //throw new JSchException("USERAUTH fail ("+buf.buffer[5]+")");
                    break;
                }
            }
            return(false);
        }
Esempio n. 40
0
        public override bool start(Session session)
        {
            base.start(session);
            //System.out.println("UserAuthNone: start");
            Packet packet   = session.packet;
            Buffer buf      = session.buf;
            String username = session.username;

            byte[] _username = null;
            try{ _username = Util.getBytesUTF8(username); }
            catch
            {            //(java.io.UnsupportedEncodingException e){
                _username = Util.getBytes(username);
            }

            // send
            // byte      SSH_MSG_USERAUTH_REQUEST(50)
            // string    user name
            // string    service name ("ssh-connection")
            // string    "none"
            packet.reset();
            buf.WriteByte((byte)Session.SSH_MSG_USERAUTH_REQUEST);
            buf.WriteString(_username);
            buf.WriteString(Util.getBytes("ssh-connection"));
            buf.WriteString(Util.getBytes("none"));
            session.write(packet);

loop:
            while (true)
            {
                // receive
                // byte      SSH_MSG_USERAUTH_SUCCESS(52)
                // string    service name
                buf = session.read(buf);
                //System.out.println("UserAuthNone: read: 52 ? "+    buf.buffer[5]);
                if (buf.buffer[5] == Session.SSH_MSG_USERAUTH_SUCCESS)
                {
                    return(true);
                }
                if (buf.buffer[5] == Session.SSH_MSG_USERAUTH_BANNER)
                {
                    buf.ReadInt(); buf.ReadByte(); buf.ReadByte();
                    byte[] _message = buf.ReadString();
                    byte[] lang     = buf.ReadString();
                    String message  = null;
                    try{ message = Util.getStringUTF8(_message); }
                    catch
                    {                            //(java.io.UnsupportedEncodingException e){
                        message = Util.getString(_message);
                    }
                    if (userinfo != null)
                    {
                        userinfo.showMessage(message);
                    }
                    goto loop;
                }
                if (buf.buffer[5] == Session.SSH_MSG_USERAUTH_FAILURE)
                {
                    buf.ReadInt(); buf.ReadByte(); buf.ReadByte();
                    byte[] foo             = buf.ReadString();
                    int    partial_success = buf.ReadByte();
                    methods = Util.getString(foo);
                    //System.out.println("UserAuthNONE: "+methods+
                    //		   " partial_success:"+(partial_success!=0));
                    //	if(partial_success!=0){
                    //	  throw new JSchPartialAuthException(Encoding.UTF8.GetString(foo));
                    //	}
                    break;
                }
                else
                {
                    //      System.out.println("USERAUTH fail ("+buf.buffer[5]+")");
                    throw new JSchException("USERAUTH fail (" + buf.buffer[5] + ")");
                }
            }
            //throw new JSchException("USERAUTH fail");
            return(false);
        }