deriveMasterKeyFromSeed 从 OTP seed 派生 master key 使用与 OTPProvider 相同的方法,确保一致性
(seed []byte, opts *otp.InitOptions)
| 130 | // deriveMasterKeyFromSeed 从 OTP seed 派生 master key |
| 131 | // 使用与 OTPProvider 相同的方法,确保一致性 |
| 132 | func deriveMasterKeyFromSeed(seed []byte, opts *otp.InitOptions) ([]byte, error) { |
| 133 | // 从配置中读取 master key salt |
| 134 | cfg, err := otp.LoadConfig(otp.ConfigPath()) |
| 135 | if err != nil { |
| 136 | return nil, fmt.Errorf("加载配置失败: %w", err) |
| 137 | } |
| 138 | |
| 139 | masterKeySalt, err := base64.StdEncoding.DecodeString(cfg.MasterKeySalt) |
| 140 | if err != nil { |
| 141 | return nil, fmt.Errorf("解码 master key salt 失败: %w", err) |
| 142 | } |
| 143 | |
| 144 | // 使用 HKDF 派生 master key |
| 145 | masterKey := crypt.HKDF(seed, masterKeySalt, []byte("fssh-master-key-v1"), 32) |
| 146 | return masterKey, nil |
| 147 | } |
no test coverage detected