fix: 拒绝过短密钥,并把对外端口只留在本机
This commit is contained in:
@@ -95,6 +95,26 @@ def ensure_admin_seed() -> None:
|
||||
db.commit()
|
||||
|
||||
|
||||
def ensure_key_check() -> None:
|
||||
"""密钥太短、是占位文字,或解不开已有数据时,拒绝启动。"""
|
||||
from euniv.crypto import decrypt_secret, encrypt_secret, require_secret
|
||||
from euniv.db import SessionLocal
|
||||
|
||||
require_secret()
|
||||
with SessionLocal() as db:
|
||||
row = load_config(db)
|
||||
if not row.key_check:
|
||||
row.key_check = encrypt_secret("euniv-key-check")
|
||||
db.commit()
|
||||
return
|
||||
try:
|
||||
matched = decrypt_secret(row.key_check) == "euniv-key-check"
|
||||
except Exception as exc:
|
||||
raise RuntimeError("EUNIV_SECRET_KEY 与已有数据不匹配,已停止启动") from exc
|
||||
if not matched:
|
||||
raise RuntimeError("EUNIV_SECRET_KEY 与已有数据不匹配,已停止启动")
|
||||
|
||||
|
||||
def load_admin_identity() -> None:
|
||||
"""从设置表重新加载管理员用户名和密码密文。"""
|
||||
from euniv.db import SessionLocal
|
||||
|
||||
Reference in New Issue
Block a user