static X509TrustManager createTrustManager()

in common/src/main/java/org/apache/omid/tls/X509Util.java [226:270]


    static X509TrustManager createTrustManager(String trustStoreLocation, char[] trustStorePassword,
                                               String trustStoreType, boolean crlEnabled, boolean ocspEnabled) throws TrustManagerException {

        if (trustStoreType == null) {
            trustStoreType = "jks";
        }

        if (trustStorePassword == null) {
            trustStorePassword = EMPTY_CHAR_ARRAY;
        }

        try {
            KeyStore ts = KeyStore.getInstance(trustStoreType);
            try (InputStream inputStream = Files.newInputStream(new File(trustStoreLocation).toPath())) {
                ts.load(inputStream, trustStorePassword);
            }

            PKIXBuilderParameters pbParams = new PKIXBuilderParameters(ts, new X509CertSelector());
            if (crlEnabled || ocspEnabled) {
                pbParams.setRevocationEnabled(true);
                System.setProperty("com.sun.net.ssl.checkRevocation", "true");
                if (crlEnabled) {
                    System.setProperty("com.sun.security.enableCRLDP", "true");
                }
                if (ocspEnabled) {
                    Security.setProperty("ocsp.enable", "true");
                }
            } else {
                pbParams.setRevocationEnabled(false);
            }

            // Revocation checking is only supported with the PKIX algorithm
            TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX");
            tmf.init(new CertPathTrustManagerParameters(pbParams));

            for (final TrustManager tm : tmf.getTrustManagers()) {
                if (tm instanceof X509ExtendedTrustManager) {
                    return (X509ExtendedTrustManager) tm;
                }
            }
            throw new TrustManagerException("Couldn't find X509TrustManager");
        } catch (IOException | GeneralSecurityException | IllegalArgumentException e) {
            throw new TrustManagerException(e);
        }
    }