This commit is contained in:
liulu
2025-01-03 15:32:50 +08:00
parent ad679f48fd
commit f84de95e9a
3 changed files with 21 additions and 5 deletions
@@ -26,6 +26,7 @@ import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -47,6 +48,7 @@ public class TmkService {
private final SpDeviceMapper spDeviceMapper;
private final ParamConfMapper paramConfMapper;
@Transactional
public void initTmk() {
boolean tmkInit = isTmkInit();
Assert.isTrue(!tmkInit, "主密钥已经初始化");
@@ -149,6 +151,7 @@ public class TmkService {
return Pair.of(device.getId(), CodecUtils.encodeBase64(publicKey.getEncoded()));
}
@Transactional
public void importTmk(Long deviceId, String encTmk) {
boolean tmkInit = isTmkInit();
Assert.isTrue(!tmkInit, "主密钥已经初始化");
@@ -323,7 +326,7 @@ public class TmkService {
private boolean enableSoftDevice;
private byte[] softEncTmk;
public synchronized boolean isTmkInit() {
public synchronized boolean isTmkInitCached() {
if (tmkInit) {
return true;
}
@@ -332,6 +335,11 @@ public class TmkService {
return tmkInit;
}
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());
@@ -356,10 +364,10 @@ public class TmkService {
check.setValue(CodecUtils.encodeHex(hash));
check.setKey(ParamConfKeyConstant.TMK_CHECK_VALUE);
check.setCreatTime(LocalDateTime.now());
paramConfMapper.insert(conf);
paramConfMapper.insert(check);
} else {
check.setValue(CodecUtils.encodeHex(hash));
paramConfMapper.updateById(conf);
paramConfMapper.updateById(check);
}
}