软加密加入但暂时隐藏

加入rtc的相关接口
bug修改
软加密采用本地计算值的方式,不再调用外部dll
采用cpu和系统uuid作为唯一标识
lanzhou-qilin
LAPTOP-S9HJSOEB\昊天 3 years ago
parent ad42458550
commit bea013d7fe

@ -0,0 +1 @@
BFEBFBFF000B06710025_38BC_21C3_A29D.

@ -0,0 +1,30 @@
package com.zhehekeji.common.encryptor;
import java.lang.reflect.Field;
public class Encryptor {
public static String encryptStr(String str){
long ulMacTmp = 0;
for (int i = 0; i < str.length(); i++) {
ulMacTmp = ulMacTmp << 4;
char cStr = str.charAt(i);
if (cStr >= '0' && cStr <= '9') {
ulMacTmp += (long)(str.charAt(i) - '0');
} else if (cStr >= 'a' && cStr <= 'f') {
ulMacTmp += (long)(str.charAt(i) - 'a' + 10);
} else if (cStr >= 'A' && cStr <= 'F') {
ulMacTmp += (long)(str.charAt(i) - 'A' + 10);
} else {
ulMacTmp += 0;
}
}
str = String.valueOf(ulMacTmp);
return str;
}
public static void main(String[] args)
{
String noEncrypt = "BFEBFBFF000B06710025_38BC_21C3_A29D.";
String encrypt = Encryptor.encryptStr(noEncrypt);
System.out.println(encrypt);
}
}

@ -0,0 +1,149 @@
package com.zhehekeji.filter.aspect;
import com.alibaba.fastjson.JSONObject;
import com.sun.management.OperatingSystemMXBean;
import com.zhehekeji.common.encryptor.Encryptor;
import com.zhehekeji.common.util.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.time.LocalDateTime;
import java.util.Enumeration;
import java.util.Scanner;
@Slf4j
public class LPLicense {
private static LocalDateTime lastUpdate = null;
private static String lic_str = null;
private static String lic_path = "./lp.lic";
private static String key_path = "./lp.key";
private static String CPU_INFO = null;
private static String DEVICE_INFO = null;
/**
*
*/
public static void createLicKeyIfNotExist() {
File file = new File(key_path);
if (!file.exists()) {
String cpu = getCpuInfo();
CPU_INFO = cpu;
String device = getDeviceId();
DEVICE_INFO = device;
FileUtil.save(cpu + device, key_path);
}
}
private static String getCpuInfo() {
String os = System.getProperty("os.name").toLowerCase();
String command = "";
if (os.contains("win")) {
command = "wmic cpu get ProcessorId";
} else if (os.contains("nix") || os.contains("nux") || os.contains("mac")) {
command = "dmidecode -t processor | grep ID";
} else {
return "Unsupported operating system";
}
try {
Process process = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder output = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
output.append(line.trim());
}
reader.close();
if (os.contains("win")) {
return output.substring(output.indexOf("Id") + 1).trim();
} else if (os.contains("nix") || os.contains("nux") || os.contains("mac")) {
return output.toString().replace("ID:", "").trim();
} else {
return "Unknown CPU ID";
}
} catch (IOException e) {
e.printStackTrace();
return "Error retrieving CPU ID";
}
}
public static void main(String[] args) {
System.out.println(getDeviceId());
}
private static String getDeviceId() {
String deviceId = null;
try {
Process process = Runtime.getRuntime().exec("sudo dmidecode -s system-uuid");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
deviceId = reader.readLine();
reader.close();
process.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
return deviceId != null ? deviceId : "Unknown";
}
private static boolean isVirtualNetworkInterface(NetworkInterface networkInterface) throws SocketException {
return networkInterface.isVirtual() || networkInterface.getName().contains("Virtual");
}
private static String getDiskInfo() {
try {
Process process = Runtime.getRuntime().exec(
new String[]{"lshw", "-c", "network", "|", "grep serial", "|", "head -n 1"});
process.getOutputStream().close();
Scanner sc = new Scanner(process.getInputStream());
String property = sc.next();
String disk = sc.next();
return disk;
} catch (IOException e) {
log.error("Get DISK error:{}", e);
return null;
}
}
public static String getLic() {
//每小时读取一次lic文件
if (lastUpdate == null || LocalDateTime.now().toLocalTime().getHour() != lastUpdate.toLocalTime().getHour()) {
lastUpdate = LocalDateTime.now();
lic_str = FileUtil.getText(lic_path);
CPU_INFO = getCpuInfo();
DEVICE_INFO = getDeviceId();
}
return lic_str;
}
public static boolean checkLic(String licStr) {
return CPU_INFO != null && DEVICE_INFO != null && licStr.equals(Encryptor.encryptStr(CPU_INFO + DEVICE_INFO));
}
public static boolean checkLic() {
String licStr = getLic();
if (StringUtils.isEmpty(licStr)) {
return false;
}
return checkLic(licStr);
}
// public static void main(String[] args) {
//
// createLicKeyIfNotExist();
//
// }
}

@ -0,0 +1,25 @@
package com.zhehekeji.filter.aspect;
import com.zhehekeji.core.util.Assert;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
@Aspect
@Component
@Slf4j
public class LicenseAspect {
/**
* leaper..*.controller
* leaper controller
*
* @param
*/
@Before("execution(public * com.zhehekeji..*.controller.*.*(..))")
public void handler(){
Assert.isTrue(LPLicense.checkLic(),"未获取授权请将lp.key发送给授权人员");
//Assert.isTrue(true,"未获取授权请将lp.key发送给授权人员");
}
}

