Blame SOURCES/TestSecurityProperties.java

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