Merge remote-tracking branch 'origin/V1.00' into V1.00
This commit is contained in:
@@ -216,8 +216,7 @@ public class OperationAuditService {
|
||||
if (!AuditStatus.PENDING.equals(existLog.getAuditStatus())) {
|
||||
throw new BizException(ErrorCode.BIZ_ERROR.getCode(), "该日志已审计,禁止重复操作");
|
||||
}
|
||||
String d = buildSignValueSource(existLog, req.getAuditResult());
|
||||
System.out.println(d);
|
||||
|
||||
String auditSign = trim(req.getAuditSign());
|
||||
|
||||
if (auditSign.isEmpty()){
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+29
-6
@@ -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);
|
||||
|
||||
@@ -334,9 +334,6 @@ tms:
|
||||
old-pin-base64: ${TMS_MK_INIT_IDENTIFY_OLD_PIN_BASE64:NjY2NjY2}
|
||||
# SDFE_InitIdentify 新 PIN(Base64 编码);主密钥初始化接口会读取该值。
|
||||
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}
|
||||
|
||||
Reference in New Issue
Block a user