mirror of
https://github.com/chatmail/relay.git
synced 2026-05-18 14:08:57 +00:00
config: make IPv4-only relays use self-signed TLS certs
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import ipaddress
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import iniconfig
|
import iniconfig
|
||||||
@@ -79,7 +80,7 @@ class Config:
|
|||||||
)
|
)
|
||||||
self.tls_cert_mode = "external"
|
self.tls_cert_mode = "external"
|
||||||
self.tls_cert_path, self.tls_key_path = parts
|
self.tls_cert_path, self.tls_key_path = parts
|
||||||
elif self.mail_domain.startswith("_"):
|
elif self.mail_domain.startswith("_") or is_valid_ipv4(params["mail_domain"]):
|
||||||
self.tls_cert_mode = "self"
|
self.tls_cert_mode = "self"
|
||||||
self.tls_cert_path = "/etc/ssl/certs/mailserver.pem"
|
self.tls_cert_path = "/etc/ssl/certs/mailserver.pem"
|
||||||
self.tls_key_path = "/etc/ssl/private/mailserver.key"
|
self.tls_key_path = "/etc/ssl/private/mailserver.key"
|
||||||
@@ -175,3 +176,12 @@ def get_default_config_content(mail_domain, **overrides):
|
|||||||
lines.append(line)
|
lines.append(line)
|
||||||
content = "\n".join(lines)
|
content = "\n".join(lines)
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
|
def is_valid_ipv4(address: str) -> bool:
|
||||||
|
"""Check if a mail_domain is an IPv4 address."""
|
||||||
|
try:
|
||||||
|
ipaddress.IPv4Address(address)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user