Is key/cert rotation possible?

Hi Stéphane et team,

I’m currently using Gatling 3.5.1 as clients sending REST requests to server application that requires mTLS for every connection/request. Using provided perUserKeyManagerFactory function, I manage to set up KeyStore for mTLS with following code snippet -

def simKeyManager(id: Long): = {
val simKeyStore = new dataKeyStore() //“pkcs12”)
simKeyStore.load(confKeyStores) // keyStore.load(new, keySecret.toCharArray())
simKeyStore.manager //, keySecret.toCharArray())

.baseUrls(confBaseUrls: *)

Periodically, the server application requires Gatling clients to rotate their keys/certificates. For that, Gatling clients need to perform these operations:

  1. Delete existing key/cert from the existing KeyStore
  2. Create and add new key/cert into the existing KeyStore
  3. Reload the existing KeyStore

My understanding is KeyStore is loaded once at the protocol level. Is it possible that it can be reloaded in the scenario at later time?

Thank you for guidance/suggestion.

No, it’s not possible out of the box. That’s something you’ll have to implement yourself. Dealing with open connections during the rotation might prove tricky.

Hi Stéphane et team -

We managed to implement key/cert rotation functionality for our application

  • We create a new key pair in keystore on demand
  • We use the new key/cert for client authentication during SSL handshakes of subsequent requests

For the SSL contexts to find the new keys, we need to re-initialize them. Currently, SSL contexts are created and initialized once when scenarios are built, and stored in the Session:

Thus, we implement a patch to enable us to replace existing SSL contexts with new instances pointing to reloaded keystores/key managers.

We need this functionality to re-initialize SSL contexts in Gatling for our application. If we could help with contribution, please let us know where to implement it properly.

Thank you for guidance.


Your solution doesn’t work because SslContextSupports is a stateless object that’s shared and used for all the protocols (remember, you can have one per scenario). You can’t make it stateful.

Generally speaking, we will never accept a change that’s only part of a solution.
If we were to support key rotation for ongoing virtual users, we would require a complete solution.


Hi Stéphane et team -

Thank you for your explanation. The forementioned patch is indeed not a proper solution for general usage. It is a small hack that enables a functionality which we desperately need as described below.

Our application requires each virtual user to have its own keystore. Gatling provides the hook perUserKeyManagerFactory ( to load the keystores once at the protocol engine which is instantiated at the beginning when scenarios are built. This functionality works well for us.

Additionally, our application requires usage of new keys/certs being added to the keystores over time (i.e. for key rotation). That requires Gatling to use the keystores more dynamically. We found that existing SSL contexts would need to be updated or replaced to use reloaded keystores on demand. We wish to avoid our current monkey patching approach and we are grateful if Gatling team would consider enabling this functionality in a near future release. If our contribution is needed, we ask to have your guidance to how best implement this functionality.


Hi Vu,

Honestly, this feature is pretty complex to design, implement and test.
And yet, it’s non-strategic at this time (single free user use case), so we can’t hardly make it a priority.
I’m afraid that’s not something we can work on any time soon outside of a contract.

Please reach out privately if that’s something your organization might be interested in.


Thank you, Stéphane. I’ll reach out to our management with your suggestion.