Search code examples
javamaven

bouncycastle NoSuchMethodError CryptoServicesRegistrar.checkConstraints


I have checked other post here and applied their solution to use dependency managment and I stil get the NoSuchMethodError

pom.xml:

 <dependencyManagement>
       <dependencies>
            <dependency>
                <groupId>org.bouncycastle</groupId>
                <artifactId>bcprov-jdk18on</artifactId>
                <version>1.78.1</version>
            </dependency>
            <dependency>
                <groupId>org.bouncycastle</groupId>
                <artifactId>bcpkix-jdk18on</artifactId>
                <version>1.78.1</version>
            </dependency>

        </dependencies>
    </dependencyManagement>

from maven command:

mvn dependency:tree -Dincludes=org.bouncycastle   


[INFO] --- dependency:3.3.0:tree (default-cli) @ direct-data-load-exporter ---
[INFO] com.company:company-company-company-exporter:jar:2.1.3
[INFO] +- org.bouncycastle:bcpkix-jdk18on:jar:1.78.1:compile
[INFO] |  \- org.bouncycastle:bcutil-jdk18on:jar:1.78.1:compile
[INFO] \- org.bouncycastle:bcprov-jdk18on:jar:1.78.1:compile

the stack trace

{"timestamp":"2024-09-26 18:09:07.849Z","level":"WARN","message":"falback using native java: 'void org.bouncycastle.crypto.CryptoServicesRegistrar.checkConstraints(org.bouncycastle.crypto.CryptoServiceProperties)'","process.thread.name":"class com.company.directDataLoader.queues.service.DirectDataLoaderQueueListener-2","logger":"com.company.directDataLoader.database.PrivateKeyReader","error.type":"java.lang.NoSuchMethodError","error.message":"'void org.bouncycastle.crypto.CryptoServicesRegistrar.checkConstraints(org.bouncycastle.crypto.CryptoServiceProperties)'","error.stack_trace":"java.lang.NoSuchMethodError: 'void org.bouncycastle.crypto.CryptoServicesRegistrar.checkConstraints(org.bouncycastle.crypto.CryptoServiceProperties)'
at org.bouncycastle.jce.provider.BouncyCastleProvider.loadAlgorithms(Unknown Source)
at org.bouncycastle.jce.provider.BouncyCastleProvider.setup(Unknown Source)
at org.bouncycastle.jce.provider.BouncyCastleProvider.access$000(Unknown Source)
at org.bouncycastle.jce.provider.BouncyCastleProvider$1.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.bouncycastle.jce.provider.BouncyCastleProvider.<init>(Unknown Source)

the command I'm running

        Security.addProvider(new BouncyCastleProvider());

trying to run verbose class on the jar name:

[root@direct-data-loader-7cf9dc47bd-9w97b directdataloader]# java -verbose:class -jar my-special-jar-exporter-2.1.3.jar | grep CryptoServicesRegistrar
[0.745s][info][class,load] org.bouncycastle.crypto.CryptoServicesRegistrar source: file:/opt/tools/Linux/jdk/openjdk_11.0.21.0.102_11.69.52_x64/lib/sfdc/modules/bc-fips-1.0.2.4.jar
[1.287s][info][class,load] org.bouncycastle.crypto.CryptoServicesRegistrar$Property source: file:/opt/tools/Linux/jdk/openjdk_11.0.21.0.102_11.69.52_x64/lib/sfdc/modules/bc-fips-1.0.2.4.jar
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass$3$1 (jar:file:/opt/specialjar/my-special-jar-exporter-2.1.3.jar!/BOOT-INF/lib/groovy-all-2.4.7.jar!/) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass$3$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[10.243s][info][class,load] net.snowflake.client.jdbc.internal.org.bouncycastle.crypto.CryptoServicesRegistrar source: jar:file:/opt/name/my-special-jar-exporter-2.1.3.jar!/BOOT-INF/lib/snowflake-jdbc-3.19.0.jar!/
[10.245s][info][class,load] net.snowflake.client.jdbc.internal.org.bouncycastle.crypto.CryptoServicesRegistrar$ThreadLocalSecureRandomProvider source: jar:file:/opt/name/my-special-jar-exporter-2.1.3.jar!/BOOT-INF/lib/snowflake-jdbc-3.19.0.jar!/
[10.246s][info][class,load] net.snowflake.client.jdbc.internal.org.bouncycastle.crypto.CryptoServicesRegistrar$1 source: jar:file:/opt/name/my-special-jar-exporter-2.1.3.jar!/BOOT-INF/lib/snowflake-jdbc-3.19.0.jar!/
[10.250s][info][class,load] net.snowflake.client.jdbc.internal.org.bouncycastle.crypto.CryptoServicesRegistrar$Property source: jar:file:/opt/name/my-special-jar-exporter-2.1.3.jar!/BOOT-INF/lib/snowflake-jdbc-3.19.0.jar!/

how can I solve it ?


Solution

  • Found the problem and solution in my docker file I had a jar file that loaded the class CryptoServicesRegistrar into the JVM

    [root@my-micro-service-7cf9dc47bd-9w97b microservice]# java -verbose:class -jar my-special-jar-exporter-2.1.3.jar | grep CryptoServicesRegistrar
    [0.745s][info][class,load] org.bouncycastle.crypto.CryptoServicesRegistrar source: file:/opt/tools/Linux/jdk/openjdk_11.0.21.0.102_11.69.52_x64/lib/sfdc/modules/bc-fips-1.0.2.4.jar
    

    the solution was to remove it from the docker image in the build phase this jar bc-fips-1.0.2.4.jar