feat: delete never-activated licenses and bundle deployment verification keys
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-12 14:31:15 +08:00
parent 03a3b9f6a9
commit f4b99e50cd
9 changed files with 221 additions and 12 deletions

View File

@@ -1,7 +1,10 @@
package httpapi
import (
"crypto/sha256"
"embed"
"encoding/hex"
"encoding/pem"
"fmt"
"net/http"
"strings"
@@ -135,15 +138,41 @@ func (a *BusinessAPI) integrationKit(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"data": buildIntegrationKit(language, mode)})
}
func (a *BusinessAPI) deploymentVerificationKeys() (string, error) {
if a.keyring == nil {
return "", fmt.Errorf("keyring unavailable")
}
var b strings.Builder
b.WriteString("## 当前部署验签公钥\n\n以下公钥来自当前服务端已配置的 keyring,不是 test-vectors.json 中的随机测试密钥。请经可信的管理员交付渠道核对公钥指纹后固定到客户端;不得直接信任网络下载或发现接口取得的密钥。轮换时按受控流程更新信任配置。私钥绝不能交付给客户端。\n\n")
fmt.Fprintf(&b, "当前签名 key_id:`%s`。所有非撤销密钥均可用于验证有效期内已签发的证书和租约。\n\n", a.keyring.Current)
for _, key := range a.keyring.Keys {
if key.Revoked {
continue
}
block, _ := pem.Decode([]byte(key.PublicKeyPEM))
if block == nil {
return "", fmt.Errorf("invalid public key")
}
digest := sha256.Sum256(block.Bytes)
fmt.Fprintf(&b, "### key_id: %s\n\nSPKI SHA-256:`%s`\n\n```pem\n%s\n```\n\n", key.KeyID, hex.EncodeToString(digest[:]), strings.TrimSpace(key.PublicKeyPEM))
}
return b.String(), nil
}
func (a *BusinessAPI) downloadIntegrationKit(c *gin.Context) {
language, mode, ok := integrationKitInput(c)
if !ok {
return
}
kit := buildIntegrationKit(language, mode)
keys, err := a.deploymentVerificationKeys()
if err != nil {
apiError(c, 503, "keyring_unavailable", "当前部署未配置可交付的验签公钥")
return
}
var b strings.Builder
fmt.Fprintf(&b, "# 授权平台客户端接入包\n\n协议版本:%s\n\n默认授权平台根地址:%s\n\n", kit.ProtocolVersion, kit.PlatformBaseURL)
fmt.Fprintf(&b, "目标:%s,%s\n\n## 工程提示词\n\n%s\n\n## 接口\n\n", kit.LanguageLabel, kit.ModeLabel, kit.Prompt)
fmt.Fprintf(&b, "目标:%s,%s\n\n%s## 工程提示词\n\n%s\n\n## 接口\n\n", kit.LanguageLabel, kit.ModeLabel, keys, kit.Prompt)
for _, endpoint := range kit.Endpoints {
fmt.Fprintf(&b, "- `%s %s`:%s\n", endpoint.Method, endpoint.Path, endpoint.Purpose)
}