feat(license): 支持授权文件导入并固定生产公钥指纹校验
This commit is contained in:
@@ -74,9 +74,11 @@ def rfc3339(dt):
|
||||
# ------------------------------------------------------------- keyring 管理
|
||||
|
||||
def build_keyring(entries):
|
||||
"""[{key_id, public_key_pem, revoked}] → {key_id: {"key": pub, "revoked": bool}}。
|
||||
"""[{key_id, public_key_pem, revoked, spki_sha256?}] → {key_id: {"key": pub, "revoked": bool}}。
|
||||
|
||||
pinned 文件本身配置错(非 P-256 / 解不开)要立刻暴露,不能静默当不可信。
|
||||
pinned 文件本身配置错(非 P-256 / 解不开 / 指纹不符)要立刻暴露,不能静默当不可信。
|
||||
spki_sha256(受控交付时随公钥附来的 SPKI DER SHA-256 十六进制)选填:
|
||||
给了就实算比对,防 PEM 在拷贝/转存中被损坏(yhy-license-trust v1 口径)。
|
||||
"""
|
||||
ring = {}
|
||||
for e in entries or []:
|
||||
@@ -86,6 +88,14 @@ def build_keyring(entries):
|
||||
key = serialization.load_pem_public_key(pem.encode("utf-8"))
|
||||
if not isinstance(key, ec.EllipticCurvePublicKey) or not isinstance(key.curve, ec.SECP256R1):
|
||||
raise VerifyError("key_id=%s 的公钥不是 EC P-256" % kid)
|
||||
want = e.get("spki_sha256")
|
||||
if want:
|
||||
der = key.public_bytes(serialization.Encoding.DER,
|
||||
serialization.PublicFormat.SubjectPublicKeyInfo)
|
||||
got = hashlib.sha256(der).hexdigest()
|
||||
if got != str(want).strip().lower():
|
||||
raise VerifyError("key_id=%s 公钥指纹不符(spki_sha256 与 PEM 不匹配,"
|
||||
"疑似拷贝损坏或调包)" % kid)
|
||||
ring[kid] = {"key": key, "revoked": bool(e.get("revoked", False))}
|
||||
return ring
|
||||
|
||||
|
||||
Reference in New Issue
Block a user