Roberto Sánchez
2014-06-18 e767d38a97828997ed3080d1332a3a2f2bcf8491
#593 fix - Added further information when license is not valid due to HW
validation
2 files modified
changed files
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 @@
99 import net.curisit.securis.utils.LicUtils;
1010
1111 import org.apache.commons.io.IOUtils;
12
+import org.apache.logging.log4j.LogManager;
13
+import org.apache.logging.log4j.Logger;
1214
1315 public class LicenseValidator {
16
+
17
+ private static final Logger log = LogManager.getLogger(LicenseValidator.class);
1418
1519 public static LicenseValidator singleton = new LicenseValidator();
1620 private byte[] LOGO_SECRET;
....@@ -28,7 +32,7 @@
2832 }
2933
3034 /**
31
- * @return true if logo is correct
35
+ * @return CRC string for customer logo
3236 */
3337 public String getCrcLogo() {
3438 InputStream is = getClass().getClassLoader().getResourceAsStream("images/logo_customer.png");
....@@ -36,21 +40,25 @@
3640 String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LOGO_SECRET);
3741 return shaLogo;
3842 } catch (IOException e) {
39
- e.printStackTrace();
43
+ log.warn("Customer logo was not found in images/logo_customer.png");
4044 return null;
4145 }
4246 }
4347
4448 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
+ }
4856 }
4957
5058 public void validateHW(RequestBean reqBean, String appCode, String customerCode) throws SeCurisException {
5159 RequestBean currentHW = ReqGenerator.getInstance().createRequest(appCode, customerCode);
5260 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));
5462 }
5563
5664 }
src/patch/java/net/curisit/securis/LicenseGenerator.java
....@@ -111,7 +111,7 @@
111111 Signature signature;
112112 try {
113113 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")));
115115
116116 sh.prepareSignature(signature, licBean);
117117
....@@ -135,12 +135,12 @@
135135 public static void main(String[] args) throws SeCurisException {
136136 Paths.get(new File("/Users/cproberto/Documents/wsCurisIT/SeCurisClient/license.req").toURI());
137137
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"));
139139 Map<String, Object> metadata = new TreeMap<>();
140140 metadata.put("maxUsers", 23);
141141 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"));
144144
145145 System.out.print("os.arch: " + System.getProperty("os.arch") + " " + System.getProperty("os.name"));
146146