def test_domains_valid(self): self.assertTrue(ValidationTools.validate_domainname("bar.de")) self.assertTrue(ValidationTools.validate_domainname("y")) self.assertTrue(ValidationTools.validate_domainname("d.y")) self.assertTrue(ValidationTools.validate_domainname("a.d.y")) self.assertTrue(ValidationTools.validate_domainname("a.d.y")) self.assertTrue(ValidationTools.validate_domainname("bar.co.uk"))
def test_domains_invalid(self): self.assertFalse(ValidationTools.validate_domainname("")) self.assertFalse(ValidationTools.validate_domainname(".")) self.assertFalse(ValidationTools.validate_domainname(".foo")) self.assertFalse(ValidationTools.validate_domainname("foo.")) self.assertFalse(ValidationTools.validate_domainname("foo bar"))
def _validate_dNSName(self): self._report("Enc_DER_Struct_GenName_DNS_Unexpected", "contains unexpected domain name \"%s\"." % (self._subject.str_value), commonness=Commonness.UNUSUAL) if self._subject.str_value == " ": return self._report( "Enc_DER_Struct_GenName_DNS_OnlyWhitespace", "got invalid DNS name \" \" (space character).", commonness=Commonness.HIGHLY_UNUSUAL, compatibility=Compatibility.STANDARDS_DEVIATION) if self._validator.allow_dnsname_wildcard_matches: (result, label) = ValidationTools.validate_domainname_template( self._subject.str_value) if result != ValidationTools.DomainnameTemplateValidationResult.Valid: if result == ValidationTools.DomainnameTemplateValidationResult.InvalidCharacter: return self._report( "Enc_DER_Struct_GenName_DNS_Malformed", "has invalid domain name \"%s\", error at label \"%s\"." % (self._subject.str_value, label), commonness=Commonness.HIGHLY_UNUSUAL, compatibility=Compatibility.STANDARDS_DEVIATION) elif result == ValidationTools.DomainnameTemplateValidationResult.FullWildcardNotLeftmost: return self._report( "Enc_DER_Struct_GenName_DNS_Wildcard_NotLeftmost", "has invalid domain name \"%s\". Full-label wildcard appears not as leftmost element." % (self._subject.str_value), commonness=Commonness.UNUSUAL, compatibility=Compatibility.STANDARDS_DEVIATION) elif result == ValidationTools.DomainnameTemplateValidationResult.MoreThanOneWildcard: return self._report( "Enc_DER_Struct_GenName_DNS_Wildcard_MulitpleWildcards", "has invalid domain name \"%s\". More than one wildcard label present." % (self._subject.str_value), commonness=Commonness.UNUSUAL, compatibility=Compatibility.STANDARDS_DEVIATION) elif result == ValidationTools.DomainnameTemplateValidationResult.WildcardInInternationalDomain: return self._report( "Enc_DER_Struct_GenName_DNS_Wildcard_InternationalLabel", "has invalid domain name \"%s\". Wildcard in international domain label \"%s\"." % (self._subject.str_value, label), commonness=Commonness.HIGHLY_UNUSUAL, compatibility=Compatibility.STANDARDS_DEVIATION) else: raise NotImplementedError(result) if "*" in self._subject.str_value: # Wildcard match labels = self._subject.str_value.split(".") if len(labels) <= 2: self._report( "Enc_DER_Struct_GenName_DNS_Wildcard_BroadMatch", "has wildcard value \"%s\", which is an extremely broad domain match." % (self._subject.str_value), commonness=Commonness.HIGHLY_UNUSUAL) else: if "*" in self._subject.str_value: # Not permitted but wildcard present self._report( "Enc_DER_Struct_GenName_DNS_Wildcard_NotPermitted", "has wildcard value \"%s\", which is not permitted for this type." % (self._subject.str_value), commonness=Commonness.HIGHLY_UNUSUAL) if not "." in self._subject.str_value: self._report( "Enc_DER_Struct_GenName_DNS_SingleLabel", "contains only single label \"%s\", which is highly unusual." % (self._subject.str_value), commonness=Commonness.HIGHLY_UNUSUAL) validation_name = self._subject.str_value if self._validator.allow_dnsname_wildcard_matches: validation_name = validation_name.replace("*", "a") result = ValidationTools.validate_domainname(validation_name) if not result: self._report( "Enc_DER_Struct_GenName_DNS_Malformed", "has invalid domain name \"%s\" (wildcard matches %s)." % (self._subject.str_value, "permitted" if self._validator.allow_dnsname_wildcard_matches else "forbidden"), commonness=Commonness.HIGHLY_UNUSUAL, compatibility=Compatibility.STANDARDS_DEVIATION)