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