Tino A.
Tino A.

Reputation: 232

NoClassDefFoundError: org/bouncycastle/jce/spec/ECPublicKeySpec even though bouncycastle is available

I have a tomcat 8.5 running and deployed my application on it. While compiling everything is fine but at runtime the following error occurs:

java.lang.NoClassDefFoundError: org/bouncycastle/jce/spec/ECPublicKeySpec
org.bouncycastle.jcajce.provider.asymmetric.ec.KeyFactorySpi.engineGeneratePublic(Unknown Source)
java.security.KeyFactory.generatePublic(KeyFactory.java:334)
COMPANY.server.impl.BouncyCastleCrypto.decodePublicKey(BouncyCastleCrypto.java:87)
COMPANY.server.impl.U2FServerReferenceImpl.processSignResponse(U2FServerReferenceImpl.java:270)
COMPANY.tools.httpserver.servlets.SignFinishServletImpl.doGet(SignFinishServletImpl.java:41)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

This is all of the stacktrace I get.

I already tried several versions of the bouncycastle dependency (1.58 and 1.50, I use maven) bcprov-jdk15on. I looked inside the produced .war file and the WEB-INF folder contains the jar. I tried re-downloading the maven dependency, did a project clean and maven clean in eclipse.

Also I added the appropriate line to the java.security file:

security.provider.10=org.bouncycastle.jce.provider.BouncyCastleProvider

The strange thing is, that I can access the ECPublicKeySpec at some point. E.g:

ECPublicKeySpec ecPublicKeySpec = new ECPublicKeySpec(point,
      new ECParameterSpec(
          curve.getCurve(),
          curve.getG(),
          curve.getN(),
          curve.getH()));
  logger.info(ecPublicKeySpec.toString());

The above works fine but:

KeyFactory.getInstance("ECDSA").generatePublic(ecPublicKeySpec);

or

KeyFactory.getInstance("ECDSA", "BC").generatePublic(ecPublicKeySpec);

This does not work and produces the NoClassDefFoundError.

EDIT: Forgot to mention: If I deploy my application to my tomcat at localhost it works. If I deploy it to a remote tomcat it does not work.

EDIT2: Output of mvn dependency:tree -Dverbose -Dincludes=org/bouncycastle/jce/spec/ECPublicKeySpec:

[WARNING] 
[WARNING] Some problems were encountered while building the effective settings
[WARNING] Unrecognised tag: 'profiles' (position: START_TAG seen ...</profile>\n     <profiles>... @276:16)  @ /Users/tinoa/.m2/settings.xml, line 276, column 16
[WARNING] 
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building application_implemented 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ application_implemented ---
...
lots of "Downloading/Downloaded" lines...
...
Downloaded: 
https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-
invoker/2.0.11/maven-invoker-2.0.11.jar (29 kB at 22 kB/s)
Downloaded: 
https://repo.maven.apache.org/maven2/org/eclipse/aether/aether-
util/0.9.0.M2/aether-util-0.9.0.M2.jar (134 kB at 102 kB/s)
Downloaded: https://repo.maven.apache.org/maven2/commons-lang/commons-
lang/2.6/commons-lang-2.6.jar (284 kB at 200 kB/s)
Downloaded: https://repo.maven.apache.org/maven2/commons-
collections/commons-collections/3.2.1/commons-collections-3.2.1.jar 
(575 kB at 333 kB/s)
[INFO] ----------------------------------------------------------------
--------
[INFO] BUILD SUCCESS
[INFO] ----------------------------------------------------------------
--------
[INFO] Total time: 15.216 s
[INFO] Finished at: 2017-10-10T15:05:40+02:00
[INFO] Final Memory: 17M/297M
[INFO] ------------------------------------------------------------------------

Upvotes: 3

Views: 4255

Answers (2)

Jack Chu
Jack Chu

Reputation: 11

I think it's due to the your local tomcat server automatically rebuild/start on save changes.

I got the same issue, but restart the tomcat server fixed it, but as soon as I made any code change and saved, the error came back.

Upvotes: 1

Dr. Mehmet Ali ATICI
Dr. Mehmet Ali ATICI

Reputation: 609

In my case, I don't get any error in remote tomcat server which is running on CentOS. However, I get the NoClassDefFoundError on my local environment that is running on Windows 10, although related maven dependency is already imported. Fortunately,in addition to maven dependency, copying the bcprov-jdk15on-1.55.jar file to $java_home/jre/lib/ext in the local environment solved the problem.

Upvotes: 1

Related Questions