/* License generation. */
- public static void generateFullLicense(Path privateKeyFile, Path licenseSkeletonFile, Path fullLicenseFile) throws MLicensingException {
+ public static void generateLicense(Path privateKeyFile, Path licenseSkeletonFile, Path licenseFile) throws MLicensingException {
if (null == privateKeyFile) {
throw new IllegalArgumentException("Invalid 'privateKeyFile': null.");
}
if (null == licenseSkeletonFile) {
throw new IllegalArgumentException("Invalid 'licenseSkeletonFile': null.");
}
- if (null == fullLicenseFile) {
- throw new IllegalArgumentException("Invalid 'fullLicenseFile': null.");
+ if (null == licenseFile) {
+ throw new IllegalArgumentException("Invalid 'licenseFile': null.");
}
//
try {
String privateKeyPemString = new String(Files.readAllBytes(privateKeyFile), MConstants.DEFAULT_CHARSET);
String licenseSkeletonJsonString = new String(Files.readAllBytes(licenseSkeletonFile), MConstants.DEFAULT_CHARSET);
//
- MJsonObject fullLicense = MLicenseManager.generateFullLicense(privateKeyPemString, licenseSkeletonJsonString);
+ MJsonObject license = MLicenseManager.generateLicense(privateKeyPemString, licenseSkeletonJsonString);
//
- Files.write(fullLicenseFile, fullLicense.getJsonValue(true).getBytes(MConstants.DEFAULT_CHARSET), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
+ Files.write(licenseFile, license.getJsonValue(true).getBytes(MConstants.DEFAULT_CHARSET), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
}
catch (IOException exception) {
- throw new MLicensingException("Could not generate full license.", exception);
+ throw new MLicensingException("Could not generate license.", exception);
}
}
- public static MJsonObject generateFullLicense(String privateKeyPemString, String licenseSkeletonJsonString) throws MLicensingException {
+ public static MJsonObject generateLicense(String privateKeyPemString, String licenseSkeletonJsonString) throws MLicensingException {
if (MText.isBlank(privateKeyPemString)) {
throw new IllegalArgumentException("Invalid 'privateKeyPemString': null or empty.");
}
return licenseSkeleton;
}
catch (InvalidKeyException exception) {
- throw new MLicensingException("Could not generate full license.", exception);
+ throw new MLicensingException("Could not generate license.", exception);
}
catch (InvalidKeySpecException exception) {
- throw new MLicensingException("Could not generate full license.", exception);
+ throw new MLicensingException("Could not generate license.", exception);
}
catch (MInvalidJsonValueException exception) {
- throw new MLicensingException("Could not generate full license.", exception);
+ throw new MLicensingException("Could not generate license.", exception);
}
catch (NoSuchAlgorithmException exception) {
- throw new MLicensingException("Could not generate full license.", exception);
+ throw new MLicensingException("Could not generate license.", exception);
}
catch (SignatureException exception) {
- throw new MLicensingException("Could not generate full license.", exception);
+ throw new MLicensingException("Could not generate license.", exception);
}
}
/* License verification. */
- public static MJsonObject verifyFullLicense(Path publicKeyFile, Path fullLicenseFile) throws MLicensingException {
+ public static MJsonObject verifyLicense(Path publicKeyFile, Path licenseFile) throws MLicensingException {
if (null == publicKeyFile) {
throw new IllegalArgumentException("Invalid 'publicKeyFile': null.");
}
- if (null == fullLicenseFile) {
- throw new IllegalArgumentException("Invalid 'fullLicenseFile': null.");
+ if (null == licenseFile) {
+ throw new IllegalArgumentException("Invalid 'licenseFile': null.");
}
//
try {
String publicKeyPemString = new String(Files.readAllBytes(publicKeyFile), MConstants.DEFAULT_CHARSET);
- String fullLicenseJsonString = new String(Files.readAllBytes(fullLicenseFile), MConstants.DEFAULT_CHARSET);
+ String licenseJsonString = new String(Files.readAllBytes(licenseFile), MConstants.DEFAULT_CHARSET);
//
- return MLicenseManager.verifyFullLicense(publicKeyPemString, fullLicenseJsonString);
+ return MLicenseManager.verifyLicense(publicKeyPemString, licenseJsonString);
}
catch (IOException exception) {
- throw new MLicensingException("Could not verify full license.", exception);
+ throw new MLicensingException("Could not verify license.", exception);
}
}
- public static MJsonObject verifyFullLicense(String publicKeyPemString, String fullLicenseJsonString) throws MLicensingException {
+ public static MJsonObject verifyLicense(String publicKeyPemString, String licenseJsonString) throws MLicensingException {
if (MText.isBlank(publicKeyPemString)) {
throw new IllegalArgumentException("Invalid 'publicKeyPemString': null or empty.");
}
- if (MText.isBlank(fullLicenseJsonString)) {
- throw new IllegalArgumentException("Invalid 'fullLicenseJsonString': null or empty.");
+ if (MText.isBlank(licenseJsonString)) {
+ throw new IllegalArgumentException("Invalid 'licenseJsonString': null or empty.");
}
//
try {
byte[] publicKeyContent = Base64.getDecoder().decode(publicKeyPemString.replace("-----BEGIN PUBLIC KEY-----", "").replaceAll("\\R", "").replace("-----END PUBLIC KEY-----", ""));
RSAPublicKey publicKey = (RSAPublicKey)KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(publicKeyContent));
//
- MJsonObject fullLicense = new MJsonObject(fullLicenseJsonString);
+ MJsonObject license = new MJsonObject(licenseJsonString);
//
- MJsonObject licenseData = (MJsonObject)fullLicense.getValue("licenseData");
+ MJsonObject licenseData = (MJsonObject)license.getValue("licenseData");
byte[] licenseDataHashContent = MessageDigest.getInstance("SHA-256").digest(licenseData.getJsonValue().getBytes(MConstants.DEFAULT_CHARSET));
//
- MJsonString licenseDataSignature = (MJsonString)fullLicense.getValue("licenseDataSignature");
+ MJsonString licenseDataSignature = (MJsonString)license.getValue("licenseDataSignature");
byte[] licenseDataSignatureContent = Base64.getDecoder().decode(licenseDataSignature.getValue());
//
Signature signature = Signature.getInstance("SHA256withRSA");
signature.update(licenseDataHashContent);
signature.verify(licenseDataSignatureContent);
//
- return fullLicense;
+ return license;
}
catch (InvalidKeyException exception) {
- throw new MLicensingException("Could not verify full license.", exception);
+ throw new MLicensingException("Could not verify license.", exception);
}
catch (InvalidKeySpecException exception) {
- throw new MLicensingException("Could not verify full license.", exception);
+ throw new MLicensingException("Could not verify license.", exception);
}
catch (MInvalidJsonValueException exception) {
- throw new MLicensingException("Could not verify full license.", exception);
+ throw new MLicensingException("Could not verify license.", exception);
}
catch (NoSuchAlgorithmException exception) {
- throw new MLicensingException("Could not verify full license.", exception);
+ throw new MLicensingException("Could not verify license.", exception);
}
catch (SignatureException exception) {
- throw new MLicensingException("Could not verify full license.", exception);
+ throw new MLicensingException("Could not verify license.", exception);
}
}