OKhttp url factory
This commit is contained in:
@@ -17,13 +17,18 @@ public class OkHttpClientFactory {
|
||||
|
||||
public static OkHttpClient getSimpleClient(){
|
||||
if(client == null){
|
||||
client = new OkHttpClient.Builder().build();
|
||||
client = new OkHttpClient.Builder()
|
||||
.connectTimeout(30000, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(45000, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
public static OkHttpClient getPinnedSimpleClient(CertificatePinner pinner){
|
||||
return new OkHttpClient.Builder()
|
||||
.connectTimeout(30000, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(45000, TimeUnit.MILLISECONDS)
|
||||
.certificatePinner(pinner)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -21,32 +21,45 @@ package org.sufficientlysecure.keychain.util;
|
||||
import com.textuality.keybase.lib.KeybaseUrlConnectionClient;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkUrlFactory;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Wrapper for Keybase Lib
|
||||
*/
|
||||
public class OkHttpKeybaseClient implements KeybaseUrlConnectionClient {
|
||||
|
||||
private OkUrlFactory generateUrlFactory() {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
return new OkUrlFactory(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OkHttpClient getClient(URL url, Proxy proxy, boolean pin) throws IOException {
|
||||
public URLConnection openConnection(URL url, Proxy proxy, boolean isKeybase) throws IOException {
|
||||
OkHttpClient client = OkHttpClientFactory.getSimpleClient();
|
||||
|
||||
OkUrlFactory factory = generateUrlFactory();
|
||||
try {
|
||||
if(pin) {
|
||||
return OkHttpClientFactory.getPinnedClient(url, proxy);
|
||||
}else{
|
||||
return OkHttpClientFactory.getClient( proxy);
|
||||
if (isKeybase && proxy != null) {
|
||||
client = OkHttpClientFactory.getPinnedClient(url, proxy);
|
||||
} else if (proxy != null) {
|
||||
client = OkHttpClientFactory.getClient(proxy);
|
||||
} else {
|
||||
client = OkHttpClientFactory.getSimpleClient();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IOException("no pinned certificate found for URL!");
|
||||
} catch (TlsHelper.TlsHelperException e) {
|
||||
Log.e(Constants.TAG, "TlsHelper failed", e);
|
||||
throw new IOException("TlsHelper failed");
|
||||
}
|
||||
factory.setClient(client);
|
||||
|
||||
return factory.open(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user