Gopenpgp related fixes (#1503)

* app: rename new crypto activities

(cherry picked from commit 89be012f995b878affb7e7a592750e130c7f0f2c)

* app: allow alt backends to work without OpenKeychain

(cherry picked from commit 7bf9f01e5ef7bb24700ce3f242e5aabbabbff09e)

* app: rename ENABLE_GOPENPGP to ENABLE_PGP_V2_BACKEND
This commit is contained in:
Harsh Shandilya 2021-09-14 22:37:55 +05:30 committed by GitHub
parent 30cb8cfceb
commit 571ab4e78e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 43 additions and 38 deletions

View File

@ -45,7 +45,7 @@
android:windowSoftInputMode="adjustResize" /> android:windowSoftInputMode="adjustResize" />
<activity <activity
android:name=".ui.crypto.GopenpgpDecryptActivity" android:name=".ui.crypto.DecryptActivityV2"
android:exported="true" /> android:exported="true" />
<activity <activity
@ -95,7 +95,7 @@
android:label="@string/new_password_title" android:label="@string/new_password_title"
android:windowSoftInputMode="adjustResize" /> android:windowSoftInputMode="adjustResize" />
<activity android:name=".ui.crypto.GopenpgpPasswordCreationActivity" <activity android:name=".ui.crypto.PasswordCreationActivityV2"
android:label="@string/new_password_title" android:label="@string/new_password_title"
android:windowSoftInputMode="adjustResize" /> android:windowSoftInputMode="adjustResize" />
@ -137,7 +137,7 @@
android:name=".ui.autofill.AutofillDecryptActivity" android:name=".ui.autofill.AutofillDecryptActivity"
android:theme="@style/NoBackgroundTheme" /> android:theme="@style/NoBackgroundTheme" />
<activity <activity
android:name=".ui.autofill.GopenpgpAutofillDecryptActivity" android:name=".ui.autofill.AutofillDecryptActivityV2"
android:theme="@style/NoBackgroundTheme" /> android:theme="@style/NoBackgroundTheme" />
<activity <activity
android:name=".ui.autofill.AutofillFilterView" android:name=".ui.autofill.AutofillFilterView"

View File

@ -25,7 +25,7 @@ import com.github.michaelbull.result.runCatching
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import dev.msfjarvis.aps.injection.crypto.CryptoSet import dev.msfjarvis.aps.injection.crypto.CryptoSet
import dev.msfjarvis.aps.injection.password.PasswordEntryFactory import dev.msfjarvis.aps.injection.password.PasswordEntryFactory
import dev.msfjarvis.aps.ui.crypto.GopenpgpDecryptActivity import dev.msfjarvis.aps.ui.crypto.DecryptActivityV2
import dev.msfjarvis.aps.util.autofill.AutofillPreferences import dev.msfjarvis.aps.util.autofill.AutofillPreferences
import dev.msfjarvis.aps.util.autofill.AutofillResponseBuilder import dev.msfjarvis.aps.util.autofill.AutofillResponseBuilder
import dev.msfjarvis.aps.util.autofill.DirectoryStructure import dev.msfjarvis.aps.util.autofill.DirectoryStructure
@ -37,7 +37,7 @@ import kotlinx.coroutines.withContext
@RequiresApi(Build.VERSION_CODES.O) @RequiresApi(Build.VERSION_CODES.O)
@AndroidEntryPoint @AndroidEntryPoint
class GopenpgpAutofillDecryptActivity : AppCompatActivity() { class AutofillDecryptActivityV2 : AppCompatActivity() {
companion object { companion object {
@ -47,7 +47,7 @@ class GopenpgpAutofillDecryptActivity : AppCompatActivity() {
private var decryptFileRequestCode = 1 private var decryptFileRequestCode = 1
fun makeDecryptFileIntent(file: File, forwardedExtras: Bundle, context: Context): Intent { fun makeDecryptFileIntent(file: File, forwardedExtras: Bundle, context: Context): Intent {
return Intent(context, GopenpgpAutofillDecryptActivity::class.java).apply { return Intent(context, AutofillDecryptActivityV2::class.java).apply {
putExtras(forwardedExtras) putExtras(forwardedExtras)
putExtra(EXTRA_SEARCH_ACTION, true) putExtra(EXTRA_SEARCH_ACTION, true)
putExtra(EXTRA_FILE_PATH, file.absolutePath) putExtra(EXTRA_FILE_PATH, file.absolutePath)
@ -56,7 +56,7 @@ class GopenpgpAutofillDecryptActivity : AppCompatActivity() {
fun makeDecryptFileIntentSender(file: File, context: Context): IntentSender { fun makeDecryptFileIntentSender(file: File, context: Context): IntentSender {
val intent = val intent =
Intent(context, GopenpgpAutofillDecryptActivity::class.java).apply { Intent(context, AutofillDecryptActivityV2::class.java).apply {
putExtra(EXTRA_SEARCH_ACTION, false) putExtra(EXTRA_SEARCH_ACTION, false)
putExtra(EXTRA_FILE_PATH, file.absolutePath) putExtra(EXTRA_FILE_PATH, file.absolutePath)
} }
@ -80,14 +80,14 @@ class GopenpgpAutofillDecryptActivity : AppCompatActivity() {
val filePath = val filePath =
intent?.getStringExtra(EXTRA_FILE_PATH) intent?.getStringExtra(EXTRA_FILE_PATH)
?: run { ?: run {
e { "GopenpgpAutofillDecryptActivity started without EXTRA_FILE_PATH" } e { "AutofillDecryptActivityV2 started without EXTRA_FILE_PATH" }
finish() finish()
return return
} }
val clientState = val clientState =
intent?.getBundleExtra(AutofillManager.EXTRA_CLIENT_STATE) intent?.getBundleExtra(AutofillManager.EXTRA_CLIENT_STATE)
?: run { ?: run {
e { "GopenpgpAutofillDecryptActivity started without EXTRA_CLIENT_STATE" } e { "AutofillDecryptActivityV2 started without EXTRA_CLIENT_STATE" }
finish() finish()
return return
} }
@ -102,7 +102,7 @@ class GopenpgpAutofillDecryptActivity : AppCompatActivity() {
} else { } else {
val fillInDataset = val fillInDataset =
AutofillResponseBuilder.makeFillInDataset( AutofillResponseBuilder.makeFillInDataset(
this@GopenpgpAutofillDecryptActivity, this@AutofillDecryptActivityV2,
credentials, credentials,
clientState, clientState,
action action
@ -129,14 +129,14 @@ class GopenpgpAutofillDecryptActivity : AppCompatActivity() {
val crypto = cryptos.first { it.canHandle(file.absolutePath) } val crypto = cryptos.first { it.canHandle(file.absolutePath) }
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
crypto.decrypt( crypto.decrypt(
GopenpgpDecryptActivity.PRIV_KEY, DecryptActivityV2.PRIV_KEY,
GopenpgpDecryptActivity.PASS.toByteArray(charset = Charsets.UTF_8), DecryptActivityV2.PASS.toByteArray(charset = Charsets.UTF_8),
encryptedInput.readBytes() encryptedInput.readBytes()
) )
} }
} }
.onFailure { e -> .onFailure { e ->
e(e) { "Decryption with Gopenpgp failed" } e(e) { "Decryption failed" }
return null return null
} }
.onSuccess { result -> .onSuccess { result ->

View File

@ -221,8 +221,8 @@ class AutofillFilterView : AppCompatActivity() {
AutofillMatcher.addMatchFor(applicationContext, formOrigin, item.file) AutofillMatcher.addMatchFor(applicationContext, formOrigin, item.file)
// intent?.extras? is checked to be non-null in onCreate // intent?.extras? is checked to be non-null in onCreate
decryptAction.launch( decryptAction.launch(
if (FeatureFlags.ENABLE_GOPENPGP) { if (FeatureFlags.ENABLE_PGP_V2_BACKEND) {
GopenpgpAutofillDecryptActivity.makeDecryptFileIntent(item.file, intent!!.extras!!, this) AutofillDecryptActivityV2.makeDecryptFileIntent(item.file, intent!!.extras!!, this)
} else { } else {
AutofillDecryptActivity.makeDecryptFileIntent(item.file, intent!!.extras!!, this) AutofillDecryptActivity.makeDecryptFileIntent(item.file, intent!!.extras!!, this)
} }

View File

@ -27,6 +27,7 @@ import com.google.android.material.snackbar.Snackbar
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import dev.msfjarvis.aps.R import dev.msfjarvis.aps.R
import dev.msfjarvis.aps.injection.prefs.SettingsPreferences import dev.msfjarvis.aps.injection.prefs.SettingsPreferences
import dev.msfjarvis.aps.util.FeatureFlags
import dev.msfjarvis.aps.util.extensions.OPENPGP_PROVIDER import dev.msfjarvis.aps.util.extensions.OPENPGP_PROVIDER
import dev.msfjarvis.aps.util.extensions.clipboard import dev.msfjarvis.aps.util.extensions.clipboard
import dev.msfjarvis.aps.util.extensions.getString import dev.msfjarvis.aps.util.extensions.getString
@ -126,6 +127,7 @@ open class BasePgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBou
/** Method for subclasses to initiate binding with [OpenPgpServiceConnection]. */ /** Method for subclasses to initiate binding with [OpenPgpServiceConnection]. */
fun bindToOpenKeychain(onBoundListener: OpenPgpServiceConnection.OnBound) { fun bindToOpenKeychain(onBoundListener: OpenPgpServiceConnection.OnBound) {
if (FeatureFlags.ENABLE_PGP_V2_BACKEND) return
val installed = val installed =
runCatching { runCatching {
packageManager.getPackageInfo(OPENPGP_PROVIDER, 0) packageManager.getPackageInfo(OPENPGP_PROVIDER, 0)

View File

@ -31,7 +31,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@AndroidEntryPoint @AndroidEntryPoint
class GopenpgpDecryptActivity : BasePgpActivity() { class DecryptActivityV2 : BasePgpActivity() {
private val binding by viewBinding(DecryptLayoutBinding::inflate) private val binding by viewBinding(DecryptLayoutBinding::inflate)
@Inject lateinit var passwordEntryFactory: PasswordEntryFactory @Inject lateinit var passwordEntryFactory: PasswordEntryFactory
@ -96,13 +96,16 @@ class GopenpgpDecryptActivity : BasePgpActivity() {
* result triggers they can be repopulated with new data. * result triggers they can be repopulated with new data.
*/ */
private fun editPassword() { private fun editPassword() {
val intent = Intent(this, PasswordCreationActivity::class.java) val intent = Intent(this, PasswordCreationActivityV2::class.java)
intent.putExtra("FILE_PATH", relativeParentPath) intent.putExtra("FILE_PATH", relativeParentPath)
intent.putExtra("REPO_PATH", repoPath) intent.putExtra("REPO_PATH", repoPath)
intent.putExtra(PasswordCreationActivity.EXTRA_FILE_NAME, name) intent.putExtra(PasswordCreationActivityV2.EXTRA_FILE_NAME, name)
intent.putExtra(PasswordCreationActivity.EXTRA_PASSWORD, passwordEntry?.password) intent.putExtra(PasswordCreationActivityV2.EXTRA_PASSWORD, passwordEntry?.password)
intent.putExtra(PasswordCreationActivity.EXTRA_EXTRA_CONTENT, passwordEntry?.extraContentString) intent.putExtra(
intent.putExtra(PasswordCreationActivity.EXTRA_EDITING, true) PasswordCreationActivityV2.EXTRA_EXTRA_CONTENT,
passwordEntry?.extraContentString
)
intent.putExtra(PasswordCreationActivityV2.EXTRA_EDITING, true)
startActivity(intent) startActivity(intent)
finish() finish()
} }

View File

@ -51,7 +51,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@AndroidEntryPoint @AndroidEntryPoint
class GopenpgpPasswordCreationActivity : BasePgpActivity() { class PasswordCreationActivityV2 : BasePgpActivity() {
private val binding by viewBinding(PasswordCreationActivityBinding::inflate) private val binding by viewBinding(PasswordCreationActivityBinding::inflate)
@Inject lateinit var passwordEntryFactory: PasswordEntryFactory @Inject lateinit var passwordEntryFactory: PasswordEntryFactory
@ -96,7 +96,7 @@ class GopenpgpPasswordCreationActivity : BasePgpActivity() {
otpImportButton.setOnClickListener { otpImportButton.setOnClickListener {
supportFragmentManager.setFragmentResultListener( supportFragmentManager.setFragmentResultListener(
OTP_RESULT_REQUEST_KEY, OTP_RESULT_REQUEST_KEY,
this@GopenpgpPasswordCreationActivity this@PasswordCreationActivityV2
) { requestKey, bundle -> ) { requestKey, bundle ->
if (requestKey == OTP_RESULT_REQUEST_KEY) { if (requestKey == OTP_RESULT_REQUEST_KEY) {
val contents = bundle.getString(RESULT) val contents = bundle.getString(RESULT)
@ -113,12 +113,12 @@ class GopenpgpPasswordCreationActivity : BasePgpActivity() {
getString(R.string.otp_import_qr_code), getString(R.string.otp_import_qr_code),
getString(R.string.otp_import_manual_entry) getString(R.string.otp_import_manual_entry)
) )
MaterialAlertDialogBuilder(this@GopenpgpPasswordCreationActivity) MaterialAlertDialogBuilder(this@PasswordCreationActivityV2)
.setItems(items) { _, index -> .setItems(items) { _, index ->
when (index) { when (index) {
0 -> 0 ->
otpImportAction.launch( otpImportAction.launch(
IntentIntegrator(this@GopenpgpPasswordCreationActivity) IntentIntegrator(this@PasswordCreationActivityV2)
.setOrientationLocked(false) .setOrientationLocked(false)
.setBeepEnabled(false) .setBeepEnabled(false)
.setDesiredBarcodeFormats(QR_CODE) .setDesiredBarcodeFormats(QR_CODE)
@ -156,7 +156,7 @@ class GopenpgpPasswordCreationActivity : BasePgpActivity() {
// in the encrypted extras. This only makes sense if the directory structure is // in the encrypted extras. This only makes sense if the directory structure is
// FileBased. // FileBased.
if (suggestedName == null && if (suggestedName == null &&
AutofillPreferences.directoryStructure(this@GopenpgpPasswordCreationActivity) == AutofillPreferences.directoryStructure(this@PasswordCreationActivityV2) ==
DirectoryStructure.FileBased DirectoryStructure.FileBased
) { ) {
encryptUsername.apply { encryptUsername.apply {
@ -367,7 +367,7 @@ class GopenpgpPasswordCreationActivity : BasePgpActivity() {
val oldFile = File("$repoPath/${oldCategory?.trim('/')}/$oldFileName.gpg") val oldFile = File("$repoPath/${oldCategory?.trim('/')}/$oldFileName.gpg")
if (oldFile.path != file.path && !oldFile.delete()) { if (oldFile.path != file.path && !oldFile.delete()) {
setResult(RESULT_CANCELED) setResult(RESULT_CANCELED)
MaterialAlertDialogBuilder(this@GopenpgpPasswordCreationActivity) MaterialAlertDialogBuilder(this@PasswordCreationActivityV2)
.setTitle(R.string.password_creation_file_fail_title) .setTitle(R.string.password_creation_file_fail_title)
.setMessage( .setMessage(
getString(R.string.password_creation_file_delete_fail_message, oldFileName) getString(R.string.password_creation_file_delete_fail_message, oldFileName)
@ -395,7 +395,7 @@ class GopenpgpPasswordCreationActivity : BasePgpActivity() {
if (e is IOException) { if (e is IOException) {
e(e) { "Failed to write password file" } e(e) { "Failed to write password file" }
setResult(RESULT_CANCELED) setResult(RESULT_CANCELED)
MaterialAlertDialogBuilder(this@GopenpgpPasswordCreationActivity) MaterialAlertDialogBuilder(this@PasswordCreationActivityV2)
.setTitle(getString(R.string.password_creation_file_fail_title)) .setTitle(getString(R.string.password_creation_file_fail_title))
.setMessage(getString(R.string.password_creation_file_write_fail_message)) .setMessage(getString(R.string.password_creation_file_write_fail_message))
.setCancelable(false) .setCancelable(false)

View File

@ -39,7 +39,7 @@ import dev.msfjarvis.aps.data.password.PasswordItem
import dev.msfjarvis.aps.data.repo.PasswordRepository import dev.msfjarvis.aps.data.repo.PasswordRepository
import dev.msfjarvis.aps.ui.crypto.BasePgpActivity.Companion.getLongName import dev.msfjarvis.aps.ui.crypto.BasePgpActivity.Companion.getLongName
import dev.msfjarvis.aps.ui.crypto.DecryptActivity import dev.msfjarvis.aps.ui.crypto.DecryptActivity
import dev.msfjarvis.aps.ui.crypto.GopenpgpDecryptActivity import dev.msfjarvis.aps.ui.crypto.DecryptActivityV2
import dev.msfjarvis.aps.ui.crypto.PasswordCreationActivity import dev.msfjarvis.aps.ui.crypto.PasswordCreationActivity
import dev.msfjarvis.aps.ui.dialogs.BasicBottomSheet import dev.msfjarvis.aps.ui.dialogs.BasicBottomSheet
import dev.msfjarvis.aps.ui.dialogs.FolderCreationDialogFragment import dev.msfjarvis.aps.ui.dialogs.FolderCreationDialogFragment
@ -426,8 +426,8 @@ class PasswordStore : BaseGitActivity() {
(authDecryptIntent.clone() as Intent).setComponent( (authDecryptIntent.clone() as Intent).setComponent(
ComponentName( ComponentName(
this, this,
if (FeatureFlags.ENABLE_GOPENPGP) { if (FeatureFlags.ENABLE_PGP_V2_BACKEND) {
GopenpgpDecryptActivity::class.java DecryptActivityV2::class.java
} else { } else {
DecryptActivity::class.java DecryptActivity::class.java
} }

View File

@ -2,5 +2,5 @@ package dev.msfjarvis.aps.util
/** Naive feature flagging functionality to allow merging incomplete features */ /** Naive feature flagging functionality to allow merging incomplete features */
object FeatureFlags { object FeatureFlags {
const val ENABLE_GOPENPGP = false const val ENABLE_PGP_V2_BACKEND = false
} }

View File

@ -22,10 +22,10 @@ import com.github.androidpasswordstore.autofillparser.fillWith
import com.github.michaelbull.result.fold import com.github.michaelbull.result.fold
import dev.msfjarvis.aps.autofill.oreo.ui.AutofillSmsActivity import dev.msfjarvis.aps.autofill.oreo.ui.AutofillSmsActivity
import dev.msfjarvis.aps.ui.autofill.AutofillDecryptActivity import dev.msfjarvis.aps.ui.autofill.AutofillDecryptActivity
import dev.msfjarvis.aps.ui.autofill.AutofillDecryptActivityV2
import dev.msfjarvis.aps.ui.autofill.AutofillFilterView import dev.msfjarvis.aps.ui.autofill.AutofillFilterView
import dev.msfjarvis.aps.ui.autofill.AutofillPublisherChangedActivity import dev.msfjarvis.aps.ui.autofill.AutofillPublisherChangedActivity
import dev.msfjarvis.aps.ui.autofill.AutofillSaveActivity import dev.msfjarvis.aps.ui.autofill.AutofillSaveActivity
import dev.msfjarvis.aps.ui.autofill.GopenpgpAutofillDecryptActivity
import dev.msfjarvis.aps.util.FeatureFlags import dev.msfjarvis.aps.util.FeatureFlags
import java.io.File import java.io.File
@ -71,8 +71,8 @@ class Api30AutofillResponseBuilder(form: FillableForm) {
if (!scenario.hasFieldsToFillOn(AutofillAction.Match)) return null if (!scenario.hasFieldsToFillOn(AutofillAction.Match)) return null
val metadata = makeFillMatchMetadata(context, file) val metadata = makeFillMatchMetadata(context, file)
val intentSender = val intentSender =
if (FeatureFlags.ENABLE_GOPENPGP) { if (FeatureFlags.ENABLE_PGP_V2_BACKEND) {
GopenpgpAutofillDecryptActivity.makeDecryptFileIntentSender(file, context) AutofillDecryptActivityV2.makeDecryptFileIntentSender(file, context)
} else { } else {
AutofillDecryptActivity.makeDecryptFileIntentSender(file, context) AutofillDecryptActivity.makeDecryptFileIntentSender(file, context)
} }

View File

@ -22,10 +22,10 @@ import com.github.androidpasswordstore.autofillparser.fillWith
import com.github.michaelbull.result.fold import com.github.michaelbull.result.fold
import dev.msfjarvis.aps.autofill.oreo.ui.AutofillSmsActivity import dev.msfjarvis.aps.autofill.oreo.ui.AutofillSmsActivity
import dev.msfjarvis.aps.ui.autofill.AutofillDecryptActivity import dev.msfjarvis.aps.ui.autofill.AutofillDecryptActivity
import dev.msfjarvis.aps.ui.autofill.AutofillDecryptActivityV2
import dev.msfjarvis.aps.ui.autofill.AutofillFilterView import dev.msfjarvis.aps.ui.autofill.AutofillFilterView
import dev.msfjarvis.aps.ui.autofill.AutofillPublisherChangedActivity import dev.msfjarvis.aps.ui.autofill.AutofillPublisherChangedActivity
import dev.msfjarvis.aps.ui.autofill.AutofillSaveActivity import dev.msfjarvis.aps.ui.autofill.AutofillSaveActivity
import dev.msfjarvis.aps.ui.autofill.GopenpgpAutofillDecryptActivity
import dev.msfjarvis.aps.util.FeatureFlags import dev.msfjarvis.aps.util.FeatureFlags
import java.io.File import java.io.File
@ -59,8 +59,8 @@ class AutofillResponseBuilder(form: FillableForm) {
if (!scenario.hasFieldsToFillOn(AutofillAction.Match)) return null if (!scenario.hasFieldsToFillOn(AutofillAction.Match)) return null
val metadata = makeFillMatchMetadata(context, file) val metadata = makeFillMatchMetadata(context, file)
val intentSender = val intentSender =
if (FeatureFlags.ENABLE_GOPENPGP) { if (FeatureFlags.ENABLE_PGP_V2_BACKEND) {
GopenpgpAutofillDecryptActivity.makeDecryptFileIntentSender(file, context) AutofillDecryptActivityV2.makeDecryptFileIntentSender(file, context)
} else { } else {
AutofillDecryptActivity.makeDecryptFileIntentSender(file, context) AutofillDecryptActivity.makeDecryptFileIntentSender(file, context)
} }