11package com .pusher .client .util ;
22
3+ import javax .net .ssl .SSLSocketFactory ;
34import java .io .BufferedReader ;
45import java .io .DataOutputStream ;
56import java .io .IOException ;
@@ -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,10 @@ protected String performAuthRequest() {
92103 HttpURLConnection connection ;
93104 if (isSSL ()) {
94105 connection = (HttpsURLConnection ) endPoint .openConnection ();
106+ if (mSslSocketFactory != null ) {
107+ ((HttpsURLConnection ) connection )
108+ .setSSLSocketFactory (mSslSocketFactory );
109+ }
95110 } else {
96111 connection = (HttpURLConnection ) endPoint .openConnection ();
97112 }
0 commit comments