Пример #1
0
 protected static bool TryParseFromRegexMatch(Match match, out string subject, out SmtpDomainWithSubdomains commonName, out string issuer, out bool invalidDomainError)
 {
     subject            = null;
     issuer             = null;
     commonName         = null;
     invalidDomainError = false;
     if (match.Success)
     {
         Match match2 = Regex.Match(match.Groups[4].Value, "CN=(.*?)($|,)", RegexOptions.IgnoreCase);
         if (!match2.Success)
         {
             return(false);
         }
         if (!SmtpDomainWithSubdomains.TryParse(match2.Groups[1].Value, out commonName))
         {
             invalidDomainError = true;
             return(false);
         }
         try
         {
             subject = new X500DistinguishedName(match.Groups[4].Value, X500DistinguishedNameFlags.None).Format(false);
             issuer  = new X500DistinguishedName(match.Groups[2].Value, X500DistinguishedNameFlags.None).Format(false);
             return(true);
         }
         catch (CryptographicException)
         {
             return(false);
         }
         return(false);
     }
     return(false);
 }
        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);
        }
Пример #3
0
 public SmtpX509Identifier(string subject, SmtpDomainWithSubdomains subjectCN, string issuer)
 {
     ArgumentValidator.ThrowIfNull("subject", subject);
     ArgumentValidator.ThrowIfNull("subjectCN", subjectCN);
     this.CertificateSubject = subject;
     this.SubjectCommonName  = subjectCN;
     this.CertificateIssuer  = issuer;
 }
Пример #4
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);
 }
        public bool Matches(SmtpDomainWithSubdomains fqdn)
        {
            if (fqdn == null)
            {
                return(false);
            }
            string fqdnString = fqdn.ToString();

            return(base.SubjectCommonName.Match(fqdnString) >= 0 || fqdn.Match(base.SubjectCommonName.ToString()) >= 0 || (this.CertificateDomains != null && this.CertificateDomains.Any((SmtpDomainWithSubdomains domain) => domain.Match(fqdnString) >= 0 || fqdn.Match(domain.ToString()) >= 0)));
        }
        public override PropertyConstraintViolationError Validate(object value, PropertyDefinition propertyDefinition, IPropertyBag propertyBag)
        {
            SmtpDomainWithSubdomains smtpDomainWithSubdomains = value as SmtpDomainWithSubdomains;

            if (smtpDomainWithSubdomains != null && smtpDomainWithSubdomains.IsStar)
            {
                return(new PropertyConstraintViolationError(DataStrings.StarDomainNotAllowed(propertyDefinition.Name), propertyDefinition, value, this));
            }
            return(null);
        }
 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;
 }
Пример #8
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);
        }
Пример #9
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 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);
        }
        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);
        }
Пример #12
0
 private AddressSpace(SmtpDomainWithSubdomains obj)
 {
     this.type = "smtp";
     this.cost = 1;
     this.smtpDomainWithSubdomains = obj;
 }
Пример #13
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));
        }
Пример #14
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));
 }
Пример #15
0
 public SmtpX509IdentifierEx(string subject, SmtpDomainWithSubdomains subjectCN, string issuer, SmtpDomainWithSubdomains[] domains) : base(subject, subjectCN, issuer)
 {
     this.CertificateDomains = domains;
 }