feat: add signed client upgrade policies
Some checks failed
Check / delivery-static (push) Has been cancelled
Check / api (push) Has been cancelled
Check / web (push) Has been cancelled

Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
2026-10-13 07:28:25 +08:00
parent 5780b27e30
commit d42067746c
25 changed files with 2154 additions and 171 deletions

View File

@@ -17,6 +17,14 @@ import (
"github.com/gin-gonic/gin"
)
func mustReadClientAsset(name string) []byte {
content, err := integrationAssets.ReadFile("integration_assets/" + name)
if err != nil {
panic(err)
}
return content
}
func languageRequirements(language string) string {
return map[string]string{
"python": "Python:使用 cryptography 的 ECDSA(SHA256) 和 httpx;base64 补齐填充后解码 DER;pytest 覆盖验签与状态机。密钥库通过可注入接口实现,禁止以硬编码加密密钥充当保护。",
@@ -77,10 +85,12 @@ func (a *BusinessAPI) downloadIntegrationArchive(c *gin.Context) {
return
}
files := map[string][]byte{
"README.md": []byte("# 客户端接入包\n\n阅读 protocol.md、upgrade.md 与 openapi.json,将 prompt.md 提供给实现工程师。verification-keys.md 包含当前部署验签公钥,经可信渠道核对指纹后预置;test-vectors.json 使用随机测试密钥,绝不能导入生产。upgrade.md 说明当前可用下载能力和自动升级待建设的契约;当前支持实例门户版本查询与授权下载,尚无签名升级清单;按 upgrade.md 实现 UpdateClient 与安装适配器。此包提供文档和实现提示词,不是已完成生产验收的 SDK。\n"),
"verification-keys.md": []byte(keys),
"prompt.md": []byte(kit.Prompt),
"test-vectors.json": vectors,
"README.md": []byte("# 客户端接入包\n\n阅读 protocol.md、upgrade.md 与 openapi.json。client/update_sdk.py 和 client/update-sdk.mjs 是可运行的参考 SDK,覆盖 update-v1 验签、TTL、策略回滚、禁止重定向下载、长度/摘要校验和注入式安装器;不执行任意命令。prompt.md 可提供给实现工程师。verification-keys.md 包含当前部署验签公钥,经可信渠道核对指纹后预置;test-vectors.json 使用随机测试密钥,绝不能导入生产。\n"),
"verification-keys.md": []byte(keys),
"prompt.md": []byte(kit.Prompt),
"test-vectors.json": vectors,
"client/update_sdk.py": mustReadClientAsset("client/update_sdk.py"),
"client/update-sdk.mjs": mustReadClientAsset("client/update-sdk.mjs"),
}
for _, name := range []string{"protocol.md", "upgrade.md", "openapi.json"} {
content, err := integrationAsset(name)
@@ -92,7 +102,7 @@ func (a *BusinessAPI) downloadIntegrationArchive(c *gin.Context) {
}
var buffer bytes.Buffer
archive := zip.NewWriter(&buffer)
for _, name := range []string{"README.md", "protocol.md", "upgrade.md", "openapi.json", "prompt.md", "verification-keys.md", "test-vectors.json"} {
for _, name := range []string{"README.md", "protocol.md", "upgrade.md", "openapi.json", "prompt.md", "verification-keys.md", "test-vectors.json", "client/update_sdk.py", "client/update-sdk.mjs"} {
file, err := archive.Create(name)
if err == nil {
_, err = file.Write(files[name])