public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            ServiceProviderSettings serviceProviderSettings = obj as ServiceProviderSettings;

            if (serviceProviderSettings == null)
            {
                return(false);
            }
            if (!string.Equals(this.ProviderName, serviceProviderSettings.ProviderName, StringComparison.InvariantCultureIgnoreCase) || !string.Equals(this.ProviderUrl, serviceProviderSettings.ProviderUrl, StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }
            if (this.IPRanges != null && serviceProviderSettings.IPRanges != null)
            {
                if (this.IPRanges.Count != serviceProviderSettings.IPRanges.Count)
                {
                    return(false);
                }
                using (List <IPRange> .Enumerator enumerator = serviceProviderSettings.IPRanges.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        IPRange ipRangeToCompare = enumerator.Current;
                        if (!this.IPRanges.Any((IPRange ipRange) => ipRange.Equals(ipRangeToCompare)))
                        {
                            return(false);
                        }
                    }
                }
            }
            if ((this.IPRanges == null && serviceProviderSettings.IPRanges != null) || (this.IPRanges != null && serviceProviderSettings.IPRanges == null))
            {
                return(false);
            }
            if (this.Certificates != null && serviceProviderSettings.Certificates != null)
            {
                if (this.Certificates.Count != serviceProviderSettings.Certificates.Count)
                {
                    return(false);
                }
                using (List <TlsCertificate> .Enumerator enumerator2 = serviceProviderSettings.Certificates.GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        TlsCertificate certificateToCompare = enumerator2.Current;
                        if (!this.Certificates.Any((TlsCertificate certificate) => certificate.Equals(certificateToCompare)))
                        {
                            return(false);
                        }
                    }
                }
            }
            return((this.Certificates == null || serviceProviderSettings.Certificates != null) && (this.Certificates != null || serviceProviderSettings.Certificates == null));
        }
Exemple #2
0
        public TlsCertificate(string certificateName)
        {
            SmtpDomainWithSubdomains smtpDomainWithSubdomains = null;
            SmtpX509Identifier       smtpX509Identifier       = null;

            if (!TlsCertificate.InternalTryParse(certificateName, out smtpDomainWithSubdomains, out smtpX509Identifier))
            {
                string s = string.IsNullOrEmpty(certificateName) ? string.Empty : certificateName;
                throw new StrongTypeFormatException(DataStrings.InvalidTlsCertificateName(s), "TlsCertificateName");
            }
            this.tlsCertificateName = (smtpDomainWithSubdomains ?? smtpX509Identifier);
        }
 public bool Matches(TlsCertificate certificate)
 {
     if (certificate == null)
     {
         return(false);
     }
     if (certificate.TlsCertificateName is SmtpDomainWithSubdomains)
     {
         return(this.Matches(certificate.TlsCertificateName as SmtpDomainWithSubdomains));
     }
     return(certificate.TlsCertificateName is SmtpX509Identifier && this.Matches(certificate.TlsCertificateName as SmtpX509Identifier));
 }
Exemple #4
0
        public static bool TryParse(string certificateName, out TlsCertificate tlsCertificate)
        {
            tlsCertificate = null;
            SmtpDomainWithSubdomains fqdn           = null;
            SmtpX509Identifier       x509Identifier = null;

            if (!TlsCertificate.InternalTryParse(certificateName, out fqdn, out x509Identifier))
            {
                return(false);
            }
            tlsCertificate = new TlsCertificate(fqdn, x509Identifier);
            return(true);
        }
        private static bool TryParse(string stringToParse, out ServiceProviderSettings settings, out string error)
        {
            settings = null;
            error    = null;
            if (string.IsNullOrWhiteSpace(stringToParse))
            {
                error = "String passed is null or empty";
                return(false);
            }
            string[] array = stringToParse.Split(new char[]
            {
                ','
            });
            if (array.Length != 4)
            {
                error = "We need a CSV with 4 values - Provider name, Provider url, IP ranges and Certificate names";
                return(false);
            }
            char[] separator = new char[]
            {
                ';'
            };
            List <IPRange>        list  = null;
            List <TlsCertificate> list2 = null;
            bool flag = true;

            if (!string.IsNullOrWhiteSpace(array[2]))
            {
                list = new List <IPRange>();
                string[] array2 = array[2].Split(separator);
                foreach (string text in array2)
                {
                    if (!string.IsNullOrWhiteSpace(text))
                    {
                        IPRange item;
                        if (IPRange.TryParse(text.Trim(), out item))
                        {
                            list.Add(item);
                        }
                        else
                        {
                            error = string.Format("{0}Invalid IP Range {1}.", error, text);
                            flag  = false;
                        }
                    }
                }
            }
            if (!string.IsNullOrWhiteSpace(array[3]))
            {
                list2 = new List <TlsCertificate>();
                string[] array4 = array[3].Split(separator);
                foreach (string text2 in array4)
                {
                    if (!string.IsNullOrWhiteSpace(text2))
                    {
                        TlsCertificate item2;
                        if (TlsCertificate.TryParse(text2.Trim(), out item2))
                        {
                            list2.Add(item2);
                        }
                        else
                        {
                            error = string.Format("{0}Invalid Tls certificate {1}.", error, text2);
                            flag  = false;
                        }
                    }
                }
            }
            if (flag)
            {
                settings = new ServiceProviderSettings(array[0].Trim(), array[1].Trim(), list, list2, stringToParse);
            }
            return(flag);
        }
Exemple #6
0
 public bool Equals(TlsCertificate rhs)
 {
     return(rhs != null && this.tlsCertificateName.Equals(rhs.tlsCertificateName));
 }