mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-08-30 13:57:47 +00:00
Switch to openpgp-ktx (#565)
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
This commit is contained in:
@@ -80,7 +80,7 @@ dependencies {
|
||||
implementation 'com.google.android.material:material:' + versions.material
|
||||
implementation 'androidx.annotation:annotation:' + versions.annotation
|
||||
implementation 'androidx.biometric:biometric:' + versions.biometric
|
||||
implementation 'com.github.msfjarvis:openpgp-api:' + versions.openpgp
|
||||
implementation 'com.github.android-password-store:openpgp-ktx:' + versions.openpgp
|
||||
implementation('org.eclipse.jgit:org.eclipse.jgit:' + versions.jgit) {
|
||||
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
|
||||
}
|
||||
|
@@ -42,8 +42,8 @@ import java.time.format.DateTimeFormatter
|
||||
import java.util.Calendar
|
||||
import java.util.HashSet
|
||||
import java.util.TimeZone
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpUtils
|
||||
import org.apache.commons.io.FileUtils
|
||||
import org.openintents.openpgp.util.OpenPgpUtils
|
||||
|
||||
typealias ClickListener = Preference.OnPreferenceClickListener
|
||||
typealias ChangeListener = Preference.OnPreferenceChangeListener
|
||||
|
@@ -39,11 +39,11 @@ import java.net.MalformedURLException
|
||||
import java.net.URL
|
||||
import java.util.ArrayList
|
||||
import java.util.Locale
|
||||
import me.msfjarvis.openpgpktx.OpenPgpError
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpApi
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpServiceConnection
|
||||
import org.apache.commons.io.FileUtils
|
||||
import org.openintents.openpgp.IOpenPgpService2
|
||||
import org.openintents.openpgp.OpenPgpError
|
||||
import org.openintents.openpgp.util.OpenPgpApi
|
||||
import org.openintents.openpgp.util.OpenPgpServiceConnection
|
||||
|
||||
class AutofillService : AccessibilityService() {
|
||||
private var serviceConnection: OpenPgpServiceConnection? = null
|
||||
@@ -197,11 +197,10 @@ class AutofillService : AccessibilityService() {
|
||||
|
||||
// get the app name and find a corresponding password
|
||||
val packageManager = packageManager
|
||||
var applicationInfo: ApplicationInfo?
|
||||
try {
|
||||
applicationInfo = packageManager.getApplicationInfo(event.packageName.toString(), 0)
|
||||
val applicationInfo: ApplicationInfo? = try {
|
||||
packageManager.getApplicationInfo(event.packageName.toString(), 0)
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
applicationInfo = null
|
||||
null
|
||||
}
|
||||
|
||||
appName = (if (applicationInfo != null) packageManager.getApplicationLabel(applicationInfo) else "").toString()
|
||||
@@ -494,10 +493,10 @@ class AutofillService : AccessibilityService() {
|
||||
|
||||
val os = ByteArrayOutputStream()
|
||||
|
||||
val api = OpenPgpApi(this@AutofillService, serviceConnection!!.service)
|
||||
val api = OpenPgpApi(this@AutofillService, serviceConnection!!.service!!)
|
||||
// TODO we are dropping frames, (did we before??) find out why and maybe make this async
|
||||
val result = api.executeApi(data, `is`, os)
|
||||
when (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
|
||||
when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
|
||||
OpenPgpApi.RESULT_CODE_SUCCESS -> {
|
||||
try {
|
||||
val entry = PasswordEntry(os)
|
||||
@@ -568,12 +567,12 @@ class AutofillService : AccessibilityService() {
|
||||
}
|
||||
|
||||
private inner class OnBoundListener : OpenPgpServiceConnection.OnBound {
|
||||
override fun onBound(service: IOpenPgpService2) {
|
||||
override fun onBound(service: IOpenPgpService2?) {
|
||||
decryptAndVerify()
|
||||
}
|
||||
|
||||
override fun onError(e: Exception) {
|
||||
e.printStackTrace()
|
||||
override fun onError(e: Exception?) {
|
||||
e?.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -51,19 +51,19 @@ import kotlinx.android.synthetic.main.encrypt_layout.crypto_password_category
|
||||
import kotlinx.android.synthetic.main.encrypt_layout.crypto_password_edit
|
||||
import kotlinx.android.synthetic.main.encrypt_layout.crypto_password_file_edit
|
||||
import kotlinx.android.synthetic.main.encrypt_layout.generate_password
|
||||
import me.msfjarvis.openpgpktx.OpenPgpError
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpApi
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpApi.Companion.ACTION_DECRYPT_VERIFY
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpApi.Companion.RESULT_CODE
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpApi.Companion.RESULT_CODE_ERROR
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpApi.Companion.RESULT_CODE_SUCCESS
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpApi.Companion.RESULT_CODE_USER_INTERACTION_REQUIRED
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpApi.Companion.RESULT_ERROR
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpApi.Companion.RESULT_INTENT
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpServiceConnection
|
||||
import org.apache.commons.io.FileUtils
|
||||
import org.apache.commons.io.FilenameUtils
|
||||
import org.openintents.openpgp.IOpenPgpService2
|
||||
import org.openintents.openpgp.OpenPgpError
|
||||
import org.openintents.openpgp.util.OpenPgpApi
|
||||
import org.openintents.openpgp.util.OpenPgpApi.ACTION_DECRYPT_VERIFY
|
||||
import org.openintents.openpgp.util.OpenPgpApi.RESULT_CODE
|
||||
import org.openintents.openpgp.util.OpenPgpApi.RESULT_CODE_ERROR
|
||||
import org.openintents.openpgp.util.OpenPgpApi.RESULT_CODE_SUCCESS
|
||||
import org.openintents.openpgp.util.OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED
|
||||
import org.openintents.openpgp.util.OpenPgpApi.RESULT_ERROR
|
||||
import org.openintents.openpgp.util.OpenPgpApi.RESULT_INTENT
|
||||
import org.openintents.openpgp.util.OpenPgpServiceConnection
|
||||
|
||||
class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
||||
private val clipboard: ClipboardManager by lazy {
|
||||
@@ -226,13 +226,13 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
||||
val error: OpenPgpError? = result.getParcelableExtra(RESULT_ERROR)
|
||||
if (error != null) {
|
||||
showSnackbar("Error from OpenKeyChain : " + error.message)
|
||||
Log.e(TAG, "onError getErrorId:" + error.errorId)
|
||||
Log.e(TAG, "onError getErrorId:" + error.message)
|
||||
Log.e(TAG, "onError getMessage:" + error.message)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initOpenPgpApi() {
|
||||
api = api ?: OpenPgpApi(this, mServiceConnection?.service)
|
||||
api = api ?: OpenPgpApi(this, mServiceConnection!!.service!!)
|
||||
}
|
||||
|
||||
private fun decryptAndVerify(receivedIntent: Intent? = null) {
|
||||
@@ -242,7 +242,8 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
||||
val iStream = FileUtils.openInputStream(File(fullPath))
|
||||
val oStream = ByteArrayOutputStream()
|
||||
|
||||
api?.executeApiAsync(data, iStream, oStream) { result: Intent? ->
|
||||
api?.executeApiAsync(data, iStream, oStream, object : OpenPgpApi.IOpenPgpCallback {
|
||||
override fun onReturn(result: Intent?) {
|
||||
when (result?.getIntExtra(RESULT_CODE, RESULT_CODE_ERROR)) {
|
||||
RESULT_CODE_SUCCESS -> {
|
||||
try {
|
||||
@@ -258,7 +259,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
||||
|
||||
if (intent.getStringExtra("OPERATION") == "EDIT") {
|
||||
editPassword()
|
||||
return@executeApiAsync
|
||||
return
|
||||
}
|
||||
|
||||
if (entry.password.isEmpty()) {
|
||||
@@ -356,11 +357,11 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
||||
}
|
||||
} else {
|
||||
// show a dialog asking permission to update the HOTP counter in the entry
|
||||
val checkInflater = LayoutInflater.from(this)
|
||||
val checkInflater = LayoutInflater.from(this@PgpActivity)
|
||||
val checkLayout = checkInflater.inflate(R.layout.otp_confirm_layout, null)
|
||||
val rememberCheck: CheckBox =
|
||||
checkLayout.findViewById(R.id.hotp_remember_checkbox)
|
||||
val dialogBuilder = MaterialAlertDialogBuilder(this)
|
||||
val dialogBuilder = MaterialAlertDialogBuilder(this@PgpActivity)
|
||||
dialogBuilder.setView(checkLayout)
|
||||
dialogBuilder.setMessage(R.string.dialog_update_body)
|
||||
.setCancelable(false)
|
||||
@@ -409,6 +410,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
||||
RESULT_CODE_ERROR -> handleError(result)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -450,7 +452,8 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
||||
|
||||
val path = if (intent.getBooleanExtra("fromDecrypt", false)) fullPath else "$fullPath/$editName.gpg"
|
||||
|
||||
api?.executeApiAsync(data, iStream, oStream) { result: Intent? ->
|
||||
api?.executeApiAsync(data, iStream, oStream, object : OpenPgpApi.IOpenPgpCallback {
|
||||
override fun onReturn(result: Intent?) {
|
||||
when (result?.getIntExtra(RESULT_CODE, RESULT_CODE_ERROR)) {
|
||||
RESULT_CODE_SUCCESS -> {
|
||||
try {
|
||||
@@ -462,7 +465,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
||||
val returnIntent = Intent()
|
||||
returnIntent.putExtra("CREATED_FILE", path)
|
||||
returnIntent.putExtra("NAME", editName)
|
||||
returnIntent.putExtra("LONG_NAME", getLongName(fullPath, repoPath, this.editName!!))
|
||||
returnIntent.putExtra("LONG_NAME", getLongName(fullPath, repoPath, editName!!))
|
||||
|
||||
// if coming from decrypt screen->edit button
|
||||
if (intent.getBooleanExtra("fromDecrypt", false)) {
|
||||
@@ -478,6 +481,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
||||
RESULT_CODE_ERROR -> handleError(result)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -553,7 +557,8 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
||||
private fun getKeyIds(receivedIntent: Intent? = null) {
|
||||
val data = receivedIntent ?: Intent()
|
||||
data.action = OpenPgpApi.ACTION_GET_KEY_IDS
|
||||
api?.executeApiAsync(data, null, null) { result: Intent? ->
|
||||
api?.executeApiAsync(data, null, null, object : OpenPgpApi.IOpenPgpCallback {
|
||||
override fun onReturn(result: Intent?) {
|
||||
when (result?.getIntExtra(RESULT_CODE, RESULT_CODE_ERROR)) {
|
||||
RESULT_CODE_SUCCESS -> {
|
||||
try {
|
||||
@@ -576,6 +581,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
||||
RESULT_CODE_ERROR -> handleError(result)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onError(e: Exception?) {}
|
||||
|
@@ -40,7 +40,7 @@
|
||||
</androidx.preference.PreferenceCategory>
|
||||
|
||||
<androidx.preference.PreferenceCategory android:title="@string/pref_crypto_title">
|
||||
<org.openintents.openpgp.util.OpenPgpAppPreference2
|
||||
<me.msfjarvis.openpgpktx.preference.OpenPgpAppPreference
|
||||
android:key="openpgp_provider_list"
|
||||
android:title="@string/pref_provider_title" />
|
||||
<androidx.preference.Preference
|
||||
|
@@ -2,4 +2,4 @@
|
||||
* Copyright © 2014-2019 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
include(":app")
|
||||
include ':app'
|
||||
|
@@ -35,7 +35,7 @@ ext {
|
||||
commons_codec: '1.13',
|
||||
jgit: '3.7.1.201504261725-r',
|
||||
jsch: '0.1.55',
|
||||
openpgp: 'v14',
|
||||
openpgp: '0.1.0',
|
||||
sshauth: '1.0'
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user