Blame SOURCES/TestSecurityProperties.java

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