// Returns major version number from os.version system property. // E.g. 3 on SLES 11.3 (for the linux kernel version). publicstaticint getOsVersionMajor() { if (osVersionMajor == -1) init_version(); return osVersionMajor;
}
// Returns minor version number from os.version system property. // E.g. 0 on SLES 11.3 (for the linux kernel version). publicstaticint getOsVersionMinor() { if (osVersionMinor == -1) init_version(); return osVersionMinor;
}
/** *ReturnabooleanforwhetherSAandjhsdbareported/available *onthisplatform.
*/ publicstaticboolean hasSA() { if (isZero()) { returnfalse; // SA is not enabled.
} if (isAix()) { returnfalse; // SA not implemented.
} elseif (isLinux()) { if (isS390x() || isARM()) { returnfalse; // SA not implemented.
}
} // Other platforms expected to work: returntrue;
}
/** *ReturntrueifthetestJDKishardened,otherwisefalse.OnlyvalidonOSX.
*/ publicstaticboolean isHardenedOSX() throws IOException { // We only care about hardened binaries for 10.14 and later (actually 10.14.5, but // for simplicity we'll also include earlier 10.14 versions). if (getOsVersionMajor() == 10 && getOsVersionMinor() < 14) { returnfalse; // assume not hardened
}
// Find the path to the java binary.
String jdkPath = System.getProperty("java.home");
Path javaPath = Paths.get(jdkPath + "/bin/java");
String javaFileName = javaPath.toAbsolutePath().toString(); if (Files.notExists(javaPath)) { thrownew FileNotFoundException("Could not find file " + javaFileName);
}
// Run codesign on the java binary.
ProcessBuilder pb = new ProcessBuilder("codesign", "--display", "--verbose", javaFileName);
pb.redirectErrorStream(true); // redirect stderr to stdout
Process codesignProcess = pb.start();
BufferedReader is = new BufferedReader(new InputStreamReader(codesignProcess.getInputStream()));
String line; boolean isHardened = false; boolean hardenedStatusConfirmed = false; // set true when we confirm whether or not hardened while ((line = is.readLine()) != null) {
System.out.println("STDOUT: " + line); if (line.indexOf("flags=0x10000(runtime)") != -1 ) {
hardenedStatusConfirmed = true;
isHardened = true;
System.out.println("Target JDK is hardened. Some tests may be skipped.");
} elseif (line.indexOf("flags=0x20002(adhoc,linker-signed)") != -1 ) {
hardenedStatusConfirmed = true;
isHardened = false;
System.out.println("Target JDK is adhoc signed, but not hardened.");
} elseif (line.indexOf("code object is not signed at all") != -1) {
hardenedStatusConfirmed = true;
isHardened = false;
System.out.println("Target JDK is not signed, therefore not hardened.");
}
} if (!hardenedStatusConfirmed) {
System.out.println("Could not confirm if TargetJDK is hardened. Assuming not hardened.");
isHardened = false;
}
try { if (codesignProcess.waitFor(10, TimeUnit.SECONDS) == false) {
System.err.println("Timed out waiting for the codesign process to complete. Assuming not hardened.");
codesignProcess.destroyForcibly(); returnfalse; // assume not hardened
}
} catch (InterruptedException e) { thrownew RuntimeException(e);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.