From e9b3e5dac238f66cb53dfb7ef4655164ec30a684 Mon Sep 17 00:00:00 2001 From: Marcel Juen Date: Mon, 24 Jul 2023 10:59:11 +0200 Subject: [PATCH] Added functionality to set custom SSL socket factory in BaseHttpAuthClient --- .../pusher/client/util/BaseHttpAuthClient.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/com/pusher/client/util/BaseHttpAuthClient.java b/src/main/java/com/pusher/client/util/BaseHttpAuthClient.java index 1a82845e..c5774380 100644 --- a/src/main/java/com/pusher/client/util/BaseHttpAuthClient.java +++ b/src/main/java/com/pusher/client/util/BaseHttpAuthClient.java @@ -12,6 +12,7 @@ import java.util.Map; import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLSocketFactory; /** * Base class for {@link com.pusher.client.util.HttpChannelAuthorizer} and {@link com.pusher.client.util.HttpUserAuthenticator} @@ -22,6 +23,7 @@ abstract class BaseHttpAuthClient { private final URL endPoint; private Map mHeaders = new HashMap<>(); protected ConnectionFactory mConnectionFactory; + protected SSLSocketFactory mSslSocketFactory = null; /** * Creates a new auth client. @@ -61,6 +63,15 @@ public void setHeaders(final Map headers) { mHeaders = headers; } + /** + * Set the SSL socket factory that is used for the connection. This allows to + * configure custom certificate handling (self-signed certificates, mutual TLS, ...) + * @param sslSocketFactory The SSL socket factory to use + */ + public void setSslSocketFactory(final SSLSocketFactory sslSocketFactory) { + mSslSocketFactory = sslSocketFactory; + } + /** * Identifies if the HTTP request will be sent over HTTPS. * @@ -92,6 +103,11 @@ protected String performAuthRequest() { HttpURLConnection connection; if (isSSL()) { connection = (HttpsURLConnection) endPoint.openConnection(); + + if(mSslSocketFactory != null) { + ((HttpsURLConnection) connection) + .setSSLSocketFactory(mSslSocketFactory); + } } else { connection = (HttpURLConnection) endPoint.openConnection(); }