fix
This commit is contained in:
parent
e4af8ecbf4
commit
5dd7b9ee7e
@ -49,12 +49,6 @@
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>33.2.1-jre</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
@ -31,7 +31,7 @@ public interface SpKeyRecordMapper extends BaseMapper<KeyRecord> {
|
||||
return selectOne(
|
||||
new LambdaQueryWrapper<KeyRecord>()
|
||||
.eq(KeyRecord::getPubIdx, pubKey.substring(0, 8))
|
||||
.lt(KeyRecord::getPubKey, pubKey)
|
||||
.eq(KeyRecord::getPubKey, pubKey)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
@ -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<String, byte[]> 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));
|
||||
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user