Exemple #1
0
        /// <summary>
        /// Parse list of excluded hosts
        /// </summary>
        /// <returns></returns>
        public List <string> GetExcludedHosts()
        {
            var exclude = new List <string>();

            if (!string.IsNullOrEmpty(ExcludeBindings))
            {
                exclude = ExcludeBindings.Split(',').Select(x => x.ToLower().Trim()).ToList();
            }
            return(exclude);
        }
        public List <string> GetHosts(bool unicode)
        {
            var hosts = new List <string>();

            if (HostIsDns == true)
            {
                hosts.Add(Host);
            }
            if (AlternativeNames != null && AlternativeNames.Any())
            {
                hosts.AddRange(AlternativeNames);
            }
            var exclude = new List <string>();

            if (!string.IsNullOrEmpty(ExcludeBindings))
            {
                exclude = ExcludeBindings.Split(',').Select(x => x.ToLower().Trim()).ToList();
            }

            var filtered = hosts.
                           Where(x => !string.IsNullOrWhiteSpace(x)).
                           Distinct().
                           Except(exclude);

            if (unicode)
            {
                var idn = new IdnMapping();
                filtered = filtered.Select(x => idn.GetUnicode(x));
            }

            if (filtered.Count() == 0)
            {
                Program.Log.Error("No DNS identifiers found.");
                throw new Exception("No DNS identifiers found.");
            }
            else if (filtered.Count() > Settings.maxNames)
            {
                Program.Log.Error("Too many hosts for a single certificate. Let's Encrypt has a maximum of {maxNames}.", Settings.maxNames);
                throw new Exception($"Too many hosts for a single certificate. Let's Encrypt has a maximum of {Settings.maxNames}.");
            }

            return(filtered.ToList());
        }