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

Include server name indication (SNI) in outgoing TLS connections. #409

Merged
merged 5 commits into from
May 16, 2019

Conversation

dvlato
Copy link
Contributor

@dvlato dvlato commented May 13, 2019

Add support for SNI in Styx-client, so the destination ServerName will be sent in outgoing TLS requests as per RFC 6066 section 3 (https://tools.ietf.org/html/rfc6066#section-3).

Copy link
Contributor

@mikkokar mikkokar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for implementing this, @dvlato. Apart from couple of stylistic points, could you check my question about the default peerPort (-1)?

Also do you think it is possible to implement a functional test for this?

return sniHost;
}

public String getSniHost() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary, or used for anything? Consider removing if not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used for the serialization to JSON. I think it was implemented the same way in HealthCheckConfig for the URI(). We could also implement a different serialization method for Optionals or remove the optional for these JSON-serializable objects and use nullability instead, but I decided to follow conventions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Let's put a comment.

@@ -56,6 +59,8 @@ private TlsSettings(Builder builder) {
this.trustStorePassword = toCharArray(builder.trustStorePassword);
this.protocols = ImmutableList.copyOf(builder.protocols);
this.cipherSuites = ImmutableList.copyOf(builder.cipherSuites);
this.sendSni = builder.sendSni;
this.sniHost = builder.sniHost;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider storing sniHost as a String in builder, and using Optional.ofNullable to wrap it inside Optional.

@@ -144,6 +165,8 @@ public int hashCode() {
private String trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword");
private List<String> protocols = Collections.emptyList();
private List<String> cipherSuites = Collections.emptyList();
private boolean sendSni = true;
private Optional<String> sniHost = Optional.empty();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sniHost doesn't really have to be wrapped inside Optional in this builder. You can create an optional in TlsSettings constructor using Optional.ofNullable, also avoiding unnecessary requireNonNull checks.

ChannelPipeline pipeline = channel.pipeline();

if (sslContext != null) {
pipeline.addLast("ssl", sslContext.newHandler(channel.alloc()));
SslHandler sslHandler = sendSni
? sslContext.newHandler(channel.alloc(), targetHost, -1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct to pass -1 as a peer port? Should we instead pass in the configured port number?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is it necessary to test for sendSni flag given that the call site has already set the target accordingly? This is from the NettyConnection constructor:

sniHost.orElse(origin.host())

Copy link
Contributor Author

@dvlato dvlato May 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sendSni flag is to disable sni, whereas the 'orElse' is to send the target hostname in the SNI ServerName instead of a preconfigured override.

It seems that -1 is a valid value as it is the one that will be set in the code with no SNI. The SNI extension doesn't specify a port number but only a server name. It's a shame that netty does not have an overload without a port number.

@dvlato dvlato merged commit b1f404a into ExpediaGroup:master May 16, 2019
dvlato added a commit that referenced this pull request Jul 3, 2019
* Include server name indication (SNI) in outgoing TLS connections.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants