コード例 #1
0
        private static bool InternalTryParse(string s, out string subject, out SmtpDomainWithSubdomains commonName, out string issuer, out SmtpDomainWithSubdomains[] domains, out bool invalidDomainError)
        {
            domains = null;
            Match match = Regex.Match(s, "^(<I>([^<]+))?(<S>([^<]+))(<D>(.+))?", RegexOptions.IgnoreCase);

            if (!SmtpX509Identifier.TryParseFromRegexMatch(match, out subject, out commonName, out issuer, out invalidDomainError))
            {
                return(false);
            }
            if (match.Success && !string.IsNullOrEmpty(match.Groups[6].Value))
            {
                string[] array = match.Groups[6].Value.Split(new string[]
                {
                    ";"
                }, StringSplitOptions.RemoveEmptyEntries);
                domains = new SmtpDomainWithSubdomains[array.Length];
                for (int i = 0; i < array.Length; i++)
                {
                    if (!SmtpDomainWithSubdomains.TryParse(array[i], out domains[i]))
                    {
                        invalidDomainError = true;
                        return(false);
                    }
                }
            }
            return(true);
        }
コード例 #2
0
 public TlsCertificate(SmtpDomainWithSubdomains fqdn, SmtpX509Identifier x509Identifier)
 {
     if ((fqdn == null && x509Identifier == null) || (fqdn != null && x509Identifier != null))
     {
         throw new ArgumentException("FQDN and X509Identifier both cannot be null or both have values");
     }
     this.tlsCertificateName = (fqdn ?? x509Identifier);
 }
コード例 #3
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);
        }
コード例 #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);
        }
コード例 #5
0
        public static bool TryParse(string s, out SmtpX509Identifier result)
        {
            result = null;
            string subject;
            SmtpDomainWithSubdomains subjectCN;
            string issuer;
            bool   flag;

            if (!SmtpX509Identifier.InternalTryParse(s, out subject, out subjectCN, out issuer, out flag))
            {
                return(false);
            }
            result = new SmtpX509Identifier(subject, subjectCN, issuer);
            return(true);
        }
コード例 #6
0
        public SmtpX509Identifier(string smtpX509Identifier)
        {
            string certificateSubject;
            SmtpDomainWithSubdomains subjectCommonName;
            string certificateIssuer;
            bool   flag;

            if (!SmtpX509Identifier.InternalTryParse(smtpX509Identifier, out certificateSubject, out subjectCommonName, out certificateIssuer, out flag))
            {
                string s       = string.IsNullOrEmpty(smtpX509Identifier) ? string.Empty : smtpX509Identifier;
                string message = flag ? DataStrings.InvalidDomainInSmtpX509Identifier(s) : DataStrings.InvalidSmtpX509Identifier(s);
                throw new StrongTypeFormatException(message, "SmtpX509Identifier");
            }
            this.CertificateIssuer  = certificateIssuer;
            this.CertificateSubject = certificateSubject;
            this.SubjectCommonName  = subjectCommonName;
        }
コード例 #7
0
        private static bool InternalTryParseFromAD(string s, bool extendedFormat, out SmtpDomainWithSubdomains domain, out SmtpReceiveCapabilities capabilities, out SmtpX509Identifier x509Identifier)
        {
            domain         = null;
            x509Identifier = null;
            capabilities   = SmtpReceiveCapabilities.None;
            if (string.IsNullOrWhiteSpace(s))
            {
                return(false);
            }
            int num = s.IndexOf(':');

            if (num <= 0 || num == s.Length - 1)
            {
                return(false);
            }
            string text = s.Substring(0, num);

            if (!SmtpDomainWithSubdomains.TryParse(text.Trim(), out domain))
            {
                return(false);
            }
            int    num2;
            string stringPart = SmtpReceiveDomainCapabilities.GetStringPart(s, extendedFormat, false, num + 1, out num2);

            if (!SmtpReceiveDomainCapabilities.TryGetCapabilities(stringPart, out capabilities))
            {
                domain = null;
                return(false);
            }
            if (num2 > num && num2 < s.Length)
            {
                int                num3;
                string             stringPart2        = SmtpReceiveDomainCapabilities.GetStringPart(s, extendedFormat, true, num2 + 1, out num3);
                SmtpX509Identifier smtpX509Identifier = null;
                if (SmtpX509Identifier.TryParse(stringPart2, out smtpX509Identifier))
                {
                    domain         = smtpX509Identifier.SubjectCommonName;
                    x509Identifier = smtpX509Identifier;
                }
                else
                {
                    x509Identifier = null;
                }
            }
            return(true);
        }
