Skip to content

Commit d939f5d

Browse files
committed
Fix certificate issue when saving blobs for iOS 15.5
1 parent 776124b commit d939f5d

File tree

8 files changed

+50
-15
lines changed

8 files changed

+50
-15
lines changed

.idea/compiler.xml

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Main__Linux_.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Main__Windows_.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Main__macOS_.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ def os = DefaultNativePlatform.currentOperatingSystem
4343
startScripts.enabled = distZip.enabled = distTar.enabled = false
4444

4545
java.toolchain.languageVersion = JavaLanguageVersion.of(18)
46+
tasks.withType(JavaCompile).configureEach {
47+
sourceCompatibility = 18
48+
}
4649

4750
repositories {
4851
mavenCentral()
@@ -65,16 +68,16 @@ javafx {
6568
modules = [ 'javafx.controls', 'javafx.fxml' ]
6669
}
6770

68-
String addExports = '--add-exports=javafx.graphics/com.sun.javafx.css=airsquared.blobsaver'
71+
def addExports = ['--add-exports=javafx.graphics/com.sun.javafx.css=airsquared.blobsaver', '--add-exports=java.base/jdk.internal.misc=airsquared.blobsaver']
6972

7073
compileJava {
71-
options.compilerArgs.add addExports
74+
options.compilerArgs.addAll addExports
7275
}
7376

7477
application {
7578
mainModule = "airsquared.blobsaver"
7679
mainClass = "airsquared.blobsaver.app.Main"
77-
applicationDefaultJvmArgs.add addExports
80+
applicationDefaultJvmArgs.addAll addExports
7881
}
7982

8083
private String getJarDirectory() {
@@ -92,14 +95,16 @@ run {
9295
test {
9396
useJUnitPlatform()
9497
systemProperty "jar.directory", getJarDirectory()
95-
jvmArgs '--add-exports=javafx.graphics/com.sun.glass.ui=org.testfx.monocle', addExports
98+
jvmArgs addExports
99+
jvmArgs '--add-exports=javafx.graphics/com.sun.glass.ui=org.testfx.monocle'
96100
}
97101

98102
jlink {
99103
addOptions '--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages', '--strip-native-commands',
100104
'--dedup-legal-notices=error-if-not-same-content'
101105
launcher {
102-
jvmArgs = [ '-Djar.directory={{BIN_DIR}}', addExports ]
106+
jvmArgs = [ '-Djar.directory={{BIN_DIR}}' ]
107+
jvmArgs.addAll addExports
103108
noConsole = true
104109
}
105110
jpackage {

src/main/java/airsquared/blobsaver/app/Main.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@
2525
import javafx.scene.Scene;
2626
import javafx.scene.image.Image;
2727
import javafx.stage.Stage;
28+
import jdk.internal.misc.Unsafe;
2829

2930
import java.io.File;
3031
import java.io.IOException;
3132
import java.io.UncheckedIOException;
33+
import java.time.LocalDate;
34+
import java.util.Map;
3235

3336
import static com.sun.jna.Platform.isMac;
3437
import static com.sun.jna.Platform.isWindows;
@@ -57,6 +60,7 @@ public class Main {
5760

5861
public static void main(String[] args) {
5962
setJNALibraryPath();
63+
fixCertificateError();
6064
if (args.length == 1 && args[0].equals("--background-autosave")) {
6165
Background.saveAllBackgroundBlobs(); // don't unnecessarily initialize any FX
6266
return;
@@ -82,6 +86,33 @@ static void setJNALibraryPath() {
8286
System.out.println("path = " + path);
8387
}
8488

89+
/**
90+
* Apple Decided use some old distrusted certificate for the iOS 15.5 IPSW, causing this error:
91+
* {@code javax.net.ssl.SSLHandshakeException: TLS Server certificate issued after 2019-12-31 and anchored by a distrusted legacy Symantec root CA: CN=GeoTrust Primary Certification Authority - G2, OU=(c) 2007 GeoTrust Inc. - For authorized use only, O=GeoTrust Inc., C=US }
92+
*
93+
* This uses reflection/unsafe to make the certificate "trusted" anyway.
94+
*s
95+
* Writing to private static final fields is from https://stackoverflow.com/a/61150853/5938387
96+
*/
97+
@SuppressWarnings({"removal", "Java9ReflectionClassVisibility"})
98+
static void fixCertificateError() {
99+
try {
100+
final var unsafe = Unsafe.getUnsafe();
101+
var field = Class.forName("sun.security.validator.SymantecTLSPolicy").getDeclaredField("EXEMPT_SUBCAS");
102+
103+
var staticFieldBase = unsafe.staticFieldBase(field);
104+
long staticFieldOffset = unsafe.staticFieldOffset(field);
105+
unsafe.putObject(staticFieldBase, staticFieldOffset, Map.of( // Copied from SymantecTLSPolicy.EXEMPT_SUBCAS
106+
"AC2B922ECFD5E01711772FEA8ED372DE9D1E2245FCE3F57A9CDBEC77296A424B",
107+
LocalDate.MAX,
108+
"A4FE7C7F15155F3F0AEF7AAA83CF6E06DEB97CA3F909DF920AC1490882D488ED",
109+
LocalDate.MAX
110+
));
111+
} catch (ClassNotFoundException | NoSuchFieldException e) {
112+
e.printStackTrace();
113+
}
114+
}
115+
85116
public static final class JavaFxApplication extends Application {
86117

87118
private static Application INSTANCE;

src/test/java/airsquared/blobsaver/app/BlobsaverTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
public class BlobsaverTest {
2424

2525
@BeforeAll
26-
public static void setJNALibraryPath() {
26+
public static void setUp() {
2727
Main.setJNALibraryPath();
28+
Main.fixCertificateError();
2829
}
2930
}

0 commit comments

Comments
 (0)