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
4e01a42e69
commit
03fb5b3b94
@ -3,13 +3,9 @@ package net.filebot;
|
||||
import static java.nio.charset.StandardCharsets.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static net.filebot.CachedResource.*;
|
||||
import static net.filebot.Settings.*;
|
||||
import static net.filebot.platform.windows.WinAppUtilities.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.net.URL;
|
||||
import java.time.Instant;
|
||||
@ -29,35 +25,10 @@ import org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider;
|
||||
|
||||
import net.filebot.util.ByteBufferOutputStream;
|
||||
import net.filebot.util.SystemProperty;
|
||||
import net.filebot.web.WebRequest;
|
||||
|
||||
public class License implements Serializable {
|
||||
|
||||
public static final SystemProperty<File> LICENSE_FILE = SystemProperty.of("net.filebot.license", File::new, ApplicationFolder.AppData.resolve("license.txt"));
|
||||
|
||||
public static final Resource<License> INSTANCE = Resource.lazy(() -> {
|
||||
return new License(readFile(LICENSE_FILE.get()));
|
||||
});
|
||||
|
||||
public static final void check() throws Exception {
|
||||
if (isAppStore()) {
|
||||
if (isWindowsApp() && "PointPlanck.FileBot".equals(getAppUserModelID())) {
|
||||
return;
|
||||
} else if (isMacSandbox() && !File.listRoots()[0].canRead()) {
|
||||
return;
|
||||
}
|
||||
throw new Exception("BAD LICENSE: " + getAppStoreName() + " sandbox not found");
|
||||
}
|
||||
|
||||
// check license file
|
||||
License license = INSTANCE.get();
|
||||
|
||||
if (!license.isValid()) {
|
||||
throw new Exception("BAD LICENSE: " + license);
|
||||
}
|
||||
};
|
||||
|
||||
private byte[] bytes;
|
||||
|
||||
private long id;
|
||||
@ -76,8 +47,8 @@ public class License implements Serializable {
|
||||
verifyLicense();
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return expires < System.currentTimeMillis();
|
||||
public boolean expired() {
|
||||
return expires > System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() throws Exception {
|
||||
@ -111,7 +82,7 @@ public class License implements Serializable {
|
||||
signature.update(clearSignMessage.getBytes(UTF_8));
|
||||
|
||||
if (!signature.verify()) {
|
||||
throw new PGPException("BAD LICENSE: Signature does not match");
|
||||
throw new PGPException("Signature does not match");
|
||||
}
|
||||
|
||||
return clearSignMessage;
|
||||
|
9
source/net/filebot/LicenseError.java
Normal file
9
source/net/filebot/LicenseError.java
Normal file
@ -0,0 +1,9 @@
|
||||
package net.filebot;
|
||||
|
||||
public class LicenseError extends Error {
|
||||
|
||||
public LicenseError(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
63
source/net/filebot/LicenseType.java
Normal file
63
source/net/filebot/LicenseType.java
Normal file
@ -0,0 +1,63 @@
|
||||
package net.filebot;
|
||||
|
||||
import static net.filebot.Settings.*;
|
||||
import static net.filebot.platform.windows.WinAppUtilities.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.filebot.util.SystemProperty;
|
||||
|
||||
public enum LicenseType {
|
||||
|
||||
MicrosoftStore {
|
||||
|
||||
@Override
|
||||
public void check() throws LicenseError {
|
||||
if (!getAppUserModelID().equals("PointPlanck.FileBot")) {
|
||||
throw new LicenseError("Invalid container state");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
MacAppStore {
|
||||
|
||||
@Override
|
||||
public void check() throws LicenseError {
|
||||
if (File.listRoots()[0].canRead()) {
|
||||
throw new LicenseError("Invalid container state");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
PGPSignedMessage {
|
||||
|
||||
public final SystemProperty<File> LICENSE_FILE = SystemProperty.of("net.filebot.license", File::new, ApplicationFolder.AppData.resolve("license.txt"));
|
||||
public final Resource<License> LICENSE = Resource.lazy(() -> new License(readFile(LICENSE_FILE.get())));
|
||||
|
||||
@Override
|
||||
public void check() throws LicenseError {
|
||||
try {
|
||||
License license = LICENSE.get();
|
||||
|
||||
if (license.expired()) {
|
||||
throw new LicenseError("Expired: " + license);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new LicenseError(e.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public abstract void check() throws LicenseError;
|
||||
|
||||
public static LicenseType get() {
|
||||
if (isUWP())
|
||||
return MicrosoftStore;
|
||||
if (isMacSandbox())
|
||||
return MacAppStore;
|
||||
|
||||
return PGPSignedMessage;
|
||||
}
|
||||
|
||||
}
|
@ -82,7 +82,7 @@ public final class Settings {
|
||||
}
|
||||
|
||||
public static boolean isAppStore() {
|
||||
return isApplicationDeployment("mas", "appx");
|
||||
return isApplicationDeployment("appx", "mas");
|
||||
}
|
||||
|
||||
public static boolean isWindowsApp() {
|
||||
@ -101,6 +101,10 @@ public final class Settings {
|
||||
return isApplicationDeployment("mas");
|
||||
}
|
||||
|
||||
public static boolean isUWP() {
|
||||
return isApplicationDeployment("appx");
|
||||
}
|
||||
|
||||
public static boolean isAutoUpdateEnabled() {
|
||||
return isApplicationDeployment("mas", "appx", "snap", "spk", "aur");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user