I’m looking at the JSSE reference guide, I need to obtain an instance of SSLContext in order to create a SSLEngine, so I can use it with Netty to enable security.
To obtain an instance of SSLContext, I use SSLContext.getInstance(). I see that the method is overridden multiple times, so I can chose the protocol and security provider to use.
Here, I can see the list of algorithms that can be used. Which algorithm should I use to enable secure communication?
Also, since it is possible to specify the security provider to use, which provider should I use?
Thanks
As you can see in the standard names documentation, all entries (SSLv3, TLSv1.0, TLSv1.1, …) say that they may support other versions.
In practice, in the Oracle JDK (and OpenJDK), they all do. If you look at the source code, the
TLS10Contextclass is what’s used for TLS, SSL, SSLv3 and TLS10,TLS11Contextis used for TLSv1.1 andTLS12Contextfor TLSv1.2. All support all versions of SSL/TLS, it’s what’s enabled by default that varies.This may be different with another provider or JRE vendor. You should of course pick one that’s at least going to support the protocol version you want to use.
Note that the protocol used is determined later on using
SSLSocket.setEnabledProtocols(...)or itsSSLEngineequivalent.As a general rule, use the highest version number you can (SSLv3 < TLSv1.0 < TLSv1.1 …), which may depend on what the parties with which you want to communicate support.
Which protocols are enabled by default varies depending on the exact version of the Oracle JRE.
When looking at the source code for
sun.security.ssl.SunJSSEin OpenJDK 7u40-b43,TLSis simply an alias forTLSv1(and so areSSLandSSLv3), in terms ofSSLContextprotocols. Looking at the various implementations ofSSLContextImpl(which are inner classes ofSSLContextImplitself):TLS10Context(used for protocolSSL,SSLv3,TLS,TLSv1) enables SSLv3 to TLSv1.0 by default on the client side.TLS11Context(used for protocolTLSv1.1) also enables TLSv1.1 by default.TLS12Context(used for protocolTLSv1.2) also enables TLSv1.2 by default.This changes in Java 8, in conjunction with the new
jdk.tls.client.protocolssystem property.Again, when looking at the source code for
sun.security.ssl.SunJSSEin OpenJDK 8u40-b25,SSLContextprotocolsTLSv1,TLSv1.1, andTLSv1.2also make use ofTLS10Context,TLS11ContextandTLS12Context, which follow the same logic as in Java 7.However, protocol
TLSis no longer aliased to any of them. Rather, it usesTLSContextwhich relies on the values in thejdk.tls.client.protocolssystem properties. From the JSSE Reference guide:If this property is empty, all protocols are enabled by default on both client and server side.
Of course, in recent versions of Oracle JRE 8, SSL is also completely disabled by default (so removed from those lists).
Note that in both cases (JRE 7 and 8), the
SSLContextyou get by default viaSSLContext.getDefault()out of the box is more or less equivalent to anSSLContextobtained with protocolTLSand initialised with the default truststore parameters and so on.