diff options
author | Scott Jackson <daneren2005@gmail.com> | 2016-10-17 17:07:43 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2016-10-17 17:07:55 -0700 |
commit | a76a2884f0457c32f4fd2284ff80b9ba9cb5ce3f (patch) | |
tree | 48185e00b4fdb76a660e23d0b45f1365938e7c72 /app/src/main | |
parent | 4f2655b59a323f1936a72b2622e693c589f18fbb (diff) | |
download | dsub-a76a2884f0457c32f4fd2284ff80b9ba9cb5ce3f.tar.gz dsub-a76a2884f0457c32f4fd2284ff80b9ba9cb5ce3f.tar.bz2 dsub-a76a2884f0457c32f4fd2284ff80b9ba9cb5ce3f.zip |
Fix accepting self signed certificates
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java | 29 | ||||
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/service/RemoteController.java | 3 |
2 files changed, 31 insertions, 1 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java index cb8871a0..913e30bf 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java @@ -86,7 +86,11 @@ import java.util.zip.GZIPInputStream; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; public class RESTMusicService implements MusicService { @@ -102,6 +106,7 @@ public class RESTMusicService implements MusicService { private static final int HTTP_REQUEST_MAX_ATTEMPTS = 5; private static final long REDIRECTION_CHECK_INTERVAL_MILLIS = 60L * 60L * 1000L; + private SSLSocketFactory sslSocketFactory; private HostnameVerifier selfSignedHostnameVerifier; private long redirectionLastChecked; private int redirectionNetworkType = -1; @@ -111,6 +116,26 @@ public class RESTMusicService implements MusicService { private boolean hasInstalledGoogleSSL = false; public RESTMusicService() { + TrustManager[] trustAllCerts = new TrustManager[]{ + new X509TrustManager() { + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return null; + } + public void checkClientTrusted( + java.security.cert.X509Certificate[] certs, String authType) { + } + public void checkServerTrusted( + java.security.cert.X509Certificate[] certs, String authType) { + } + } + }; + try { + SSLContext sslContext = SSLContext.getInstance("TLS"); + sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); + sslSocketFactory = sslContext.getSocketFactory(); + } catch (Exception e) { + } + selfSignedHostnameVerifier = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; @@ -1868,6 +1893,7 @@ public class RESTMusicService implements MusicService { if(connection instanceof HttpsURLConnection) { HttpsURLConnection sslConnection = (HttpsURLConnection) connection; + sslConnection.setSSLSocketFactory(sslSocketFactory); sslConnection.setHostnameVerifier(selfSignedHostnameVerifier); } @@ -1968,6 +1994,9 @@ public class RESTMusicService implements MusicService { } } + public SSLSocketFactory getSSLSocketFactory() { + return sslSocketFactory; + } public HostnameVerifier getHostNameVerifier() { return selfSignedHostnameVerifier; } diff --git a/app/src/main/java/github/daneren2005/dsub/service/RemoteController.java b/app/src/main/java/github/daneren2005/dsub/service/RemoteController.java index c6702e3e..617144d7 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/RemoteController.java +++ b/app/src/main/java/github/daneren2005/dsub/service/RemoteController.java @@ -117,7 +117,8 @@ public abstract class RemoteController { protected WebProxy createWebProxy() { MusicService musicService = MusicServiceFactory.getMusicService(downloadService); if(musicService instanceof CachedMusicService) { - return new WebProxy(downloadService, ((CachedMusicService)musicService).getMusicService().getHostNameVerifier()); + RESTMusicService restMusicService = ((CachedMusicService)musicService).getMusicService(); + return new WebProxy(downloadService, restMusicService.getSSLSocketFactory(), restMusicService.getHostNameVerifier()); } else { return new WebProxy(downloadService); } |