一个基于 TrueLicense 的证书生成和验证系统,包含后端服务和管理前端。
本项目是一个完整的软件授权验证解决方案,包含以下功能:
- 证书生成与管理
- 证书验证与安装
- 硬件信息采集
- 权限控制
- Web管理界面
license-verify/
├── license-verify-starter/ # 核心starter包
├── license-verify-web/ # Web服务端
└── license-verify-ui/ # Web管理前端
- Spring Boot 2.7.x
- Spring Data JPA
- MySQL 8.x
- Redis
- TrueLicense
- Vue 3
- TypeScript
- Element Plus
- Vite
- Axios
- JDK 1.8+
- Maven 3.6+
- Node.js 16+
- MySQL 8.0+
- Redis 6.0+
# 创建数据库
CREATE DATABASE license_verify DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
修改 license-verify-web/src/main/resources/application.yml
:
spring:
datasource:
url: jdbc:mysql://localhost:3306/license_verify
username: your_username
password: your_password
redis:
host: localhost
port: 6379
password: your_password
# 进入脚本目录
cd license-verify-web/scripts
# 添加执行权限
chmod +x generate-keys.sh
# 生成密钥
./generate-keys.sh
# 编译并启动后端服务
cd license-verify-web
mvn spring-boot:run
# 启动前端开发服务
cd license-verify-ui
npm install
npm run dev
在你的项目中添加依赖:
<dependency>
<groupId>com.license</groupId>
<artifactId>license-verify-starter</artifactId>
<version>1.0.0</version>
</dependency>
在 application.yml 中添加配置:
license:
subject: 你的公司名
publicAlias: publicCert
privateAlias: privateKey
storePass: Admin@123$
licensePath: conf/license.lic
publicKeysStorePath: conf/publicCerts.keystore
privateKeysStorePath: conf/privateKeys.keystore
keyPass: Admin@123$
@Resource
private LicenseTemplate licenseTemplate;
// 获取硬件信息
LicenseCheckModel hardwareInfo = licenseTemplate.acquireHardwareInfo();
// 安装证书
LicenseVerifyInfo verifyInfo = licenseTemplate.installLicense(param);
// 验证证书
LicenseVerifyInfo verifyInfo = licenseTemplate.verify();
接口 | 方法 | 描述 |
---|---|---|
/api/license/create | POST | 创建证书 |
/api/license/list | GET | 获取证书列表 |
/api/license/download/{id} | GET | 下载证书 |
接口 | 方法 | 描述 |
---|---|---|
/api/hardware/info | GET | 获取当前设备硬件信息 |
- 实现
AbstractLicenseVerifier
接口 - 在
verify
方法中添加自定义验证逻辑 - 通过
@Component
注册为 Spring Bean
@Component
public class CustomLicenseVerifier implements AbstractLicenseVerifier {
@Override
public boolean verify(LicenseCheckModel param) {
// 自定义验证逻辑
return true;
}
}
- 实现
AbstractServerInfos
接口 - 在
getServerInfos
方法中添加信息采集逻辑 - 通过
@Component
注册为 Spring Bean
@Component
public class CustomServerInfos implements AbstractServerInfos {
@Override
public List<String> getServerInfos() {
// 自定义信息采集逻辑
return Arrays.asList("custom-info-1", "custom-info-2");
}
}
- 证书验证失败
- 检查硬件信息是否匹配
- 确认证书是否过期
- 验证公钥是否正确
- 硬件信息获取失败
- 确保有足够的系统权限
- 检查系统兼容性
- 查看详细错误日志