it
This commit is contained in:
@@ -478,57 +478,56 @@ class CrtShProvider(BaseProvider):
|
||||
common_name = cert_data.get('common_name', '')
|
||||
if common_name:
|
||||
cleaned_cn = self._clean_domain_name(common_name)
|
||||
if cleaned_cn and _is_valid_domain(cleaned_cn):
|
||||
domains.add(cleaned_cn)
|
||||
if cleaned_cn:
|
||||
domains.update(cleaned_cn)
|
||||
|
||||
# Extract from name_value field (contains SANs)
|
||||
name_value = cert_data.get('name_value', '')
|
||||
if name_value:
|
||||
# Split by newlines and clean each domain
|
||||
for line in name_value.split('\n'):
|
||||
cleaned_domain = self._clean_domain_name(line.strip())
|
||||
if cleaned_domain and _is_valid_domain(cleaned_domain):
|
||||
domains.add(cleaned_domain)
|
||||
cleaned_domains = self._clean_domain_name(line.strip())
|
||||
if cleaned_domains:
|
||||
domains.update(cleaned_domains)
|
||||
|
||||
return domains
|
||||
|
||||
def _clean_domain_name(self, domain_name: str) -> str:
|
||||
def _clean_domain_name(self, domain_name: str) -> List[str]:
|
||||
"""
|
||||
Clean and normalize domain name from certificate data.
|
||||
|
||||
Args:
|
||||
domain_name: Raw domain name from certificate
|
||||
|
||||
Returns:
|
||||
Cleaned domain name or empty string if invalid
|
||||
Now returns a list to handle wildcards correctly.
|
||||
"""
|
||||
if not domain_name:
|
||||
return ""
|
||||
|
||||
# Remove common prefixes and clean up
|
||||
return []
|
||||
|
||||
domain = domain_name.strip().lower()
|
||||
|
||||
|
||||
# Remove protocol if present
|
||||
if domain.startswith(('http://', 'https://')):
|
||||
domain = domain.split('://', 1)[1]
|
||||
|
||||
|
||||
# Remove path if present
|
||||
if '/' in domain:
|
||||
domain = domain.split('/', 1)[0]
|
||||
|
||||
|
||||
# Remove port if present
|
||||
if ':' in domain and not domain.count(':') > 1: # Avoid breaking IPv6
|
||||
domain = domain.split(':', 1)[0]
|
||||
|
||||
|
||||
# Handle wildcard domains
|
||||
cleaned_domains = []
|
||||
if domain.startswith('*.'):
|
||||
domain = domain[2:]
|
||||
|
||||
# Remove any remaining invalid characters
|
||||
domain = re.sub(r'[^\w\-\.]', '', domain)
|
||||
|
||||
# Ensure it's not empty and doesn't start/end with dots or hyphens
|
||||
if domain and not domain.startswith(('.', '-')) and not domain.endswith(('.', '-')):
|
||||
return domain
|
||||
|
||||
return ""
|
||||
# Add both the wildcard and the base domain
|
||||
cleaned_domains.append(domain)
|
||||
cleaned_domains.append(domain[2:])
|
||||
else:
|
||||
cleaned_domains.append(domain)
|
||||
|
||||
# Remove any remaining invalid characters and validate
|
||||
final_domains = []
|
||||
for d in cleaned_domains:
|
||||
d = re.sub(r'[^\w\-\.]', '', d)
|
||||
if d and not d.startswith(('.', '-')) and not d.endswith(('.', '-')):
|
||||
final_domains.append(d)
|
||||
|
||||
return [d for d in final_domains if _is_valid_domain(d)]
|
||||
Reference in New Issue
Block a user