Spring Boot License 认证系统
Spring Boot License 认证系统
本项目适用于对软件进行授权保护。项目分为三个主要模块:
licence-core
:核心逻辑模块,包含 License 生成与校验的公共类。licence-server
:服务端模块,提供生成 License 的 Web 接口。licence-client
:客户端模块,提供验证 License 的功能。
项目结构
.
├── licence-client # 客户端模块
│ ├── config # 拦截器配置
│ ├── entity # 验证参数
│ ├── service # 服务接口
│ └── util # 许可证校验工具类
├── licence-core # 核心模块
│ ├── entity # 证书参数实体
│ └── serverinfo # 服务器信息采集(Windows/Linux)
├── licence-server # 服务端模块
│ ├── controller # 证书生成接口
│ ├── util # 证书生成工具类
│ └── static # 前端页面(cs.html)
└── README.md # 项目文档
项目操作流程
生成密钥对
生成密钥
- 通过KeyStoreGenerator类中generateKeyStore方法生成私钥库文件保存到指定文件中。可通过接口生成密钥对。
- 生成证书接口参数
{//证书主题"subject": "lcz_demo",//证书到期时间"expireTime": "2025-12-31 23:59:59",//证书签发时间"issuedTime": "2025-01-01 00:00:00",//证书描述"description": "授权给[lcz_demo]的证书,时长1年",//密钥库访问密码"storePass": "lcz1234",//私钥别称"privateAlias": "privateKeyLcz",//私钥访问密码"keyPass": "lcz1234",//保存证书的文件路径"licensePath": "/Users/lcz/Downloads/license.lic",//密钥库文件保存路径"privateKeysStorePath": "/Users/lcz/Downloads/privateKeys.keystore",//服务器信息,填写为空则表示无限制"additionInfo": {//ip地址范围,为空则表示无限制"ipAddress": ["192.168.2.x"],//mac地址,为空则表示无限制"macAddress": ["80-00-0B-67-5E-BC"],//cpu序列号,为空则表示无限制"cpuSerial": "xxxBFBFF000306C3",//主板序列号,为空则表示无限制"mainBoardSerial": "/7xxxH72/CN129xxx1G0009/"},//允许的授权数,为空则表示无限制"consumerAmount": 1,//授权类型,可选值:user,host,process,默认为user"consumerType": "user",//公钥库文件保存路径"publicKeysStorePath": "/Users/lcz/Downloads/publicCerts.keystore",//公钥别称"publicAlias": "publicCert"
}
- 通过页面生成密钥对 生成密钥对
从私钥库导出证书
- 通过KeyStoreGenerator类中exportCertificate方法生成,用来生成公钥文件。
通过证书到公钥库
- 通过KeyStoreGenerator类中importPublicCertificate方法生成公钥文件
上述命令执行完成后会在当前目录生成三个文件:
- certfile.cer 认证证书文件,暂时无用
- privateKeys.keystore 私钥文件,自己保存
- publicKeys.keystore 公钥文件,需要放到客户端项目目录里
licence-server生成证书
licence-server接口文档
licence-client安装、校验证书
添加依赖
- maven install
- 通过打包生成jar包,把targetlicence-clientjar包引入到客户端需要配置软件授权保护项目中下
mvn install:install-file -DgroupId=com.lcz -DartifactId=licence-client -Dversion=1.0 -Dpackaging=jar -Dfile=licence-client-1.0.jar
- 用户可通过实现VerificationExpirationProcessingService.java接口实现证书到期之后的处理逻辑
添加配置信息到软件授权保护项目中
- 添加配置信息到文件application.yml
#证书配置
license:#证书subjectsubject: lcz_demo#公钥别称publicAlias: publicCert#访问公钥的密码storePass: public_password1234#证书路径licensePath: C://Users/User/Desktop/tmp/license.lic#公钥存储路径publicKeysStorePath: C://Users/User/Desktop/tmp/publicCerts.keystore
添加证书相关文件到软件授权保护项目中
- 通过设置的证书路径和公钥存储路径把认证证书文件(license.lic)、公钥文件(publicCerts.keystore)文件复制到软件授权保护项目下
项目地址