Could somebody who is on linux  or uses openjdk test this code? I know it works on windows with oracle jdk but I'd like to know about others.

I'd like to know whether it works on linux (is an InvalidAlgorithmParameterException trace getting printed or is a different exception being thrown?) or with openjdk (does the cacerts file exist?)

If all is good, then the set returned is not empty.

Tilman


    private Set<X509Certificate> getRootCertificates()
            throws GeneralSecurityException, IOException
    {
        Set<X509Certificate> rootCertificates = new HashSet<>();

        // https://stackoverflow.com/questions/3508050/
        String filename = System.getProperty("java.home") + "/lib/security/cacerts";
        KeyStore keystore;
        try (FileInputStream is = new FileInputStream(filename))
        {
            keystore = KeyStore.getInstance(KeyStore.getDefaultType());
            keystore.load(is, null);
        }
        PKIXParameters params = new PKIXParameters(keystore);
        for (TrustAnchor trustAnchor : params.getTrustAnchors())
        {
            rootCertificates.add(trustAnchor.getTrustedCert());
        }

        // https://www.oracle.com/technetwork/articles/javase/security-137537.html
        try
        {
            keystore = KeyStore.getInstance("Windows-ROOT");
            keystore.load(null, null);
            params = new PKIXParameters(keystore);
            for (TrustAnchor trustAnchor : params.getTrustAnchors())
            {
rootCertificates.add(trustAnchor.getTrustedCert());
            }
        }
        catch (InvalidAlgorithmParameterException ex)
        {
            // not on windows

            ex.printStackTrace();

        }

        return rootCertificates;
    }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to