Search in sources :

Example 1 with LicenseException

use of com.atlassian.extras.common.LicenseException in project env-tool-suite by stormning.

the class Version2LicenseDecoder method packLicense.

public static String packLicense(byte[] text, byte[] hash) throws LicenseException {
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DataOutputStream dOut = new DataOutputStream(out);
        dOut.writeInt(text.length);
        dOut.write(text);
        dOut.write(hash);
        byte[] allData = out.toByteArray();
        String result = (new String(Base64.encodeBase64(allData))).trim();
        result = result + 'X' + "0" + 2 + Integer.toString(result.length(), 31);
        result = split(result);
        return result;
    } catch (IOException var6) {
        throw new LicenseException(var6);
    }
}
Also used : LicenseException(com.atlassian.extras.common.LicenseException) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 2 with LicenseException

use of com.atlassian.extras.common.LicenseException in project env-tool-suite by stormning.

the class Version2LicenseDecoder method unzipText.

private Reader unzipText(byte[] licenseText) {
    ByteArrayInputStream in = new ByteArrayInputStream(licenseText);
    in.skip((long) LICENSE_PREFIX.length);
    InflaterInputStream zipIn = new InflaterInputStream(in, new Inflater());
    try {
        return new InputStreamReader(zipIn, "UTF-8");
    } catch (UnsupportedEncodingException var5) {
        throw new LicenseException(var5);
    }
}
Also used : LicenseException(com.atlassian.extras.common.LicenseException) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Inflater(java.util.zip.Inflater)

Example 3 with LicenseException

use of com.atlassian.extras.common.LicenseException in project env-tool-suite by stormning.

the class Version2LicenseDecoder method checkAndGetLicenseText.

private byte[] checkAndGetLicenseText(String licenseContent) {
    try {
        byte[] decodedBytes = Base64.decodeBase64(licenseContent.getBytes());
        ByteArrayInputStream in = new ByteArrayInputStream(decodedBytes);
        DataInputStream dIn = new DataInputStream(in);
        int textLength = dIn.readInt();
        byte[] licenseText = new byte[textLength];
        dIn.read(licenseText);
        byte[] hash = new byte[dIn.available()];
        dIn.read(hash);
        try {
            Signature signature = Signature.getInstance("SHA1withDSA");
            signature.initVerify(PUBLIC_KEY);
            signature.update(licenseText);
            if (!signature.verify(hash)) {
                throw new LicenseException("Failed to verify the license.");
            } else {
                return licenseText;
            }
        } catch (InvalidKeyException var9) {
            throw new LicenseException(var9);
        } catch (SignatureException var10) {
            throw new LicenseException(var10);
        } catch (NoSuchAlgorithmException var11) {
            throw new LicenseException(var11);
        }
    } catch (IOException var12) {
        throw new LicenseException(var12);
    }
}
Also used : LicenseException(com.atlassian.extras.common.LicenseException) ByteArrayInputStream(java.io.ByteArrayInputStream) Signature(java.security.Signature) SignatureException(java.security.SignatureException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) InvalidKeyException(java.security.InvalidKeyException)

Example 4 with LicenseException

use of com.atlassian.extras.common.LicenseException in project env-tool-suite by stormning.

the class Version2LicenseDecoder method loadLicenseConfiguration.

private Properties loadLicenseConfiguration(Reader text) {
    try {
        Properties props = new Properties();
        (new DefaultPropertiesPersister()).load(props, text);
        return props;
    } catch (IOException var3) {
        throw new LicenseException("Could NOT load properties from reader", var3);
    }
}
Also used : LicenseException(com.atlassian.extras.common.LicenseException) DefaultPropertiesPersister(com.atlassian.extras.common.org.springframework.util.DefaultPropertiesPersister) IOException(java.io.IOException) Properties(java.util.Properties)

Aggregations

LicenseException (com.atlassian.extras.common.LicenseException)4 IOException (java.io.IOException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DefaultPropertiesPersister (com.atlassian.extras.common.org.springframework.util.DefaultPropertiesPersister)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Signature (java.security.Signature)1 SignatureException (java.security.SignatureException)1 Properties (java.util.Properties)1 Inflater (java.util.zip.Inflater)1 InflaterInputStream (java.util.zip.InflaterInputStream)1