コード例 #1
0
 public override HostKey[] GetHostKey(string host, string type)
 {
     lock (pool)
     {
         int count = 0;
         for (int i = 0; i < pool.Count; i++)
         {
             HostKey hk = (HostKey)pool[i];
             if (hk.type == HostKey.UNKNOWN)
             {
                 continue;
             }
             if (host == null || (hk.IsMatched(host) && (type == null || hk.GetType().Equals(type
                                                                                             ))))
             {
                 count++;
             }
         }
         if (count == 0)
         {
             return(null);
         }
         HostKey[] foo = new HostKey[count];
         int       j   = 0;
         for (int i_1 = 0; i_1 < pool.Count; i_1++)
         {
             HostKey hk = (HostKey)pool[i_1];
             if (hk.type == HostKey.UNKNOWN)
             {
                 continue;
             }
             if (host == null || (hk.IsMatched(host) && (type == null || hk.GetType().Equals(type
                                                                                             ))))
             {
                 foo[j++] = hk;
             }
         }
         return(foo);
     }
 }
コード例 #2
0
        public override void Remove(string host, string type, byte[] key)
        {
            bool sync = false;

            lock (pool)
            {
                for (int i = 0; i < pool.Count; i++)
                {
                    HostKey hk = (HostKey)(pool[i]);
                    if (host == null || (hk.IsMatched(host) && (type == null || (hk.GetType().Equals(
                                                                                     type) && (key == null || Util.Array_equals(key, hk.key))))))
                    {
                        string hosts = hk.GetHost();
                        if (hosts.Equals(host) || ((hk is KnownHosts.HashedHostKey) && ((KnownHosts.HashedHostKey
                                                                                         )hk).IsHashed()))
                        {
                            pool.RemoveElement(hk);
                        }
                        else
                        {
                            hk.host = DeleteSubString(hosts, host);
                        }
                        sync = true;
                    }
                }
            }
            if (sync)
            {
                try
                {
                    Sync();
                }
                catch (Exception)
                {
                }
            }
        }
コード例 #3
0
        public override void Add(HostKey hostkey, UserInfo userinfo)
        {
            int    type = hostkey.type;
            string host = hostkey.GetHost();

            byte[]  key = hostkey.key;
            HostKey hk  = null;

            lock (pool)
            {
                for (int i = 0; i < pool.Count; i++)
                {
                    hk = (HostKey)(pool[i]);
                    if (hk.IsMatched(host) && hk.type == type)
                    {
                    }
                }
            }
            hk = hostkey;
            pool.Add(hk);
            string bar = GetKnownHostsRepositoryID();

            if (bar != null)
            {
                bool     foo = true;
                FilePath goo = new FilePath(bar);
                if (!goo.Exists())
                {
                    foo = false;
                    if (userinfo != null)
                    {
                        foo = userinfo.PromptYesNo(bar + " does not exist.\n" + "Are you sure you want to create it?"
                                                   );
                        goo = goo.GetParentFile();
                        if (foo && goo != null && !goo.Exists())
                        {
                            foo = userinfo.PromptYesNo("The parent directory " + goo + " does not exist.\n" +
                                                       "Are you sure you want to create it?");
                            if (foo)
                            {
                                if (!goo.Mkdirs())
                                {
                                    userinfo.ShowMessage(goo + " has not been created.");
                                    foo = false;
                                }
                                else
                                {
                                    userinfo.ShowMessage(goo + " has been succesfully created.\nPlease check its access permission."
                                                         );
                                }
                            }
                        }
                        if (goo == null)
                        {
                            foo = false;
                        }
                    }
                }
                if (foo)
                {
                    try
                    {
                        Sync(bar);
                    }
                    catch (Exception e)
                    {
                        System.Console.Error.WriteLine("sync known_hosts: " + e);
                    }
                }
            }
        }