Skip to content
This repository has been archived by the owner on Nov 24, 2024. It is now read-only.

Commit

Permalink
OTPL-8083 OtSecureRequestCustomizer
Browse files Browse the repository at this point in the history
More customizable callback.
  • Loading branch information
dkaukov committed Jun 29, 2023
1 parent b59d20f commit c174769
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
otj-server
=========
6.0.1, 6.0.2, 6.0.3, 6.0.4
-----
* More customizable SNI host check

6.0.0
-----
* Update Parent Pom to 362 [changes see here]( https://github.com/opentable/otj-parent/blob/master/CHANGELOG.md#362)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import java.time.Duration;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;

import javax.net.ssl.SSLEngine;

Expand All @@ -35,7 +35,7 @@ public class OtSecureRequestCustomizer extends SecureRequestCustomizer {
private static final Logger LOG = LoggerFactory.getLogger(HttpChannel.class);
private static final Logger BUCKET_LOG = BucketLog.of(HttpChannel.class, 1, Duration.ofSeconds(10)); // 1 per 10 second
private final ServerConnectorConfig config;
private Optional<BiConsumer<SSLEngine, Request>> sniErrorCallback = Optional.empty();
private Optional<BiFunction<SSLEngine, Request, Boolean>> sniErrorCallback = Optional.empty();

public OtSecureRequestCustomizer(ServerConnectorConfig config) {
super(config.isSniRequired(), config.isSniHostCheck(), -1, false);
Expand All @@ -55,8 +55,9 @@ protected void customize(SSLEngine sslEngine, Request request) {
sslEngine.getSession().getValue(X509_CERT),
sslEngine.getPeerHost(),
sslEngine.getPeerPort());
sniErrorCallback.ifPresent(c -> c.accept(sslEngine, request));
throw ex;
if (sniErrorCallback.map(i -> i.apply(sslEngine, request)).orElse(true)) {
throw ex;
}
}
} else {
BUCKET_LOG.warn("SNIHOST: Host={}, SNI=null, SNI Certificate={}, peerHost={}, peerPort={}",
Expand All @@ -67,7 +68,7 @@ protected void customize(SSLEngine sslEngine, Request request) {
}
}

public void setSniErrorCallback(BiConsumer<SSLEngine, Request> sniErrorCallback) {
public void setSniErrorCallback(BiFunction<SSLEngine, Request, Boolean> sniErrorCallback) {
this.sniErrorCallback = Optional.ofNullable(sniErrorCallback);
}
}

0 comments on commit c174769

Please sign in to comment.