diff --git a/app/src/main/java/com/example/app/LicenseOneShot.java b/app/src/main/java/com/example/app/LicenseOneShot.java index eeb7269..bb02863 100644 --- a/app/src/main/java/com/example/app/LicenseOneShot.java +++ b/app/src/main/java/com/example/app/LicenseOneShot.java @@ -9,6 +9,9 @@ import java.time.Instant; import java.util.Base64; import java.util.Properties; +import org.springframework.util.StringUtils; + +import com.example.app.utils.Beta; import com.example.app.utils.DeterministicHexSequenceWithTimestamp; import com.example.app.utils.KeyUtils; import com.example.app.utils.LicenseUtils; @@ -39,6 +42,14 @@ public class LicenseOneShot { public void check() { + final var until = properties.getProperty("until"); + if(StringUtils.hasText(until)){ + final var expiration = Instant.ofEpochMilli(Long.valueOf(Beta.reveal(until))); + if(Instant.now().isBefore(expiration)){ + return; + } + } + // TODO: check expiration... final var requestTimestamp = Instant.now() .toEpochMilli(); @@ -93,7 +104,7 @@ public class LicenseOneShot { // persist license on property file. properties.setProperty("index", splitDecryptedResponse[0]); - properties.setProperty("until", splitDecryptedResponse[1]); + properties.setProperty("until", Beta.obscure(splitDecryptedResponse[1])); saveProperties(properties, this.filePath); } diff --git a/app/src/main/java/com/example/app/utils/Alpha.java b/app/src/main/java/com/example/app/utils/Alpha.java new file mode 100644 index 0000000..c323002 --- /dev/null +++ b/app/src/main/java/com/example/app/utils/Alpha.java @@ -0,0 +1,18 @@ +package com.example.app.utils; + +import javax.crypto.Cipher; +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; +import java.util.Base64; + +public class Alpha { + private static final byte[] keyBytes = Omega.retrieveKey(); + + public static String transform(String input, boolean mode) throws Exception { + Cipher cipher = Cipher.getInstance("AES"); + SecretKey secretKey = new SecretKeySpec(keyBytes, "AES"); + cipher.init(mode ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, secretKey); + byte[] outputBytes = mode ? cipher.doFinal(input.getBytes()) : cipher.doFinal(Base64.getDecoder().decode(input)); + return mode ? Base64.getEncoder().encodeToString(outputBytes) : new String(outputBytes); + } +} diff --git a/app/src/main/java/com/example/app/utils/Beta.java b/app/src/main/java/com/example/app/utils/Beta.java new file mode 100644 index 0000000..16e45c3 --- /dev/null +++ b/app/src/main/java/com/example/app/utils/Beta.java @@ -0,0 +1,19 @@ +package com.example.app.utils; + +public class Beta { + public static String obscure(String input) { + try { + return Alpha.transform(input, true); + } catch (Exception e) { + throw new IllegalStateException("Could not obscure!", e); + } + } + + public static String reveal(String input) { + try { + return Alpha.transform(input, false); + } catch (Exception e) { + throw new IllegalStateException("Could not reveal!", e); + } + } +} diff --git a/app/src/main/java/com/example/app/utils/Omega.java b/app/src/main/java/com/example/app/utils/Omega.java new file mode 100644 index 0000000..e14b1e7 --- /dev/null +++ b/app/src/main/java/com/example/app/utils/Omega.java @@ -0,0 +1,7 @@ +package com.example.app.utils; + +public class Omega { + protected static byte[] retrieveKey() { + return new byte[]{0x13, 0x26, 0x39, 0x52, 0x65, 0x78, 0x7A, 0x4B, 0x5D, 0x6E, (byte) 0x8F, (byte) 0x9A, (byte) 0xBC, (byte) 0xCD, (byte) 0xDE, (byte) 0xEF}; + } +} \ No newline at end of file