Skip to content

Commit

Permalink
The TCP server/client updateSslOptions method does not update the opt…
Browse files Browse the repository at this point in the history
…ions when the comparison using equals against the previous options returns true. Sometimes this behavior is not desirable, e.g. when the path to the certificate does not change and such certificates has been overwritten.
  • Loading branch information
vietj committed Nov 13, 2023
1 parent 29ebcb1 commit 75d6dc2
Show file tree
Hide file tree
Showing 15 changed files with 312 additions and 92 deletions.
6 changes: 5 additions & 1 deletion src/main/asciidoc/net.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,11 @@ implement certificate rotation).
{@link examples.NetExamples#updateSSLOptions}
----

When the update succeeds the new SSL configuration is used, otherwise the previous configuration is kept.
When the update succeeds the new SSL configuration is used, otherwise the previous configuration is preserved.

NOTE: The options object is compared (using `equals`) against the existing options to prevent an update when the objects
are equals since loading options can be costly. When object are equals, you can use the `force` parameter to force
the update.

==== Self-signed certificates for testing and development purposes

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/examples/NetExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public void example41(Vertx vertx) {
}

public void updateSSLOptions(HttpServer server) {
Future<Void> fut = server.updateSSLOptions(new SSLOptions()
Future<Boolean> fut = server.updateSSLOptions(new SSLOptions()
.setKeyCertOptions(
new JksOptions()
.setPath("/path/to/your/server-keystore.jks").
Expand Down
44 changes: 39 additions & 5 deletions src/main/java/io/vertx/core/http/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,24 +196,58 @@ default Future<HttpClientRequest> request(HttpMethod method, String requestURI)
Future<WebSocket> webSocketAbs(String url, MultiMap headers, WebsocketVersion version, List<String> subProtocols);

/**
* Update the client SSL options.
* <p>Update the client with new SSL {@code options}, the update happens if the options object is valid and different
* from the existing options object.
*
* Update only happens if the SSL options is valid.
* <p>The boolean succeeded future result indicates whether the update occurred.
*
* @param options the new SSL options
* @return a future signaling the update success
*/
Future<Void> updateSSLOptions(SSLOptions options);
default Future<Boolean> updateSSLOptions(SSLOptions options) {
return updateSSLOptions(options, false);
}

/**
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
* happened (or has failed).
*
* @param options the new SSL options
* @param handler the update handler
*/
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Boolean>> handler) {
Future<Boolean> fut = updateSSLOptions(options);
if (handler != null) {
fut.onComplete(handler);
}
}

/**
* <p>Update the client with new SSL {@code options}, the update happens if the options object is valid and different
* from the existing options object.
*
* <p>The {@code options} object is compared using its {@code equals} method against the existing options to prevent
* an update when the objects are equals since loading options can be costly, this can happen for share TCP servers.
* When object are equals, setting {@code force} to {@code true} forces the update.
*
* <p>The boolean succeeded future result indicates whether the update occurred.
*
* @param options the new SSL options
* @param force force the update when options are equals
* @return a future signaling the update success
*/
Future<Boolean> updateSSLOptions(SSLOptions options, boolean force);

/**
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
* happened (or has failed).
*
* @param options the new SSL options
* @param force force the update when options are equals
* @param handler the update handler
*/
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Void>> handler) {
Future<Void> fut = updateSSLOptions(options);
default void updateSSLOptions(SSLOptions options, boolean force, Handler<AsyncResult<Boolean>> handler) {
Future<Boolean> fut = updateSSLOptions(options, force);
if (handler != null) {
fut.onComplete(handler);
}
Expand Down
44 changes: 39 additions & 5 deletions src/main/java/io/vertx/core/http/HttpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,58 @@ public interface HttpServer extends Measured {
Handler<ServerWebSocket> webSocketHandler();

/**
* Update the server SSL options.
* Update the server with new SSL {@code options}, the update happens if the options object is valid and different
* from the existing options object.
*
* Update only happens if the SSL options is valid.
* <p>The boolean succeeded future result indicates whether the update occurred.
*
* @param options the new SSL options
* @return a future signaling the update success
*/
Future<Void> updateSSLOptions(SSLOptions options);
default Future<Boolean> updateSSLOptions(SSLOptions options) {
return updateSSLOptions(options, false);
}

/**
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
* happened (or has failed).
*
* @param options the new SSL options
* @param handler the update handler
*/
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Boolean>> handler) {
Future<Boolean> fut = updateSSLOptions(options);
if (handler != null) {
fut.onComplete(handler);
}
}

/**
* <p>Update the server with new SSL {@code options}, the update happens if the options object is valid and different
* from the existing options object.
*
* <p>The {@code options} object is compared using its {@code equals} method against the existing options to prevent
* an update when the objects are equals since loading options can be costly, this can happen for share TCP servers.
* When object are equals, setting {@code force} to {@code true} forces the update.
*
* <p>The boolean succeeded future result indicates whether the update occurred.
*
* @param options the new SSL options
* @param force force the update when options are equals
* @return a future signaling the update success
*/
Future<Boolean> updateSSLOptions(SSLOptions options, boolean force);

/**
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
* happened (or has failed).
*
* @param options the new SSL options
* @param force force the update when options are equals
* @param handler the update handler
*/
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Void>> handler) {
Future<Void> fut = updateSSLOptions(options);
default void updateSSLOptions(SSLOptions options, boolean force, Handler<AsyncResult<Boolean>> handler) {
Future<Boolean> fut = updateSSLOptions(options, force);
if (handler != null) {
fut.onComplete(handler);
}
Expand Down
40 changes: 35 additions & 5 deletions src/main/java/io/vertx/core/http/WebSocketClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,54 @@ default Future<WebSocket> connect(String requestURI) {
Future<WebSocket> connect(WebSocketConnectOptions options);

/**
* Update the client SSL options.
* Update the client with new SSL {@code options}, the update happens if the options object is valid and different
* from the existing options object.
*
* Update only happens if the SSL options is valid.
* @param options the new SSL options
* @return a future signaling the update success
*/
default Future<Boolean> updateSSLOptions(SSLOptions options) {
return updateSSLOptions(options, false);
}

/**
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
* happened (or has failed).
*
* @param options the new SSL options
* @param handler the update handler
*/
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Boolean>> handler) {
Future<Boolean> fut = updateSSLOptions(options);
if (handler != null) {
fut.onComplete(handler);
}
}

/**
* <p>Update the client with new SSL {@code options}, the update happens if the options object is valid and different
* from the existing options object.
*
* <p>The {@code options} object is compared using its {@code equals} method against the existing options to prevent
* an update when the objects are equals since loading options can be costly, this can happen for share TCP servers.
* When object are equals, setting {@code force} to {@code true} forces the update.
*
* @param options the new SSL options
* @param force force the update when options are equals
* @return a future signaling the update success
*/
Future<Void> updateSSLOptions(SSLOptions options);
Future<Boolean> updateSSLOptions(SSLOptions options, boolean force);

/**
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
* happened (or has failed).
*
* @param options the new SSL options
* @param force force the update when options are equals
* @param handler the update handler
*/
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Void>> handler) {
Future<Void> fut = updateSSLOptions(options);
default void updateSSLOptions(SSLOptions options, boolean force, Handler<AsyncResult<Boolean>> handler) {
Future<Boolean> fut = updateSSLOptions(options, force);
if (handler != null) {
fut.onComplete(handler);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/vertx/core/http/impl/HttpClientBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ public Metrics getMetrics() {
}

// @Override
public Future<Void> updateSSLOptions(SSLOptions options) {
return netClient.updateSSLOptions(options);
public Future<Boolean> updateSSLOptions(SSLOptions options, boolean force) {
return netClient.updateSSLOptions(options, force);
}

public HttpClientBase proxyFilter(Predicate<SocketAddress> filter) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/vertx/core/http/impl/SharedHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ public Future<WebSocket> webSocketAbs(String url, MultiMap headers, WebsocketVer
}

@Override
public Future<Void> updateSSLOptions(SSLOptions options) {
return delegate.updateSSLOptions(options);
public Future<Boolean> updateSSLOptions(SSLOptions options, boolean force) {
return delegate.updateSSLOptions(options, force);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,8 @@ public Future<WebSocket> connect(WebSocketConnectOptions options) {
}

@Override
public Future<Void> updateSSLOptions(SSLOptions options) {
return delegate.updateSSLOptions(options);
}

@Override
public void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Void>> handler) {
delegate.updateSSLOptions(options, handler);
public Future<Boolean> updateSSLOptions(SSLOptions options, boolean force) {
return delegate.updateSSLOptions(options, force);
}

@Override
Expand Down
44 changes: 39 additions & 5 deletions src/main/java/io/vertx/core/net/NetClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,58 @@ public interface NetClient extends Measured {
Future<Void> close();

/**
* Update the client SSL options.
* <p>Update the client with new SSL {@code options}, the update happens if the options object is valid and different
* from the existing options object.
*
* Update only happens if the SSL options is valid.
* <p>The boolean succeeded future result indicates whether the update occurred.
*
* @param options the new SSL options
* @return a future signaling the update success
*/
Future<Void> updateSSLOptions(SSLOptions options);
default Future<Boolean> updateSSLOptions(SSLOptions options) {
return updateSSLOptions(options, false);
}

/**
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
* happened (or has failed).
*
* @param options the new SSL options
* @param handler the update handler
*/
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Boolean>> handler) {
Future<Boolean> fut = updateSSLOptions(options);
if (handler != null) {
fut.onComplete(handler);
}
}

/**
* <p>Update the client with new SSL {@code options}, the update happens if the options object is valid and different
* from the existing options object.
*
* <p>The {@code options} object is compared using its {@code equals} method against the existing options to prevent
* an update when the objects are equals since loading options can be costly, this can happen for share TCP servers.
* When object are equals, setting {@code force} to {@code true} forces the update.
*
* <p>The boolean succeeded future result indicates whether the update occurred.
*
* @param options the new SSL options
* @param force force the update when options are equals
* @return a future signaling the update success
*/
Future<Boolean> updateSSLOptions(SSLOptions options, boolean force);

/**
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
* happened (or has failed).
*
* @param options the new SSL options
* @param force force the update when options are equals
* @param handler the update handler
*/
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Void>> handler) {
Future<Void> fut = updateSSLOptions(options);
default void updateSSLOptions(SSLOptions options, boolean force, Handler<AsyncResult<Boolean>> handler) {
Future<Boolean> fut = updateSSLOptions(options, force);
if (handler != null) {
fut.onComplete(handler);
}
Expand Down
47 changes: 41 additions & 6 deletions src/main/java/io/vertx/core/net/NetServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,25 +200,60 @@ default NetServer listen(SocketAddress localAddress, Handler<AsyncResult<NetServ
int actualPort();

/**
* Update the server SSL options.
* <p>Update the server with new SSL {@code options}, the update happens if the options object is valid and different
* from the existing options object.
*
* Update only happens if the SSL options is valid.
* <p>The boolean succeeded future result indicates whether the update occurred.
*
* @param options the new SSL options
* @return a future signaling the update success
*/
Future<Void> updateSSLOptions(SSLOptions options);
default Future<Boolean> updateSSLOptions(SSLOptions options) {
return updateSSLOptions(options, false);
}

/**
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
* happened (or has failed).
*
* @param options the new SSL options
* @param handler the update handler
*/
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Boolean>> handler) {
Future<Boolean> fut = updateSSLOptions(options);
if (handler != null) {
fut.onComplete(handler);
}
}

/**
* <p>Update the server with new SSL {@code options}, the update happens if the options object is valid and different
* from the existing options object.
*
* <p>The {@code options} object is compared using its {@code equals} method against the existing options to prevent
* an update when the objects are equals since loading options can be costly, this can happen for share TCP servers.
* When object are equals, setting {@code force} to {@code true} forces the update.
*
* <p>The boolean succeeded future result indicates whether the update occurred.
*
* @param options the new SSL options
* @param force force the update when options are equals
* @return a future signaling the update success
*/
Future<Boolean> updateSSLOptions(SSLOptions options, boolean force);

/**
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
* happened (or has failed).
*
* @param options the new SSL options
* @param force force the update when options are equals
* @param handler the update handler
*/
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Void>> handler) {
Future<Void> fut = updateSSLOptions(options);
default void updateSSLOptions(SSLOptions options, boolean force, Handler<AsyncResult<Boolean>> handler) {
Future<Boolean> fut = updateSSLOptions(options, force);
if (handler != null) {
fut.onComplete(handler);
}
}}
}
}
Loading

0 comments on commit 75d6dc2

Please sign in to comment.