Commit 2976ebf9 by hy

.

parent 9cea664d
...@@ -36,4 +36,5 @@ build/ ...@@ -36,4 +36,5 @@ build/
### Mac OS ### ### Mac OS ###
.DS_Store .DS_Store
.idea/ .idea/
\ No newline at end of file *.lic
\ No newline at end of file
...@@ -2,7 +2,6 @@ package com.tbyf.license; ...@@ -2,7 +2,6 @@ package com.tbyf.license;
import global.namespace.fun.io.bios.BIOS; import global.namespace.fun.io.bios.BIOS;
import global.namespace.truelicense.api.License; import global.namespace.truelicense.api.License;
import global.namespace.truelicense.api.LicenseInitialization;
import global.namespace.truelicense.api.LicenseManagementContext; import global.namespace.truelicense.api.LicenseManagementContext;
import global.namespace.truelicense.api.LicenseManagementException; import global.namespace.truelicense.api.LicenseManagementException;
import global.namespace.truelicense.api.VendorLicenseManager; import global.namespace.truelicense.api.VendorLicenseManager;
...@@ -12,14 +11,12 @@ import global.namespace.truelicense.v4.V4; ...@@ -12,14 +11,12 @@ import global.namespace.truelicense.v4.V4;
import javax.security.auth.x500.X500Principal; import javax.security.auth.x500.X500Principal;
public class LicenseManager { public class LicenseGenerator {
private static final String SUBJECT = "HIP"; private static final String SUBJECT = "HIP";
private static final String DISTINGUISHED_NAME = "CN=TBYF HIP"; private static final String DISTINGUISHED_NAME = "CN=TBYF HIP";
private static final String KEY_STORE_FILE = "private.ks"; private static final String KEY_STORE_FILE = "private.ks";
static LicenseInitialization licenseInitialization;
private static final LicenseManagementContext _managementContext = V4 private static final LicenseManagementContext _managementContext = V4
.builder() .builder()
.initialization(license -> { .initialization(license -> {
...@@ -41,13 +38,13 @@ public class LicenseManager { ...@@ -41,13 +38,13 @@ public class LicenseManager {
return _managementContext return _managementContext
.vendor() .vendor()
.encryption() .encryption()
.protection(protection(new long[]{0xa62021d62ef7e061L, 0xd32b4d88c40291afL})) /* "P@ssw0rd" */ .protection(protection(new long[]{0xa62021d62ef7e061L, 0xd32b4d88c40291afL})) /* "P@ssw0rd" */
.up() .up()
.authentication() .authentication()
.alias("standard") .alias("standard")
.loadFromResource(KEY_STORE_FILE) .loadFromResource(KEY_STORE_FILE)
.storeProtection(protection(new long[]{0x1bc1838eb8e7378cL, 0x88679932d1e8bedcL, 0x6e59d724487b1939L})) /* "Esb@123$%^" */ .storeProtection(protection(new long[]{0x1bc1838eb8e7378cL, 0x88679932d1e8bedcL, 0x6e59d724487b1939L})) /* "Esb@123$%^" */
.up() .up()
.build(); .build();
} }
...@@ -62,7 +59,7 @@ public class LicenseManager { ...@@ -62,7 +59,7 @@ public class LicenseManager {
license.setNotAfter(params.getExpirationDate()); license.setNotAfter(params.getExpirationDate());
license.setExtra(params.getMAC()); license.setExtra(params.getMAC());
manager.generateKeyFrom(license) manager.generateKeyFrom(license)
.saveTo(BIOS.file(params.getFilename())); .saveTo(BIOS.file(params.getLicensePath()));
} }
} }
...@@ -10,7 +10,7 @@ import java.util.Date; ...@@ -10,7 +10,7 @@ import java.util.Date;
public class LicenseParams { public class LicenseParams {
@Getter @Getter
private String filename; private String licensePath;
private Date startDate; private Date startDate;
......
package com.tbyf.license;
import global.namespace.truelicense.api.LicenseManagementException;
import org.junit.jupiter.api.Test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
class LicenseGeneratorTest {
@Test
void generate() throws LicenseManagementException, ParseException {
LicenseGenerator licenseGenerator = new LicenseGenerator();
licenseGenerator.generate(
LicenseParams.builder()
.licensePath("hip.lic")
.validity(3)
// .expirationDate(toDate("2024-01-11 15:12:00"))
.MAC("00-50-56-C0-00-08")
.build());
}
Date toDate(String dateStr) throws ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return dateFormat.parse(dateStr);
}
}
\ No newline at end of file
package com.tbyf.license;
import global.namespace.truelicense.api.LicenseManagementException;
import org.junit.jupiter.api.Test;
import java.util.Date;
import static org.junit.jupiter.api.Assertions.*;
class LicenseManagerTest {
@Test
void generate() throws LicenseManagementException {
new LicenseManager()
.generate(LicenseParams
.builder()
.filename("hip.lic")
.startDate(new Date())
.validity(5)
.MAC("CC-F9-E4-97-CA-48")
.build());
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment