You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
They all have different use-cases. Some need to reload the ssl configuration more frequently than others, but the main goal is to have some kind of reloading mechanism without the need of restarting the server or recreating the client. A kind developer, @tsaarni has even created this pull request which does the trick already: #4372 However it is limited to a KeyStore/PEM File. The Vert.x core library has two interfaces which needs to be supported: TrustOptions and KeyCertOptions which should return a KeyManager/TrustManager.
I was reading through all of the comments and noticed this one of @vietj and it seems like he prefers a solution outside of the core library:
ok, I would like to see if we can have it as something more decoupled from vertx core
I think we could provide in Vert.x an SPI to integrate Vertx to more easily integrate with SSLContext library
So based on the remarks of @vietj I thought it would be maybe a good to provide additional documentation to the project for this kind of use case. It seems like the maintainer does not want to have this in the core library, but want to provide it as a separate util library combining for other utilities which can be added in the future. I already have created a library couple of years ago which has this capability since last year, see here: GitHub - SSLCcontext Kickstart. I also created a reference implementation with a live demo to demonstrate how to configure it and demonstrate that it is working. So therefor I though to create a pull request to include code snippets as example ssl configuration to help the end-user of enabling this kind of feature. The vertx core library won't get additional code complexity and also does not need to maintain it. If developers would like to enable this feature they can just add an additional library. Next to that by giving the control to the end-user he/she can decide when to update the ssl configuration, either via a file listener, scheduled on a fixed interval of minutes, hours, or maybe days, or based on triggers?
Below is one example for a server and two examples for the webclient:
Scheduled reload for server
importio.vertx.core.AbstractVerticle;
importio.vertx.core.http.ClientAuth;
importio.vertx.core.http.HttpServerOptions;
importio.vertx.core.json.JsonObject;
importio.vertx.core.net.KeyCertOptions;
importio.vertx.core.net.TrustOptions;
importio.vertx.ext.web.Router;
importnl.altindag.ssl.SSLFactory;
importnl.altindag.ssl.util.SSLFactoryUtils;
importjava.nio.file.Paths;
importjava.util.concurrent.Executors;
importjava.util.concurrent.TimeUnit;
publicclassMainVerticleextendsAbstractVerticle {
@Overridepublicvoidstart() {
Routerrouter = Router.router(vertx);
router.route().handler(context -> context.json(
newJsonObject().put("message", "Hello World!")
));
SSLFactorybaseSslFactory = SSLFactory.builder()
.withDummyIdentityMaterial()
.withDummyTrustMaterial()
.withSwappableIdentityMaterial()
.withSwappableTrustMaterial()
.build();
RunnablesslUpdater = () -> {
SSLFactoryupdatedSslFactory = SSLFactory.builder()
.withIdentityMaterial(Paths.get("/path/to/your/identity.jks"), "password".toCharArray())
.withTrustMaterial(Paths.get("/path/to/your/truststore.jks"), "password".toCharArray())
.build();
SSLFactoryUtils.reload(baseSslFactory, updatedSslFactory);
};
// initial update of ssl material to replace the dummiessslUpdater.run();
// update ssl material every hourExecutors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(sslUpdater, 1, 1, TimeUnit.HOURS);
HttpServerOptionsserverOptions = newHttpServerOptions()
.setSsl(true)
.setClientAuth(ClientAuth.REQUIRED)
.setKeyCertOptions(KeyCertOptions.wrap(baseSslFactory.getKeyManager().orElseThrow()))
.setTrustOptions(TrustOptions.wrap(baseSslFactory.getTrustManager().orElseThrow()));
vertx.createHttpServer(serverOptions)
.requestHandler(router)
.listen(8443)
.onSuccess(server -> System.out.println("HTTP server started on port " + server.actualPort()));
}
}
Reload on demand for webclient
SSLFactorybaseSslFactory = SSLFactory.builder()
.withIdentityMaterial(Paths.get("/path/to/your/identity.jks"), "password".toCharArray())
.withTrustMaterial(Paths.get("/path/to/your/truststore.jks"), "password".toCharArray())
.withSwappableIdentityMaterial()
.withSwappableTrustMaterial()
.build();
WebClientOptionsclientOptions = newWebClientOptions();
sslFactory.getKeyManager()
.map(KeyCertOptions::wrap)
.ifPresent(clientOptions::setKeyCertOptions);
sslFactory.getTrustManager()
.map(TrustOptions::wrap)
.ifPresent(clientOptions::setTrustOptions);
WebClientwebClient = WebClient.create(Vertx.vertx(), clientOptions);
// After some time whenever needed the code below// can be executed to reload the ssl configurationSSLFactoryupdatedSslFactory = SSLFactory.builder()
.withIdentityMaterial(Paths.get("/path/to/your/identity.jks"), "password".toCharArray())
.withTrustMaterial(Paths.get("/path/to/your/truststore.jks"), "password".toCharArray())
.build();
SSLFactoryUtils.reload(baseSslFactory, updatedSslFactory);
Scheduled reload for http client
SSLFactorybaseSslFactory = SSLFactory.builder()
.withDummyIdentityMaterial()
.withDummyTrustMaterial()
.withSwappableIdentityMaterial()
.withSwappableTrustMaterial()
.build();
WebClientOptionsclientOptions = newWebClientOptions();
sslFactory.getKeyManager()
.map(KeyCertOptions::wrap)
.ifPresent(clientOptions::setKeyCertOptions);
sslFactory.getTrustManager()
.map(TrustOptions::wrap)
.ifPresent(clientOptions::setTrustOptions);
WebClientwebClient = WebClient.create(Vertx.vertx(), clientOptions);
RunnablesslUpdater = () -> {
SSLFactoryupdatedSslFactory = SSLFactory.builder()
.withIdentityMaterial(Paths.get("/path/to/your/identity.jks"), "password".toCharArray())
.withTrustMaterial(Paths.get("/path/to/your/truststore.jks"), "password".toCharArray())
.build();
SSLFactoryUtils.reload(baseSslFactory, updatedSslFactory);
};
// initial update of ssl material to replace the dummiessslUpdater.run();
// update ssl material every hourExecutors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(sslUpdater, 1, 1, TimeUnit.HOURS);
Using PEM files
It is also possible to have ssl reloading based on PEM files instead of p12 files with a similar setup as shown on the other examples.
Just call the PemUtils to generate a KeyManager and TrustManager for the SSLFactory as shown below:
The current PR #4453 makes it possible to enable ssl reloading in the vertx server out of the box with the example server configuration below.
Vertxvertx = Vertx.vertx();
Routerrouter = ...; // initialized RouterKeyCertOptionskeyCertOptions = ...; // initialized KeyCertOptionsTrustOptionstrustOptions = ...; // initialized TrustOptionsHttpServerOptionsserverOptions = newHttpServerOptions()
.setSsl(true)
.setKeyCertOptions(keyCertOptions)
.setTrustOptions(trustOptions);
HttpServerhttpServer = vertx.createHttpServer(serverOptions);
httpServer.requestHandler(router)
.listen(8443)
.onSuccess(server -> System.out.println("HTTP server started on port " + server.actualPort()));
// the method below will reread the keystores/pem files and apply it to the running serverhttpServer.reloadSsl();
The text was updated successfully, but these errors were encountered:
I discovered that the community of Vert.x wants ssl reloading mechanism from the following 4 issues:
They all have different use-cases. Some need to reload the ssl configuration more frequently than others, but the main goal is to have some kind of reloading mechanism without the need of restarting the server or recreating the client. A kind developer, @tsaarni has even created this pull request which does the trick already: #4372 However it is limited to a KeyStore/PEM File. The Vert.x core library has two interfaces which needs to be supported: TrustOptions and KeyCertOptions which should return a KeyManager/TrustManager.
I was reading through all of the comments and noticed this one of @vietj and it seems like he prefers a solution outside of the core library:
I even added my input in this issue: #2870 (comment)
However there is no follow-up till this day although the library maintainer appreciated the solution:
So based on the remarks of @vietj I thought it would be maybe a good to provide additional documentation to the project for this kind of use case. It seems like the maintainer does not want to have this in the core library, but want to provide it as a separate util library combining for other utilities which can be added in the future. I already have created a library couple of years ago which has this capability since last year, see here: GitHub - SSLCcontext Kickstart. I also created a reference implementation with a live demo to demonstrate how to configure it and demonstrate that it is working. So therefor I though to create a pull request to include code snippets as example ssl configuration to help the end-user of enabling this kind of feature. The vertx core library won't get additional code complexity and also does not need to maintain it. If developers would like to enable this feature they can just add an additional library. Next to that by giving the control to the end-user he/she can decide when to update the ssl configuration, either via a file listener, scheduled on a fixed interval of minutes, hours, or maybe days, or based on triggers?
Below is one example for a server and two examples for the webclient:
Scheduled reload for server
Reload on demand for webclient
Scheduled reload for http client
Using PEM files
It is also possible to have ssl reloading based on PEM files instead of p12 files with a similar setup as shown on the other examples.
Just call the PemUtils to generate a KeyManager and TrustManager for the SSLFactory as shown below:
UPDATE 09-12-2022
The current PR #4453 makes it possible to enable ssl reloading in the vertx server out of the box with the example server configuration below.
The text was updated successfully, but these errors were encountered: