Files
yhy-mager/backend/internal/httpapi/integration_trust.go
xiewenjun 03a3b9f6a9
Some checks failed
Check / delivery-static (push) Has been cancelled
Check / api (push) Has been cancelled
Check / web (push) Has been cancelled
feat: deliver deployment verification keys and instance trust config
Co-Authored-By: Craft Agent <agents-noreply@craft.do>
2026-10-12 12:20:53 +08:00

33 lines
1.0 KiB
Go

package httpapi
import (
"crypto/sha256"
"crypto/x509"
"encoding/hex"
"encoding/pem"
"github.com/gin-gonic/gin"
)
func (a *BusinessAPI) integrationTrust(c *gin.Context) {
c.Header("Cache-Control", "no-store")
if a.keyring == nil {
apiError(c, 503, "keyring_unavailable", "当前部署未配置 v2 公钥环,请配置 LICENSE_KEYRING_FILE 及匹配签名私钥")
return
}
keys := make([]gin.H, 0, len(a.keyring.Keys))
for _, key := range a.keyring.Keys {
block, _ := pem.Decode([]byte(key.PublicKeyPEM))
if block == nil {
apiError(c, 503, "keyring_unavailable", "公钥格式无效")
return
}
if _, err := x509.ParsePKIXPublicKey(block.Bytes); err != nil {
apiError(c, 503, "keyring_unavailable", "公钥格式无效")
return
}
digest := sha256.Sum256(block.Bytes)
keys = append(keys, gin.H{"key_id": key.KeyID, "public_key_pem": key.PublicKeyPEM, "revoked": key.Revoked, "spki_sha256": hex.EncodeToString(digest[:])})
}
c.JSON(200, gin.H{"data": gin.H{"current_key_id": a.keyring.Current, "keys": keys}})
}