Skip to content

Commit

Permalink
fix: ssl cipher not working for android 7
Browse files Browse the repository at this point in the history
  • Loading branch information
teolemon authored and VaiTon committed Sep 12, 2020
1 parent 6823445 commit 245f5ba
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.BatteryManager;
import android.os.Build;
import android.os.Environment;
import android.text.Spannable;
import android.text.SpannableString;
Expand Down Expand Up @@ -77,13 +78,16 @@
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import okhttp3.CipherSuite;
import okhttp3.ConnectionSpec;
import okhttp3.OkHttpClient;
import okhttp3.TlsVersion;
import okhttp3.logging.HttpLoggingInterceptor;
import openfoodfacts.github.scrachx.openfood.BuildConfig;
import openfoodfacts.github.scrachx.openfood.R;
Expand Down Expand Up @@ -251,7 +255,6 @@ public static boolean isApplicationInstalled(Context context, String packageName
}
}


/**
* Returns the Nutri-Score graphic asset given the grade
*/
Expand Down Expand Up @@ -335,7 +338,7 @@ public static <T extends View> List<T> getViewsByType(ViewGroup root, Class<T> t
}
return result;
}

/**
* Returns the NOVA group graphic asset given the group
*/
Expand Down Expand Up @@ -504,12 +507,24 @@ public static synchronized void scheduleProductUploadJob(Context context) {
isUploadJobInitialised = true;
}

@NonNull
public static OkHttpClient httpClientBuilder() {

OkHttpClient.Builder builder = new OkHttpClient.Builder()
.connectTimeout(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
.readTimeout(RW_TIMEOUT, TimeUnit.MILLISECONDS)
.writeTimeout(RW_TIMEOUT, TimeUnit.MILLISECONDS)
.connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS));
.writeTimeout(RW_TIMEOUT, TimeUnit.MILLISECONDS);

if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N) {
builder.connectionSpecs(Collections.singletonList(
new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.tlsVersions(TlsVersion.TLS_1_2)
.cipherSuites(CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256)
.build())
);
} else {
builder.connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS));
}

if (BuildConfig.DEBUG) {
builder.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY));
Expand Down

0 comments on commit 245f5ba

Please sign in to comment.