1919import java .net .URI ;
2020import java .net .URISyntaxException ;
2121import java .net .URL ;
22- import java .security .GeneralSecurityException ;
23- import java .security .SecureRandom ;
24- import java .security .cert .X509Certificate ;
2522import java .util .HashMap ;
2623import java .util .List ;
2724import 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-
3726import de .greenrobot .event .EventBus ;
3827import de .mygrades .database .dao .Action ;
3928import de .mygrades .database .dao .ActionParam ;
4433import de .mygrades .util .Config ;
4534import de .mygrades .util .Constants ;
4635import de .mygrades .util .exceptions .ParseException ;
47- import info .guardianproject .netcipher .client .TlsOnlySocketFactory ;
4836
4937
5038/**
5442public 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