This commit is contained in:
liulu
2024-12-10 17:21:17 +08:00
parent 4febd0520d
commit 63fce073dd
15 changed files with 490 additions and 44 deletions
@@ -167,13 +167,14 @@ public class TmkService {
}
Optional.ofNullable(hs).ifPresent(sdfApi::closeSession);
Optional.ofNullable(hd).ifPresent(sdfApi::closeDevice);
res.setSdfApiAdapter(sdfApi);
log.debug("==========> end check device : {}", res);
return res;
}
public void checkSoftDeviceTmk() {
if (!isTmkInit() || !enableSoftDevice()) {
if (!isTmkInit() || !isEnableSoftDevice()) {
return;
}
byte[] softTmk = getSoftDeviceEncTmk();
@@ -203,7 +204,7 @@ public class TmkService {
if (Objects.nonNull(device)) {
return device;
}
if (enableSoftDevice()) {
if (isEnableSoftDevice()) {
device = new Device();
device.setManufacturerModel(BouncyCastleProvider.PROVIDER_NAME);
device.setEncKeyIdx(1);
@@ -219,11 +220,16 @@ public class TmkService {
return null;
}
private boolean isTmkInit() {
public boolean isTmkInit() {
ParamConf conf = paramConfMapper.selectByKey(ParamConfKeyConstant.TMK_INIT);
return conf != null && String.valueOf(true).equals(conf.getValue());
}
public boolean isEnableSoftDevice() {
ParamConf conf = paramConfMapper.selectByKey(ParamConfKeyConstant.ENABLE_SOFT_DEVICE);
return conf != null && String.valueOf(true).equals(conf.getValue());
}
private void updateTmkInit(boolean value) {
ParamConf conf = paramConfMapper.selectByKey(ParamConfKeyConstant.TMK_INIT);
if (conf == null) {
@@ -238,15 +244,10 @@ public class TmkService {
}
}
private boolean enableSoftDevice() {
ParamConf conf = paramConfMapper.selectByKey(ParamConfKeyConstant.ENABLE_SOFT_DEVICE);
return conf != null && String.valueOf(true).equals(conf.getValue());
}
private byte[] getSoftDeviceEncTmk() {
boolean tmkInit = isTmkInit();
Assert.isTrue(tmkInit, "主密钥未初始化");
boolean enabled = enableSoftDevice();
boolean enabled = isEnableSoftDevice();
Assert.isTrue(enabled, "未启用软设备");
ParamConf conf = paramConfMapper.selectByKey(ParamConfKeyConstant.SOFT_ENC_TMK);
if (conf == null || ObjectUtils.isEmpty(conf.getValue())) {