fix: make client integration kit self-contained and clarify capabilities
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 15:22:09 +08:00
parent d42067746c
commit 5353a4a128
15 changed files with 198 additions and 32 deletions

View File

@@ -31,7 +31,7 @@ func languageRequirements(language string) string {
"go": "Go:使用 crypto/ecdsa.VerifyASN1、crypto/x509、sha256 和 base64.RawStdEncoding;所有网络调用支持 context、超时及取消;sync.Mutex 与跨进程文件锁保护状态;go test 覆盖行为。",
"java": "Java:使用 JCA SHA256withECDSA、KeyFactory EC、X509EncodedKeySpec 与 HttpClient;Base64 解码 DER;受控调度器与原子文件替换;JUnit 覆盖行为。",
"dotnet": ".NET:使用 ECDsa.VerifyData 并显式选择 DSASignatureFormat.Rfc3279DerSequence,不使用默认 P1363;HttpClient、CancellationToken、受控 IHostedService 与可注入受保护存储;xUnit 覆盖行为。",
"nodejs": "Node.js:使用 node:crypto 的 verify('sha256', canonicalBytes, publicKey, DER),参照 client/verify.mjs;使用安全整数解析 ID;node:test 覆盖行为;不得将服务端 SDK 打包进浏览器。",
"nodejs": "Node.js:使用 node:crypto 的 verify('sha256', canonicalBytes, publicKey, DER);license-v2/lease-v2 使用 protocol.md 的 canonical bytes,update-v1 使用解码后的原始 JSON bytes;使用安全整数解析 ID;node:test 覆盖行为;不得将服务端 SDK 打包进浏览器。",
}[language]
}
@@ -85,12 +85,26 @@ func (a *BusinessAPI) downloadIntegrationArchive(c *gin.Context) {
return
}
files := map[string][]byte{
"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"),
"README.md": []byte(`# 客户端接入参考包
阅读 protocol.md、upgrade.md 与 openapi.json。Python/Node SDK 提供 update-v1 验签、TTL、revision 检查、完整 HTTP 200 下载及长度/摘要校验;不支持 Range 续传。Installer 仅为应用回调,不替换程序、不重启、不健康检查或回滚,不执行任意命令。LicenseClient、canRun、可信时间、持久化 StateStore 与本地强制升级评估由应用实现,升级检查不能替代 license-v2/lease-v2 授权。
Python 3.11+、Node.js 20+。在 client 目录运行:
python -m pip install -r requirements.txt
python -m unittest test_update_sdk -v
node test-update-sdk.mjs
测试使用本地密钥和模拟网络,不证明生产安装可用。test-vectors.json 仅包含 license-v2/lease-v2;update-v1 测试由测试脚本生成本地签名。
prompt.md 可提供给实现工程师。verification-keys.md 为当前部署公钥,须通过可信渠道核对指纹;test-vectors.json 的随机测试密钥绝不能导入生产。
`),
"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"),
"client/test_update_sdk.py": mustReadClientAsset("client/test_update_sdk.py"),
"client/test-update-sdk.mjs": mustReadClientAsset("client/test-update-sdk.mjs"),
"client/requirements.txt": mustReadClientAsset("client/requirements.txt"),
}
for _, name := range []string{"protocol.md", "upgrade.md", "openapi.json"} {
content, err := integrationAsset(name)
@@ -102,7 +116,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", "client/update_sdk.py", "client/update-sdk.mjs"} {
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", "client/test_update_sdk.py", "client/test-update-sdk.mjs", "client/requirements.txt"} {
file, err := archive.Create(name)
if err == nil {
_, err = file.Write(files[name])