diff options
| author | Fabian Henneke <FabianHenneke@users.noreply.github.com> | 2020-05-28 06:27:30 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-28 09:57:30 +0530 |
| commit | 97911c587754a7c11e594004b77c4ac53af8a468 (patch) | |
| tree | 680453c63fc3873139a3937268f73ec6985cf03a /app/src/main/java/com/zeapo/pwdstore/Application.kt | |
| parent | fea82fed47d87138a9a24eb0358fc9a917474dc7 (diff) | |
| download | HardenedPass-97911c587754a7c11e594004b77c4ac53af8a468.tar.gz HardenedPass-97911c587754a7c11e594004b77c4ac53af8a468.zip | |
Use SSHJ for SSH public key authentication (#801)
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/Application.kt')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/Application.kt | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/Application.kt b/app/src/main/java/com/zeapo/pwdstore/Application.kt index d162e461..ec115639 100644 --- a/app/src/main/java/com/zeapo/pwdstore/Application.kt +++ b/app/src/main/java/com/zeapo/pwdstore/Application.kt @@ -14,6 +14,8 @@ import androidx.preference.PreferenceManager import com.github.ajalt.timberkt.Timber.DebugTree import com.github.ajalt.timberkt.Timber.plant import com.haroldadmin.whatthestack.WhatTheStack +import org.bouncycastle.jce.provider.BouncyCastleProvider +import java.security.Security @Suppress("Unused") class Application : android.app.Application(), SharedPreferences.OnSharedPreferenceChangeListener { @@ -29,6 +31,7 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere } prefs?.registerOnSharedPreferenceChangeListener(this) setNightMode() + setUpBouncyCastle() } override fun onTerminate() { @@ -42,6 +45,25 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere } } + private fun setUpBouncyCastle() { + // Replace the Android BC provider with the Java BouncyCastle provider since the former does + // not include all the required algorithms. + // TODO: Verify that we are indeed using the fast Android-native implementation whenever + // possible. + // Note: This may affect crypto operations in other parts of the application. + val bcIndex = Security.getProviders().indexOfFirst { + it.name == BouncyCastleProvider.PROVIDER_NAME + } + if (bcIndex == -1) { + // No Android BC found, install Java BC at lowest priority. + Security.addProvider(BouncyCastleProvider()) + } else { + // Replace Android BC with Java BC, inserted at the same position. + Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME) + Security.insertProviderAt(BouncyCastleProvider(), bcIndex + 1) + } + } + private fun setNightMode() { AppCompatDelegate.setDefaultNightMode(when (prefs?.getString("app_theme", getString(R.string.app_theme_def))) { "light" -> MODE_NIGHT_NO |
