| src/main/java/net/curisit/securis/LicenseValidator.java | patch | view | blame | history | |
| src/patch/java/net/curisit/securis/LicenseGenerator.java | patch | view | blame | history |
src/main/java/net/curisit/securis/LicenseValidator.java
.. .. @@ -9,8 +9,12 @@ 9 9 import net.curisit.securis.utils.LicUtils; 10 10 11 11 import org.apache.commons.io.IOUtils; 12 +import org.apache.logging.log4j.LogManager;13 +import org.apache.logging.log4j.Logger;12 14 13 15 public class LicenseValidator { 16 +17 + private static final Logger log = LogManager.getLogger(LicenseValidator.class);14 18 15 19 public static LicenseValidator singleton = new LicenseValidator(); 16 20 private byte[] LOGO_SECRET; .. .. @@ -28,7 +32,7 @@ 28 32 } 29 33 30 34 /** 31 - * @return true if logo is correct35 + * @return CRC string for customer logo32 36 */ 33 37 public String getCrcLogo() { 34 38 InputStream is = getClass().getClassLoader().getResourceAsStream("images/logo_customer.png"); .. .. @@ -36,21 +40,25 @@ 36 40 String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LOGO_SECRET); 37 41 return shaLogo; 38 42 } catch (IOException e) { 39 - e.printStackTrace();43 + log.warn("Customer logo was not found in images/logo_customer.png");40 44 return null; 41 45 } 42 46 } 43 47 44 48 public void validateLogo(RequestBean reqBean) throws SeCurisException { 45 - String currentCRC = getCrcLogo();46 - if (!currentCRC.equals(reqBean.getCrcLogo()))47 - throw new SeCurisException("License logo validation failed for request data: " + JsonUtils.toJSON(reqBean));49 + if (reqBean.getCrcLogo() == null) {50 + log.info("Customer logo is not included in license file and won't be validated");51 + } else {52 + String currentCRC = getCrcLogo();53 + if (!currentCRC.equals(reqBean.getCrcLogo()))54 + throw new SeCurisException("License logo validation failed for request data: " + JsonUtils.toJSON(reqBean));55 + }48 56 } 49 57 50 58 public void validateHW(RequestBean reqBean, String appCode, String customerCode) throws SeCurisException { 51 59 RequestBean currentHW = ReqGenerator.getInstance().createRequest(appCode, customerCode); 52 60 if (!currentHW.match(reqBean)) 53 - throw new SeCurisException("Current System info mismatch the License System info: " + JsonUtils.toJSON(reqBean));61 + throw new SeCurisException("Current System info mismatch the License System info:\n Licensed: " + JsonUtils.toJSON(reqBean, true) + "\n Expected: " + JsonUtils.toJSON(currentHW, true));54 62 } 55 63 56 64 } src/patch/java/net/curisit/securis/LicenseGenerator.java
.. .. @@ -111,7 +111,7 @@ 111 111 Signature signature; 112 112 try { 113 113 signature = Signature.getInstance(SignatureHelper.SIGNATURE_GENERATION_ALGORITHM); 114 - signature.initSign(sh.generatePrivateKey(new File("/Users/cproberto/Documents/wsPython/doky/tests/privkey.pkcs8")));114 + signature.initSign(sh.generatePrivateKey(new File("/Users/cproberto/Documents/wsPython/doky/tests/securis_private_key.pkcs8")));115 115 116 116 sh.prepareSignature(signature, licBean); 117 117 .. .. @@ -135,12 +135,12 @@ 135 135 public static void main(String[] args) throws SeCurisException { 136 136 Paths.get(new File("/Users/cproberto/Documents/wsCurisIT/SeCurisClient/license.req").toURI()); 137 137 138 - RequestBean req = ReqGenerator.getInstance().loadRequest(new File("/Users/cproberto/Documents/wsCurisIT/SeCurisClient/license.req"));138 + RequestBean req = ReqGenerator.getInstance().loadRequest(new File("/Users/cproberto/Downloads/license.req"));139 139 Map<String, Object> metadata = new TreeMap<>(); 140 140 metadata.put("maxUsers", 23); 141 141 metadata.put("maxInstances", 12); 142 - LicenseBean lic = LicenseGenerator.getInstance().generateLicense(req, metadata, new Date(new Date().getTime() + 3600 * 1000), "L01", "LIC-9812987123-12837129873");143 - LicenseGenerator.getInstance().save(lic, new File("/Users/cproberto/Documents/wsCurisIT/SeCurisClient/license.lic"));142 + LicenseBean lic = LicenseGenerator.getInstance().generateLicense(req, metadata, new Date(new Date().getTime() + 3600 * 1000), "CurisData01", "LIC-9812987123-12837129873");143 + LicenseGenerator.getInstance().save(lic, new File("/Users/cproberto/Downloads/license_curisdata.lic"));144 144 145 145 System.out.print("os.arch: " + System.getProperty("os.arch") + " " + System.getProperty("os.name")); 146 146