feat: 完善服务端工程化、发布流程和自动化测试
This commit is contained in:
@@ -21,11 +21,15 @@ def load_manifest_private_key():
|
||||
|
||||
|
||||
def canonical_manifest_bytes(manifest_obj: dict) -> bytes:
|
||||
# 签名之前必须先规范化 JSON:固定字段顺序、去掉空格、排除 signature 字段。
|
||||
# 否则同一份 Manifest 在不同环境下序列化结果不同,会导致客户端验签失败。
|
||||
copy = {k: manifest_obj[k] for k in manifest_obj if k != "signature"}
|
||||
return json.dumps(copy, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8")
|
||||
|
||||
|
||||
def sign_manifest(manifest_obj: dict) -> str:
|
||||
# 服务端只保存私钥,客户端只分发公钥。
|
||||
# 客户端能验证 Manifest 确实由服务端签发,但无法伪造新的签名。
|
||||
json_text = canonical_manifest_bytes(manifest_obj)
|
||||
private_key = load_manifest_private_key()
|
||||
signature = private_key.sign(json_text, padding.PKCS1v15(), hashes.SHA256())
|
||||
|
||||
Reference in New Issue
Block a user