feat: deliver deployment verification keys and instance trust config
Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
32
backend/internal/httpapi/integration_trust.go
Normal file
32
backend/internal/httpapi/integration_trust.go
Normal file
@@ -0,0 +1,32 @@
|
||||
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}})
|
||||
}
|
||||
Reference in New Issue
Block a user