Bouncy Castle with Play 2.4.4

195 views
Skip to first unread message

Harshana Gurusingha

unread,
Mar 2, 2017, 1:53:10 AM3/2/17
to Play Framework
Hello, 

We faced a problem when using Play framework along with BouncyCastle. When we try to connect to a third party SMS application, the following error comes up randomly. It is at the end of this question.

Application Details : Play 2.4.4, Java "1.8.0_73".

Tried and Failed
1. Exclude this dependency in the build.sbt,  - "com.typesafe.play" % "play_2.10" % "2.4.4" exclude("org.bouncycastle", "bcprov-jdk14"),
2. Include the latest Bouncycastle jar (This will still download the older version and refer to it.)- "org.bouncycastle" % "bcprov-jdk15on" % "1.54"

Is there any way we can eliminate BouncyCastle altogether, or is there any workaround?


Best Regards, 
Harshana 

Error : 

2017-03-02 14:42:49,873:[[error]]: Thread: application-akka.actor.default-dispatcher-3109 : Error Sending text message
javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair
        at sun.security.ssl.Alerts.getSSLException(Alerts.java:208) ~[na:1.8.0_73]
        at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949) ~[na:1.8.0_73]
        at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1906) ~[na:1.8.0_73]
        at sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1889) ~[na:1.8.0_73]
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1410) ~[na:1.8.0_73]
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387) ~[na:1.8.0_73]
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:261) ~[org.apache.httpcomponents.httpclient-4.3.1.jar:4.3.1]
        at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:118) ~[org.apache.httpcomponents.httpclient-4.3.1.jar:4.3.1]
        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) ~[org.apache.httpcomponents.httpclient-4.3.1.jar:4.3.1]
        at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) ~[org.apache.httpcomponents.httpclient-4.3.1.jar:4.3.1]
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) ~[org.apache.httpcomponents.httpclient-4.3.1.jar:4.3.1]
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) ~[org.apache.httpcomponents.httpclient-4.3.1.jar:4.3.1]
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) ~[org.apache.httpcomponents.httpclient-4.3.1.jar:4.3.1]
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) ~[org.apache.httpcomponents.httpclient-4.3.1.jar:4.3.1]
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) ~[org.apache.httpcomponents.httpclient-4.3.1.jar:4.3.1]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) ~[org.apache.httpcomponents.httpclient-4.3.1.jar:4.3.1]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) ~[org.apache.httpcomponents.httpclient-4.3.1.jar:4.3.1]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57) ~[org.apache.httpcomponents.httpclient-4.3.1.jar:4.3.1]
        at util.TextMessageUtil.sendText(TextMessageUtil.java:58) ~[aaproto.aaproto-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
        at services.AdministrationServiceImpl.sendText(AdministrationServiceImpl.java:120) [aaproto.aaproto-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
        at services.AdministrationServiceImpl.sendTextMessages(AdministrationServiceImpl.java:71) [aaproto.aaproto-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
        at services.AdministrationServiceImpl.sendNotifications(AdministrationServiceImpl.java:34) [aaproto.aaproto-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
        at controllers.Administrations.sendNotifications(Administrations.java:68) [aaproto.aaproto-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
        at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$790$$anonfun$apply$3864.apply(Routes.scala:19297) [aaproto.aaproto-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
        at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$790$$anonfun$apply$3864.apply(Routes.scala:19297) [aaproto.aaproto-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
        at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:136) [com.typesafe.play.play_2.10-2.4.6.jar:2.4.6]
        at play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$14$$anon$3$$anon$1.invocation(HandlerInvoker.scala:127) [com.typesafe.play.play_2.10-2.4.6.jar:2.4.6]
        at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:70) [com.typesafe.play.play_2.10-2.4.6.jar:2.4.6]
        at globals.ApplicationGlobal$1.call(ApplicationGlobal.java:79) [aaproto.aaproto-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
        at play.db.jpa.TransactionalAction.lambda$call$5(TransactionalAction.java:19) [com.typesafe.play.play-java-jpa_2.10-2.4.6.jar:2.4.6]
        at play.db.jpa.DefaultJPAApi.withTransaction(DefaultJPAApi.java:136) ~[com.typesafe.play.play-java-jpa_2.10-2.4.6.jar:2.4.6]
        at play.db.jpa.JPA.withTransaction(JPA.java:159) ~[com.typesafe.play.play-java-jpa_2.10-2.4.6.jar:2.4.6]
        at play.db.jpa.TransactionalAction.call(TransactionalAction.java:16) [com.typesafe.play.play-java-jpa_2.10-2.4.6.jar:2.4.6]
        at play.mvc.Security$AuthenticatedAction.call(Security.java:56) ~[com.typesafe.play.play_2.10-2.4.6.jar:2.4.6]
        at play.core.j.JavaAction$$anonfun$7.apply(JavaAction.scala:94) ~[com.typesafe.play.play_2.10-2.4.6.jar:2.4.6]
        at play.core.j.JavaAction$$anonfun$7.apply(JavaAction.scala:94) ~[com.typesafe.play.play_2.10-2.4.6.jar:2.4.6]
        at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) ~[org.scala-lang.scala-library-2.10.5.jar:na]
        at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[org.scala-lang.scala-library-2.10.5.jar:na]
        at play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:40) ~[com.typesafe.play.play_2.10-2.4.6.jar:2.4.6]
        at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:70) ~[com.typesafe.play.play-iteratees_2.10-2.4.6.jar:2.4.6]
        at play.core.j.HttpExecutionContext.execute(HttpExecutionContext.scala:32) ~[com.typesafe.play.play_2.10-2.4.6.jar:2.4.6]
        at scala.concurrent.impl.Future$.apply(Future.scala:31) ~[org.scala-lang.scala-library-2.10.5.jar:na]
        at scala.concurrent.Future$.apply(Future.scala:485) ~[org.scala-lang.scala-library-2.10.5.jar:na]
        at play.core.j.JavaAction.apply(JavaAction.scala:94) ~[com.typesafe.play.play_2.10-2.4.6.jar:2.4.6]
        at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:105) ~[com.typesafe.play.play_2.10-2.4.6.jar:2.4.6]
        at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:105) ~[com.typesafe.play.play_2.10-2.4.6.jar:2.4.6]
        at play.utils.Threads$.withContextClassLoader(Threads.scala:21) ~[com.typesafe.play.play_2.10-2.4.6.jar:2.4.6]
        at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:104) ~[com.typesafe.play.play_2.10-2.4.6.jar:2.4.6]
        at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:103) ~[com.typesafe.play.play_2.10-2.4.6.jar:2.4.6]
        at scala.Option.map(Option.scala:145) ~[org.scala-lang.scala-library-2.10.5.jar:na]
        at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:103) ~[com.typesafe.play.play_2.10-2.4.6.jar:2.4.6]
        at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:96) ~[com.typesafe.play.play_2.10-2.4.6.jar:2.4.6]
        at play.api.libs.iteratee.Iteratee$$anonfun$mapM$1.apply(Iteratee.scala:524) ~[com.typesafe.play.play-iteratees_2.10-2.4.6.jar:2.4.6]
        at play.api.libs.iteratee.Iteratee$$anonfun$mapM$1.apply(Iteratee.scala:524) ~[com.typesafe.play.play-iteratees_2.10-2.4.6.jar:2.4.6]
        at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM$1.apply(Iteratee.scala:560) ~[com.typesafe.play.play-iteratees_2.10-2.4.6.jar:2.4.6]
        at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM$1.apply(Iteratee.scala:560) ~[com.typesafe.play.play-iteratees_2.10-2.4.6.jar:2.4.6]
        at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$1$$anonfun$apply$14.apply(Iteratee.scala:537) ~[com.typesafe.play.play-iteratees_2.10-2.4.6.jar:2.4.6]
        at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$1$$anonfun$apply$14.apply(Iteratee.scala:537) ~[com.typesafe.play.play-iteratees_2.10-2.4.6.jar:2.4.6]
        at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) ~[org.scala-lang.scala-library-2.10.5.jar:na]
        at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[org.scala-lang.scala-library-2.10.5.jar:na]
        at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40) ~[com.typesafe.akka.akka-actor_2.10-2.3.13.jar:na]
        at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397) ~[com.typesafe.akka.akka-actor_2.10-2.3.13.jar:na]
        at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) ~[org.scala-lang.scala-library-2.10.5.jar:na]
        at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) ~[org.scala-lang.scala-library-2.10.5.jar:na]
        at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) ~[org.scala-lang.scala-library-2.10.5.jar:na]
        at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) ~[org.scala-lang.scala-library-2.10.5.jar:na]
