Skip to content

一个基于 TrueLicense 的证书生成和验证系统,包含后端服务和管理前端。

Notifications You must be signed in to change notification settings

Estelle925/-spring-license-starter

Repository files navigation

License Verify System

一个基于 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

快速开始

1. 环境要求

  • JDK 1.8+
  • Maven 3.6+
  • Node.js 16+
  • MySQL 8.0+
  • Redis 6.0+

2. 配置数据库

# 创建数据库
CREATE DATABASE license_verify DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

3. 修改配置

修改 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

4. 生成密钥

# 进入脚本目录
cd license-verify-web/scripts

# 添加执行权限
chmod +x generate-keys.sh

# 生成密钥
./generate-keys.sh

5. 启动服务

# 编译并启动后端服务
cd license-verify-web
mvn spring-boot:run

# 启动前端开发服务
cd license-verify-ui
npm install
npm run dev

使用说明

1. 引入 Starter

在你的项目中添加依赖:

<dependency>
    <groupId>com.license</groupId>

    <artifactId>license-verify-starter</artifactId>

    <version>1.0.0</version>

</dependency>

2. 配置参数

在 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$

3. 使用示例

@Resource
private LicenseTemplate licenseTemplate;

// 获取硬件信息
LicenseCheckModel hardwareInfo = licenseTemplate.acquireHardwareInfo();

// 安装证书
LicenseVerifyInfo verifyInfo = licenseTemplate.installLicense(param);

// 验证证书
LicenseVerifyInfo verifyInfo = licenseTemplate.verify();

API 文档

证书管理接口

接口 方法 描述
/api/license/create POST 创建证书
/api/license/list GET 获取证书列表
/api/license/download/{id} GET 下载证书

硬件信息接口

接口 方法 描述
/api/hardware/info GET 获取当前设备硬件信息

开发指南

自定义验证规则

  1. 实现 AbstractLicenseVerifier 接口
  2. verify 方法中添加自定义验证逻辑
  3. 通过 @Component 注册为 Spring Bean
@Component
public class CustomLicenseVerifier implements AbstractLicenseVerifier {
    @Override
    public boolean verify(LicenseCheckModel param) {
        // 自定义验证逻辑
        return true;
    }
}

扩展硬件信息采集

  1. 实现 AbstractServerInfos 接口
  2. getServerInfos 方法中添加信息采集逻辑
  3. 通过 @Component 注册为 Spring Bean
@Component
public class CustomServerInfos implements AbstractServerInfos {
    @Override
    public List<String> getServerInfos() {
        // 自定义信息采集逻辑
        return Arrays.asList("custom-info-1", "custom-info-2");
    }
}

常见问题

  1. 证书验证失败
    • 检查硬件信息是否匹配
    • 确认证书是否过期
    • 验证公钥是否正确
  2. 硬件信息获取失败
    • 确保有足够的系统权限
    • 检查系统兼容性
    • 查看详细错误日志

About

一个基于 TrueLicense 的证书生成和验证系统,包含后端服务和管理前端。

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published