feat(sdk): 应用心跳 CRL 并实现离线强制校验点
sdk-ci / test (push) Successful in 1m50s
sdk-release / release (push) Failing after 40s
sdk-release / cleanup (push) Successful in 7s

- 心跳响应携带的 CRL 验签后应用,版本单调防回滚,命中当前 jti 立即转 REVOKED
- 新增 WithValidationServer + pol.forced_check:文件模式到期强制在线校验,验签 verdict 并检查时效,失败转 EXPIRED
- 未配置校验源时保持完全离线兼容(告警跳过)
- 新增 CRL 应用/回滚防护/强制校验/伪造 verdict 测试
This commit is contained in:
iceking2nd committed 2026-11-14 20:55:20 +08:00
1 parent 834882e044
commit 2c1eeae070
6 files changed
+577 -20

No files matched your search

+16 -3
View File
@@ -178,7 +178,7 @@ func (c *Client) heartbeatOnce(ctx context.Context) error {
body := map[string]any{
"entitlements_hash": c.currentHash(),
"agent": "sdk-go/" + sdkVersion,
"crl_version": int64(0),
"crl_version": c.crlVersion.Load(),
}
var resp heartbeatResp
err := c.postJSON(ctx, "/v1/heartbeat", token, body, &resp)
@@ -187,6 +187,14 @@ func (c *Client) heartbeatOnce(ctx context.Context) error {
return err
}
// 先应用 CRL:命中当前 jti 直接转 REVOKED(docs/design/04-crypto.md §4)
if resp.CRL != "" {
c.applyCRL(resp.CRL)
} else if resp.CRLVersion > c.crlVersion.Load() {
// 服务端版本更新但未携带内容:记录版本,避免重复请求
c.crlVersion.Store(resp.CRLVersion)
}
s := c.snap.Load()
if resp.Terminate {
// 吊销:终态(07 §5 状态机)
@@ -258,13 +266,18 @@ func (c *Client) currentHash() string {
return license.EntitlementsHash(s.payload.Ent)
}
// postJSON 发送 JSON POST 并解码响应;网络错误/非 2xx 均返回错误。
// postJSON 发送 JSON POST 到远程/代理基址。
func (c *Client) postJSON(ctx context.Context, path, bearer string, body any, out any) error {
return c.postJSONTo(ctx, c.opts.remoteServer, path, bearer, body, out)
}
// postJSONTo 发送 JSON POST 到指定基址(强制校验点复用)。
func (c *Client) postJSONTo(ctx context.Context, base, path, bearer string, body any, out any) error {
b, err := json.Marshal(body)
if err != nil {
return err
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.opts.remoteServer+path, bytes.NewReader(b))
req, err := http.NewRequestWithContext(ctx, http.MethodPost, base+path, bytes.NewReader(b))
if err != nil {
return err
}