Caused by: java.lang.RuntimeException: Could not generate DH keypair
        at sun.security.ssl.ECDHCrypt.<init>(ECDHCrypt.java:81) ~[na:1.8.0_73]
        at sun.security.ssl.ClientHandshaker.serverKeyExchange(ClientHandshaker.java:721) ~[na:1.8.0_73]
        at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:281) ~[na:1.8.0_73]
        at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979) ~[na:1.8.0_73]
        at sun.security.ssl.Handshaker.process_record(Handshaker.java:914) ~[na:1.8.0_73]
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062) ~[na:1.8.0_73]
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) ~[na:1.8.0_73]
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403) ~[na:1.8.0_73]
        ... 61 common frames omitted
Caused by: java.security.InvalidAlgorithmParameterException: parameter object not a ECParameterSpec
        at org.bouncycastle.jce.provider.JDKKeyPairGenerator$EC.initialize(Unknown Source) ~[bouncycastle.bcprov-jdk14-138.jar:1.38.0]
        at sun.security.ssl.ECDHCrypt.<init>(ECDHCrypt.java:76) ~[na:1.8.0_73]
        ... 68 common frames omitted



Igmar Palsenberg

unread,
Mar 2, 2017, 2:05:06 AM3/2/17
to Play Framework
 
We faced a problem when using Play framework along with BouncyCastle. When we try to connect to a third party SMS application, the following error comes up randomly. It is at the end of this question.

Application Details : Play 2.4.4, Java "1.8.0_73".

Tried and Failed
1. Exclude this dependency in the build.sbt,  - "com.typesafe.play" % "play_2.10" % "2.4.4" exclude("org.bouncycastle", "bcprov-jdk14"),
2. Include the latest Bouncycastle jar (This will still download the older version and refer to it.)- "org.bouncycastle" % "bcprov-jdk15on" % "1.54"

That version does not match the JDK in use. You need bcprov-jdk15on for this to work. Try :

activator clean cleanFiles update

If that fails, remove the offending jars from your .ivy2 directory.


Igmar

Will Sargent

unread,
Mar 2, 2017, 2:22:20 PM3/2/17
to play-fr...@googlegroups.com
That is not a bouncycastle exception -- it is from JSSE.  That looks like the 1024 key size limitation 


Do you have jdk.tls.ephemeralDHKeySize set?


--
Will Sargent
Engineer, Lightbend, Inc.


--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/77edac3d-9555-4813-8f8b-910085d9c85d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages