Skip to content

Commit

Permalink
Add workaround for JDK-8266929 (qzind#819)
Browse files Browse the repository at this point in the history
Closes qzind#814
  • Loading branch information
tresf authored Jun 4, 2021
1 parent 0fcd662 commit 23639f2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/qz/installer/certificate/CertificateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
* Stores and maintains reading and writing of certificate related files
*/
public class CertificateManager {
static {
// Workaround for JDK-8266929
// See also https://github.com/qzind/tray/issues/814
SystemUtilities.clearAlgorithms();
}
private static final Logger log = LoggerFactory.getLogger(CertificateManager.class);

public static String DEFAULT_KEYSTORE_FORMAT = "PKCS12";
Expand Down
47 changes: 47 additions & 0 deletions src/qz/utils/SystemUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -537,4 +537,51 @@ public static boolean hasMonocle() {
}
return hasMonocle;
}

public static final Version[] JDK_8266929_VERSIONS = {
Version.valueOf("11.0.11"),
Version.valueOf("1.8.0+291"),
Version.valueOf("1.8.0+292")
};

/**
* Fixes JDK-8266929 by clearing the oidTable
* See also: https://github.com/qzind/tray/issues/814
*/
public static void clearAlgorithms() {
boolean needsPatch = false;
for(Version affected : JDK_8266929_VERSIONS) {
if(affected.getMajorVersion() == 1) {
// Java 1.8 honors build/update information
if(affected.compareWithBuildsTo(Constants.JAVA_VERSION) == 0) {
needsPatch = true;
}
} else if (affected.compareTo(Constants.JAVA_VERSION) == 0) {
// Java 9.0+ ignores build/update information
needsPatch = true;
}
}
if(!needsPatch) {
log.debug("Skipping JDK-8266929 patch for {}", Constants.JAVA_VERSION);
return;
}
try {
log.info("Applying JDK-8266929 patch");
Class<?> algorithmIdClass = Class.forName("sun.security.x509.AlgorithmId");
java.lang.reflect.Field oidTableField = algorithmIdClass.getDeclaredField("oidTable");
oidTableField.setAccessible(true);
// Set oidTable to null
oidTableField.set(algorithmIdClass, null);
// Java 1.8
if(Constants.JAVA_VERSION.getMajorVersion() == 1) {
java.lang.reflect.Field initOidTableField = algorithmIdClass.getDeclaredField("initOidTable");
initOidTableField.setAccessible(true);
// Set init flag back to false
initOidTableField.set(algorithmIdClass, false);
}
log.info("Successfully applied JDK-8266929 patch");
} catch (Exception e) {
log.warn("Unable to apply JDK-8266929 patch. Some algorithms may fail.", e);
}
}
}

0 comments on commit 23639f2

Please sign in to comment.