|
|
f8e459 |
import java.io.File;
|
|
|
f8e459 |
import java.io.FileInputStream;
|
|
|
f8e459 |
import java.security.Security;
|
|
|
f8e459 |
import java.util.Properties;
|
|
|
f8e459 |
|
|
|
f8e459 |
public class TestSecurityProperties {
|
|
|
f8e459 |
// JDK 11
|
|
|
f8e459 |
private static final String JDK_PROPS_FILE_JDK_11 = System.getProperty("java.home") + "/conf/security/java.security";
|
|
|
f8e459 |
// JDK 8
|
|
|
f8e459 |
private static final String JDK_PROPS_FILE_JDK_8 = System.getProperty("java.home") + "/lib/security/java.security";
|
|
|
f8e459 |
|
|
|
249eac |
private static final String POLICY_FILE = "/etc/crypto-policies/back-ends/java.config";
|
|
|
249eac |
|
|
|
249eac |
private static final String MSG_PREFIX = "DEBUG: ";
|
|
|
249eac |
|
|
|
f8e459 |
public static void main(String[] args) {
|
|
|
249eac |
if (args.length == 0) {
|
|
|
249eac |
System.err.println("TestSecurityProperties <true|false>");
|
|
|
249eac |
System.err.println("Invoke with 'true' if system security properties should be enabled.");
|
|
|
249eac |
System.err.println("Invoke with 'false' if system security properties should be disabled.");
|
|
|
249eac |
System.exit(1);
|
|
|
249eac |
}
|
|
|
249eac |
boolean enabled = Boolean.valueOf(args[0]);
|
|
|
249eac |
System.out.println(MSG_PREFIX + "System security properties enabled: " + enabled);
|
|
|
f8e459 |
Properties jdkProps = new Properties();
|
|
|
f8e459 |
loadProperties(jdkProps);
|
|
|
249eac |
if (enabled) {
|
|
|
249eac |
loadPolicy(jdkProps);
|
|
|
249eac |
}
|
|
|
f8e459 |
for (Object key: jdkProps.keySet()) {
|
|
|
f8e459 |
String sKey = (String)key;
|
|
|
f8e459 |
String securityVal = Security.getProperty(sKey);
|
|
|
f8e459 |
String jdkSecVal = jdkProps.getProperty(sKey);
|
|
|
f8e459 |
if (!securityVal.equals(jdkSecVal)) {
|
|
|
249eac |
String msg = "Expected value '" + jdkSecVal + "' for key '" +
|
|
|
f8e459 |
sKey + "'" + " but got value '" + securityVal + "'";
|
|
|
f8e459 |
throw new RuntimeException("Test failed! " + msg);
|
|
|
f8e459 |
} else {
|
|
|
249eac |
System.out.println(MSG_PREFIX + sKey + " = " + jdkSecVal + " as expected.");
|
|
|
f8e459 |
}
|
|
|
f8e459 |
}
|
|
|
f8e459 |
System.out.println("TestSecurityProperties PASSED!");
|
|
|
f8e459 |
}
|
|
|
249eac |
|
|
|
f8e459 |
private static void loadProperties(Properties props) {
|
|
|
f8e459 |
String javaVersion = System.getProperty("java.version");
|
|
|
249eac |
System.out.println(MSG_PREFIX + "Java version is " + javaVersion);
|
|
|
f8e459 |
String propsFile = JDK_PROPS_FILE_JDK_11;
|
|
|
f8e459 |
if (javaVersion.startsWith("1.8.0")) {
|
|
|
f8e459 |
propsFile = JDK_PROPS_FILE_JDK_8;
|
|
|
f8e459 |
}
|
|
|
249eac |
try (FileInputStream fin = new FileInputStream(propsFile)) {
|
|
|
249eac |
props.load(fin);
|
|
|
249eac |
} catch (Exception e) {
|
|
|
249eac |
throw new RuntimeException("Test failed!", e);
|
|
|
249eac |
}
|
|
|
249eac |
}
|
|
|
249eac |
|
|
|
249eac |
private static void loadPolicy(Properties props) {
|
|
|
249eac |
try (FileInputStream fin = new FileInputStream(POLICY_FILE)) {
|
|
|
f8e459 |
props.load(fin);
|
|
|
f8e459 |
} catch (Exception e) {
|
|
|
f8e459 |
throw new RuntimeException("Test failed!", e);
|
|
|
f8e459 |
}
|
|
|
f8e459 |
}
|
|
|
249eac |
|
|
|
f8e459 |
}
|