Example #1
0
        public override void init(Session session,
                                  byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C)
        {
            this.session = session;
            this.V_S     = V_S;
            this.V_C     = V_C;
            this.I_S     = I_S;
            this.I_C     = I_C;

            //    sha=new SHA1();
            //    sha.init();
            try
            {
                Type t = Type.GetType(session.getConfig("sha-1"));
                sha = (HASH)(Activator.CreateInstance(t));
                sha.init();
            }
            catch (Exception ee)
            {
                Console.WriteLine(ee);
            }

            buf    = new Buffer();
            packet = new Packet(buf);

            try
            {
                Type t = Type.GetType(session.getConfig("dh"));
                dh = (DH)(Activator.CreateInstance(t));
                dh.init();
            }
            catch (Exception ee)
            {
                throw ee;
            }

            dh.setP(p);
            dh.setG(g);

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

            e = dh.getE();

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

            state = SSH_MSG_KEXDH_REPLY;
        }
Example #2
0
        //private byte[] f;

        public override void init(Session session,
                                  byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C)
        {
            this.session = session;
            this.V_S     = V_S;
            this.V_C     = V_C;
            this.I_S     = I_S;
            this.I_C     = I_C;

            try
            {
                Type c = Type.GetType(session.getConfig("sha-1"));
                sha = (HASH)(c.newInstance());
                sha.init();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
            }

            buf    = new Buffer();
            packet = new Packet(buf);

            try
            {
                Type c = Type.GetType(session.getConfig("dh"));
                dh = (DH)(c.newInstance());
                dh.init();
            }
            catch (Exception e)
            {
                //      Console.Error.WriteLine(e);
                throw e;
            }

            packet.reset();
            buf.putByte((byte)SSH_MSG_KEX_DH_GEX_REQUEST);
            buf.putInt(min);
            buf.putInt(preferred);
            buf.putInt(max);
            session.write(packet);

            if (JSch.getLogger().isEnabled(Logger.INFO))
            {
                JSch.getLogger().log(Logger.INFO,
                                     "SSH_MSG_KEX_DH_GEX_REQUEST(" + min + "<" + preferred + "<" + max + ") sent");
                JSch.getLogger().log(Logger.INFO,
                                     "expecting SSH_MSG_KEX_DH_GEX_GROUP");
            }

            state = SSH_MSG_KEX_DH_GEX_GROUP;
        }
Example #3
0
        //private byte[] f;
        public override void init(Session session,
            byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C)
        {
            this.session = session;
            this.V_S = V_S;
            this.V_C = V_C;
            this.I_S = I_S;
            this.I_C = I_C;

            try
            {
                Type c = Type.GetType(session.getConfig("sha-1"));
                sha = (HASH)(c.newInstance());
                sha.init();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
            }

            buf = new Buffer();
            packet = new Packet(buf);

            try
            {
                Type c = Type.GetType(session.getConfig("dh"));
                dh = (DH)(c.newInstance());
                dh.init();
            }
            catch (Exception e)
            {
                //      Console.Error.WriteLine(e);
                throw e;
            }

            packet.reset();
            buf.putByte((byte)SSH_MSG_KEX_DH_GEX_REQUEST);
            buf.putInt(min);
            buf.putInt(preferred);
            buf.putInt(max);
            session.write(packet);

            if (JSch.getLogger().isEnabled(Logger.INFO))
            {
                JSch.getLogger().log(Logger.INFO,
                                     "SSH_MSG_KEX_DH_GEX_REQUEST(" + min + "<" + preferred + "<" + max + ") sent");
                JSch.getLogger().log(Logger.INFO,
                                     "expecting SSH_MSG_KEX_DH_GEX_GROUP");
            }

            state = SSH_MSG_KEX_DH_GEX_GROUP;
        }
