Skip to content

Commit 4dbed21

Browse files
authored
Merge pull request #359 from mjuen/master
Allow custom SSL socket factory for BaseHttpAuthClient
2 parents 43bd6a9 + e9b3e5d commit 4dbed21

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎src/main/java/com/pusher/client/util/BaseHttpAuthClient.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Map;
1313

1414
import javax.net.ssl.HttpsURLConnection;
15+
import javax.net.ssl.SSLSocketFactory;
1516

1617
/**
1718
* Base class for {@link com.pusher.client.util.HttpChannelAuthorizer} and {@link com.pusher.client.util.HttpUserAuthenticator}
@@ -22,6 +23,7 @@ abstract class BaseHttpAuthClient {
2223
private final URL endPoint;
2324
private Map<String, String> mHeaders = new HashMap<>();
2425
protected ConnectionFactory mConnectionFactory;
26+
protected SSLSocketFactory mSslSocketFactory = null;
2527

2628
/**
2729
* Creates a new auth client.
@@ -61,6 +63,15 @@ public void setHeaders(final Map<String, String> headers) {
6163
mHeaders = headers;
6264
}
6365

66+
/**
67+
* Set the SSL socket factory that is used for the connection. This allows to
68+
* configure custom certificate handling (self-signed certificates, mutual TLS, ...)
69+
* @param sslSocketFactory The SSL socket factory to use
70+
*/
71+
public void setSslSocketFactory(final SSLSocketFactory sslSocketFactory) {
72+
mSslSocketFactory = sslSocketFactory;
73+
}
74+
6475
/**
6576
* Identifies if the HTTP request will be sent over HTTPS.
6677
*
@@ -92,6 +103,11 @@ protected String performAuthRequest() {
92103
HttpURLConnection connection;
93104
if (isSSL()) {
94105
connection = (HttpsURLConnection) endPoint.openConnection();
106+
107+
if(mSslSocketFactory != null) {
108+
((HttpsURLConnection) connection)
109+
.setSSLSocketFactory(mSslSocketFactory);
110+
}
95111
} else {
96112
connection = (HttpURLConnection) endPoint.openConnection();
97113
}

0 commit comments

Comments
 (0)