Skip to content

Commit

Permalink
Merge pull request #2242 from dimagi/ctsims/hotfix_248_conscrypt
Browse files Browse the repository at this point in the history
[hotfix] Introduce Conscrypt security layer for API16-19
  • Loading branch information
ctsims authored May 20, 2020
2 parents ae8841b + 6192b78 commit 148209a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ dependencies {
implementation "androidx.work:work-runtime:2.2.0"
implementation "androidx.work:work-runtime-ktx:2.2.0"

//Robust TLS 1.2 ciphers on Android 9-19
implementation "org.conscrypt:conscrypt-android:2.4.0"
}

ext {
Expand Down
10 changes: 10 additions & 0 deletions app/src/org/commcare/CommCareApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
import org.commcare.utils.SessionActivityRegistration;
import org.commcare.utils.SessionStateUninitException;
import org.commcare.utils.SessionUnavailableException;
import org.conscrypt.Conscrypt;
import org.javarosa.core.model.User;
import org.javarosa.core.reference.ReferenceManager;
import org.javarosa.core.reference.RootTranslator;
Expand All @@ -113,6 +114,7 @@
import org.javarosa.core.util.externalizable.PrototypeFactory;

import java.io.File;
import java.security.Security;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -231,7 +233,15 @@ public void onCreate() {
LocalePreferences.saveDeviceLocale(Locale.getDefault());
}

public static boolean isRoboUnitTest() {
return "robolectric".equals(Build.FINGERPRINT);
}

private void initTls12IfNeeded() {
if (Build.VERSION.SDK_INT >= 16 && Build.VERSION.SDK_INT < 20 && !isRoboUnitTest()) {
Security.insertProviderAt(Conscrypt.newProvider(), 1);
}

if (Build.VERSION.SDK_INT >= 16 && Build.VERSION.SDK_INT < 22) {
CommCareNetworkServiceGenerator.customizeRetrofitSetup(new ForceTLS12BuilderConfig());
}
Expand Down

0 comments on commit 148209a

Please sign in to comment.