Example #4
0
        //private byte[] f;

        public override void init(Session session,
                                  byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C)
        {
            this.session = session;
            this.V_S     = V_S;
            this.V_C     = V_C;
            this.I_S     = I_S;
            this.I_C     = I_C;

            //    sha=new SHA1();
            //    sha.init();

            try
            {
                Type t = Type.GetType(session.getConfig("sha-1"));
                sha = (HASH)(Activator.CreateInstance(t));
                sha.init();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            buf    = new Buffer();
            packet = new Packet(buf);

            try
            {
                Type t = Type.GetType(session.getConfig("dh"));
                dh = (DH)(Activator.CreateInstance(t));
                dh.init();
            }
            catch (Exception e)
            {
                throw e;
            }

            packet.reset();
            buf.putByte((byte)0x22);
            buf.putInt(min);
            buf.putInt(preferred);
            buf.putInt(max);
            session.write(packet);

            state = SSH_MSG_KEX_DH_GEX_GROUP;
        }
Example #5
0
        public static void test()
        {
            JSch jsch = new JSch();
            DH   dh1  = null;
            DH   dh2  = null;

            try
            {
                Type t = Type.GetType(jsch.getConfig("dh"));
                dh1 = (DH)(Activator.CreateInstance(t));
                dh1.init();
                dh2 = (DH)(Activator.CreateInstance(t));
                dh2.init();
            }
            catch (Exception ee)
            {
                Console.WriteLine(ee);
            }

            dh1.setP(DHG1.p);
            dh1.setG(DHG1.g);
            dh2.setP(DHG1.p);
            dh2.setG(DHG1.g);

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

            byte[] e = dh1.getE();
            byte[] f = dh2.getE();
            Console.WriteLine("Private1 = {0}", hex(e));
            Console.WriteLine();
            Console.WriteLine("Private2 = {0}", hex(f));
            Console.WriteLine();
            dh1.setF(f);
            dh2.setF(e);
            byte[] k1 = dh1.getK();
            byte[] k2 = dh2.getK();
            Console.WriteLine("Public1 = {0}", hex(k1));
            Console.WriteLine();
            Console.WriteLine("Public2 = {0}", hex(k2));
            Console.WriteLine();
        }
Example #6
0
        public override void init(Session session, byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C)
        {
            m_session = session;
            m_V_S = V_S;
            m_V_C = V_C;
            m_I_S = I_S;
            m_I_C = I_C;

            try
            {
                Type t = Type.GetType(session.getConfig("sha-1"));
                m_sha = (HASH)(Activator.CreateInstance(t));
                m_sha.init();
            }
            catch (Exception) { }

            m_buf = new Buffer();
            m_packet = new Packet(m_buf);

            try
            {
                Type t = Type.GetType(session.getConfig("dh"));
                m_dh = (DH)(Activator.CreateInstance(t));
                m_dh.init();
            }
            catch (Exception e)
            {
                throw e;
            }

            m_packet.reset();
            m_buf.putByte((byte)0x22);
            m_buf.putInt(m_min);
            m_buf.putInt(m_preferred);
            m_buf.putInt(m_max);
            session.write(m_packet);

            m_state = SSH_MSG_KEX_DH_GEX_GROUP;
        }
Example #7
0
		public override void init(Session session,
			byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) 
		{
			this.session=session;
			this.V_S=V_S;      
			this.V_C=V_C;      
			this.I_S=I_S;      
			this.I_C=I_C;      

			//    sha=new SHA1();
			//    sha.init();
			try
			{
				Type t=Type.GetType(session.getConfig("sha-1"));
				sha=(HASH)(Activator.CreateInstance(t));
				sha.init();
			}
			catch(Exception ee)
			{
				Console.WriteLine(ee);
			}

			buf=new Buffer();
			packet=new Packet(buf);

			try
			{
				Type t=Type.GetType(session.getConfig("dh"));
				dh=(DH)(Activator.CreateInstance(t));
				dh.init();
			}
			catch(Exception ee)
			{
				throw ee;
			}

			dh.setP(p);
			dh.setG(g);

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

			e=dh.getE();

			packet.reset();
			buf.putByte((byte)SSH_MSG_KEXDH_INIT);
			buf.putMPInt(e);
			session.write(packet);

			state=SSH_MSG_KEXDH_REPLY;
		}
Example #8
0
        //private byte[] f;
        public override void init(Session session,
            byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C)
        {
            this.session = session;
            this.V_S = V_S;
            this.V_C = V_C;
            this.I_S = I_S;
            this.I_C = I_C;

            //    sha=new SHA1();
            //    sha.init();

            try
            {
                Type t = Type.GetType(session.getConfig("sha-1"));
                sha = (HASH) (Activator.CreateInstance(t));
                sha.init();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            buf = new Buffer();
            packet = new Packet(buf);

            try
            {
                Type t = Type.GetType(session.getConfig("dh"));
                dh = (DH) (Activator.CreateInstance(t));
                dh.init();
            }
            catch (Exception e)
            {
                throw e;
            }

            packet.reset();
            buf.putByte(0x22);
            buf.putInt(min);
            buf.putInt(preferred);
            buf.putInt(max);
            session.write(packet);

            state = SSH_MSG_KEX_DH_GEX_GROUP;
        }
Example #9
0
        public override void init(Session session, byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C)
        {
            m_session = session;
            m_V_S = V_S;
            m_V_C = V_C;
            m_I_S = I_S;
            m_I_C = I_C;
            try
            {
                Type t = Type.GetType(session.getConfig("sha-1"));
                m_sha = (HASH)(Activator.CreateInstance(t));
                m_sha.init();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            m_buf = new Buffer();
            m_packet = new Packet(m_buf);

            try
            {
                Type t = Type.GetType(session.getConfig("dh"));
                m_dh = (DH)(Activator.CreateInstance(t));
                m_dh.init();
            }
            catch (Exception ee)
            {
                throw ee;
            }

            m_dh.P = m_p;
            m_dh.G = m_g;

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

            m_e = m_dh.E;

            m_packet.reset();
            m_buf.putByte((byte)SSH_MSG_KEXDH_INIT);
            m_buf.putMPInt(m_e);
            session.write(m_packet);

            m_state = SSH_MSG_KEXDH_REPLY;
        }
Example #10
0
        public override void init(Session session,
                                  byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C)
        {
            this.session = session;
            this.V_S     = V_S;
            this.V_C     = V_C;
            this.I_S     = I_S;
            this.I_C     = I_C;

            //    sha=new SHA1();
            //    sha.init();
            try
            {
                Type c = Type.GetType(session.getConfig("sha-1"));
                sha = (HASH)(c.newInstance());
                sha.init();
            }
            catch (Exception ee)
            {
                Console.Error.WriteLine(ee);
            }

            buf    = new Buffer();
            packet = new Packet(buf);

            try
            {
                Type c = Type.GetType(session.getConfig("dh"));
                dh = (DH)(c.newInstance());
                dh.init();
            }
            catch (Exception ee)
            {
                //Console.Error.WriteLine(e);
                throw ee;
            }

            dh.setP(p);
            dh.setG(g);

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

            e = dh.getE();

            packet.reset();
            buf.putByte((byte)SSH_MSG_KEXDH_INIT);
            buf.putMPInt(e);
            session.write(packet);

            if (JSch.getLogger().isEnabled(Logger.INFO))
            {
                JSch.getLogger().log(Logger.INFO,
                                     "SSH_MSG_KEXDH_INIT sent");
                JSch.getLogger().log(Logger.INFO,
                                     "expecting SSH_MSG_KEXDH_REPLY");
            }

            state = SSH_MSG_KEXDH_REPLY;
        }
Example #11
0
        public override void init(Session session,
            byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C)
        {
            this.session = session;
            this.V_S = V_S;
            this.V_C = V_C;
            this.I_S = I_S;
            this.I_C = I_C;

            //    sha=new SHA1();
            //    sha.init();
            try
            {
                Type c = Type.GetType(session.getConfig("sha-1"));
                sha = (HASH)(c.newInstance());
                sha.init();
            }
            catch (Exception ee)
            {
                Console.Error.WriteLine(ee);
            }

            buf = new Buffer();
            packet = new Packet(buf);

            try
            {
                Type c = Type.GetType(session.getConfig("dh"));
                dh = (DH)(c.newInstance());
                dh.init();
            }
            catch (Exception ee)
            {
                //Console.Error.WriteLine(e);
                throw ee;
            }

            dh.setP(p);
            dh.setG(g);

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

            e = dh.getE();

            packet.reset();
            buf.putByte((byte)SSH_MSG_KEXDH_INIT);
            buf.putMPInt(e);
            session.write(packet);

            if (JSch.getLogger().isEnabled(Logger.INFO))
            {
                JSch.getLogger().log(Logger.INFO,
                                     "SSH_MSG_KEXDH_INIT sent");
                JSch.getLogger().log(Logger.INFO,
                                     "expecting SSH_MSG_KEXDH_REPLY");
            }

            state = SSH_MSG_KEXDH_REPLY;
        }