fix(sdk): 修复审计确认的 SDK-01~SDK-06/SDK-08 缺陷
sdk-ci / test (push) Successful in 2m17s
sdk-release / release (push) Successful in 57s
sdk-release / cleanup (push) Successful in 5s

- SDK-01:时钟回拨补偿只做一次(水位线跟随回拨后的时钟),避免 trustedNow 重复膨胀
- SDK-02:代理请求显式传 proxyAddr,消除运行期改写共享 opts 的数据竞争
- SDK-03:Decode 增加 256KB 结构层上限(与服务端 license 字节流上限对齐)
- SDK-04:修正 license key 熵注释为 80bit
- SDK-05:兼容服务端 version=0 空 CRL(携带吊销条目仍拒绝)
- SDK-06:Validate 状态显式枚举,UNKNOWN/空值给出明确 fail-closed 错误
- SDK-08:缓存密钥混合 0600 随机 secret(旧 HKDF(指纹) 缓存读取后自动迁移)
- SDK-07:README 记录 proxycert/Proxy 公钥旁路分发的设计信任假设
- 新增对应回归测试,go test -race -shuffle=on 全绿
This commit is contained in:
iceking2nd committed 2026-11-24 21:14:55 +08:00
1 parent cce993ac0a
commit 20945777af
13 files changed
+440 -58

No files matched your search

+33 -6
View File
@@ -14,12 +14,13 @@ import (
)
type validationServer struct {
mu sync.Mutex
server *httptest.Server
valid bool
calls int
lastCRLV int64
clock *fakeClock
mu sync.Mutex
server *httptest.Server
valid bool
stateOverride string // 非空时覆盖返回的 state(SDK-06 测试)
calls int
lastCRLV int64
clock *fakeClock
}
func newValidationServer(t *testing.T, e *testEnv, clock *fakeClock) *validationServer {
@@ -38,6 +39,9 @@ func newValidationServer(t *testing.T, e *testEnv, clock *fakeClock) *validation
if !vs.valid {
state = "REVOKED"
}
if vs.stateOverride != "" {
state = vs.stateOverride
}
vs.mu.Unlock()
verdictPayload, _ := json.Marshal(map[string]any{
@@ -173,3 +177,26 @@ func TestValidationServer_TrimTrailingSlash(t *testing.T) {
t.Fatal(got)
}
}
// TestValidation_UnknownStateFailsClosed SDK-06:UNKNOWN 表示服务端无法确认,
// 错误信息应明确区分(行为仍 fail-closed)。
func TestValidation_UnknownStateFailsClosed(t *testing.T) {
e := newEnv(t)
clock := &fakeClock{now: e.now}
vs := newValidationServer(t, e, clock)
vs.stateOverride = validateStateUnknown
path := writeFileLicense(t, e, 0)
client, err := New(WithLicenseFile(path), WithProductKey("prod_test"),
WithTrustChain(e.trust()), WithClock(clock), WithValidationServer(vs.server.URL))
if err != nil {
t.Fatal(err)
}
defer client.Close()
if err := client.Start(context.Background()); err != nil {
t.Fatal(err)
}
err = client.validateOnline(context.Background())
if err == nil || !strings.Contains(err.Error(), validateStateUnknown) {
t.Fatalf("UNKNOWN 应明确报错: %v", err)
}
}