使用场景

1、 开发的软件产品在交付使用的时候,往往有一段时间的试用期,这期间我们不希望自己的代码被客户二次拷贝,这个时候 license 就派上用场了,license 的功能包括设定有效期、绑定 ip、绑定 mac 等。

2、 授权方直接生成一个 license 给使用方使用,如果需要延长试用期,也只需要重新生成一份 license 即可,无需手动修改源代码。

原理简介

1、TrueLicense 是一个开源的证书管理引擎,详细介绍见 https://truelicense.java.net/

2、license 授权机制的原理

生成证书利用jdk keytool工具制作证书

keytool-genkeypair-keysize1024-validity3650-alias"privateKey"-keystore"privateKeys.keystore"-storepass"deepglint_store_pwd123"-keypass"deepglint_key_pwd123"-dname"CN=localhost,OU=localhost,O=localhost,L=SH,ST=SH,C=CN"

利用jdk keytool工具导出证书文件

keytool-exportcert-alias"privateKey"-keystore"privateKeys.keystore"-storepass"deepglint_store_pwd123"-file"certfile.cer"

利用jdk keytool工具将证书文件导入到证书库中

keytool-import-alias"publicCert"-file"certfile.cer"-keystore"publicCerts.keystore"-storepass"deepglint_store_pwd123"

sip协议注册验证算法(基于TrueLicense的项目证书验证)(1)

两个子项目说明

sip协议注册验证算法(基于TrueLicense的项目证书验证)(2)

获取服务器信息

http://127.0.0.1:10000/license/getServerInfos

sip协议注册验证算法(基于TrueLicense的项目证书验证)(3)

给客户机生成license

sip协议注册验证算法(基于TrueLicense的项目证书验证)(4)

http://127.0.0.1:10000/license/generateLicense header Content-Typeapplication/json;charset=UTF-8 { "subject":"license_sub",#证书subject "privateAlias":"privateKey",#秘钥别名 "keyPass":"deepglint_key_pwd123",#秘钥口令 "storePass":"deepglint_store_pwd123",#秘钥库口令 "licensePath":"/Users/mengfanxiao/Documents/work/license/cert/license.lic",#存放license文件位置 "privateKeysStorePath":"/Users/mengfanxiao/Documents/work/license/cert/privateKeys.keystore",#秘钥库文件文件 "issuedTime":"2020-11-2500:00:01",#license有效期起始时间 "expiryTime":"2020-11-2522:00:00",#license有效期截止时间 "licenseCheckModel":{ "ipAddress":["192.168.5.121"],#客户机ip "macAddress":["A4-83-E7-BE-3D-D9"],#客户机mac地址 "cpuSerial":"",#客户机cpu序列号 "mainBoardSerial":""#客户机主板序列号 } }

sip协议注册验证算法(基于TrueLicense的项目证书验证)(5)

在客户机使用license

sip协议注册验证算法(基于TrueLicense的项目证书验证)(6)

在项目启动的时候安装证书

sip协议注册验证算法(基于TrueLicense的项目证书验证)(7)

访问接口进行测试

http://127.0.0.1:10001/auth/api/1.0/getUserInfo header Content-Typeapplication/json;charset=UTF-8

sip协议注册验证算法(基于TrueLicense的项目证书验证)(8)

如果证书过期

sip协议注册验证算法(基于TrueLicense的项目证书验证)(9)

源码

https://gitee.com/pingfanrenbiji/lic-auth

,