fix: 设备激活

This commit is contained in:
xydkj 2026-05-18 16:17:09 +08:00
parent 16f2fefec8
commit a3abd8a98f
2 changed files with 25 additions and 1 deletions

View File

@ -106,9 +106,12 @@ public class WebMvcConfig implements WebMvcConfigurer {
"/api/v1/auth/ukey-login/randoms",
"/api/v1/auth/captcha",
"/api/v1/auth/super-admin/ukeys/issue-sign",
"/api/v1/device/network/**"
"/api/v1/device/network/**",
"/api/v1/masterKey/activate",
"/api/v1/masterKey/activate/info"
);
registry.addInterceptor(internalApiReplayInterceptor)
.addPathPatterns("/api/**");

View File

@ -233,6 +233,18 @@ public class LmkServiceImpl implements LmkService {
if (pcieCryptoService.checkLmk()) {
throw new BizException(ErrorCode.CONFLICT.getCode(), "主密钥已存在,拒绝重新初始化");
}
MasterKeyActivateEntity masterKeyActivateEntity = masterKeyActivateRepository.find().
orElseThrow(() -> new BizException(ErrorCode.VALIDATE_FAILED.getCode(), "激活记录不存在"));
boolean everInitialized = masterKeyActivateEntity.getEverInitialized();
boolean activationStatus = masterKeyActivateEntity.getActivationStatus();
if (!everInitialized) {
if (!activationStatus) {
throw new BizException(ErrorCode.FORBIDDEN.getCode(), "需要先进行激活");
}
}
// 进入恢复流程后旧的备份轮次缓存不再可信避免和恢复后的新密钥体系混用
clearCachedBackupRound();
// 调用方可以任意顺序传入两份包这里统一按 packetIndex 排序并校验必须是 12 两包
@ -259,6 +271,15 @@ public class LmkServiceImpl implements LmkService {
MasterKeyStateResult result = new MasterKeyStateResult();
result.setStatus(true);
result.setSeedMac(Hex.toHexString(recoveryResult.getLmkSeedMac()));
try {
masterKeyActivateEntity.setActivationStatus(false);
masterKeyActivateEntity.setEverInitialized(false);
masterKeyActivateRepository.update(masterKeyActivateEntity);
} catch (RuntimeException ex) {
log.error("主密钥恢复后更新激活记录失败", ex);
}
return result;
}