激活服务添加ip和端口
This commit is contained in:
parent
f24d3d7e65
commit
0c61c06e9f
@ -3,8 +3,8 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.cisd</groupId>
|
<groupId>com.cisd</groupId>
|
||||||
<artifactId>openapi-sdk</artifactId>
|
<artifactId>netsignapi</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0.0</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
|
|||||||
@ -37,6 +37,7 @@ public class PBCAgent2G{
|
|||||||
|
|
||||||
public String rawSign(byte[] origBytes, String dn) {
|
public String rawSign(byte[] origBytes, String dn) {
|
||||||
|
|
||||||
|
System.out.println("调用rawSign, dn:" + dn);
|
||||||
String sessionId = UUID.randomUUID().toString().replace("-", "");
|
String sessionId = UUID.randomUUID().toString().replace("-", "");
|
||||||
|
|
||||||
if (origBytes == null) {
|
if (origBytes == null) {
|
||||||
@ -112,7 +113,7 @@ public class PBCAgent2G{
|
|||||||
|
|
||||||
|
|
||||||
public boolean rawVerify(byte[] origBytes, String certStr, String dn) {
|
public boolean rawVerify(byte[] origBytes, String certStr, String dn) {
|
||||||
|
System.out.println("调用rawVerify, dn:" + dn);
|
||||||
String sessionId = UUID.randomUUID().toString().replace("-", "");
|
String sessionId = UUID.randomUUID().toString().replace("-", "");
|
||||||
|
|
||||||
if (origBytes == null) {
|
if (origBytes == null) {
|
||||||
@ -192,7 +193,7 @@ public class PBCAgent2G{
|
|||||||
|
|
||||||
|
|
||||||
public String dettachedSign(byte[] origBytes, String dn) {
|
public String dettachedSign(byte[] origBytes, String dn) {
|
||||||
|
System.out.println("调用dettachedSign, dn:" + dn);
|
||||||
String sessionId = UUID.randomUUID().toString().replace("-", "");
|
String sessionId = UUID.randomUUID().toString().replace("-", "");
|
||||||
|
|
||||||
if (origBytes == null) {
|
if (origBytes == null) {
|
||||||
|
|||||||
@ -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.apiKey=key
|
||||||
|
|
||||||
sign-server.rawSignPath=/rawSign
|
sign-server.rawSignPath=/rawSign
|
||||||
|
|||||||
@ -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;
|
private String credential;
|
||||||
@Schema(description = "设备激活码", example = "1234567")
|
@Schema(description = "设备激活码", example = "1234567")
|
||||||
private String activationCode;
|
private String activationCode;
|
||||||
|
|
||||||
|
@Schema(description = "网络地址", example = "192.168.10.100")
|
||||||
|
private String ipAddress;
|
||||||
|
|
||||||
|
@Schema(description = "端口号", example = "80")
|
||||||
|
private Integer port;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.entity.DeviceSoftwareVersionEntity;
|
||||||
import com.cisd.tms.modules.device.repository.DeviceSoftwareVersionRepository;
|
import com.cisd.tms.modules.device.repository.DeviceSoftwareVersionRepository;
|
||||||
import com.cisd.tms.modules.device.service.DeviceService;
|
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.MasterKeyActivateInfoResponse;
|
||||||
import com.cisd.tms.modules.mk.dto.MasterKeyActivateRequest;
|
import com.cisd.tms.modules.mk.dto.MasterKeyActivateRequest;
|
||||||
import com.cisd.tms.modules.mk.entity.MasterKeyActivateEntity;
|
import com.cisd.tms.modules.mk.entity.MasterKeyActivateEntity;
|
||||||
@ -29,10 +28,12 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.net.ConnectException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.http.HttpClient;
|
import java.net.http.HttpClient;
|
||||||
import java.net.http.HttpRequest;
|
import java.net.http.HttpRequest;
|
||||||
import java.net.http.HttpResponse;
|
import java.net.http.HttpResponse;
|
||||||
|
import java.net.http.HttpTimeoutException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
@ -47,15 +48,15 @@ import java.util.Optional;
|
|||||||
public class MasterKeyActivateServiceImpl implements MasterKeyActivateService {
|
public class MasterKeyActivateServiceImpl implements MasterKeyActivateService {
|
||||||
|
|
||||||
private static final String DEVICE_DIR = "/home/tms/device";
|
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_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 ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||||
|
|
||||||
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
|
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
|
||||||
|
|
||||||
private final PcieCryptoService pcieCryptoService;
|
private final PcieCryptoService pcieCryptoService;
|
||||||
private final MasterKeyActivateProperties masterKeyActivateProperties;
|
|
||||||
private final DeviceSoftwareVersionRepository deviceSoftwareVersionRepository;
|
private final DeviceSoftwareVersionRepository deviceSoftwareVersionRepository;
|
||||||
private final DeviceProfileProperties deviceProfileProperties;
|
private final DeviceProfileProperties deviceProfileProperties;
|
||||||
private final DeviceService deviceService;
|
private final DeviceService deviceService;
|
||||||
@ -139,6 +140,23 @@ public class MasterKeyActivateServiceImpl implements MasterKeyActivateService {
|
|||||||
throw new IllegalArgumentException("设备激活码不能为空");
|
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 {
|
try {
|
||||||
DeviceFingerprintService deviceFingerprintService = new DeviceFingerprintService();
|
DeviceFingerprintService deviceFingerprintService = new DeviceFingerprintService();
|
||||||
DeviceFingerprint deviceFingerprint = deviceFingerprintService.getDeviceFingerprint();
|
DeviceFingerprint deviceFingerprint = deviceFingerprintService.getDeviceFingerprint();
|
||||||
@ -175,10 +193,9 @@ public class MasterKeyActivateServiceImpl implements MasterKeyActivateService {
|
|||||||
request.setHash(hash);
|
request.setHash(hash);
|
||||||
|
|
||||||
String json = OBJECT_MAPPER.writeValueAsString(request);
|
String json = OBJECT_MAPPER.writeValueAsString(request);
|
||||||
//todo 抛异常
|
|
||||||
// System.out.print(json);
|
// System.out.print(json);
|
||||||
HttpRequest httpRequest = HttpRequest.newBuilder()
|
HttpRequest httpRequest = HttpRequest.newBuilder()
|
||||||
.uri(URI.create(masterKeyActivateProperties.getPlatformUrl()))
|
.uri(URI.create(url))
|
||||||
.header("Content-Type", "application/json;charset=UTF-8")
|
.header("Content-Type", "application/json;charset=UTF-8")
|
||||||
.header("Accept", "application/json")
|
.header("Accept", "application/json")
|
||||||
.POST(HttpRequest.BodyPublishers.ofString(json, StandardCharsets.UTF_8))
|
.POST(HttpRequest.BodyPublishers.ofString(json, StandardCharsets.UTF_8))
|
||||||
@ -204,9 +221,15 @@ public class MasterKeyActivateServiceImpl implements MasterKeyActivateService {
|
|||||||
masterKeyActivateRepository.update(masterKeyActivateEntity);
|
masterKeyActivateRepository.update(masterKeyActivateEntity);
|
||||||
writeFile(ACTIVATION_PUBLIC_KEY_FILE, deviceActivationPublicKey.getBytes(StandardCharsets.UTF_8));
|
writeFile(ACTIVATION_PUBLIC_KEY_FILE, deviceActivationPublicKey.getBytes(StandardCharsets.UTF_8));
|
||||||
} else {
|
} 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) {
|
} catch (Exception e) {
|
||||||
masterKeyActivateEntity.setActivationStatus(false);
|
masterKeyActivateEntity.setActivationStatus(false);
|
||||||
masterKeyActivateRepository.update(masterKeyActivateEntity);
|
masterKeyActivateRepository.update(masterKeyActivateEntity);
|
||||||
|
|||||||
@ -334,9 +334,6 @@ tms:
|
|||||||
old-pin-base64: ${TMS_MK_INIT_IDENTIFY_OLD_PIN_BASE64:NjY2NjY2}
|
old-pin-base64: ${TMS_MK_INIT_IDENTIFY_OLD_PIN_BASE64:NjY2NjY2}
|
||||||
# SDFE_InitIdentify 新 PIN(Base64 编码);主密钥初始化接口会读取该值。
|
# SDFE_InitIdentify 新 PIN(Base64 编码);主密钥初始化接口会读取该值。
|
||||||
new-pin-base64: ${TMS_MK_INIT_IDENTIFY_NEW_PIN_BASE64:NjY2NjY2}
|
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:
|
security:
|
||||||
# 内部接口鉴权 token(前后端内部调用需一致)。
|
# 内部接口鉴权 token(前后端内部调用需一致)。
|
||||||
internal-token: ${TMS_INTERNAL_TOKEN:change-me-internal-token}
|
internal-token: ${TMS_INTERNAL_TOKEN:change-me-internal-token}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user