Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add web socket transport sender hostname verification #3766

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import io.netty.handler.codec.http.websocketx.WebSocketVersion;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.SslHandler;
import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import org.apache.axis2.description.Parameter;
Expand All @@ -48,7 +49,9 @@
import java.net.URI;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLParameters;
import javax.xml.namespace.QName;

public class WebsocketConnectionFactory {
Expand Down Expand Up @@ -220,7 +223,19 @@ public WebSocketClientHandler cacheNewConnection(final URI uri, final String sou
protected void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc(), host, port));
SslHandler sslHandler = sslCtx.newHandler(ch.alloc(), host, port);
Parameter wsEnableHostnameVerification = transportOut
.getParameter(WebsocketConstants.WEBSOCKET_HOSTNAME_VERIFICATION_CONFIG);
if (wsEnableHostnameVerification != null
&& wsEnableHostnameVerification.getValue() != null
&& !wsEnableHostnameVerification.getValue().toString().isEmpty()
&& Boolean.parseBoolean(wsEnableHostnameVerification.getValue().toString())) {
SSLEngine sslEngine = sslHandler.engine();
SSLParameters sslParams = sslEngine.getSSLParameters();
sslParams.setEndpointIdentificationAlgorithm("HTTPS");
sslEngine.setSSLParameters(sslParams);
}
p.addLast(sslHandler);
}
p.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192),
new WebSocketFrameAggregator(Integer.MAX_VALUE), handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class WebsocketConstants {

public static final String WEBSOCKET_CUSTOM_HEADER_PREFIX = "websocket.custom.header.";
public static final String WEBSOCKET_CUSTOM_HEADER_CONFIG = "ws.custom.header";
public static final String WEBSOCKET_HOSTNAME_VERIFICATION_CONFIG = "ws.client.enable.hostname.verification";

public static final String CONNECTION_TERMINATE = "connection.terminate";

Expand Down
Loading