Skip to content

Commit

Permalink
Use a custom SSL context (instead of messing with the global SSL cont…
Browse files Browse the repository at this point in the history
…ext).

See: square/okhttp#184
  • Loading branch information
buddy-ouya committed Feb 3, 2014
1 parent 3197082 commit 4afd7e5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/com/squareup/picasso/OkHttpLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import android.net.Uri;
import com.squareup.okhttp.HttpResponseCache;
import com.squareup.okhttp.OkHttpClient;

import javax.net.ssl.SSLContext;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.GeneralSecurityException;

import static com.squareup.picasso.Utils.parseResponseSourceHeader;

Expand Down Expand Up @@ -66,6 +69,15 @@ public OkHttpLoader(final File cacheDir, final int maxSize) {
*/
public OkHttpLoader(OkHttpClient client) {
this.client = client;

SSLContext sslContext;
try {
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, null, null);
} catch (GeneralSecurityException e) {
throw new AssertionError(); // The system has no TLS. Just give up.
}
this.client.setSslSocketFactory(sslContext.getSocketFactory());
}

@Override public Response load(Uri uri, boolean localCacheOnly) throws IOException {
Expand Down

0 comments on commit 4afd7e5

Please sign in to comment.