Include local IP in certificate SAN for LAN access
This commit is contained in:
+13
-2
@@ -103,7 +103,18 @@ def generate_cert():
|
||||
return str(cert_file), str(key_file)
|
||||
|
||||
CERT_DIR.mkdir(exist_ok=True)
|
||||
print('[HTTPS Bridge] 🔐 首次运行,生成自签名证书(有效期 10 年)...')
|
||||
|
||||
# 收集本机所有需要覆盖的 IP
|
||||
local_ip = _get_local_ip()
|
||||
san_ips = {ipaddress.IPv4Address('127.0.0.1')}
|
||||
if local_ip != '127.0.0.1':
|
||||
try:
|
||||
san_ips.add(ipaddress.IPv4Address(local_ip))
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
print(f'[HTTPS Bridge] 🔐 首次运行,生成自签名证书(有效期 10 年)...')
|
||||
print(f' 覆盖地址: localhost, 127.0.0.1' + (f', {local_ip}' if local_ip != '127.0.0.1' else ''))
|
||||
|
||||
key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
|
||||
|
||||
@@ -121,7 +132,7 @@ def generate_cert():
|
||||
.add_extension(
|
||||
x509.SubjectAlternativeName([
|
||||
x509.DNSName('localhost'),
|
||||
x509.IPAddress(ipaddress.IPv4Address('127.0.0.1')),
|
||||
*[x509.IPAddress(ip) for ip in san_ips],
|
||||
]),
|
||||
critical=False,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user