Skip to content

Add support for setting io.netty.handler.ssl.SslContext #734

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

Merged
merged 4 commits into from
Jun 25, 2021

Conversation

stIncMale
Copy link
Member

@stIncMale stIncMale commented Jun 19, 2021

This may be used as a convenient way to utilize OpenSSL as an alternative to the TLS/SSL protocol implementation in a JDK.

JAVA-4177

@stIncMale stIncMale requested a review from rozza June 19, 2021 05:25
* To achieve this, specify {@link SslProvider#OPENSSL}
* {@linkplain SslContextBuilder#sslProvider(SslProvider) TLS/SSL protocol provider} via the tuner.
* Note that doing so adds a runtime dependency on
* <a href="https://netty.io/wiki/forked-tomcat-native.html">netty-tcnative</a>, which you must satisfy.
Copy link
Member Author

Choose a reason for hiding this comment

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

There are multiple artifacts that may be used to satisfy this dependency. They differ by the target OS, ISA, native dependencies which are linked either dynamically or statically. As a result, I don't think we can specify this dependency in the published POM as an optional runtime dependency.

dependencies {
api project(path: ':bson', configuration: 'default')

implementation "com.github.jnr:jnr-unixsocket:$jnrUnixsocketVersion", optional
api "io.netty:netty-buffer:$nettyVersion", optional
api "io.netty:netty-transport:$nettyVersion", optional
implementation "io.netty:netty-handler:$nettyVersion", optional
api "io.netty:netty-handler:$nettyVersion", optional
Copy link
Member Author

Choose a reason for hiding this comment

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

This changes the dependency in the published POM from optional runtime to optional compile time.

This may be used as a convenient way to utilize OpenSSL as an alternative
to the TLS/SSL protocol implementation in a JDK.
See also https://netty.io/wiki/requirements-for-4.x.html#tls-with-openssl.

JAVA-4177
Copy link
Member

@rozza rozza left a comment

Choose a reason for hiding this comment

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

A couple of comments

@stIncMale stIncMale requested a review from rozza June 23, 2021 22:35
Copy link
Member

@rozza rozza left a comment

Choose a reason for hiding this comment

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

Looks really good, just a couple of questions for my edification.

public Builder nettySslContext(final SslContext nettySslContext) {
this.nettySslContext = notNull("nettySslContext", nettySslContext);
isTrueArgument("nettySslContext must be client-side", nettySslContext.isClient());
isTrueArgument("nettySslContext must not be reference counted",
Copy link
Member

Choose a reason for hiding this comment

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

Should this requirement be in the api docs?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is there, formulated as "Only {@link SslProvider#JDK} and {@link SslProvider#OPENSSL} TLS/SSL protocol providers are supported." The constraint is implemented as is because checking the provided context against a blacklist is shorter and saves us from relying on specific classes implementing allowed values of SslProvider (if Netty starts implementing a forbidden value with a different class - not a big deal, our check becomes useless; but if Netty starts implementing an allowed value with a different class - our users will not be able to use it).

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed the error message for this check to "sslContext must use either SslProvider.JDK or SslProvider.OPENSSL TLS/SSL protocol provider".

Done.

*
* @since 4.3
*/
public Builder nettySslContext(final SslContext nettySslContext) {
Copy link
Member

Choose a reason for hiding this comment

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

Naming convention question: Why nettySslContext and not just SslContext?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to emphasize that Netty SslContext is not of type javax.net.ssl.SSLContext, however I was not sure whether it is a good idea to make names longer just for that purpose. I interpret your question as a sign that it was not a good idea.

Removed the netty prefix.

Done.

if (streamType.equals("netty")) {
return new NettyStreamFactory(getSocketSettings(), getSslSettings());
} else if (streamType.equals("nio2")) {
StreamFactoryFactory overriddenStreamMetafactory = getOverriddenStreamFactoryFactory();
Copy link
Member

Choose a reason for hiding this comment

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

Naming convention question: why Metafactory and not FactoryFactory?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thought I would use "metafactory" as this is what should have been used instead of "factoryFactory". Replaced with "factoryFactory".

Done.

if (nettyStreamFactoryFactory == null) {
nettyStreamFactoryFactory = NettyStreamFactoryFactory.builder().build();
if (nettyStreamFactoryFactory == null) {
if (streamType.equals("netty")) {
Copy link
Member

Choose a reason for hiding this comment

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

this double if statement could be joined.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! Done.

@stIncMale stIncMale requested a review from rozza June 24, 2021 18:19
Copy link
Member

@rozza rozza left a comment

Choose a reason for hiding this comment

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

LGTM

@stIncMale stIncMale merged commit 74d6b59 into mongodb:master Jun 25, 2021
@stIncMale stIncMale deleted the JAVA-4177 branch June 25, 2021 15:27
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.

2 participants