check expiration
This commit is contained in:
parent
661e783f24
commit
002b76a33a
4 changed files with 56 additions and 1 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
18
app/src/main/java/com/example/app/utils/Alpha.java
Normal file
18
app/src/main/java/com/example/app/utils/Alpha.java
Normal file
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
19
app/src/main/java/com/example/app/utils/Beta.java
Normal file
19
app/src/main/java/com/example/app/utils/Beta.java
Normal file
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
7
app/src/main/java/com/example/app/utils/Omega.java
Normal file
7
app/src/main/java/com/example/app/utils/Omega.java
Normal file
|
|
@ -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};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue