使用truelicense进行Java程序license控制 经过扩张可以验证licen

使用truelicense进行Java程序license控制

经过扩张可以验证license开始结束日期,,验证绑定给定mac地址。

Truelicense 是一个开源的java license 验证项目。

使用truelicense实现用于JAVA工程license机制(包括license生成和验证)请参考

其中包括license授权机制的原理和制作license的具体步骤

本文主要是在此文基础上增加了mac 地址验证:

在createparam.properties

中增加 ip地址和 mac 地址的配置

##########common parameters############aliasPRIVATEALIAS=privateKeys#key(important!)KEYPWD=iptv1234#STOREPWDSTOREPWD=iptv1234#SUBJECTSUBJECT=bigdata#licPathlicPath=C:/9exce/license/license.lic#priPathpriPath=C:/9exce/license/PrivateKeys.keystore##########license content############issuedTimeissuedTime=2015-03-09#notBeforeTimenotBefore=2015-03-09#notAfterTimenotAfter=2016-03-20#ip addressipAddress=150.236.220.200#mac addressmacAddress=80-00-0B-56-3B-32#consumerTypeconsumerType=user#ConsumerAmountconsumerAmount=1#infoinfo=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) && (localDate1.before(localDate2))) {throw new LicenseContentException(EXC_LICENSE_IS_NOT_YET_VALID);}Date localDate3 = paramLicenseContent.getNotAfter();if ((localDate3 != null) && (localDate1.after(localDate3))) {throw new LicenseContentException(EXC_LICENSE_HAS_EXPIRED);}String str = paramLicenseContent.getConsumerType();if (str == null) {throw new LicenseContentException(EXC_CONSUMER_TYPE_IS_NULL);}Preferences localPreferences = localLicenseParam.getPreferences();if ((localPreferences != null) && (localPreferences.isUserNode())) {if (!USER.equalsIgnoreCase(str)) {throw new LicenseContentException(EXC_CONSUMER_TYPE_IS_NOT_USER);}if (paramLicenseContent.getConsumerAmount() != 1) {throw new LicenseContentException(EXC_CONSUMER_AMOUNT_IS_NOT_ONE);}} else if (paramLicenseContent.getConsumerAmount() <= 0) {throw new LicenseContentException(EXC_CONSUMER_AMOUNT_IS_NOT_POSITIVE);}}

更新validate增加验证客户server的mac地址。

protected synchronized void 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) && (localDate1.before(localDate2))) {throw new LicenseContentException(EXC_LICENSE_IS_NOT_YET_VALID);}Date localDate3 = paramLicenseContent.getNotAfter();if ((localDate3 != null) && (localDate1.after(localDate3))) {throw new LicenseContentException(EXC_LICENSE_HAS_EXPIRED);}LicenseCheckModel licenseCheckModel = (LicenseCheckModel)paramLicenseContent.getExtra();String macAddress = licenseCheckModel.getIpMacAddress();try {if (!ListNets.validateMacAddress(macAddress)) {throw new LicenseContentException(EXC_LICENSE_HAS_EXPIRED);}} catch (SocketException e) {// TODO Auto-generated catch blockthrow new LicenseContentException(EXC_LICENSE_HAS_EXPIRED);}String str = paramLicenseContent.getConsumerType();if (str == null) {throw new LicenseContentException(EXC_CONSUMER_TYPE_IS_NULL);}Preferences localPreferences = localLicenseParam.getPreferences();if ((localPreferences != null) && (localPreferences.isUserNode())) {if (!USER.equalsIgnoreCase(str)) {throw new LicenseContentException(EXC_CONSUMER_TYPE_IS_NOT_USER);}if (paramLicenseContent.getConsumerAmount() != 1) {throw new LicenseContentException(EXC_CONSUMER_AMOUNT_IS_NOT_ONE);}} else if (paramLicenseContent.getConsumerAmount() <= 0) {throw new LicenseContentException(EXC_CONSUMER_AMOUNT_IS_NOT_POSITIVE);}}却只能这样。只有对爱的人,我们才会斤斤计较,锱铢必较。

使用truelicense进行Java程序license控制 经过扩张可以验证licen

相关文章:

你感兴趣的文章:

标签云: