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

* SSL session caching/reusing disabled to prevent memory corruption #785

Merged
merged 2 commits into from
May 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
*/
public class ClientSessionContext extends AbstractSessionContext {

// dkimitsa: FIXME: session caching was disabled as current implementation cause
// multiple usage of SINGLE native session.
// ISSUE: this session was de-allocated multiple times in OpenSSLSocketImpl.free
// as SSL_free also frees session
// can be enabled by declaring SSL_FAULTY_RFC4507_ON property.
// it known to cause connection issues and application crashes.
// check #601 #585 #557 #306
final boolean sessionCachingEnabled = System.getProperty("SSL_FAULTY_RFC4507_ON") != null;

/**
* Sessions indexed by host and port. Protect from concurrent
* access by holding a lock on sessionsByHostAndPort.
Expand All @@ -40,6 +49,8 @@ public ClientSessionContext() {
}

public int size() {
if (!sessionCachingEnabled) return 0;

return sessionsByHostAndPort.size();
}

Expand All @@ -48,6 +59,8 @@ public void setPersistentCache(SSLClientSessionCache persistentCache) {
}

protected void sessionRemoved(SSLSession session) {
if (!sessionCachingEnabled) return;

String host = session.getPeerHost();
int port = session.getPeerPort();
if (host == null) {
Expand All @@ -67,6 +80,8 @@ protected void sessionRemoved(SSLSession session) {
* @return cached session or null if none found
*/
public SSLSession getSession(String host, int port) {
if (!sessionCachingEnabled) return null;

if (host == null) {
return null;
}
Expand Down Expand Up @@ -99,6 +114,8 @@ public SSLSession getSession(String host, int port) {

@Override
public void putSession(SSLSession session) {
if (!sessionCachingEnabled) return;

super.putSession(session);

String host = session.getPeerHost();
Expand Down
Loading