Gatling encryption failed

Hi,

I have to test my API which received a encrypted message from client. I need to encrypt message using public key. I have a simple java code (JAR) which I use to generate encrypted message for endpoint input. When I run this java program outside Gatling it works fine and give me proper encrypted message. I write a simple Scala test (not Gatling) and call this Java code inside Scala test and its also works fine.

But whenever I try to call this java code (using Jar in gatling lib directory) I got encryption error “illegal key size”. Here is my Gatling code.

import io.gatling.core.Predef._
import io.gatling.core.session.Expression
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import scala.concurrent.duration._

import awscala., sqs.
import org.slf4j._
import uk.co.bbc.notifications.subscriber.sqs.service._
import scala.collection.JavaConverters._
import java.util.Calendar

class SQSGatling extends Simulation {

val sqsMessageService: SqsMessageService = new SqsMessageService()
val messages = sqsMessageService.getBatchMessages().asScala

val httpConf = http.proxy(Proxy(“myproxy.xyz”, 80));

val scn = scenario(“https2kb”)
.exec(
http(“request_0”)

setUp(scn.inject(atOnceUsers(5)).protocols(httpConf))
}

Its fails Inside my java service as soon as I called it.

// val messages = sqsMessageService.getBatchMessages().asScala

Stack trace

org.bouncycastle.openpgp.PGPException: Exception creating cipher
at org.bouncycastle.openpgp.PGPEncryptedDataGenerator.open(Unknown Source)
at org.bouncycastle.openpgp.PGPEncryptedDataGenerator.open(Unknown Source)
at uk.co.bbc.notifications.subscriber.util.PGPEncryptionUtil.(PGPEncryptionUtil.java:58)
at uk.co.bbc.notifications.subscriber.sqs.service.SqsMessageService.encryptMessage(SqsMessageService.java:120)
at uk.co.bbc.notifications.subscriber.sqs.service.SqsMessageService.prepareMessages(SqsMessageService.java:62)
at uk.co.bbc.notifications.subscriber.sqs.service.SqsMessageService.getBatchMessages(SqsMessageService.java:44)
at SQSGatling.(SQSGatling.scala:16)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at io.gatling.core.runner.Runner.run(Runner.scala:36)
at io.gatling.app.Gatling$$anonfun$runSimulationIfNecessary$1.apply(Gatling.scala:138)
at io.gatling.app.Gatling$$anonfun$runSimulationIfNecessary$1.apply(Gatling.scala:123)
at scala.Option.getOrElse(Option.scala:121)
at io.gatling.app.Gatling.runSimulationIfNecessary(Gatling.scala:123)
at io.gatling.app.Gatling.start(Gatling.scala:73)
at io.gatling.app.Gatling$.fromArgs(Gatling.scala:59)
at io.gatling.app.Gatling$.main(Gatling.scala:44)
at io.gatling.app.Gatling.main(Gatling.scala)
Caused by: org.bouncycastle.openpgp.PGPException: invalid key: Illegal key size
at org.bouncycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder$MyPGPDataEncryptor.(Unknown Source)
at org.bouncycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder.build(Unknown Source)
… 21 more

Again it work fine independently so there is no issue with JCE unlimited Strength (its already installed).

Your help is much appreciated.

Regards

Wild guess: you have multiple JDKs on your machine.
When you run your standalone programs, you indeed use one where you’ve patched JCE.
But when you run Gatling from the command line, our scripts (gatling.sh or gatling.bat) honor your JAVA_HOME that targets another JDK that hasn’t been patched.

Am I right?

I have already confirmed this thing. I have only one JDK on my machine and its sets to correct JAVA_HOME and Gatling using it from there.

I’m sorry, but that’s the only explanation…
Do your standalone samples use the sample bc version?
Can you please provide a reproducer?

Are you sure you patched BOTH your JDK and your JRE?

We only need to patch JRE (in my case it resides inside JDK). Advise me if I am wrong.

If you’re running on Windows, you most likely both have a JDK, and a standalone JRE.
If so, please trying patching it too.
Otherwise, please provide a reproducer, and more information (OS, Gatling version, way to launch Gatling: cli, sbt, maven?).

Hi Muhammad,

You are using a BBC import which makes me think that you work at the BBC.

If you send me the test via my BBC email, I could try it myself.

Aidy