Blame SOURCES/TestSecurityProperties.java

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