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

Session reuse with different port #458

Open
Stefan4112 opened this issue Feb 4, 2019 · 8 comments
Open

Session reuse with different port #458

Stefan4112 opened this issue Feb 4, 2019 · 8 comments
Assignees

Comments

@Stefan4112
Copy link

We have a problem with our FTP client implementation and TLS session resumption required by some servers, for example FileZilla server that has it enabled by default. This option requires the client to use the same TLS session in the data session and control session. That means different ports for two connections and same TLS session.

For more information you can look up the common message "TLS session of data connection has not resumed or the session does not match the control connection".

We tried Oracle Java at first and found a workaround. But the workaround does not work with IBM i, were our client will run. Now we tried BouncyCastle as a SSLContext provider. Unfortunately the feature is not supported either.

Will TLS session reuse on different ports be supported?

@peterdettman
Copy link
Collaborator

We can look at adding support. Do you have an idea about how the API should work to access this feature? Note that BCJSSE does provide an extended API so you can contemplate features that aren't in the JSSE API itself, although relying on them of course creates a dependency.

Please also describe the workaround that you are using with the Oracle JRE.

@peterdettman peterdettman self-assigned this Feb 26, 2019
@Stefan4112
Copy link
Author

We use the Apache commons net FTPSClient to connect to a FileZilla server. The workaround for Oracle JRE uses the method „prepareDataSocket“ (FTPSClient) that was implemented by Apache to make this workaround possible.
Code example can be found at https://stackoverflow.com/questions/51405161/ftps-connection-is-throwing-an-error-in-android
Oracle changed something, so this workaround is not possible anymore. I found a java property that can be set to make it work again (untested on my side). But let me just describe what it does:

It takes the SSLSessionContext from the current SSLSession. Then it adds the current key (host and port) to the sessionHostPortCache.
Yes, that is everything. Using BouncyCastle I get the ProvSSLSessionContext that implements SSLSessionContext. Seems like you use hostName and port, too.

For an API idea:
I only use BouncyCastle once and that is on provider registration or calling SSLContext.getInstance with the specific provider. Example:
SSLContext clientContext = SSLContext.getInstance("TLS", new BouncyCastleJsseProvider());

So my idea is to add the option bindSessionToPort(boolean) to the provider. Example use:
BouncyCastleJsseProvider provider = new BouncyCastleJsseProvider(); provider.bindSessionToPort(false); SSLContext clientContext = SSLContext.getInstance("TLS", provider);

@Stefan4112
Copy link
Author

Is this issue being worked on, the possibilities discussed or is it paused?

@vionixt
Copy link

vionixt commented Aug 6, 2024

Hi @Stefan4112 have you been able to handle this?
If so, can you please share your findings?

@Stefan4112
Copy link
Author

Stefan4112 commented Aug 6, 2024

I still use the reflection workaround in standard Java. I have no idea how to implement it with BouncyCastle myself.

The current workaround in Java can be found here.
It is possible that it changes with each Java release.

For situations where the workaround is not possible I do a OpenSSL command call.

@vionixt
Copy link

vionixt commented Aug 6, 2024

ons where the workaround is not possible I

Java 17 is not allowing reflection any more,
"module java.base does not "opens sun.security.ssl" to unnamed module"

And ClientHello depends on the host/port
image

Trying out different approaches, but without any luck so far :)

@peterdettman
Copy link
Collaborator

If you are happy to use the BCJSSE extension API, then for the first connection collect the session like so (after connected):

BCExtendedSSLSession sessionToResume = ((BCSSLSocket)sslSocket1).getBCSession();

Then when initialising the second connection, you can configure it to reuse this exact session like so (before connecting):

((BCSSLSocket)sslSocket2).setBCSessionToResume(sessionToResume);

The same methods exist also for BCSSLEngine.

@And390
Copy link

And390 commented Nov 24, 2024

Correct me if I'm wrong but the last suggestion (with setBCSessionToResume) works for TLS 1.2 only. Is there a solution for TLS 1.3? I can hardly find an information on whether bctls even supports session reuse for 1.3 at all.

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

No branches or pull requests

4 participants