mirror of
https://github.com/mitb-archive/filebot
synced 2025-03-09 22:09:47 -04:00
Experiment with PGP signed messages
This commit is contained in:
parent
be082ab863
commit
d392beae82
@ -3,6 +3,7 @@ package net.filebot;
|
|||||||
import static java.nio.charset.StandardCharsets.*;
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
import static java.util.stream.Collectors.*;
|
import static java.util.stream.Collectors.*;
|
||||||
import static net.filebot.CachedResource.*;
|
import static net.filebot.CachedResource.*;
|
||||||
|
import static net.filebot.util.JsonUtilities.*;
|
||||||
import static net.filebot.util.RegularExpressions.*;
|
import static net.filebot.util.RegularExpressions.*;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@ -84,7 +85,7 @@ public class License implements Serializable {
|
|||||||
signature.update(clearSignMessage.getBytes(UTF_8));
|
signature.update(clearSignMessage.getBytes(UTF_8));
|
||||||
|
|
||||||
if (!signature.verify()) {
|
if (!signature.verify()) {
|
||||||
throw new PGPException("Signature does not match");
|
throw new PGPException("Bad Signature");
|
||||||
}
|
}
|
||||||
|
|
||||||
return clearSignMessage;
|
return clearSignMessage;
|
||||||
@ -92,10 +93,10 @@ public class License implements Serializable {
|
|||||||
|
|
||||||
private void verifyLicense() throws Exception {
|
private void verifyLicense() throws Exception {
|
||||||
Cache cache = CacheManager.getInstance().getCache("license", CacheType.Persistent);
|
Cache cache = CacheManager.getInstance().getCache("license", CacheType.Persistent);
|
||||||
String message = new CachedResource<Long, String>(id, i -> new URL("https://license.filebot.net/verify/" + id), (url, modified) -> WebRequest.post(url, bytes, "application/octet-stream", null), getText(UTF_8), String.class::cast, Cache.ONE_MONTH, cache).get().trim();
|
Object json = new CachedResource<Long, Object>(id, i -> new URL("https://license.filebot.net/verify/" + id), (url, modified) -> WebRequest.post(url, bytes, "application/octet-stream", null), getText(UTF_8), getJson(String.class::cast), Cache.ONE_MONTH, cache).get();
|
||||||
|
|
||||||
if (!message.equals("OK")) {
|
if (getInteger(json, "status") != 200) {
|
||||||
throw new PGPException(message);
|
throw new PGPException(getString(json, "message"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,14 +105,14 @@ public class License implements Serializable {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expires > System.currentTimeMillis()) {
|
if (expires < System.currentTimeMillis()) {
|
||||||
throw new IllegalStateException("Expired: " + toString());
|
throw new IllegalStateException("Expired: " + toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%s (Valid-Until: %s)", id, Instant.ofEpochMilli(expires).atZone(ZoneOffset.UTC).format(DateTimeFormatter.ISO_LOCAL_DATE));
|
return String.format("License %s (Valid-Until: %s)", id, Instant.ofEpochMilli(expires).atZone(ZoneOffset.UTC).format(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user