激活服务添加ip和端口

This commit is contained in:
xydkj 2026-05-25 16:03:10 +08:00
parent f24d3d7e65
commit 0c61c06e9f
7 changed files with 41 additions and 29 deletions

View File

@ -3,8 +3,8 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.cisd</groupId>
<artifactId>openapi-sdk</artifactId>
<version>1.0-SNAPSHOT</version>
<artifactId>netsignapi</artifactId>
<version>1.0.0</version>
<properties>
<java.version>1.8</java.version>

View File

@ -37,6 +37,7 @@ public class PBCAgent2G{
public String rawSign(byte[] origBytes, String dn) {
System.out.println("调用rawSign, dn:" + dn);
String sessionId = UUID.randomUUID().toString().replace("-", "");
if (origBytes == null) {
@ -112,7 +113,7 @@ public class PBCAgent2G{
public boolean rawVerify(byte[] origBytes, String certStr, String dn) {
System.out.println("调用rawVerify, dn:" + dn);
String sessionId = UUID.randomUUID().toString().replace("-", "");
if (origBytes == null) {
@ -192,7 +193,7 @@ public class PBCAgent2G{
public String dettachedSign(byte[] origBytes, String dn) {
System.out.println("调用dettachedSign, dn:" + dn);
String sessionId = UUID.randomUUID().toString().replace("-", "");
if (origBytes == null) {

View File

@ -1,4 +1,4 @@
sign-server.baseUrl=http://127.0.0.1:8080
sign-server.baseUrl=http://127.0.0.1:8080/api/v1/openapi
sign-server.apiKey=key
sign-server.rawSignPath=/rawSign

View File

@ -1,15 +0,0 @@
package com.cisd.tms.modules.mk.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "tms.mk.activate")
public class MasterKeyActivateProperties {
//todo 后续添加到配置文件
private String platformUrl = "http://127.0.0.1:8080/device/active";
public String getPlatformUrl() { return platformUrl; }
public void setPlatformUrl(String platformUrl) { this.platformUrl = platformUrl; }
}

View File

@ -13,4 +13,10 @@ public class MasterKeyActivateRequest {
private String credential;
@Schema(description = "设备激活码", example = "1234567")
private String activationCode;
@Schema(description = "网络地址", example = "192.168.10.100")
private String ipAddress;
@Schema(description = "端口号", example = "80")
private Integer port;
}

View File

@ -9,7 +9,6 @@ import com.cisd.tms.modules.device.dto.DeviceInfoResponse;
import com.cisd.tms.modules.device.entity.DeviceSoftwareVersionEntity;
import com.cisd.tms.modules.device.repository.DeviceSoftwareVersionRepository;
import com.cisd.tms.modules.device.service.DeviceService;
import com.cisd.tms.modules.mk.config.MasterKeyActivateProperties;
import com.cisd.tms.modules.mk.dto.MasterKeyActivateInfoResponse;
import com.cisd.tms.modules.mk.dto.MasterKeyActivateRequest;
import com.cisd.tms.modules.mk.entity.MasterKeyActivateEntity;
@ -29,10 +28,12 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpTimeoutException;
import java.nio.charset.StandardCharsets;
import java.security.PublicKey;
import java.security.SecureRandom;
@ -47,15 +48,15 @@ import java.util.Optional;
public class MasterKeyActivateServiceImpl implements MasterKeyActivateService {
private static final String DEVICE_DIR = "/home/tms/device";
public static final String SIGN_FILE = DEVICE_DIR + "/dev.sign";
private static final String SIGN_FILE = DEVICE_DIR + "/dev.sign";
private static final String ACTIVATION_PUBLIC_KEY_FILE = DEVICE_DIR + "/dev.active.pub";
private static final String ACTIVATION_PLATFORM_URL = "/device/active";
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
private final PcieCryptoService pcieCryptoService;
private final MasterKeyActivateProperties masterKeyActivateProperties;
private final DeviceSoftwareVersionRepository deviceSoftwareVersionRepository;
private final DeviceProfileProperties deviceProfileProperties;
private final DeviceService deviceService;
@ -139,6 +140,23 @@ public class MasterKeyActivateServiceImpl implements MasterKeyActivateService {
throw new IllegalArgumentException("设备激活码不能为空");
}
if (masterKeyActivateRequest.getIpAddress() == null){
throw new IllegalArgumentException("IP地址不能为空");
}
String ipAddress = masterKeyActivateRequest.getIpAddress().trim();
Integer portValue = masterKeyActivateRequest.getPort();
if (portValue == null || portValue < 1 || portValue > 65535) {
throw new IllegalArgumentException("非法端口: " + portValue);
}
String port = String.valueOf(portValue);
String url = "http://" + ipAddress + ":" + port + ACTIVATION_PLATFORM_URL;
try {
DeviceFingerprintService deviceFingerprintService = new DeviceFingerprintService();
DeviceFingerprint deviceFingerprint = deviceFingerprintService.getDeviceFingerprint();
@ -175,10 +193,9 @@ public class MasterKeyActivateServiceImpl implements MasterKeyActivateService {
request.setHash(hash);
String json = OBJECT_MAPPER.writeValueAsString(request);
//todo 抛异常
// System.out.print(json);
HttpRequest httpRequest = HttpRequest.newBuilder()
.uri(URI.create(masterKeyActivateProperties.getPlatformUrl()))
.uri(URI.create(url))
.header("Content-Type", "application/json;charset=UTF-8")
.header("Accept", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json, StandardCharsets.UTF_8))
@ -204,9 +221,15 @@ public class MasterKeyActivateServiceImpl implements MasterKeyActivateService {
masterKeyActivateRepository.update(masterKeyActivateEntity);
writeFile(ACTIVATION_PUBLIC_KEY_FILE, deviceActivationPublicKey.getBytes(StandardCharsets.UTF_8));
} else {
throw new Exception(result.getMsg());
throw new RuntimeException(result.getMsg());
}
} catch (ConnectException | HttpTimeoutException e) {
masterKeyActivateEntity.setActivationStatus(false);
masterKeyActivateRepository.update(masterKeyActivateEntity);
throw new BizException(ErrorCode.BIZ_ERROR.getCode(), "连接激活平台失败");
} catch (Exception e) {
masterKeyActivateEntity.setActivationStatus(false);
masterKeyActivateRepository.update(masterKeyActivateEntity);

View File

@ -334,9 +334,6 @@ tms:
old-pin-base64: ${TMS_MK_INIT_IDENTIFY_OLD_PIN_BASE64:NjY2NjY2}
# SDFE_InitIdentify 新 PINBase64 编码);主密钥初始化接口会读取该值。
new-pin-base64: ${TMS_MK_INIT_IDENTIFY_NEW_PIN_BASE64:NjY2NjY2}
activate:
# 激活服务平台路径
platform-url: ${TMS_MK_ACTIVATE_PLATFORM_URL:http://172.16.18.195:8170/device/active}
security:
# 内部接口鉴权 token前后端内部调用需一致
internal-token: ${TMS_INTERNAL_TOKEN:change-me-internal-token}