Switch to openpgp-ktx (#565)

Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
This commit is contained in:
Harsh Shandilya
2019-11-12 02:14:28 +05:30
committed by GitHub
parent eb9754ba79
commit 4c7f46aa8a
7 changed files with 205 additions and 200 deletions

View File

@@ -80,7 +80,7 @@ dependencies {
implementation 'com.google.android.material:material:' + versions.material implementation 'com.google.android.material:material:' + versions.material
implementation 'androidx.annotation:annotation:' + versions.annotation implementation 'androidx.annotation:annotation:' + versions.annotation
implementation 'androidx.biometric:biometric:' + versions.biometric 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) { implementation('org.eclipse.jgit:org.eclipse.jgit:' + versions.jgit) {
exclude group: 'org.apache.httpcomponents', module: 'httpclient' exclude group: 'org.apache.httpcomponents', module: 'httpclient'
} }

View File

@@ -42,8 +42,8 @@ import java.time.format.DateTimeFormatter
import java.util.Calendar import java.util.Calendar
import java.util.HashSet import java.util.HashSet
import java.util.TimeZone import java.util.TimeZone
import me.msfjarvis.openpgpktx.util.OpenPgpUtils
import org.apache.commons.io.FileUtils import org.apache.commons.io.FileUtils
import org.openintents.openpgp.util.OpenPgpUtils
typealias ClickListener = Preference.OnPreferenceClickListener typealias ClickListener = Preference.OnPreferenceClickListener
typealias ChangeListener = Preference.OnPreferenceChangeListener typealias ChangeListener = Preference.OnPreferenceChangeListener

View File

@@ -39,11 +39,11 @@ import java.net.MalformedURLException
import java.net.URL import java.net.URL
import java.util.ArrayList import java.util.ArrayList
import java.util.Locale 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.apache.commons.io.FileUtils
import org.openintents.openpgp.IOpenPgpService2 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() { class AutofillService : AccessibilityService() {
private var serviceConnection: OpenPgpServiceConnection? = null private var serviceConnection: OpenPgpServiceConnection? = null
@@ -197,11 +197,10 @@ class AutofillService : AccessibilityService() {
// get the app name and find a corresponding password // get the app name and find a corresponding password
val packageManager = packageManager val packageManager = packageManager
var applicationInfo: ApplicationInfo? val applicationInfo: ApplicationInfo? = try {
try { packageManager.getApplicationInfo(event.packageName.toString(), 0)
applicationInfo = packageManager.getApplicationInfo(event.packageName.toString(), 0)
} catch (e: PackageManager.NameNotFoundException) { } catch (e: PackageManager.NameNotFoundException) {
applicationInfo = null null
} }
appName = (if (applicationInfo != null) packageManager.getApplicationLabel(applicationInfo) else "").toString() appName = (if (applicationInfo != null) packageManager.getApplicationLabel(applicationInfo) else "").toString()
@@ -494,10 +493,10 @@ class AutofillService : AccessibilityService() {
val os = ByteArrayOutputStream() 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 // TODO we are dropping frames, (did we before??) find out why and maybe make this async
val result = api.executeApi(data, `is`, os) 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 -> { OpenPgpApi.RESULT_CODE_SUCCESS -> {
try { try {
val entry = PasswordEntry(os) val entry = PasswordEntry(os)
@@ -568,12 +567,12 @@ class AutofillService : AccessibilityService() {
} }
private inner class OnBoundListener : OpenPgpServiceConnection.OnBound { private inner class OnBoundListener : OpenPgpServiceConnection.OnBound {
override fun onBound(service: IOpenPgpService2) { override fun onBound(service: IOpenPgpService2?) {
decryptAndVerify() decryptAndVerify()
} }
override fun onError(e: Exception) { override fun onError(e: Exception?) {
e.printStackTrace() e?.printStackTrace()
} }
} }

View File

@@ -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_edit
import kotlinx.android.synthetic.main.encrypt_layout.crypto_password_file_edit import kotlinx.android.synthetic.main.encrypt_layout.crypto_password_file_edit
import kotlinx.android.synthetic.main.encrypt_layout.generate_password 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.FileUtils
import org.apache.commons.io.FilenameUtils import org.apache.commons.io.FilenameUtils
import org.openintents.openpgp.IOpenPgpService2 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 { class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
private val clipboard: ClipboardManager by lazy { private val clipboard: ClipboardManager by lazy {
@@ -226,13 +226,13 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
val error: OpenPgpError? = result.getParcelableExtra(RESULT_ERROR) val error: OpenPgpError? = result.getParcelableExtra(RESULT_ERROR)
if (error != null) { if (error != null) {
showSnackbar("Error from OpenKeyChain : " + error.message) 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) Log.e(TAG, "onError getMessage:" + error.message)
} }
} }
private fun initOpenPgpApi() { private fun initOpenPgpApi() {
api = api ?: OpenPgpApi(this, mServiceConnection?.service) api = api ?: OpenPgpApi(this, mServiceConnection!!.service!!)
} }
private fun decryptAndVerify(receivedIntent: Intent? = null) { private fun decryptAndVerify(receivedIntent: Intent? = null) {
@@ -242,7 +242,8 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
val iStream = FileUtils.openInputStream(File(fullPath)) val iStream = FileUtils.openInputStream(File(fullPath))
val oStream = ByteArrayOutputStream() 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)) { when (result?.getIntExtra(RESULT_CODE, RESULT_CODE_ERROR)) {
RESULT_CODE_SUCCESS -> { RESULT_CODE_SUCCESS -> {
try { try {
@@ -258,7 +259,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
if (intent.getStringExtra("OPERATION") == "EDIT") { if (intent.getStringExtra("OPERATION") == "EDIT") {
editPassword() editPassword()
return@executeApiAsync return
} }
if (entry.password.isEmpty()) { if (entry.password.isEmpty()) {
@@ -356,11 +357,11 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
} }
} else { } else {
// show a dialog asking permission to update the HOTP counter in the entry // 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 checkLayout = checkInflater.inflate(R.layout.otp_confirm_layout, null)
val rememberCheck: CheckBox = val rememberCheck: CheckBox =
checkLayout.findViewById(R.id.hotp_remember_checkbox) checkLayout.findViewById(R.id.hotp_remember_checkbox)
val dialogBuilder = MaterialAlertDialogBuilder(this) val dialogBuilder = MaterialAlertDialogBuilder(this@PgpActivity)
dialogBuilder.setView(checkLayout) dialogBuilder.setView(checkLayout)
dialogBuilder.setMessage(R.string.dialog_update_body) dialogBuilder.setMessage(R.string.dialog_update_body)
.setCancelable(false) .setCancelable(false)
@@ -409,6 +410,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
RESULT_CODE_ERROR -> handleError(result) 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" 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)) { when (result?.getIntExtra(RESULT_CODE, RESULT_CODE_ERROR)) {
RESULT_CODE_SUCCESS -> { RESULT_CODE_SUCCESS -> {
try { try {
@@ -462,7 +465,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
val returnIntent = Intent() val returnIntent = Intent()
returnIntent.putExtra("CREATED_FILE", path) returnIntent.putExtra("CREATED_FILE", path)
returnIntent.putExtra("NAME", editName) 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 coming from decrypt screen->edit button
if (intent.getBooleanExtra("fromDecrypt", false)) { if (intent.getBooleanExtra("fromDecrypt", false)) {
@@ -478,6 +481,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
RESULT_CODE_ERROR -> handleError(result) RESULT_CODE_ERROR -> handleError(result)
} }
} }
})
} }
/** /**
@@ -553,7 +557,8 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
private fun getKeyIds(receivedIntent: Intent? = null) { private fun getKeyIds(receivedIntent: Intent? = null) {
val data = receivedIntent ?: Intent() val data = receivedIntent ?: Intent()
data.action = OpenPgpApi.ACTION_GET_KEY_IDS 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)) { when (result?.getIntExtra(RESULT_CODE, RESULT_CODE_ERROR)) {
RESULT_CODE_SUCCESS -> { RESULT_CODE_SUCCESS -> {
try { try {
@@ -576,6 +581,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
RESULT_CODE_ERROR -> handleError(result) RESULT_CODE_ERROR -> handleError(result)
} }
} }
})
} }
override fun onError(e: Exception?) {} override fun onError(e: Exception?) {}

View File

@@ -40,7 +40,7 @@
</androidx.preference.PreferenceCategory> </androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory android:title="@string/pref_crypto_title"> <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:key="openpgp_provider_list"
android:title="@string/pref_provider_title" /> android:title="@string/pref_provider_title" />
<androidx.preference.Preference <androidx.preference.Preference

View File

@@ -2,4 +2,4 @@
* Copyright © 2014-2019 The Android Password Store Authors. All Rights Reserved. * Copyright © 2014-2019 The Android Password Store Authors. All Rights Reserved.
* SPDX-License-Identifier: GPL-3.0-only * SPDX-License-Identifier: GPL-3.0-only
*/ */
include(":app") include ':app'

View File

@@ -35,7 +35,7 @@ ext {
commons_codec: '1.13', commons_codec: '1.13',
jgit: '3.7.1.201504261725-r', jgit: '3.7.1.201504261725-r',
jsch: '0.1.55', jsch: '0.1.55',
openpgp: 'v14', openpgp: '0.1.0',
sshauth: '1.0' sshauth: '1.0'
] ]
} }