Replies: 5 comments 1 reply
-
These options are a bit tricky to be honest. It is not possible to adjust the protocols of the sslcontext with the sslfactory builder protocol option as the sslcontext has no option to modify those properties. The only way I could manupulate it was by creating a custom SSLContextSpi under the covers. I tried that in the past, but it is difficult. However some objects are possible to modify and luckily SSLFactory will provide those. The SSLSocketFactory, SSLServerSocketFactory and SSLEngine have the adjusted protocols. See here for an example: import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLSocket;
import java.io.IOException;
import java.util.Arrays;
public class App {
public static void main(String[] args) throws IOException {
SSLFactory sslFactory = SSLFactory.builder()
.withDefaultTrustMaterial()
.withProtocols("TLSv1.3")
.build();
System.out.println("SSLFactory");
System.out.println(sslFactory.getProtocols());
System.out.println("SSLContext");
System.out.println(Arrays.toString(sslFactory.getSslContext().getDefaultSSLParameters().getProtocols()));
System.out.println(Arrays.toString(sslFactory.getSslContext().getSupportedSSLParameters().getProtocols()));
System.out.println("SSLSocket");
SSLSocket socket = (SSLSocket) sslFactory.getSslSocketFactory().createSocket();
System.out.println(Arrays.toString(socket.getSupportedProtocols()));
System.out.println(Arrays.toString(socket.getEnabledProtocols()));
System.out.println("SSLEngine");
SSLEngine sslEngine = sslFactory.getSSLEngine();
System.out.println(Arrays.toString(sslEngine.getSupportedProtocols()));
System.out.println(Arrays.toString(sslEngine.getEnabledProtocols()));
}
} And the output:
The method So if you are able to use SSLSocketFactory/SSLSocket or SSLEngine then it will work. If you only want to use SSLContext then it is very limited to what you can adjust. So if you want only TLSv1.2 for the SSLContext, then you should do something like this: import java.io.IOException;
import java.util.Arrays;
public class App {
public static void main(String[] args) throws IOException {
SSLFactory sslFactory = SSLFactory.builder()
.withDefaultTrustMaterial()
.withSslContextAlgorithm("TLSv1.2")
.build();
System.out.println("SSLContext");
System.out.println(Arrays.toString(sslFactory.getSslContext().getDefaultSSLParameters().getProtocols()));
System.out.println(Arrays.toString(sslFactory.getSslContext().getSupportedSSLParameters().getProtocols()));
}
} which outputs:
As you can see it will have TLSv1.2 configured. However if you adjust the withSslContextAlgorithm to TLSv1.3, then it will have the following output:
I saw on your code snippet that you are using the SSLContext to create the SSLEngine, I would advice to call the SSLEngine of the SSLFactory as shown in my code examples to create the SSLEngine with the specified protocol. Can you give it a try on your side? |
Beta Was this translation helpful? Give feedback.
-
I also found now a way to do it with the SSLContext objects itself, but still refactoring it and testing it, see here for the changes: #360 |
Beta Was this translation helpful? Give feedback.
-
Hi @Hakky54 and thanks for the detailed response.
I just noticed the same problem with IMHO, if there is a way to make it work directly (as noted in #360 - from the cursory look it looks promising) it would be splendid. |
Beta Was this translation helpful? Give feedback.
-
The
Do you mean with the exsiting latest version? I have run a test and the values are consitent through out all of the objects, see also this comment here: #360 (comment) Can you maybe try it out locally on your side, by forking it building it locally and using the snapshot version on your machine for your project? |
Beta Was this translation helpful? Give feedback.
-
Yes, I meant if you need multiple of them then adjusting each engine requires additional code (
You mean
8.1.1, though after your comment I checked 8.1.2 with same result. I'll take a look at the PR and comments there. EDIT: with 8.1.2 EDIT2: tested 8.1.3-SNAPSHOT from PR #360 branch and |
Beta Was this translation helpful? Give feedback.
-
I'm trying to set enabled protocols but I can't make it work. Sample code:
results in:
So it seems that
.withProtocols()
correctly sets the protocols, but it's ignored the actualSSLContext
.Am I doing anything wrong?
Beta Was this translation helpful? Give feedback.
All reactions