Blame SOURCES/TestSecurityProperties.java

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