| .. | .. |
|---|
| 3 | 3 | import java.io.IOException; |
|---|
| 4 | 4 | import java.io.InputStream; |
|---|
| 5 | 5 | import java.io.UnsupportedEncodingException; |
|---|
| 6 | +import java.util.UUID; |
|---|
| 6 | 7 | |
|---|
| 7 | 8 | import net.curisit.securis.beans.RequestBean; |
|---|
| 8 | 9 | import net.curisit.securis.utils.JsonUtils; |
|---|
| .. | .. |
|---|
| 14 | 15 | |
|---|
| 15 | 16 | public class LicenseValidator { |
|---|
| 16 | 17 | |
|---|
| 17 | | - private static final Logger LOG = LogManager.getLogger(LicenseValidator.class); |
|---|
| 18 | + private static final Logger LOG = LogManager.getLogger(LicenseValidator.class); |
|---|
| 18 | 19 | |
|---|
| 19 | | - private static LicenseValidator singleton = new LicenseValidator(); |
|---|
| 20 | | - protected static byte[] LOGO_SECRET; |
|---|
| 20 | + private static LicenseValidator singleton = new LicenseValidator(); |
|---|
| 21 | + protected static byte[] LOGO_SECRET; |
|---|
| 21 | 22 | |
|---|
| 22 | | - static { |
|---|
| 23 | | - try { |
|---|
| 24 | | - LOGO_SECRET = "Logo ipsum s3cr3t test áíóú".getBytes("utf-8"); |
|---|
| 25 | | - } catch (UnsupportedEncodingException e) { |
|---|
| 26 | | - LOG.error("Unexpected error getting LOGO secret", e); |
|---|
| 27 | | - } |
|---|
| 28 | | - } |
|---|
| 23 | + static { |
|---|
| 24 | + try { |
|---|
| 25 | + LOGO_SECRET = "Logo ipsum s3cr3t test áíóú".getBytes("utf-8"); |
|---|
| 26 | + } catch (UnsupportedEncodingException e) { |
|---|
| 27 | + LOG.error("Unexpected error getting LOGO secret", e); |
|---|
| 28 | + } |
|---|
| 29 | + } |
|---|
| 29 | 30 | |
|---|
| 30 | | - private LicenseValidator() { |
|---|
| 31 | | - } |
|---|
| 31 | + private LicenseValidator() { |
|---|
| 32 | + } |
|---|
| 32 | 33 | |
|---|
| 33 | | - public static LicenseValidator getInstance() { |
|---|
| 34 | | - return singleton; |
|---|
| 35 | | - } |
|---|
| 34 | + public static LicenseValidator getInstance() { |
|---|
| 35 | + return singleton; |
|---|
| 36 | + } |
|---|
| 36 | 37 | |
|---|
| 37 | | - /** |
|---|
| 38 | | - * @return CRC string for customer logo |
|---|
| 39 | | - */ |
|---|
| 40 | | - public String getCrcLogo() { |
|---|
| 41 | | - InputStream is = getClass().getClassLoader().getResourceAsStream("images/logo_customer.png"); |
|---|
| 42 | | - try { |
|---|
| 43 | | - String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LOGO_SECRET); |
|---|
| 44 | | - return shaLogo; |
|---|
| 45 | | - } catch (IOException e) { |
|---|
| 46 | | - LOG.warn("Customer logo was not found in images/logo_customer.png"); |
|---|
| 47 | | - return null; |
|---|
| 48 | | - } |
|---|
| 49 | | - } |
|---|
| 38 | + /** |
|---|
| 39 | + * @return CRC string for customer logo |
|---|
| 40 | + */ |
|---|
| 41 | + public String getCrcLogo() { |
|---|
| 42 | + InputStream is = getClass().getClassLoader().getResourceAsStream("images/logo_customer.png"); |
|---|
| 43 | + try { |
|---|
| 44 | + String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LOGO_SECRET); |
|---|
| 45 | + return shaLogo; |
|---|
| 46 | + } catch (IOException e) { |
|---|
| 47 | + LOG.warn("Customer logo was not found in images/logo_customer.png"); |
|---|
| 48 | + return null; |
|---|
| 49 | + } |
|---|
| 50 | + } |
|---|
| 50 | 51 | |
|---|
| 51 | | - public void validateLogo(RequestBean reqBean) throws SeCurisException { |
|---|
| 52 | | - if (reqBean.getCrcLogo() == null) { |
|---|
| 53 | | - LOG.info("Customer logo is not included in license file and won't be validated"); |
|---|
| 54 | | - } else { |
|---|
| 55 | | - String currentCRC = getCrcLogo(); |
|---|
| 56 | | - if (!currentCRC.equals(reqBean.getCrcLogo())) |
|---|
| 57 | | - throw new SeCurisException("License logo validation failed for request data: " + JsonUtils.toJSON(reqBean)); |
|---|
| 58 | | - } |
|---|
| 59 | | - } |
|---|
| 52 | + public void validateLogo(RequestBean reqBean) throws SeCurisException { |
|---|
| 53 | + if (reqBean.getCrcLogo() == null) { |
|---|
| 54 | + LOG.info("Customer logo is not included in license file and won't be validated"); |
|---|
| 55 | + } else { |
|---|
| 56 | + String currentCRC = getCrcLogo(); |
|---|
| 57 | + if (!currentCRC.equals(reqBean.getCrcLogo())) |
|---|
| 58 | + throw new SeCurisException("License logo validation failed for request data: " + JsonUtils.toJSON(reqBean)); |
|---|
| 59 | + } |
|---|
| 60 | + } |
|---|
| 60 | 61 | |
|---|
| 61 | | - public void validateHW(RequestBean reqBean, String licTypeCode, String customerCode, String packCode) throws SeCurisException { |
|---|
| 62 | | - RequestBean currentHW = ReqGenerator.getInstance().createRequest(licTypeCode, customerCode, packCode); |
|---|
| 63 | | - if (!currentHW.match(reqBean)) { |
|---|
| 64 | | - throw new SeCurisException("Current System info mismatch the License System info:\n Licensed: \n" |
|---|
| 65 | | - + JsonUtils.toPrettyJSON(reqBean, RequestBean.class) + "\n Expected: \n" + JsonUtils.toPrettyJSON(currentHW)); |
|---|
| 66 | | - } |
|---|
| 67 | | - } |
|---|
| 62 | + public void validateHW(RequestBean reqBean, String licTypeCode, String customerCode, String packCode) throws SeCurisException { |
|---|
| 63 | + RequestBean currentHW = ReqGenerator.getInstance().createRequest(licTypeCode, customerCode, packCode); |
|---|
| 64 | + if (!currentHW.match(reqBean)) { |
|---|
| 65 | + throw new SeCurisException("Current System info mismatch the License System info:\n Licensed: \n" + JsonUtils.toPrettyJSON(reqBean, RequestBean.class) |
|---|
| 66 | + + "\n Expected: \n" + JsonUtils.toPrettyJSON(currentHW)); |
|---|
| 67 | + } |
|---|
| 68 | + } |
|---|
| 68 | 69 | |
|---|
| 69 | | - public void validateHW(RequestBean reqBean, String appCode, String activationCode) throws SeCurisException { |
|---|
| 70 | | - RequestBean currentHW = ReqGenerator.getInstance().createRequest(appCode, activationCode); |
|---|
| 71 | | - if (!currentHW.match(reqBean)) { |
|---|
| 72 | | - throw new SeCurisException("Current System info mismatch the License System info:\n Licensed: \n" |
|---|
| 73 | | - + JsonUtils.toPrettyJSON(reqBean, RequestBean.class) + "\n Expected: \n" + JsonUtils.toPrettyJSON(currentHW)); |
|---|
| 74 | | - } |
|---|
| 75 | | - } |
|---|
| 70 | + public void validateHW(RequestBean reqBean, String appCode, String activationCode) throws SeCurisException { |
|---|
| 71 | + RequestBean currentHW = ReqGenerator.getInstance().createRequest(appCode, activationCode); |
|---|
| 72 | + if (!currentHW.match(reqBean)) { |
|---|
| 73 | + throw new SeCurisException("Current System info mismatch the License System info:\n Licensed: \n" + JsonUtils.toPrettyJSON(reqBean, RequestBean.class) |
|---|
| 74 | + + "\n Expected: \n" + JsonUtils.toPrettyJSON(currentHW)); |
|---|
| 75 | + } |
|---|
| 76 | + } |
|---|
| 76 | 77 | |
|---|
| 78 | + public static boolean isValidActivationCode(String activationCode) { |
|---|
| 79 | + try { |
|---|
| 80 | + UUID.fromString(activationCode); |
|---|
| 81 | + return true; |
|---|
| 82 | + } catch (Exception ex) { |
|---|
| 83 | + return false; |
|---|
| 84 | + } |
|---|
| 85 | + } |
|---|
| 77 | 86 | } |
|---|