コード例 #8
0
        private static bool InternalTryParse(string s, bool extendedFormat, out SmtpDomainWithSubdomains domain, out SmtpReceiveCapabilities capabilities, out SmtpX509Identifier x509Identifier)
        {
            domain         = null;
            x509Identifier = null;
            capabilities   = SmtpReceiveCapabilities.None;
            if (string.IsNullOrWhiteSpace(s))
            {
                return(false);
            }
            int    num;
            string stringPart = SmtpReceiveDomainCapabilities.GetStringPart(s, true, true, 0, out num);

            if (num == s.Length - 1 || num == s.Length)
            {
                return(false);
            }
            SmtpX509Identifier smtpX509Identifier = null;

            if (SmtpX509Identifier.TryParse(stringPart, out smtpX509Identifier))
            {
                domain         = smtpX509Identifier.SubjectCommonName;
                x509Identifier = smtpX509Identifier;
            }
            if (domain == null && !SmtpDomainWithSubdomains.TryParse(stringPart.Trim(), out domain))
            {
                return(false);
            }
            int    num2;
            string stringPart2 = SmtpReceiveDomainCapabilities.GetStringPart(s, extendedFormat, false, num + 1, out num2);

            if (!SmtpReceiveDomainCapabilities.TryGetCapabilities(stringPart2, out capabilities))
            {
                domain         = null;
                x509Identifier = null;
                return(false);
            }
            return(true);
        }
コード例 #9
0
 public bool Equals(SmtpX509Identifier rhs)
 {
     return(rhs != null && string.Equals(this.CertificateSubject, rhs.CertificateSubject, StringComparison.OrdinalIgnoreCase) && string.Equals(this.CertificateIssuer, rhs.CertificateIssuer, StringComparison.OrdinalIgnoreCase));
 }
コード例 #10
0
        private static bool InternalTryParse(string s, out string subject, out SmtpDomainWithSubdomains commonName, out string issuer, out bool invalidDomainError)
        {
            Match match = Regex.Match(s, "^(<I>([^<]+))?(<S>(.+))", RegexOptions.IgnoreCase);

            return(SmtpX509Identifier.TryParseFromRegexMatch(match, out subject, out commonName, out issuer, out invalidDomainError));
        }
コード例 #11
0
 private static bool InternalTryParse(string certificateName, out SmtpDomainWithSubdomains fqdn, out SmtpX509Identifier x509Identifier)
 {
     fqdn           = null;
     x509Identifier = null;
     return(SmtpDomainWithSubdomains.TryParse(certificateName, out fqdn) || SmtpX509Identifier.TryParse(certificateName, out x509Identifier));
 }
コード例 #12
0
 public bool Matches(SmtpX509Identifier certificate)
 {
     return(certificate != null && string.Equals(base.CertificateSubject, certificate.CertificateSubject, StringComparison.OrdinalIgnoreCase) && (string.IsNullOrEmpty(base.CertificateIssuer) || string.IsNullOrEmpty(certificate.CertificateIssuer) || string.Equals(base.CertificateIssuer, certificate.CertificateIssuer, StringComparison.OrdinalIgnoreCase)));
 }
コード例 #13
0
 public SmtpReceiveDomainCapabilities(SmtpDomainWithSubdomains domain, SmtpReceiveCapabilities capabilities, SmtpX509Identifier x509Identifier)
 {
     if (domain == null)
     {
         throw new ArgumentNullException("Domain or the Common Name in the X509 Identifier");
     }
     this.domain             = domain;
     this.capabilities       = capabilities;
     this.smtpX509Identifier = x509Identifier;
 }