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

View File

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

View File

@ -221,8 +221,8 @@ class AutofillFilterView : AppCompatActivity() {
AutofillMatcher.addMatchFor(applicationContext, formOrigin, item.file)
// intent?.extras? is checked to be non-null in onCreate
decryptAction.launch(
if (FeatureFlags.ENABLE_GOPENPGP) {
GopenpgpAutofillDecryptActivity.makeDecryptFileIntent(item.file, intent!!.extras!!, this)
if (FeatureFlags.ENABLE_PGP_V2_BACKEND) {
AutofillDecryptActivityV2.makeDecryptFileIntent(item.file, intent!!.extras!!, this)
} else {
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 dev.msfjarvis.aps.R
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.clipboard
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]. */
fun bindToOpenKeychain(onBoundListener: OpenPgpServiceConnection.OnBound) {
if (FeatureFlags.ENABLE_PGP_V2_BACKEND) return
val installed =
runCatching {
packageManager.getPackageInfo(OPENPGP_PROVIDER, 0)

View File

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

View File

@ -51,7 +51,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@AndroidEntryPoint
class GopenpgpPasswordCreationActivity : BasePgpActivity() {
class PasswordCreationActivityV2 : BasePgpActivity() {
private val binding by viewBinding(PasswordCreationActivityBinding::inflate)
@Inject lateinit var passwordEntryFactory: PasswordEntryFactory
@ -96,7 +96,7 @@ class GopenpgpPasswordCreationActivity : BasePgpActivity() {
otpImportButton.setOnClickListener {
supportFragmentManager.setFragmentResultListener(
OTP_RESULT_REQUEST_KEY,
this@GopenpgpPasswordCreationActivity
this@PasswordCreationActivityV2
) { requestKey, bundle ->
if (requestKey == OTP_RESULT_REQUEST_KEY) {
val contents = bundle.getString(RESULT)
@ -113,12 +113,12 @@ class GopenpgpPasswordCreationActivity : BasePgpActivity() {
getString(R.string.otp_import_qr_code),
getString(R.string.otp_import_manual_entry)
)
MaterialAlertDialogBuilder(this@GopenpgpPasswordCreationActivity)
MaterialAlertDialogBuilder(this@PasswordCreationActivityV2)
.setItems(items) { _, index ->
when (index) {
0 ->
otpImportAction.launch(
IntentIntegrator(this@GopenpgpPasswordCreationActivity)
IntentIntegrator(this@PasswordCreationActivityV2)
.setOrientationLocked(false)
.setBeepEnabled(false)
.setDesiredBarcodeFormats(QR_CODE)
@ -156,7 +156,7 @@ class GopenpgpPasswordCreationActivity : BasePgpActivity() {
// in the encrypted extras. This only makes sense if the directory structure is
// FileBased.
if (suggestedName == null &&
AutofillPreferences.directoryStructure(this@GopenpgpPasswordCreationActivity) ==
AutofillPreferences.directoryStructure(this@PasswordCreationActivityV2) ==
DirectoryStructure.FileBased
) {
encryptUsername.apply {
@ -367,7 +367,7 @@ class GopenpgpPasswordCreationActivity : BasePgpActivity() {
val oldFile = File("$repoPath/${oldCategory?.trim('/')}/$oldFileName.gpg")
if (oldFile.path != file.path && !oldFile.delete()) {
setResult(RESULT_CANCELED)
MaterialAlertDialogBuilder(this@GopenpgpPasswordCreationActivity)
MaterialAlertDialogBuilder(this@PasswordCreationActivityV2)
.setTitle(R.string.password_creation_file_fail_title)
.setMessage(
getString(R.string.password_creation_file_delete_fail_message, oldFileName)
@ -395,7 +395,7 @@ class GopenpgpPasswordCreationActivity : BasePgpActivity() {
if (e is IOException) {
e(e) { "Failed to write password file" }
setResult(RESULT_CANCELED)
MaterialAlertDialogBuilder(this@GopenpgpPasswordCreationActivity)
MaterialAlertDialogBuilder(this@PasswordCreationActivityV2)
.setTitle(getString(R.string.password_creation_file_fail_title))
.setMessage(getString(R.string.password_creation_file_write_fail_message))
.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.ui.crypto.BasePgpActivity.Companion.getLongName
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.dialogs.BasicBottomSheet
import dev.msfjarvis.aps.ui.dialogs.FolderCreationDialogFragment
@ -426,8 +426,8 @@ class PasswordStore : BaseGitActivity() {
(authDecryptIntent.clone() as Intent).setComponent(
ComponentName(
this,
if (FeatureFlags.ENABLE_GOPENPGP) {
GopenpgpDecryptActivity::class.java
if (FeatureFlags.ENABLE_PGP_V2_BACKEND) {
DecryptActivityV2::class.java
} else {
DecryptActivity::class.java
}

View File

@ -2,5 +2,5 @@ package dev.msfjarvis.aps.util
/** Naive feature flagging functionality to allow merging incomplete features */
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 dev.msfjarvis.aps.autofill.oreo.ui.AutofillSmsActivity
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.AutofillPublisherChangedActivity
import dev.msfjarvis.aps.ui.autofill.AutofillSaveActivity
import dev.msfjarvis.aps.ui.autofill.GopenpgpAutofillDecryptActivity
import dev.msfjarvis.aps.util.FeatureFlags
import java.io.File
@ -71,8 +71,8 @@ class Api30AutofillResponseBuilder(form: FillableForm) {
if (!scenario.hasFieldsToFillOn(AutofillAction.Match)) return null
val metadata = makeFillMatchMetadata(context, file)
val intentSender =
if (FeatureFlags.ENABLE_GOPENPGP) {
GopenpgpAutofillDecryptActivity.makeDecryptFileIntentSender(file, context)
if (FeatureFlags.ENABLE_PGP_V2_BACKEND) {
AutofillDecryptActivityV2.makeDecryptFileIntentSender(file, context)
} else {
AutofillDecryptActivity.makeDecryptFileIntentSender(file, context)
}

View File

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