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

Additional logging for SNI #5319

Merged
merged 1 commit into from
May 16, 2023
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 @@ -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