diff options
author | Tad Fisher <tadfisher@gmail.com> | 2022-10-09 16:10:42 -0700 |
---|---|---|
committer | Tad Fisher <tadfisher@gmail.com> | 2022-10-09 16:17:20 -0700 |
commit | 75040136ae5ca6108335975430b411f8a560d0ba (patch) | |
tree | 05fe8daf46eee5ec300d6f15f681867f81b4b09d /app/src | |
parent | 4b7457c7f712b92f21604d8612ec8ff19df75c81 (diff) |
Add decryption callback to CryptoHandler
Diffstat (limited to 'app/src')
3 files changed, 34 insertions, 7 deletions
diff --git a/app/src/main/java/app/passwordstore/Application.kt b/app/src/main/java/app/passwordstore/Application.kt index fb4c0f63..9ec32f15 100644 --- a/app/src/main/java/app/passwordstore/Application.kt +++ b/app/src/main/java/app/passwordstore/Application.kt @@ -12,6 +12,7 @@ import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES +import app.passwordstore.crypto.HWSecurityManager import app.passwordstore.injection.context.FilesDirPath import app.passwordstore.injection.prefs.SettingsPreferences import app.passwordstore.util.extensions.getString @@ -43,14 +44,15 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere @Inject lateinit var proxyUtils: ProxyUtils @Inject lateinit var gitSettings: GitSettings @Inject lateinit var features: Features + @Inject lateinit var deviceManager: HWSecurityManager override fun onCreate() { super.onCreate() instance = this - if ( - BuildConfig.ENABLE_DEBUG_FEATURES || - prefs.getBoolean(PreferenceKeys.ENABLE_DEBUG_LOGGING, false) - ) { + + val enableLogging = BuildConfig.ENABLE_DEBUG_FEATURES || + prefs.getBoolean(PreferenceKeys.ENABLE_DEBUG_LOGGING, false) + if (enableLogging) { LogcatLogger.install(AndroidLogcatLogger(DEBUG)) setVmPolicy() } @@ -60,6 +62,7 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere runMigrations(filesDirPath, prefs, gitSettings) proxyUtils.setDefaultProxy() DynamicColors.applyToActivitiesIfAvailable(this) + deviceManager.init(enableLogging) Sentry.configureScope { scope -> val user = User() user.data = diff --git a/app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt b/app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt index b673e94c..9f8dfbd5 100644 --- a/app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt +++ b/app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt @@ -6,16 +6,19 @@ package app.passwordstore.data.crypto import app.passwordstore.crypto.GpgIdentifier +import app.passwordstore.crypto.HWSecurityDeviceHandler import app.passwordstore.crypto.PGPKeyManager import app.passwordstore.crypto.PGPainlessCryptoHandler import app.passwordstore.crypto.errors.CryptoHandlerException import com.github.michaelbull.result.Result import com.github.michaelbull.result.getAll +import com.github.michaelbull.result.getOrThrow import com.github.michaelbull.result.unwrap import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import javax.inject.Inject import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext class CryptoRepository @@ -23,6 +26,7 @@ class CryptoRepository constructor( private val pgpKeyManager: PGPKeyManager, private val pgpCryptoHandler: PGPainlessCryptoHandler, + private val deviceHandler: HWSecurityDeviceHandler ) { suspend fun decrypt( @@ -43,7 +47,11 @@ constructor( out: ByteArrayOutputStream, ): Result<Unit, CryptoHandlerException> { val keys = pgpKeyManager.getAllKeys().unwrap() - return pgpCryptoHandler.decrypt(keys, password, message, out) + return pgpCryptoHandler.decrypt(keys, password, message, out) { encryptedSessionKey -> + runBlocking { + deviceHandler.decryptSessionKey(encryptedSessionKey).getOrThrow() + } + } } private suspend fun encryptPgp( diff --git a/app/src/main/java/app/passwordstore/injection/crypto/CryptoHandlerModule.kt b/app/src/main/java/app/passwordstore/injection/crypto/CryptoHandlerModule.kt index 5a863d8d..6eca052f 100644 --- a/app/src/main/java/app/passwordstore/injection/crypto/CryptoHandlerModule.kt +++ b/app/src/main/java/app/passwordstore/injection/crypto/CryptoHandlerModule.kt @@ -5,14 +5,30 @@ package app.passwordstore.injection.crypto +import android.app.Activity +import androidx.fragment.app.FragmentActivity +import app.passwordstore.crypto.HWSecurityDeviceHandler +import app.passwordstore.crypto.HWSecurityManager import app.passwordstore.crypto.PGPainlessCryptoHandler import dagger.Module import dagger.Provides import dagger.hilt.InstallIn -import dagger.hilt.components.SingletonComponent +import dagger.hilt.android.components.ActivityComponent +import dagger.hilt.android.scopes.ActivityScoped @Module -@InstallIn(SingletonComponent::class) +@InstallIn(ActivityComponent::class) object CryptoHandlerModule { + + @Provides + @ActivityScoped + fun provideDeviceHandler( + activity: Activity, + deviceManager: HWSecurityManager + ): HWSecurityDeviceHandler = HWSecurityDeviceHandler( + deviceManager = deviceManager, + fragmentManager = (activity as FragmentActivity).supportFragmentManager + ) + @Provides fun providePgpCryptoHandler() = PGPainlessCryptoHandler() } |