Skip to content

Commit

Permalink
Additional logging for SNI
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <[email protected]>
  • Loading branch information
jansupol committed May 16, 2023
1 parent 99042d6 commit f6e849b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.glassfish.jersey.client.innate.http;

import org.glassfish.jersey.client.internal.LocalizationMessages;

import javax.net.ssl.SNIHostName;
import javax.net.ssl.SNIServerName;
import javax.net.ssl.SSLEngine;
Expand All @@ -27,12 +29,14 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Logger;

/**
* A unified routines to set {@link SNIHostName} for the {@link javax.net.ssl.SSLContext}.
* To be reused in connectors.
*/
final class SniConfigurator {
private static final Logger LOGGER = Logger.getLogger(SniConfigurator.class.getName());
private final String hostName;
private SniConfigurator(String hostName) {
this.hostName = hostName;
Expand Down Expand Up @@ -85,6 +89,7 @@ void setServerNames(SSLEngine sslEngine) {
SSLParameters sslParameters = sslEngine.getSSLParameters();
updateSSLParameters(sslParameters);
sslEngine.setSSLParameters(sslParameters);
LOGGER.fine(LocalizationMessages.SNI_ON_SSLENGINE());
}

/**
Expand All @@ -95,6 +100,7 @@ void setServerNames(SSLSocket sslSocket) {
SSLParameters sslParameters = sslSocket.getSSLParameters();
updateSSLParameters(sslParameters);
sslSocket.setSSLParameters(sslParameters);
LOGGER.fine(LocalizationMessages.SNI_ON_SSLSOCKET());
}

private SSLParameters updateSSLParameters(SSLParameters sslParameters) {
Expand All @@ -103,6 +109,7 @@ private SSLParameters updateSSLParameters(SSLParameters sslParameters) {
serverNames.add(serverName);

sslParameters.setServerNames(serverNames);
LOGGER.finer(LocalizationMessages.SNI_UPDATE_SSLPARAMS(hostName));

return sslParameters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,13 @@ private ClientResponse _apply(final ClientRequest request) throws IOException {
final HttpURLConnection uc;
final Optional<ClientProxy> proxy = ClientProxy.proxyFromRequest(request);
final SSLParamConfigurator sniConfig = SSLParamConfigurator.builder().request(request).build();
final URI sniUri = sniConfig.isSNIRequired() ? sniConfig.toIPRequestUri() : request.getUri();
final URI sniUri;
if (sniConfig.isSNIRequired()) {
sniUri = sniConfig.toIPRequestUri();
LOGGER.fine(LocalizationMessages.SNI_URI_REPLACED(sniUri.getHost(), request.getUri().getHost()));
} else {
sniUri = request.getUri();
}

proxy.ifPresent(clientProxy -> ClientProxy.setBasicAuthorizationHeader(request.getHeaders(), proxy.get()));
uc = this.connectionFactory.getConnection(sniUri.toURL(), proxy.isPresent() ? proxy.get().proxy() : null);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ restricted.header.property.setting.false=Restricted headers are not enabled usin
restricted.header.property.setting.true=Restricted headers are enabled using [{0}] system property(setting only takes effect on\
connections created after the property has been set/changed).
request.entity.already.written=The entity was already written in this request. The entity can be written (serialized into the output stream) only once per a request.
sni.on.sslsocket=Setting SNIServerName on SSLSocket
sni.on.sslengine=Setting SNIServerName on SSLEngine
sni.uri.replaced=HTTP Request sent with request to IP address {0} rather than the hostname {1}.
sni.update.sslparams=Updating SSLParameters for SNIServerName={0}.
unexpected.error.response.processing=Unexpected error during response processing.
use.encoding.ignored=Value {1} of {0} client property will be ignored as it is not a valid supported encoding. \
Valid supported encodings are: {2}
Expand Down

0 comments on commit f6e849b

Please sign in to comment.