Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues after 8u282 -> 8u292 update: "NoSuchAlgorithmException: unrecognized algorithm name: PBEWithSHA1AndDESede" #306

Closed
lutkerd opened this issue May 24, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@lutkerd
Copy link
Contributor

lutkerd commented May 24, 2021

An issue has been reported by users of BouncyCastle, after upgrading from 8u282 or earlier to 8u292, a "NoSuchAlgorithmException: unrecognized algorithm name" exception is thrown at runtime. This issue will be fixed in the next release 8u302 which is expected on 7/19.

Workarounds:
There are 2 few possible workarounds, the 1st is preferred if it works for your application.

  1. Call "new EncryptedPrivateKeyInfo("PBEWithSHA1AndDESede", new byte[] { 0 });" from your code as early as possible before any BouncyCastle jars are loaded.

  2. Clear out the algorithms so they are reinitialized on next call using something like this

    public static void clearAlgorithms() {
        try {
            Class<?> clazz = sun.security.x509.AlgorithmId.class;
            java.lang.reflect.Field f1 = clazz.getDeclaredField("oidTable");
            f1.setAccessible(true);
            f1.set(clazz, null);
            java.lang.reflect.Field f2 = clazz.getDeclaredField("initOidTable");
            f2.setAccessible(true);
            f2.set(clazz, false);
        } catch (Exception e) {
            System.out.println(e);
            e.printStackTrace();
        }
    }

Root Cause Analysis:
There was a change in the upstream OpenJDK to improve JARs verification, which caused the list of Algorithms be to cached with only a subset of the SecurityProviders enabled. When an algorithm from SunJCE or BouncyCastle is requested the table is not refreshed and a NoSuchAlgorithmException is being thrown.

Additional information:
bcgit/bc-java#941
https://bugs.openjdk.java.net/browse/JDK-8266929

@lutkerd
Copy link
Contributor Author

lutkerd commented Nov 2, 2021

This was resolved in 8u302.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant