使用truelicense进行Java程序license控制
经过扩张可以验证license 开始结束日期,验证绑定给定mac地址。
Truelicense 是一个开源的java license 验证项目。
使用truelicense实现用于JAVA工程license机制(包括license生成和验证)请参考http://www.it165.net/pro/html/201404/11540.html
其中包括license授权机制的原理和制作license的具体步骤
本文主要是在此文基础上增加了mac 地址验证:
在createparam.properties
中增加 ip地址和 mac 地址的配置
##########common parameters###########
#alias
PRIVATEALIAS=privateKeys
#key(important!)
KEYPWD=iptv1234
#STOREPWD
STOREPWD=iptv1234
#SUBJECT
SUBJECT=bigdata
#licPath
licPath=C:/9exce/license/license.lic
#priPath
priPath=C:/9exce/license/PrivateKeys.keystore
##########license content###########
#issuedTime
issuedTime=2015-03-09
#notBeforeTime
notBefore=2015-03-09
#notAfterTime
notAfter=2016-03-20
#ip address
ipAddress=150.236.220.200
#mac address
macAddress=80-00-0B-56-3B-32
#consumerType
consumerType=user
#ConsumerAmount
consumerAmount=1
#info
info=this is a license
因为增加了mac地址,需要改变LicenseManager中的validate函数增加create_validate 用于create时的verify, 因为创建证书的时候 不能验证mac地址。
protected synchronized void create_validate(LicenseContent paramLicenseContent)
throws LicenseContentException {
LicenseParam localLicenseParam = getLicenseParam();
if (!localLicenseParam.getSubject().equals(
paramLicenseContent.getSubject())) {
throw new LicenseContentException(EXC_INVALID_SUBJECT);
}
if (paramLicenseContent.getHolder() == null) {
throw new LicenseContentException(EXC_HOLDER_IS_NULL);
}
if (paramLicenseContent.getIssuer() == null) {
throw new LicenseContentException(EXC_ISSUER_IS_NULL);
}
if (paramLicenseContent.getIssued() == null) {
throw new LicenseContentException(EXC_ISSUED_IS_NULL);
}
Date localDate1 = new Date();
Date localDate2 = paramLicenseContent.getNotBefore();
if ((localDate2 != null) && (local