Skip to content

Commit

Permalink
Respond to comments, update usages and update docstring
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Oct 18, 2024
1 parent d390bd9 commit a0844e9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.net.SocketAddress;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Optional;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
Expand Down Expand Up @@ -142,9 +143,14 @@ public SSLServerChannelInitializer(String name) {
protected void initChannel(Channel ch) throws Exception {
super.initChannel(ch);

final boolean dualModeEnabled = secureTransportSettingsProvider.isDualModeEnabled(settings);
boolean dualModeEnabled = false;
Optional<SecureTransportSettingsProvider.SecureTransportParameters> parameters = secureTransportSettingsProvider.parameters(
settings
);
if (parameters.isPresent()) {
dualModeEnabled = parameters.get().dualModeEnabled();
}
if (dualModeEnabled) {
logger.info("SSL Dual mode enabled, using port unification handler");
final ChannelHandler portUnificationHandler = new DualModeSslHandler(
settings,
secureTransportSettingsProvider,
Expand Down Expand Up @@ -258,7 +264,13 @@ protected class SSLClientChannelInitializer extends Netty4Transport.ClientChanne
public SSLClientChannelInitializer(DiscoveryNode node) {
this.node = node;

final boolean dualModeEnabled = secureTransportSettingsProvider.isDualModeEnabled(settings);
boolean dualModeEnabled = false;
Optional<SecureTransportSettingsProvider.SecureTransportParameters> parameters = secureTransportSettingsProvider.parameters(
settings
);
if (parameters.isPresent()) {
dualModeEnabled = parameters.get().dualModeEnabled();
}
hostnameVerificationEnabled = NetworkModule.TRANSPORT_SSL_ENFORCE_HOSTNAME_VERIFICATION.get(settings);
hostnameVerificationResolveHostName = NetworkModule.TRANSPORT_SSL_ENFORCE_HOSTNAME_VERIFICATION_RESOLVE_HOST_NAME.get(settings);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,30 @@ default Collection<TransportAdapterProvider<Transport>> getTransportAdapterProvi
}

/**
* Returns true if dual mode is enabled. Dual mode domains support both encrypted and non-encrypted traffic
* Returns parameters that can be dynamically provided by a plugin providing a {@link SecureTransportSettingsProvider}
* implementation
* @param settings settings
* @return a boolean indicating if dual mode is enabled
* @return an instance of {@link SecureTransportParameters}
*/
default boolean isDualModeEnabled(Settings settings) {
return NetworkModule.TRANSPORT_SSL_DUAL_MODE_ENABLED.get(settings);
default Optional<SecureTransportParameters> parameters(Settings settings) {
return Optional.of(new DefaultSecureTransportParameters(settings));
}

interface SecureTransportParameters {
boolean dualModeEnabled();
}

class DefaultSecureTransportParameters implements SecureTransportParameters {
private final Settings settings;

DefaultSecureTransportParameters(Settings settings) {
this.settings = settings;
}

@Override
public boolean dualModeEnabled() {
return NetworkModule.TRANSPORT_SSL_DUAL_MODE_ENABLED.get(settings);
}
}

/**
Expand Down

0 comments on commit a0844e9

Please sign in to comment.