使用 TrueLicense 生成软件许可(License)证书及证书的验证

一、整体说明

软件许可(License)证书,可以控制服务部署的情况,比如服务部署的硬件环境和服务到期日期。生产证书的服务端需要根据部署服务器的信息(如MAC地址等)和指定到期日期生成License证书。在具体使用License证书的应用程序,需要加载证书,进行校验证书的有效性。

二、生成公私钥

 使用JDK自带的 keytool 工具生成公私钥证书库
(1)生成命令:用KeyTool工具来生成私匙库(-alias别名 –validity 3650表示10年有效)
keytool -genkeypair -keysize 1024 -validity 3650 -alias "privateKey" -keystore "privateKeys.keystore" -storepass "public_password1234" -keypass "private_password1234" -dname "CN=localhost, OU=localhost, O=localhost, L=SH, ST=SH, C=CN"

注意:-dname参数要和代码BSLicense工程中LicenseCreator.X500Principal DEFAULT_HOLDER_AND_ISSUER保持一致。

(2)导出命令:把私匙库内的公匙导出到一个文件当中
keytool -exportcert -alias "privateKey" -keystore "privateKeys.keystore" -storepass "public_password1234" -file "certfile.cer"

(3)导入命令:把这个证书文件导入到公匙库
keytool -import -alias "publicCert" -file "certfile.cer" -keystore "publicCerts.keystore" -storepass "public_password1234"

     会在当前路径下生成三个文件,分别是:privateKeys.keystore、publicCerts.keystore、certfile.cer。其中文件certfile.cer不再需要可以删除,文件privateKeys.keystore用于当前的BSLicense项目给客户生成license文件,而文件publicCerts.keystore则随应用代码工程BCLicense部署到客户服务器,用户解密license文件并校验其许可信息。
最后生成文件privateKeys.store、publicCerts.store拷贝出来备用。

三、BSLicense和BCLicense工程代码

(1)BCLicense

客户端代码工程加载License,验证其有效性。

获取客户服务器的信息接口:http://localhost:7080/license/getServerInfos

{
  "ipAddress": [
    "172.20.52.78"
  ],
  "macAddress": [
    "4G-14-88-11-6L-54"
  ],
  "cpuSerial": "BFEB23233406D4",
  "mainBoardSerial": "L1H21434341YB"
}

(2)BSLicense

生成License证书的springboot工程,开发工具eclipse+maven

为客户生成license文件接口:http://localhost:7000/license/generateLicense,请求时需要在Header中添加一个Content-Type,其值为:application/json;charset=UTF-8。

参数示例如下:
(keyPass/storePass是通过KeyTool工具设置的私钥)
{
    "subject": "license_demo",
    "privateAlias": "privateKey",
    "keyPass": "private_password1234",
    "storePass": "public_password1234",
    "licensePath": "C:/Users/Administrator/Desktop/trueLicense/license.lic",
    "privateKeysStorePath": "C:/Users/Administrator/Desktop/trueLicense/privateKeys.keystore",
    "issuedTime": "2020-06-19 00:00:01",
    "expiryTime": "2020-06-22 09:59:59",
    "consumerType": "User",
    "consumerAmount": 1,
    "description": "这是证书描述信息",
    "licenseCheckModel": {
        "ipAddress": ["172.20.52.78"],
        "macAddress": ["4G-14-88-11-6L-54"],
        "cpuSerial": "BFEB23233406D4",
        "mainBoardSerial": "L1H21434341YB"
    }

}

如果请求成功,那么最后会在 licensePath 参数设置的路径生成一个license.lic的文件,这个文件就是给客户部署代码的服务器许可文件。

四、源代码工程下载

百度网盘链接:https://pan.baidu.com/s/15R8SN2PVCTJRgr-Bf4oSQg 
提取码:md2l

 

-------------------------------------------------------------------------------------------------------

本文参考:https://blog.csdn.net/Appleyk/article/details/101530203?utm_medium=distribute.pc_relevant_download.none-task-blog-BlogCommendFromBaidu-2.nonecase&depth_1-utm_source=distribute.pc_relevant_download.none-task-blog-BlogCommendFromBaidu-2.nonecas

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值