linces 验证调整
parent
7ef3763a14
commit
f903828f4d
|
|
@ -60,11 +60,6 @@ public class AppRun {
|
||||||
springApplication.run(args);
|
springApplication.run(args);
|
||||||
|
|
||||||
log.error(JSONUtil.toJsonStr(LicenseValidate.getDeviceInfo()));
|
log.error(JSONUtil.toJsonStr(LicenseValidate.getDeviceInfo()));
|
||||||
try{
|
|
||||||
log.error(JSONUtil.toJsonStr(LicenseValidate.getLicense("2024-05-26")));
|
|
||||||
}catch (Exception e){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,13 +18,13 @@ import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
public class LicenseValidate {
|
public class LicenseValidate {
|
||||||
|
|
||||||
public static void validate() throws Exception{
|
public static void validate() throws Exception{
|
||||||
//读取本地文件
|
//读取本地文件
|
||||||
FileProperties properties= SpringContextHolder.getBean(FileProperties.class);
|
FileProperties properties= SpringContextHolder.getBean(FileProperties.class);
|
||||||
log.info(properties.getPath().getPath());
|
|
||||||
String result="";
|
String result="";
|
||||||
try{
|
try{
|
||||||
FileReader fileReader = new FileReader(properties.getPath().getPath()+"key/"+"license.key");
|
FileReader fileReader = new FileReader(properties.getPath().getPath()+"key/"+"license.key");
|
||||||
|
|
@ -34,9 +34,8 @@ public class LicenseValidate {
|
||||||
throw new BadRequestException("License不存在,请上传License");
|
throw new BadRequestException("License不存在,请上传License");
|
||||||
}
|
}
|
||||||
|
|
||||||
log.error(result);
|
|
||||||
String rsaResult= RsaUtils.decryptByPublicKey(RsaProperties.licenseKey,result);
|
String rsaResult= RsaUtils.decryptByPublicKey(RsaProperties.licenseKey,result);
|
||||||
log.error("------------------------解密完成-----------------------");
|
|
||||||
LicenseCheck key_price = JSONUtil.toBean(rsaResult, LicenseCheck.class);
|
LicenseCheck key_price = JSONUtil.toBean(rsaResult, LicenseCheck.class);
|
||||||
LicenseCheck system_price = getDeviceInfo();
|
LicenseCheck system_price = getDeviceInfo();
|
||||||
|
|
||||||
|
|
@ -44,15 +43,15 @@ public class LicenseValidate {
|
||||||
|
|
||||||
|
|
||||||
if(key_price.getMainBoardSerial().equals(system_price.getMainBoardSerial())){
|
if(key_price.getMainBoardSerial().equals(system_price.getMainBoardSerial())){
|
||||||
log.error("主板匹配成功");
|
|
||||||
}else{
|
}else{
|
||||||
log.error("主板匹配失败");
|
|
||||||
throw new BadRequestException("主板匹配失败");
|
throw new BadRequestException("主板匹配失败");
|
||||||
}
|
}
|
||||||
if(key_price.getCpuSerial().equals(system_price.getCpuSerial())){
|
if(key_price.getCpuSerial().equals(system_price.getCpuSerial())){
|
||||||
log.error("CPU匹配成功");
|
|
||||||
}else{
|
}else{
|
||||||
log.error("CPU匹配失败");
|
|
||||||
throw new BadRequestException("CPU匹配失败");
|
throw new BadRequestException("CPU匹配失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,7 +62,7 @@ public class LicenseValidate {
|
||||||
if(end_date.before(now_date)){
|
if(end_date.before(now_date)){
|
||||||
throw new BadRequestException("过期的License,请重新生成");
|
throw new BadRequestException("过期的License,请重新生成");
|
||||||
}else{
|
}else{
|
||||||
log.error("有效期验证通过");
|
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
throw new BadRequestException("无效的License,请重新生成");
|
throw new BadRequestException("无效的License,请重新生成");
|
||||||
|
|
@ -72,67 +71,18 @@ public class LicenseValidate {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static String getLicense(String time) throws Exception{
|
|
||||||
LicenseCheck licenseCheck=getDeviceInfo();
|
|
||||||
licenseCheck.setEndTime(time);
|
|
||||||
String rest= JSONUtil.toJsonStr(licenseCheck).trim();
|
|
||||||
String priKey = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDFlDBnrKTnnAbXTCfUh3fhq81dXZUd/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Gwkxe0iNIxIN2+LBO/+VjflMh3DmRHRoP0q228FMuJde2jwlvq7UP9+qn8NPX/+MuD4R3XKnJAu0FoBykWXeFD+gHQ6RkWwvzt5I8ohAxZYDmjKSQKBgB5gwhM9+5v7U7raCi5enJ0d4buzx33nwSfTdbQGFaaVwtPOU7JgvQhK6GckX5r63WuBpsMvQ488VftLXBBl6FaIK8iy2gWLyXtSgyN4nChHo3/78ogtwt2EMI/8rJooDPvEZfzlHbbD57rmOxJoEWb/rrsxfq40eRAP6oHX547BAoGBAMK7GGdYkzxkD2xuMZSfPro/sO0EbghJdJ/l8nioTEPTPyRx5AZBe/7OhiKYohpUdi5F8+S18ACn88rJkZn7iQGuJvjXCFYnt9bec+w8lqiUcjfw3l4+aAkNTfquIdKz6gJyUBVjbuQYYkzGf052HbMacDwwfbHIlDvpfAS7FUpq";
|
|
||||||
|
|
||||||
String result=RsaUtils.encryptByPrivateKey(priKey,rest);
|
|
||||||
//读取本地文件
|
|
||||||
|
|
||||||
log.error("------------------------加密完成-----------------------");
|
|
||||||
|
|
||||||
log.error(result);
|
|
||||||
String rsaResult= RsaUtils.decryptByPublicKey(RsaProperties.licenseKey,result);
|
|
||||||
|
|
||||||
log.error(rsaResult);
|
|
||||||
log.error("------------------------解密完成-----------------------");
|
|
||||||
LicenseCheck key_price = JSONUtil.toBean(rsaResult, LicenseCheck.class);
|
|
||||||
LicenseCheck system_price = getDeviceInfo();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(key_price.getMainBoardSerial().equals(system_price.getMainBoardSerial())){
|
|
||||||
log.error("主板匹配成功");
|
|
||||||
}else{
|
|
||||||
log.error("主板匹配失败");
|
|
||||||
throw new BadRequestException("主板匹配失败");
|
|
||||||
}
|
|
||||||
if(key_price.getCpuSerial().equals(system_price.getCpuSerial())){
|
|
||||||
log.error("CPU匹配成功");
|
|
||||||
}else{
|
|
||||||
log.error("CPU匹配失败");
|
|
||||||
throw new BadRequestException("CPU匹配失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
try{
|
|
||||||
Date end_date = DateUtil.parse(key_price.getEndTime());
|
|
||||||
Date now_date = DateUtil.date();
|
|
||||||
|
|
||||||
if(end_date.before(now_date)){
|
|
||||||
throw new BadRequestException("过期的License,请重新生成");
|
|
||||||
}else{
|
|
||||||
log.error("有效期验证通过");
|
|
||||||
}
|
|
||||||
}catch (Exception e){
|
|
||||||
throw new BadRequestException("无效的License,请重新生成");
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void saveCode(String license_code) throws Exception{
|
public static void saveCode(String license_code) throws Exception{
|
||||||
//读取本地文件
|
//读取本地文件
|
||||||
log.error(license_code);
|
|
||||||
String rsaResult="";
|
String rsaResult="";
|
||||||
try{
|
try{
|
||||||
rsaResult= RsaUtils.decryptByPublicKey(RsaProperties.licenseKey,license_code);
|
rsaResult= RsaUtils.decryptByPublicKey(RsaProperties.licenseKey,license_code);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
throw new BadRequestException("License无效,请重新生成");
|
throw new BadRequestException("License无效,请重新生成");
|
||||||
}
|
}
|
||||||
log.error("解密完成");
|
|
||||||
log.error(rsaResult);
|
|
||||||
|
|
||||||
LicenseCheck key_price = JSONUtil.toBean(rsaResult, LicenseCheck.class);
|
LicenseCheck key_price = JSONUtil.toBean(rsaResult, LicenseCheck.class);
|
||||||
LicenseCheck system_price = getDeviceInfo();
|
LicenseCheck system_price = getDeviceInfo();
|
||||||
|
|
@ -141,15 +91,15 @@ public class LicenseValidate {
|
||||||
|
|
||||||
|
|
||||||
if(key_price.getMainBoardSerial().equals(system_price.getMainBoardSerial())){
|
if(key_price.getMainBoardSerial().equals(system_price.getMainBoardSerial())){
|
||||||
log.error("主板匹配成功");
|
|
||||||
}else{
|
}else{
|
||||||
log.error("主板匹配失败");
|
|
||||||
throw new BadRequestException("主板匹配失败");
|
throw new BadRequestException("主板匹配失败");
|
||||||
}
|
}
|
||||||
if(key_price.getCpuSerial().equals(system_price.getCpuSerial())){
|
if(key_price.getCpuSerial().equals(system_price.getCpuSerial())){
|
||||||
log.error("CPU匹配成功");
|
|
||||||
}else{
|
}else{
|
||||||
log.error("CPU匹配失败");
|
|
||||||
throw new BadRequestException("CPU匹配失败");
|
throw new BadRequestException("CPU匹配失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -160,14 +110,14 @@ public class LicenseValidate {
|
||||||
if(end_date.before(now_date)){
|
if(end_date.before(now_date)){
|
||||||
throw new BadRequestException("过期的License,请重新生成");
|
throw new BadRequestException("过期的License,请重新生成");
|
||||||
}else{
|
}else{
|
||||||
log.error("有效期验证通过");
|
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
throw new BadRequestException("无效的License,请重新生成");
|
throw new BadRequestException("无效的License,请重新生成");
|
||||||
}
|
}
|
||||||
|
|
||||||
FileProperties properties= SpringContextHolder.getBean(FileProperties.class);
|
FileProperties properties= SpringContextHolder.getBean(FileProperties.class);
|
||||||
log.info(properties.getPath().getPath());
|
|
||||||
|
|
||||||
FileWriter writer = new FileWriter(properties.getPath().getPath()+"key/"+"license.key");
|
FileWriter writer = new FileWriter(properties.getPath().getPath()+"key/"+"license.key");
|
||||||
writer.write(license_code);
|
writer.write(license_code);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue