Skip to content

Commit 6421e1f

Browse files
jansupololotenko
andcommitted
Support null PROXY_USERNAME
Support SSL Hostname verification Update request host and port in SSL Context Correct order of TLS handler vs Proxy handler Co-authored-by: olotenko <Oleksandr.Otenko@oracle.com>
1 parent 08bfa50 commit 6421e1f

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyClientProperties.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@ public class NettyClientProperties {
5353
* </p>
5454
*/
5555
public static final String MAX_CONNECTIONS = "jersey.config.client.maxConnections";
56+
57+
public static final String ENABLE_SSL_HOSTNAME_VERIFICATION = "jersey.config.client.tls.enableHostnameVerification";
5658
}

connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyConnector.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
import java.util.concurrent.Future;
3333
import java.util.concurrent.TimeUnit;
3434

35+
import javax.net.ssl.SSLEngine;
36+
import javax.net.ssl.SSLParameters;
37+
3538
import javax.ws.rs.ProcessingException;
3639
import javax.ws.rs.client.Client;
3740
import javax.ws.rs.core.Configuration;
@@ -60,6 +63,7 @@
6063
import io.netty.handler.proxy.HttpProxyHandler;
6164
import io.netty.handler.ssl.ClientAuth;
6265
import io.netty.handler.ssl.JdkSslContext;
66+
import io.netty.handler.ssl.SslHandler;
6367
import io.netty.handler.stream.ChunkedWriteHandler;
6468
import io.netty.handler.timeout.IdleState;
6569
import io.netty.handler.timeout.IdleStateEvent;
@@ -216,15 +220,9 @@ protected CompletableFuture<ClientResponse> execute(final ClientRequest jerseyRe
216220
protected void initChannel(SocketChannel ch) throws Exception {
217221
ChannelPipeline p = ch.pipeline();
218222

219-
// Enable HTTPS if necessary.
220-
if ("https".equals(requestUri.getScheme())) {
221-
// making client authentication optional for now; it could be extracted to configurable property
222-
JdkSslContext jdkSslContext = new JdkSslContext(client.getSslContext(), true, ClientAuth.NONE);
223-
p.addLast(jdkSslContext.newHandler(ch.alloc()));
224-
}
223+
Configuration config = jerseyRequest.getConfiguration();
225224

226225
// http proxy
227-
Configuration config = jerseyRequest.getConfiguration();
228226
final Object proxyUri = config.getProperties().get(ClientProperties.PROXY_URI);
229227
if (proxyUri != null) {
230228
final URI u = getProxyUri(proxyUri);
@@ -234,9 +232,28 @@ protected void initChannel(SocketChannel ch) throws Exception {
234232
final String password = ClientProperties.getValue(
235233
config.getProperties(), ClientProperties.PROXY_PASSWORD, String.class);
236234

237-
p.addLast(new HttpProxyHandler(new InetSocketAddress(u.getHost(),
238-
u.getPort() == -1 ? 8080 : u.getPort()),
239-
userName, password));
235+
InetSocketAddress proxyAddr = new InetSocketAddress(u.getHost(),
236+
u.getPort() == -1 ? 8080 : u.getPort());
237+
p.addLast(userName == null ? new HttpProxyHandler(proxyAddr)
238+
: new HttpProxyHandler(proxyAddr, userName, password));
239+
}
240+
241+
// Enable HTTPS if necessary.
242+
if ("https".equals(requestUri.getScheme())) {
243+
// making client authentication optional for now; it could be extracted to configurable property
244+
JdkSslContext jdkSslContext = new JdkSslContext(client.getSslContext(), true, ClientAuth.NONE);
245+
int port = requestUri.getPort();
246+
SslHandler sslHandler = jdkSslContext.newHandler(ch.alloc(), requestUri.getHost(),
247+
port <= 0 ? 443 : port, executorService);
248+
if (ClientProperties.getValue(config.getProperties(),
249+
NettyClientProperties.ENABLE_SSL_HOSTNAME_VERIFICATION, true)) {
250+
SSLEngine sslEngine = sslHandler.engine();
251+
SSLParameters sslParameters = sslEngine.getSSLParameters();
252+
sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
253+
sslEngine.setSSLParameters(sslParameters);
254+
}
255+
256+
p.addLast(sslHandler);
240257
}
241258

242259
p.addLast(new HttpClientCodec());

0 commit comments

Comments
 (0)