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