コード例 #1
0
        protected internal static string[] Guess(byte[] I_S, byte[] I_C)
        {
            string[] guess = new string[PROPOSAL_MAX];
            Buffer   sb    = new Buffer(I_S);

            sb.SetOffSet(17);
            Buffer cb = new Buffer(I_C);

            cb.SetOffSet(17);
            for (int i = 0; i < PROPOSAL_MAX; i++)
            {
                byte[] sp = sb.GetString();
                // server proposal
                byte[] cp = cb.GetString();
                // client proposal
                int j = 0;
                int k = 0;
                while (j < cp.Length)
                {
                    while (j < cp.Length && cp[j] != ',')
                    {
                        j++;
                    }
                    if (k == j)
                    {
                        return(null);
                    }
                    string algorithm = Util.Byte2str(cp, k, j - k);
                    int    l         = 0;
                    int    m         = 0;
                    while (l < sp.Length)
                    {
                        while (l < sp.Length && sp[l] != ',')
                        {
                            l++;
                        }
                        if (m == l)
                        {
                            return(null);
                        }
                        if (algorithm.Equals(Util.Byte2str(sp, m, l - m)))
                        {
                            guess[i] = algorithm;
                            goto loop_break;
                        }
                        l++;
                        m = l;
                    }
                    j++;
                    k = j;
                    loop_continue :;
                }
                loop_break :;
                if (j == 0)
                {
                    guess[i] = string.Empty;
                }
                else
                {
                    if (guess[i] == null)
                    {
                        return(null);
                    }
                }
            }
            if (JSch.GetLogger().IsEnabled(Logger.INFO))
            {
                JSch.GetLogger().Log(Logger.INFO, "kex: server->client" + " " + guess[PROPOSAL_ENC_ALGS_STOC
                                     ] + " " + guess[PROPOSAL_MAC_ALGS_STOC] + " " + guess[PROPOSAL_COMP_ALGS_STOC]);
                JSch.GetLogger().Log(Logger.INFO, "kex: client->server" + " " + guess[PROPOSAL_ENC_ALGS_CTOS
                                     ] + " " + guess[PROPOSAL_MAC_ALGS_CTOS] + " " + guess[PROPOSAL_COMP_ALGS_CTOS]);
            }
            //    for(int i=0; i<PROPOSAL_MAX; i++){
            //      System.err.println("guess: ["+guess[i]+"]");
            //    }
            return(guess);
        }
コード例 #2
0
ファイル: Session.cs プロジェクト: yayanyang/monodevelop
		/// <exception cref="System.Exception"></exception>
		private void Send_kexinit()
		{
			if (in_kex)
			{
				return;
			}
			string cipherc2s = GetConfig("cipher.c2s");
			string ciphers2c = GetConfig("cipher.s2c");
			string[] not_available = CheckCiphers(GetConfig("CheckCiphers"));
			if (not_available != null && not_available.Length > 0)
			{
				cipherc2s = Util.DiffString(cipherc2s, not_available);
				ciphers2c = Util.DiffString(ciphers2c, not_available);
				if (cipherc2s == null || ciphers2c == null)
				{
					throw new JSchException("There are not any available ciphers.");
				}
			}
			in_kex = true;
			kex_start_time = Runtime.CurrentTimeMillis();
			// byte      SSH_MSG_KEXINIT(20)
			// byte[16]  cookie (random bytes)
			// string    kex_algorithms
			// string    server_host_key_algorithms
			// string    encryption_algorithms_client_to_server
			// string    encryption_algorithms_server_to_client
			// string    mac_algorithms_client_to_server
			// string    mac_algorithms_server_to_client
			// string    compression_algorithms_client_to_server
			// string    compression_algorithms_server_to_client
			// string    languages_client_to_server
			// string    languages_server_to_client
			Buffer buf = new Buffer();
			// send_kexinit may be invoked
			Packet packet = new Packet(buf);
			// by user thread.
			packet.Reset();
			buf.PutByte(unchecked((byte)SSH_MSG_KEXINIT));
			lock (random)
			{
				random.Fill(buf.buffer, buf.index, 16);
				buf.Skip(16);
			}
			buf.PutString(Util.Str2byte(GetConfig("kex")));
			buf.PutString(Util.Str2byte(GetConfig("server_host_key")));
			buf.PutString(Util.Str2byte(cipherc2s));
			buf.PutString(Util.Str2byte(ciphers2c));
			buf.PutString(Util.Str2byte(GetConfig("mac.c2s")));
			buf.PutString(Util.Str2byte(GetConfig("mac.s2c")));
			buf.PutString(Util.Str2byte(GetConfig("compression.c2s")));
			buf.PutString(Util.Str2byte(GetConfig("compression.s2c")));
			buf.PutString(Util.Str2byte(GetConfig("lang.c2s")));
			buf.PutString(Util.Str2byte(GetConfig("lang.s2c")));
			buf.PutByte(unchecked((byte)0));
			buf.PutInt(0);
			buf.SetOffSet(5);
			I_C = new byte[buf.GetLength()];
			buf.GetByte(I_C);
			Write(packet);
			if (JSch.GetLogger().IsEnabled(Logger.INFO))
			{
				JSch.GetLogger().Log(Logger.INFO, "SSH_MSG_KEXINIT sent");
			}
		}
コード例 #3
0
ファイル: KeyExchange.cs プロジェクト: LunarLanding/ngit
		protected internal static string[] Guess(byte[] I_S, byte[] I_C)
		{
			string[] guess = new string[PROPOSAL_MAX];
			Buffer sb = new Buffer(I_S);
			sb.SetOffSet(17);
			Buffer cb = new Buffer(I_C);
			cb.SetOffSet(17);
			for (int i = 0; i < PROPOSAL_MAX; i++)
			{
				byte[] sp = sb.GetString();
				// server proposal
				byte[] cp = cb.GetString();
				// client proposal
				int j = 0;
				int k = 0;
				while (j < cp.Length)
				{
					while (j < cp.Length && cp[j] != ',')
					{
						j++;
					}
					if (k == j)
					{
						return null;
					}
					string algorithm = Util.Byte2str(cp, k, j - k);
					int l = 0;
					int m = 0;
					while (l < sp.Length)
					{
						while (l < sp.Length && sp[l] != ',')
						{
							l++;
						}
						if (m == l)
						{
							return null;
						}
						if (algorithm.Equals(Util.Byte2str(sp, m, l - m)))
						{
							guess[i] = algorithm;
							goto loop_break;
						}
						l++;
						m = l;
					}
					j++;
					k = j;
loop_continue: ;
				}
loop_break: ;
				if (j == 0)
				{
					guess[i] = string.Empty;
				}
				else
				{
					if (guess[i] == null)
					{
						return null;
					}
				}
			}
			if (JSch.GetLogger().IsEnabled(Logger.INFO))
			{
				JSch.GetLogger().Log(Logger.INFO, "kex: server->client" + " " + guess[PROPOSAL_ENC_ALGS_STOC
					] + " " + guess[PROPOSAL_MAC_ALGS_STOC] + " " + guess[PROPOSAL_COMP_ALGS_STOC]);
				JSch.GetLogger().Log(Logger.INFO, "kex: client->server" + " " + guess[PROPOSAL_ENC_ALGS_CTOS
					] + " " + guess[PROPOSAL_MAC_ALGS_CTOS] + " " + guess[PROPOSAL_COMP_ALGS_CTOS]);
			}
			//    for(int i=0; i<PROPOSAL_MAX; i++){
			//      System.err.println("guess: ["+guess[i]+"]");
			//    }
			return guess;
		}