refactor(crypto): 拆分签发与验证,新增 sign 包
- crypto 仅保留验证:验签、信任链、CRL/verdict、指纹 - 新增 sign 包:SignToken/SignBundle、密钥生成、私钥加解密 - TrustChain 移除 SignBundle 方法,改由 Bundle() 导出快照, 避免反射可达性把 SignToken 链入纯验证二进制 - Bundle 快照单次读锁,修复旧 SignBundle 递归读锁死锁窗口 - 新增 golden token 与 go tool nm 符号级回归测试
This commit is contained in:
21 files changed
+461
-168
No files matched your search
+38
@@ -0,0 +1,38 @@
|
||||
package sign
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
// KeyPair 是一对 Ed25519 密钥。Signing Key 携带 kid;Root Key 的 kid 为空
|
||||
// (root 不签发 license,只签 trust bundle)。
|
||||
type KeyPair struct {
|
||||
Kid string
|
||||
Pub ed25519.PublicKey
|
||||
Priv ed25519.PrivateKey
|
||||
}
|
||||
|
||||
// GenerateSigningKey 生成签发密钥。kid 为私钥随机 8 字节的 hex(16 字符),
|
||||
// 不派生自公钥(防指纹追踪,docs/design/04-crypto.md §1.2)。
|
||||
func GenerateSigningKey() (*KeyPair, error) {
|
||||
pub, priv, err := ed25519.GenerateKey(rand.Reader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var kidRaw [8]byte
|
||||
if _, err := rand.Read(kidRaw[:]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &KeyPair{Kid: hex.EncodeToString(kidRaw[:]), Pub: pub, Priv: priv}, nil
|
||||
}
|
||||
|
||||
// GenerateRootKey 生成根密钥(离线保管,只用于签 trust bundle)。
|
||||
func GenerateRootKey() (*KeyPair, error) {
|
||||
pub, priv, err := ed25519.GenerateKey(rand.Reader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &KeyPair{Pub: pub, Priv: priv}, nil
|
||||
}
|
||||
Reference in new issue
Block a user