@ -197,4 +197,29 @@ public class CameraController {
return Result.success(); return Result.success();
} }
@GetMapping("/rtcConfig")
@ApiOperation(value = "获取rtcConfig")
public Result<String> rtcConfig(String rtcServer) {
List<Camera> cameraList = cameraService.getCamerasByRtcServer(rtcServer);
JSONObject jsonObject = new JSONObject();
JSONObject server = new JSONObject();
server.put("http_port",":8083");
String [] strings = new String[1];
strings[0] = "stun:stun.l.google.com:19302";
server.put("ice_servers",strings);
server.put("ice_username","");
server.put("ice_credential","");
jsonObject.put("server",server);
JSONObject streams = new JSONObject();
cameraList.forEach(camera -> {
JSONObject obj = new JSONObject();
obj.put("on_demand",false);
obj.put("disable_audio",true);
obj.put("url",camera.getRtsp());
streams.put("camera"+camera.getId(),obj);
});
jsonObject.put("streams",streams);
return Result.success(jsonObject.toJSONString());
}
} }

@ -1,6 +1,7 @@
package com.zhehekeji.web.service; package com.zhehekeji.web.service;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.zhehekeji.core.util.Assert; import com.zhehekeji.core.util.Assert;
@ -59,6 +60,13 @@ public class CameraService {
private CameraControlLoginModule cameraControlLoginModule; private CameraControlLoginModule cameraControlLoginModule;
public List<Camera> getCamerasByRtcServer(String rtcServer){
if(StringUtils.isEmpty(rtcServer)){
rtcServer = "127.0.0.1";
}
return cameraMapper.selectList(new QueryWrapper<Camera>().eq("rtc_server",rtcServer));
}
public void setCameraControlModule(CameraControlModule cameraControlModule){ public void setCameraControlModule(CameraControlModule cameraControlModule){
this.cameraControlModule = cameraControlModule; this.cameraControlModule = cameraControlModule;
} }

@ -1,5 +1,6 @@
package com.zhehekeji.web.service; package com.zhehekeji.web.service;
import com.zhehekeji.filter.aspect.LPLicense;
import com.zhehekeji.web.config.ConfigProperties; import com.zhehekeji.web.config.ConfigProperties;
import com.zhehekeji.web.entity.Camera; import com.zhehekeji.web.entity.Camera;
import com.zhehekeji.web.entity.Street; import com.zhehekeji.web.entity.Street;
@ -84,6 +85,7 @@ public class InitService implements ApplicationRunner {
LoginThread loginThread = new LoginThread(camera); LoginThread loginThread = new LoginThread(camera);
loginThread.start(); loginThread.start();
}); });
LPLicense.createLicKeyIfNotExist();
//plc连接 //plc连接
if(configProperties.getServerMode() == 0){ if(configProperties.getServerMode() == 0){
log.info("PLC TCP MODE"); log.info("PLC TCP MODE");

@ -12,6 +12,8 @@ spring:
path: /api/ path: /api/
cache: cache:
type: simple type: simple
config:
additional-location:
mybatis-plus: mybatis-plus:
mapper-locations: classpath*:mapper/**/*.xml mapper-locations: classpath*:mapper/**/*.xml
#实体扫描多个package用逗号或者分号分隔 #实体扫描多个package用逗号或者分号分隔
@ -31,4 +33,4 @@ zhehe:
enable: true enable: true
postToken: w89euijon2&UHBTY$%huni34ri postToken: w89euijon2&UHBTY$%huni34ri
logging: logging:
config: classpath:logback-spring.xml config: classpath:logback-spring.xml

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configuration> <configuration>
<property name="LOG_HOME" value=".log"></property> <property name="LOG_HOME" value="log"></property>
<springProperty scope="context" name="logName" source="spring.application.name" defaultValue="localhost.log"/> <springProperty scope="context" name="logName" source="spring.application.name" defaultValue="localhost.log"/>
<!--自定义控制台日志格式--> <!--自定义控制台日志格式-->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">

@ -5,15 +5,15 @@
<select id="list" parameterType="com.zhehekeji.web.pojo.street.StreetSearch" resultType="com.zhehekeji.web.pojo.street.StreetVO"> <select id="list" parameterType="com.zhehekeji.web.pojo.street.StreetSearch" resultType="com.zhehekeji.web.pojo.street.StreetVO">
select t.*,c1.name as camera1Name,c2.name as camera2Name,l.ip as lightSourceIp,l.port as lightSourcePort, select t.*,c1.name as camera1Name,c2.name as camera2Name,l.ip as lightSourceIp,l.port as lightSourcePort,
s1.ip as leftSensorGunIp ,s1.port as leftSensorGunPort, s1.ip as leftSensorGunIp ,s1.port as leftSensorGunPort,
s2.ip as rightSensorGunIp ,s2.port as rightSensorGunPort, s2.ip as rightSensorGunIp ,s2.port as rightSensorGunPort
rf.ip as RFIDIp,rf.port as RFIDPort -- rf.ip as RFIDIp,rf.port as RFIDPort
from street t from street t
left join light_source l on l.street_id = t.id left join light_source l on l.street_id = t.id
left join camera c1 on t.camera1_id = c1.id left join camera c1 on t.camera1_id = c1.id
left join camera c2 on t.camera2_id = c2.id left join camera c2 on t.camera2_id = c2.id
left join sensor_gun s1 on s1.street_id = t.id and s1.direction = 1 left join sensor_gun s1 on s1.street_id = t.id and s1.direction = 1
left join sensor_gun s2 on s2.street_id = t.id and s2.direction = 2 left join sensor_gun s2 on s2.street_id = t.id and s2.direction = 2
left join RFID rf on rf.street_id = t.id -- left join RFID rf on rf.street_id = t.id
order by t.id desc order by t.id desc
</select> </select>

Loading…
Cancel
Save