Blame SOURCES/TestSecurityProperties.java

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