Skip to content

Commit

Permalink
Fix accepting self signed certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
daneren2005 committed Oct 18, 2016
1 parent ed3ff58 commit a8a7562
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/github/daneren2005/serverproxy/WebProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@
import java.util.Map;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;

public class WebProxy extends ServerProxy {
private static String TAG = WebProxy.class.getSimpleName();
private static List REMOVE_REQUEST_HEADERS = Arrays.asList("Host", "Accept-Encoding", "Referer");
private static List REMOVE_RESPONSE_HEADERS = Arrays.asList("Transfer-Encoding");
private SSLSocketFactory sslSocketFactory;
private HostnameVerifier hostnameVerifier;

public WebProxy(Context context) {
super(context);
}
public WebProxy(Context context, HostnameVerifier hostnameVerifier) {
public WebProxy(Context context, SSLSocketFactory sslSocketFactory, HostnameVerifier hostnameVerifier) {
super(context);
this.sslSocketFactory = sslSocketFactory;
this.hostnameVerifier = hostnameVerifier;
}

Expand Down Expand Up @@ -125,6 +129,17 @@ public void run() {
connection.setRequestProperty(header.getKey(), header.getValue());
}
}
if(connection instanceof HttpsURLConnection) {
HttpsURLConnection sslConnection = (HttpsURLConnection) connection;

if(sslSocketFactory != null) {
sslConnection.setSSLSocketFactory(sslSocketFactory);
}

if(hostnameVerifier != null) {
sslConnection.setHostnameVerifier(hostnameVerifier);
}
}

if(connection.getResponseCode() == HttpURLConnection.HTTP_OK || connection.getResponseCode() == HttpURLConnection.HTTP_PARTIAL) {
responseHeaders = getHeaders(connection.getHeaderFields());
Expand Down

0 comments on commit a8a7562

Please sign in to comment.