Skip to content

Commit 83c72b9

Browse files
committed
Use native HostnameVerifier
1 parent 911f29a commit 83c72b9

2 files changed

Lines changed: 2 additions & 57 deletions

File tree

app/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ dependencies {
5656
compile 'in.srain.cube:ultra-ptr:1.0.11'
5757
compile 'com.github.PhilJay:MPAndroidChart:v2.2.5'
5858
compile 'net.xpece.android:support-preference:0.8.1'
59-
compile 'info.guardianproject.netcipher:netcipher:1.2'
6059
compile 'net.sf.jtidy:jtidy:r938'
6160
compile 'com.melnykov:floatingactionbutton:1.3.0'
6261
testCompile 'junit:junit:4.12'

app/src/main/java/de/mygrades/main/core/Scraper.java

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,10 @@
1919
import java.net.URI;
2020
import java.net.URISyntaxException;
2121
import java.net.URL;
22-
import java.security.GeneralSecurityException;
23-
import java.security.SecureRandom;
24-
import java.security.cert.X509Certificate;
2522
import java.util.HashMap;
2623
import java.util.List;
2724
import java.util.Map;
2825

29-
import javax.net.ssl.HostnameVerifier;
30-
import javax.net.ssl.HttpsURLConnection;
31-
import javax.net.ssl.SSLContext;
32-
import javax.net.ssl.SSLSession;
33-
import javax.net.ssl.SSLSocketFactory;
34-
import javax.net.ssl.TrustManager;
35-
import javax.net.ssl.X509TrustManager;
36-
3726
import de.greenrobot.event.EventBus;
3827
import de.mygrades.database.dao.Action;
3928
import de.mygrades.database.dao.ActionParam;
@@ -44,7 +33,6 @@
4433
import de.mygrades.util.Config;
4534
import de.mygrades.util.Constants;
4635
import de.mygrades.util.exceptions.ParseException;
47-
import info.guardianproject.netcipher.client.TlsOnlySocketFactory;
4836

4937

5038
/**
@@ -54,48 +42,6 @@
5442
public class Scraper {
5543
private static final String TAG = Scraper.class.getSimpleName();
5644

57-
/**
58-
* Avoid SSLv3 as the only protocol available.
59-
* http://stackoverflow.com/questions/2793150/using-java-net-urlconnection-to-fire-and-handle-http-requests/2793153#2793153
60-
* (not used) http://stackoverflow.com/questions/26633349/disable-ssl-as-a-protocol-in-httpsurlconnection
61-
* (not used) http://stackoverflow.com/a/29946540 -> initializing of SSLv3 Context
62-
*/
63-
static {
64-
TrustManager[] trustAllCertificates = new TrustManager[] {
65-
new X509TrustManager() {
66-
@Override
67-
public X509Certificate[] getAcceptedIssuers() {
68-
return null; // Not relevant.
69-
}
70-
@Override
71-
public void checkClientTrusted(X509Certificate[] certs, String authType) {
72-
// Do nothing. Just allow them all.
73-
}
74-
@Override
75-
public void checkServerTrusted(X509Certificate[] certs, String authType) {
76-
// Do nothing. Just allow them all.
77-
}
78-
}
79-
};
80-
81-
HostnameVerifier trustAllHostnames = new HostnameVerifier() {
82-
@Override
83-
public boolean verify(String hostname, SSLSession session) {
84-
return true; // Just allow them all.
85-
}
86-
};
87-
88-
try {
89-
SSLContext sc = SSLContext.getInstance("TLSv1");
90-
sc.init(null, trustAllCertificates, new SecureRandom());
91-
SSLSocketFactory noSSLv3Factory = new TlsOnlySocketFactory(sc.getSocketFactory());
92-
HttpsURLConnection.setDefaultSSLSocketFactory(noSSLv3Factory);
93-
HttpsURLConnection.setDefaultHostnameVerifier(trustAllHostnames);
94-
}
95-
catch (GeneralSecurityException e) {
96-
}
97-
}
98-
9945
/**
10046
* List of Actions which are processed step by step.
10147
*/
@@ -355,7 +301,7 @@ private void makeJsoupRequest(Map<String, String> requestData, Connection.Method
355301
String content = meta.attr("content");
356302
if (content != null) {
357303
meta.attr("refresh-url", content.replaceAll("(?i)^(\\d+;.*URL=)(.+)$", "$2"));
358-
makeJsoupRequest(requestData, Connection.Method.GET, meta.absUrl("refresh-url"));
304+
makeJsoupRequest(new HashMap<String, String>(), Connection.Method.GET, meta.absUrl("refresh-url"));
359305
}
360306
}
361307

@@ -364,7 +310,7 @@ private void makeJsoupRequest(Map<String, String> requestData, Connection.Method
364310
if (refreshHeader != null) {
365311
String relativeUrl = refreshHeader.replaceAll("(?i)^(\\d+;.*URL=)(.+)$", "$2");
366312
String redirectUrl = StringUtil.resolve(document.baseUri(), relativeUrl);
367-
makeJsoupRequest(requestData, Connection.Method.GET, redirectUrl);
313+
makeJsoupRequest(new HashMap<String, String>(), Connection.Method.GET, redirectUrl);
368314
}
369315
}
370316

0 commit comments

Comments
 (0)