package net.curisit.securis; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import net.curisit.securis.beans.RequestBean; import net.curisit.securis.utils.JsonUtils; import net.curisit.securis.utils.LicUtils; import org.apache.commons.io.IOUtils; public class LicenseValidator { public static LicenseValidator singleton = new LicenseValidator(); private byte[] LOGO_SECRET; private LicenseValidator() { try { LOGO_SECRET = "Logo ipsum s3cr3t test áíóú".getBytes("utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } public static LicenseValidator getInstance() { return singleton; } /** * @return true if logo is correct */ public String getCrcLogo() { InputStream is = getClass().getClassLoader().getResourceAsStream("images/logo_customer.png"); try { String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LOGO_SECRET); return shaLogo; } catch (IOException e) { e.printStackTrace(); return null; } } public void validateLogo(RequestBean reqBean) throws SeCurisException { String currentCRC = getCrcLogo(); if (!currentCRC.equals(reqBean.getCrcLogo())) throw new SeCurisException("License logo validation failed for request data: " + JsonUtils.toJSON(reqBean)); } public void validateHW(RequestBean reqBean, String appCode, String customerCode) throws SeCurisException { RequestBean currentHW = ReqGenerator.getInstance().createRequest(appCode, customerCode); if (!currentHW.match(reqBean)) throw new SeCurisException("Current System info mismatch the License System info: " + JsonUtils.toJSON(reqBean)); } }