| .. | .. |
|---|
| 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 | 32 | } |
|---|
| 29 | 33 | |
|---|
| 30 | 34 | /** |
|---|
| 31 | | - * @return true if logo is correct |
|---|
| 35 | + * @return CRC string for customer logo |
|---|
| 32 | 36 | */ |
|---|
| 33 | 37 | public String getCrcLogo() { |
|---|
| 34 | 38 | InputStream is = getClass().getClassLoader().getResourceAsStream("images/logo_customer.png"); |
|---|
| .. | .. |
|---|
| 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 | } |
|---|