From b55a8de94a8bd4d93e8a40f75fd938f99255940d Mon Sep 17 00:00:00 2001 From: Marco Zanon Date: Sat, 2 Mar 2024 17:22:29 +0000 Subject: [PATCH] Renamed some methods and variables. --- CHANGELOG | 5 ++ .../com/marcozanon/macaco/MConstants.java | 2 +- .../macaco/licensing/MLicenseManager.java | 60 +++++++++---------- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5ca2149..cab32f4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,11 @@ Macaco Copyright (c) 2009-2024 Marco Zanon . See LICENSE for details. +=================== +10.0.0 (2024-03-02) +=================== +* Renamed some methods and variables. + ------------------ 9.2.1 (2024-03-02) ------------------ diff --git a/src/main/java/com/marcozanon/macaco/MConstants.java b/src/main/java/com/marcozanon/macaco/MConstants.java index e3e391f..a64c57f 100644 --- a/src/main/java/com/marcozanon/macaco/MConstants.java +++ b/src/main/java/com/marcozanon/macaco/MConstants.java @@ -13,7 +13,7 @@ public class MConstants extends MObject { /* Generic information. */ - public static final String MACACO_VERSION = "9.x"; + public static final String MACACO_VERSION = "10.x"; /* Environment configuration. */ diff --git a/src/main/java/com/marcozanon/macaco/licensing/MLicenseManager.java b/src/main/java/com/marcozanon/macaco/licensing/MLicenseManager.java index 7969d2b..f99df29 100644 --- a/src/main/java/com/marcozanon/macaco/licensing/MLicenseManager.java +++ b/src/main/java/com/marcozanon/macaco/licensing/MLicenseManager.java @@ -32,31 +32,31 @@ public class MLicenseManager { /* 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."); } @@ -83,61 +83,61 @@ public class MLicenseManager { 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"); @@ -145,22 +145,22 @@ public class MLicenseManager { 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); } } -- 2.30.2