feat(license): 接入授权平台客户端门禁(license-v2/lease-v2)并烧入交付版信任根

This commit is contained in:
lianjianwei2024
2026-10-10 18:05:04 +08:00
parent 6de1370ce5
commit d3a805ede0
25 changed files with 3123 additions and 25 deletions

View File

@@ -11,6 +11,7 @@
产物:release/PricingReview-Windows-x64/(目录,可直接拷贝)与同名 .zip。
"""
import io
import json
import os
import pathlib
import shutil
@@ -103,6 +104,41 @@ def write_gbk(path, text):
f.write(text)
# ---- 交付版授权信任根(决策 31,P0-1 烧根)----
# 生产公钥维护在 app/server/license_client/pinned_keys.json(运维交付后追加),
# 构建时把公钥/平台地址/强制开关烧进包内 license_build_config.py —— 客户侧改
# pinned_keys.json / data\license\config.json / 环境变量都不再影响交付版门禁。
RELEASE_API_BASE = "https://license.yihuiyong.cn"
RELEASE_PRODUCT_ID = None # 上线后填平台分配的产品 ID(int),None=不校验产品线
def write_license_build_config(app_target):
lic_pkg = app_target / "server" / "license_client"
pinned_file = lic_pkg / "pinned_keys.json"
keys = []
if pinned_file.is_file():
try:
keys = json.loads(pinned_file.read_text(encoding="utf-8")).get("pinned_keys") or []
except Exception as e:
raise RuntimeError("pinned_keys.json 解析失败:%s" % e)
if not keys:
log("⚠⚠⚠ pinned_keys.json 为空:这个包交付出去客户将无法激活(fail closed)!")
log("⚠⚠⚠ 上线前必须把运维交付的生产公钥填进 app/server/license_client/pinned_keys.json 再构建。")
conf = lic_pkg / "license_build_config.py"
conf.write_text(
"# 自动生成于构建期(build_portable.py)——交付版信任根,客户侧不可改、不可覆盖。\n"
"# 本文件存在时,license 门禁只信这里:data/license/config.json、LICENSE_API_BASE_URL、\n"
"# pinned_keys.json 在交付环境一律不参与(防自建信任根绕过授权)。\n"
"API_BASE = %r\n"
"ENFORCE = True\n"
"PRODUCT_ID = %r\n"
"SELFHEAL_SECONDS = 300\n"
"PINNED_KEYS = %s\n" % (RELEASE_API_BASE, RELEASE_PRODUCT_ID,
json.dumps(keys, ensure_ascii=False, indent=4)),
encoding="utf-8")
log("授权信任根已烧入 → server/license_client/license_build_config.py(公钥 %d 把)" % len(keys))
def main():
if os.name != "nt":
raise RuntimeError("请在 Windows x64 上构建")
@@ -136,6 +172,7 @@ def main():
app_target = PACKAGE / "造价审核" / "app"
shutil.copytree(APP, app_target,
ignore=shutil.ignore_patterns("__pycache__", "*.pyc"), dirs_exist_ok=True)
write_license_build_config(app_target)
data = PACKAGE / "造价审核" / "data"
for folder in ("", "uploads", "attachments", "inquiry"):
(data / folder).mkdir(parents=True, exist_ok=True)