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

Allow custom SSL socket factory for BaseHttpAuthClient #359

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions src/main/java/com/pusher/client/util/BaseHttpAuthClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -22,6 +23,7 @@ abstract class BaseHttpAuthClient {
private final URL endPoint;
private Map<String, String> mHeaders = new HashMap<>();
protected ConnectionFactory mConnectionFactory;
protected SSLSocketFactory mSslSocketFactory = null;

/**
* Creates a new auth client.
Expand Down Expand Up @@ -61,6 +63,15 @@ public void setHeaders(final Map<String, String> 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.
*
Expand Down Expand Up @@ -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();
}
Expand Down