From 5dd7b9ee7ef19b7e35f4b6120429a872ee5ba6de Mon Sep 17 00:00:00 2001 From: liulu Date: Fri, 8 Nov 2024 16:11:23 +0800 Subject: [PATCH] fix --- chsm-common/pom.xml | 6 ----- .../chsm/mapper/SpKeyRecordMapper.java | 2 +- .../chsm/sdf/adapter/BcSdfApiAdaptor.java | 23 +++++++++++++------ .../chsm/sdf/adapter/JnaSdfAdaptor.java | 2 +- .../sunyard/chsm/sdf/model/DeviceInfo.java | 8 +++---- .../chsm/service/impl/AppCertServiceImpl.java | 4 +++- .../com/sunyard/chsm/task/DeviceTask.java | 8 ++++++- 7 files changed, 32 insertions(+), 21 deletions(-) diff --git a/chsm-common/pom.xml b/chsm-common/pom.xml index 4609f70..b148e70 100644 --- a/chsm-common/pom.xml +++ b/chsm-common/pom.xml @@ -49,12 +49,6 @@ net.java.dev.jna jna - - com.google.guava - guava - 33.2.1-jre - - diff --git a/chsm-common/src/main/java/com/sunyard/chsm/mapper/SpKeyRecordMapper.java b/chsm-common/src/main/java/com/sunyard/chsm/mapper/SpKeyRecordMapper.java index 335669e..4a0a7ea 100644 --- a/chsm-common/src/main/java/com/sunyard/chsm/mapper/SpKeyRecordMapper.java +++ b/chsm-common/src/main/java/com/sunyard/chsm/mapper/SpKeyRecordMapper.java @@ -31,7 +31,7 @@ public interface SpKeyRecordMapper extends BaseMapper { return selectOne( new LambdaQueryWrapper() .eq(KeyRecord::getPubIdx, pubKey.substring(0, 8)) - .lt(KeyRecord::getPubKey, pubKey) + .eq(KeyRecord::getPubKey, pubKey) ); } diff --git a/chsm-common/src/main/java/com/sunyard/chsm/sdf/adapter/BcSdfApiAdaptor.java b/chsm-common/src/main/java/com/sunyard/chsm/sdf/adapter/BcSdfApiAdaptor.java index 4ce558a..024134d 100644 --- a/chsm-common/src/main/java/com/sunyard/chsm/sdf/adapter/BcSdfApiAdaptor.java +++ b/chsm-common/src/main/java/com/sunyard/chsm/sdf/adapter/BcSdfApiAdaptor.java @@ -4,13 +4,13 @@ import com.sunyard.chsm.sdf.model.DeviceInfo; import com.sunyard.chsm.sdf.model.EccKey; import com.sunyard.chsm.sdf.model.EccPriKey; import com.sunyard.chsm.sdf.model.EccPubKey; +import com.sunyard.chsm.sdf.util.LangUtils; import com.sunyard.chsm.utils.gm.BCSM2Utils; import lombok.SneakyThrows; import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey; import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey; import org.bouncycastle.math.ec.ECPoint; import org.bouncycastle.util.BigIntegers; -import org.bouncycastle.util.encoders.Hex; import java.math.BigInteger; import java.security.KeyPair; @@ -27,17 +27,19 @@ public class BcSdfApiAdaptor implements SdfApiAdapter { static { deviceInfo = new DeviceInfo(); - deviceInfo.setIssuerName("bouncycastle"); - deviceInfo.setDeviceName("2356621c1a5976bcd6fe2303e5bbf9a9dddc1c1160a521ac61257b04e12b75df"); + deviceInfo.setIssuerName("BC"); + deviceInfo.setDeviceName("BC-3000"); deviceInfo.setDeviceSerial("BC00202411051037"); deviceInfo.setDeviceVersion(1); deviceInfo.setStandardVersion(1); + deviceInfo.setAsymAlgAbility(new long[]{7493065891348563935L, 3000543215027029126L}); + deviceInfo.setSymAlgAbility(2782707529341253316L); + deviceInfo.setHashAlgAbility(7010608454676760881L); } - @Override public String openDevice() { - return "c95a78d9c04a557b7b46dbcb5f36cc665f7446ad73fa75f954220232292f768e"; + return "c95a78d9c04a557b7b46dbcb5f36cc66"; } @Override @@ -47,7 +49,7 @@ public class BcSdfApiAdaptor implements SdfApiAdapter { @Override public String openSession(String deviceHandle) { - return "6975feaffaa35b31b6d4e4555ac403a1ad82f46c3d3ce0ee5005e397d3d07fed"; + return "6975feaffaa35b31b6d4e4555ac403a1"; } @Override @@ -69,11 +71,18 @@ public class BcSdfApiAdaptor implements SdfApiAdapter { @Override public EccPubKey exportEncPublicKeyECC(String sessionHandle, int uiKeyIndex) { - BigInteger d = new BigInteger(1, Hex.decode(deviceInfo.getDeviceName())); + BigInteger d = new BigInteger(1, getD()); ECPoint q = BCSM2Utils.G_POINT.multiply(d).normalize(); return new EccPubKey(256, q.getXCoord().getEncoded(), q.getYCoord().getEncoded()); } + private byte[] getD() { + return LangUtils.merge(LangUtils.toByteArray(deviceInfo.getAsymAlgAbility()[0]), + LangUtils.toByteArray(deviceInfo.getAsymAlgAbility()[1]), + LangUtils.toByteArray(deviceInfo.getSymAlgAbility()), + LangUtils.toByteArray(deviceInfo.getHashAlgAbility())); + } + @SneakyThrows @Override public EccKey generateKeyPairECC(String sessionHandle, String alg, int uiKeyBits) { diff --git a/chsm-common/src/main/java/com/sunyard/chsm/sdf/adapter/JnaSdfAdaptor.java b/chsm-common/src/main/java/com/sunyard/chsm/sdf/adapter/JnaSdfAdaptor.java index 65cfcca..2e68105 100644 --- a/chsm-common/src/main/java/com/sunyard/chsm/sdf/adapter/JnaSdfAdaptor.java +++ b/chsm-common/src/main/java/com/sunyard/chsm/sdf/adapter/JnaSdfAdaptor.java @@ -101,7 +101,7 @@ public abstract class JnaSdfAdaptor implements SdfApiAdapter { deviceInfo.setDeviceSerial(new String(sdfInfo.DeviceSerial)); deviceInfo.setDeviceVersion(sdfInfo.DeviceVersion); deviceInfo.setStandardVersion(sdfInfo.StandardVersion); - deviceInfo.setAsymAlgAbility(sdfInfo.AsymAlgAbility); + deviceInfo.setAsymAlgAbility(new long[]{sdfInfo.AsymAlgAbility[0], sdfInfo.AsymAlgAbility[1]}); deviceInfo.setSymAlgAbility(sdfInfo.SymAlgAbility); deviceInfo.setHashAlgAbility(sdfInfo.HashAlgAbility); deviceInfo.setBufferSize(sdfInfo.BufferSize); diff --git a/chsm-common/src/main/java/com/sunyard/chsm/sdf/model/DeviceInfo.java b/chsm-common/src/main/java/com/sunyard/chsm/sdf/model/DeviceInfo.java index 1233084..72b1891 100755 --- a/chsm-common/src/main/java/com/sunyard/chsm/sdf/model/DeviceInfo.java +++ b/chsm-common/src/main/java/com/sunyard/chsm/sdf/model/DeviceInfo.java @@ -15,9 +15,9 @@ public class DeviceInfo { private String deviceSerial; private int deviceVersion; private int standardVersion; - private int[] asymAlgAbility; - private int symAlgAbility; - private int hashAlgAbility; - private int bufferSize; + private long[] asymAlgAbility; + private long symAlgAbility; + private long hashAlgAbility; + private long bufferSize; } diff --git a/chsm-web-manage/src/main/java/com/sunyard/chsm/service/impl/AppCertServiceImpl.java b/chsm-web-manage/src/main/java/com/sunyard/chsm/service/impl/AppCertServiceImpl.java index 1a9b436..a546ece 100644 --- a/chsm-web-manage/src/main/java/com/sunyard/chsm/service/impl/AppCertServiceImpl.java +++ b/chsm-web-manage/src/main/java/com/sunyard/chsm/service/impl/AppCertServiceImpl.java @@ -2,6 +2,7 @@ package com.sunyard.chsm.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.sunyard.chsm.dto.CertDTO; import com.sunyard.chsm.enums.KeyCategory; @@ -215,6 +216,7 @@ public class AppCertServiceImpl implements AppCertService { private AppCert genCert(X509Certificate x509Cert, Long appId, KeyRecord record, CertDTO.ImportCert importCert) { AppCert cert = new AppCert(); + cert.setId(IdWorker.getId()); cert.setApplicationId(appId); cert.setKeyId(record.getKeyId()); cert.setKeyRecordId(record.getId()); @@ -238,7 +240,7 @@ public class AppCertServiceImpl implements AppCertService { private static Pair decryptEnvelopedKey(byte[] d, byte[] envelopedKey) throws Exception { - ECPrivateKeyParameters pri = BCECUtils.createECPrivateKeyParameters(Hex.decode(d)); + ECPrivateKeyParameters pri = BCECUtils.createECPrivateKeyParameters(d); ASN1Sequence seq = DLSequence.getInstance(envelopedKey); AlgorithmIdentifier oid = AlgorithmIdentifier.getInstance(seq.getObjectAt(0)); diff --git a/chsm-web-manage/src/main/java/com/sunyard/chsm/task/DeviceTask.java b/chsm-web-manage/src/main/java/com/sunyard/chsm/task/DeviceTask.java index 84b77f0..5e2a787 100644 --- a/chsm-web-manage/src/main/java/com/sunyard/chsm/task/DeviceTask.java +++ b/chsm-web-manage/src/main/java/com/sunyard/chsm/task/DeviceTask.java @@ -2,6 +2,7 @@ package com.sunyard.chsm.task; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.sun.jna.Platform; import com.sunyard.chsm.mapper.SpDeviceMapper; import com.sunyard.chsm.model.entity.Device; import com.sunyard.chsm.sdf.adapter.SdfApiAdapter; @@ -88,6 +89,11 @@ public class DeviceTask implements InitializingBean { @Override public void afterPropertiesSet() throws Exception { - threadPoolTaskScheduler.scheduleWithFixedDelay(this::checkDeviceStatus, Duration.ofMinutes(5L)); + if (Platform.isLinux() || Platform.isWindows()) { + threadPoolTaskScheduler.scheduleWithFixedDelay(this::checkDeviceStatus, Duration.ofMinutes(5L)); + } else { + log.warn("操作系统: {} 不支持启动检查设备状态定时任务", System.getProperty("os.name")); + } + } }