summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fietz <Martin.Fietz@gmail.com>2015-08-16 17:37:43 +0200
committerMartin Fietz <Martin.Fietz@gmail.com>2015-08-19 00:19:48 +0200
commit3321e8db4f51834eb9bd7de54f081fe4c14d1fca (patch)
treeebcb437776b690e40884f93b0bf860fb16b6f909
parenta7acfc484c076488924071b0235cde2fe9695734 (diff)
downloadAntennaPod-3321e8db4f51834eb9bd7de54f081fe4c14d1fca.zip
Custom SSL Socket Factory for Android 4.1+ (but below 5)
-rw-r--r--app/build.gradle4
-rw-r--r--app/src/main/java/de/danoeh/antennapod/PodcastApp.java2
-rw-r--r--core/build.gradle4
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java80
4 files changed, 84 insertions, 6 deletions
diff --git a/app/build.gradle b/app/build.gradle
index 77a1cebba..ed02fa642 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -18,8 +18,8 @@ dependencies {
compile 'commons-io:commons-io:2.4'
compile 'org.jsoup:jsoup:1.7.3'
compile 'com.github.bumptech.glide:glide:3.6.1'
- compile 'com.squareup.okhttp:okhttp:2.3.0'
- compile 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'
+ compile 'com.squareup.okhttp:okhttp:2.4.0'
+ compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0'
compile 'com.squareup.okio:okio:1.2.0'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.joanzapata.android:android-iconify:1.0.9'
diff --git a/app/src/main/java/de/danoeh/antennapod/PodcastApp.java b/app/src/main/java/de/danoeh/antennapod/PodcastApp.java
index 7167dc7a9..026e3b087 100644
--- a/app/src/main/java/de/danoeh/antennapod/PodcastApp.java
+++ b/app/src/main/java/de/danoeh/antennapod/PodcastApp.java
@@ -1,13 +1,11 @@
package de.danoeh.antennapod;
import android.app.Application;
-import android.content.Intent;
import android.content.res.Configuration;
import de.danoeh.antennapod.core.feed.EventDistributor;
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
import de.danoeh.antennapod.core.preferences.UserPreferences;
-import de.danoeh.antennapod.core.service.FeedMediaSizeService;
import de.danoeh.antennapod.core.util.NetworkUtils;
import de.danoeh.antennapod.spa.SPAUtil;
diff --git a/core/build.gradle b/core/build.gradle
index 14667ba37..46b2e3ce9 100644
--- a/core/build.gradle
+++ b/core/build.gradle
@@ -45,8 +45,8 @@ dependencies {
compile 'org.jsoup:jsoup:1.7.3'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.github.bumptech.glide:okhttp-integration:1.3.0'
- compile 'com.squareup.okhttp:okhttp:2.3.0'
- compile 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'
+ compile 'com.squareup.okhttp:okhttp:2.4.0'
+ compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0'
compile 'com.squareup.okio:okio:1.2.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'de.greenrobot:eventbus:2.4.0'
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java
index ec3d3e2fe..402a7a8bd 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java
@@ -1,13 +1,22 @@
package de.danoeh.antennapod.core.service.download;
+import android.os.Build;
import android.util.Log;
import com.squareup.okhttp.OkHttpClient;
+import java.io.IOException;
import java.net.CookieManager;
import java.net.CookiePolicy;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.security.GeneralSecurityException;
import java.util.concurrent.TimeUnit;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
+
import de.danoeh.antennapod.core.BuildConfig;
/**
@@ -50,6 +59,10 @@ public class AntennapodHttpClient {
client.setFollowRedirects(true);
client.setFollowSslRedirects(true);
+ if(16 <= Build.VERSION.SDK_INT && Build.VERSION.SDK_INT < 21) {
+ client.setSslSocketFactory(new CustomSslSocketFactory());
+ }
+
httpClient = client;
}
return httpClient;
@@ -64,4 +77,71 @@ public class AntennapodHttpClient {
// does nothing at the moment
}
}
+
+ private static class CustomSslSocketFactory extends SSLSocketFactory {
+
+ private SSLSocketFactory factory;
+
+ public CustomSslSocketFactory() {
+ try {
+ SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
+ sslContext.init(null, null, null);
+ factory= sslContext.getSocketFactory();
+ } catch(GeneralSecurityException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public String[] getDefaultCipherSuites() {
+ return factory.getDefaultCipherSuites();
+ }
+
+ @Override
+ public String[] getSupportedCipherSuites() {
+ return factory.getSupportedCipherSuites();
+ }
+
+ public Socket createSocket() throws IOException {
+ SSLSocket result = (SSLSocket) factory.createSocket();
+ configureSocket(result);
+ return result;
+ }
+
+ public Socket createSocket(String var1, int var2) throws IOException {
+ SSLSocket result = (SSLSocket) factory.createSocket(var1, var2);
+ configureSocket(result);
+ return result;
+ }
+
+ public Socket createSocket(Socket var1, String var2, int var3, boolean var4) throws IOException {
+ SSLSocket result = (SSLSocket) factory.createSocket(var1, var2, var3, var4);
+ configureSocket(result);
+ return result;
+ }
+
+ public Socket createSocket(InetAddress var1, int var2) throws IOException {
+ SSLSocket result = (SSLSocket) factory.createSocket(var1, var2);
+ configureSocket(result);
+ return result;
+ }
+
+ public Socket createSocket(String var1, int var2, InetAddress var3, int var4) throws IOException {
+ SSLSocket result = (SSLSocket) factory.createSocket(var1, var2, var3, var4);
+ configureSocket(result);
+ return result;
+ }
+
+ public Socket createSocket(InetAddress var1, int var2, InetAddress var3, int var4) throws IOException {
+ SSLSocket result = (SSLSocket) factory.createSocket(var1, var2, var3, var4);
+ configureSocket(result);
+ return result;
+ }
+
+ private void configureSocket(SSLSocket s) {
+ s.setEnabledProtocols(new String[] { "TLSv1.2", "TLSv1.1" } );
+ }
+
+ }
+
}