first code to manage merge with yubikey

This commit is contained in:
J-Jamet 2023-01-02 19:30:19 +01:00
parent d049ed39e8
commit adbdb9a642
8 changed files with 57 additions and 39 deletions

View file

@ -8,8 +8,8 @@ GEM
artifactory (3.0.15)
atomos (0.1.3)
aws-eventstream (1.2.0)
aws-partitions (1.626.0)
aws-sdk-core (3.140.0)
aws-partitions (1.646.0)
aws-sdk-core (3.160.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.525.0)
aws-sigv4 (~> 1.1)
@ -21,7 +21,7 @@ GEM
aws-sdk-core (~> 3, >= 3.127.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.4)
aws-sigv4 (1.5.1)
aws-sigv4 (1.5.2)
aws-eventstream (~> 1, >= 1.0.2)
babosa (1.0.4)
claide (1.1.0)
@ -36,7 +36,7 @@ GEM
unf (>= 0.0.5, < 1.0.0)
dotenv (2.8.1)
emoji_regex (3.2.3)
excon (0.92.4)
excon (0.93.0)
faraday (1.10.2)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
@ -66,7 +66,7 @@ GEM
faraday_middleware (1.2.0)
faraday (~> 1.0)
fastimage (2.2.6)
fastlane (2.209.1)
fastlane (2.210.1)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.8, < 3.0.0)
artifactory (~> 3.0)
@ -107,9 +107,9 @@ GEM
xcpretty-travis-formatter (>= 0.0.3)
fastlane-plugin-versioning_android (0.1.0)
gh_inspector (1.1.3)
google-apis-androidpublisher_v3 (0.25.0)
google-apis-core (>= 0.7, < 2.a)
google-apis-core (0.7.0)
google-apis-androidpublisher_v3 (0.29.0)
google-apis-core (>= 0.9.0, < 2.a)
google-apis-core (0.9.0)
addressable (~> 2.5, >= 2.5.1)
googleauth (>= 0.16.2, < 2.a)
httpclient (>= 2.8.1, < 3.a)
@ -118,23 +118,23 @@ GEM
retriable (>= 2.0, < 4.a)
rexml
webrick
google-apis-iamcredentials_v1 (0.13.0)
google-apis-core (>= 0.7, < 2.a)
google-apis-playcustomapp_v1 (0.10.0)
google-apis-core (>= 0.7, < 2.a)
google-apis-storage_v1 (0.17.0)
google-apis-core (>= 0.7, < 2.a)
google-apis-iamcredentials_v1 (0.15.0)
google-apis-core (>= 0.9.0, < 2.a)
google-apis-playcustomapp_v1 (0.11.0)
google-apis-core (>= 0.9.0, < 2.a)
google-apis-storage_v1 (0.19.0)
google-apis-core (>= 0.9.0, < 2.a)
google-cloud-core (1.6.0)
google-cloud-env (~> 1.0)
google-cloud-errors (~> 1.0)
google-cloud-env (1.6.0)
faraday (>= 0.17.3, < 3.0)
google-cloud-errors (1.2.0)
google-cloud-storage (1.39.0)
google-cloud-errors (1.3.0)
google-cloud-storage (1.43.0)
addressable (~> 2.8)
digest-crc (~> 0.4)
google-apis-iamcredentials_v1 (~> 0.1)
google-apis-storage_v1 (~> 0.17.0)
google-apis-storage_v1 (~> 0.19.0)
google-cloud-core (~> 1.6)
googleauth (>= 0.16.2, < 2.a)
mini_mime (~> 1.0)

View file

@ -90,8 +90,8 @@ abstract class DatabaseLockActivity : DatabaseModeActivity(),
mDatabaseTaskProvider?.startDatabaseSave(save)
}
mDatabaseViewModel.mergeDatabase.observe(this) {
mDatabaseTaskProvider?.startDatabaseMerge()
mDatabaseViewModel.mergeDatabase.observe(this) { save ->
mDatabaseTaskProvider?.startDatabaseMerge(save)
}
mDatabaseViewModel.reloadDatabase.observe(this) { fixDuplicateUuid ->
@ -227,6 +227,9 @@ abstract class DatabaseLockActivity : DatabaseModeActivity(),
// Reload the current activity
if (result.isSuccess) {
reloadActivity()
if (actionTask == DatabaseTaskNotificationService.ACTION_DATABASE_MERGE_TASK) {
Toast.makeText(this, R.string.merge_success, Toast.LENGTH_LONG).show()
}
} else {
this.showActionErrorIfNeeded(result)
finish()
@ -270,11 +273,11 @@ abstract class DatabaseLockActivity : DatabaseModeActivity(),
}
fun mergeDatabase() {
mDatabaseTaskProvider?.startDatabaseMerge()
mDatabaseTaskProvider?.startDatabaseMerge(mAutoSaveEnable)
}
fun mergeDatabaseFrom(uri: Uri, mainCredential: MainCredential) {
mDatabaseTaskProvider?.startDatabaseMerge(uri, mainCredential)
mDatabaseTaskProvider?.startDatabaseMerge(mAutoSaveEnable, uri, mainCredential)
}
fun reloadDatabase() {

View file

@ -412,9 +412,11 @@ class DatabaseTaskProvider {
, ACTION_DATABASE_LOAD_TASK)
}
fun startDatabaseMerge(fromDatabaseUri: Uri? = null,
fun startDatabaseMerge(save: Boolean,
fromDatabaseUri: Uri? = null,
mainCredential: MainCredential? = null) {
start(Bundle().apply {
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
putParcelable(DatabaseTaskNotificationService.DATABASE_URI_KEY, fromDatabaseUri)
putParcelable(DatabaseTaskNotificationService.MAIN_CREDENTIAL_KEY, mainCredential)
}

View file

@ -27,25 +27,28 @@ import com.kunzisoft.keepass.database.element.binary.BinaryData
import com.kunzisoft.keepass.database.exception.DatabaseException
import com.kunzisoft.keepass.hardware.HardwareKey
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.tasks.ActionRunnable
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater
class MergeDatabaseRunnable(private val context: Context,
private val mDatabase: Database,
private val mDatabaseToMergeUri: Uri?,
private val mDatabaseToMergeMainCredential: MainCredential?,
private val mDatabaseToMergeChallengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray,
private val progressTaskUpdater: ProgressTaskUpdater?,
private val mLoadDatabaseResult: ((Result) -> Unit)?)
: ActionRunnable() {
class MergeDatabaseRunnable(
context: Context,
private val mDatabaseToMergeUri: Uri?,
private val mDatabaseToMergeMainCredential: MainCredential?,
private val mDatabaseToMergeChallengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray,
database: Database,
saveDatabase: Boolean,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray,
private val progressTaskUpdater: ProgressTaskUpdater?,
private val mLoadDatabaseResult: ((Result) -> Unit)?)
: SaveDatabaseRunnable(context, database, saveDatabase, null, challengeResponseRetriever) {
override fun onStartRun() {
mDatabase.wasReloaded = true
database.wasReloaded = true
super.onStartRun()
}
override fun onActionRun() {
try {
mDatabase.mergeData(
database.mergeData(
context.contentResolver,
mDatabaseToMergeUri,
mDatabaseToMergeMainCredential,
@ -63,9 +66,11 @@ class MergeDatabaseRunnable(private val context: Context,
// Register the current time to init the lock timer
PreferencesUtil.saveCurrentTime(context)
}
super.onActionRun()
}
override fun onFinishRun() {
super.onFinishRun()
mLoadDatabaseResult?.invoke(result)
}
}

View file

@ -753,9 +753,14 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
return MergeDatabaseRunnable(
this,
database,
databaseToMergeUri,
databaseToMergeMainCredential,
{ hardwareKey, seed ->
// TODO fix first challenge response
retrieveResponseFromChallenge(hardwareKey, seed)
},
database,
!database.isReadOnly && intent.getBooleanExtra(SAVE_DATABASE_KEY, false),
{ hardwareKey, seed ->
retrieveResponseFromChallenge(hardwareKey, seed)
},

View file

@ -115,8 +115,8 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment(), DatabaseRetriev
mDatabaseViewModel.saveDatabase(save)
}
private fun mergeDatabase() {
mDatabaseViewModel.mergeDatabase(false)
private fun mergeDatabase(save: Boolean) {
mDatabaseViewModel.mergeDatabase(save)
}
private fun reloadDatabase() {
@ -671,7 +671,7 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment(), DatabaseRetriev
true
}
R.id.menu_merge_database -> {
mergeDatabase()
mergeDatabase(!mDatabaseReadOnly)
true
}
R.id.menu_reload_database -> {

View file

@ -87,8 +87,8 @@ class DatabaseViewModel: ViewModel() {
_saveDatabase.value = save
}
fun mergeDatabase(fixDuplicateUuid: Boolean) {
_mergeDatabase.value = fixDuplicateUuid
fun mergeDatabase(save: Boolean) {
_mergeDatabase.value = save
}
fun reloadDatabase(fixDuplicateUuid: Boolean) {
@ -196,6 +196,8 @@ class DatabaseViewModel: ViewModel() {
data class SuperLong(val oldValue: Long,
val newValue: Long,
val save: Boolean)
data class SuperMerge(val fixDuplicateUuid: Boolean,
val save: Boolean)
data class SuperCompression(val oldValue: CompressionAlgorithm,
val newValue: CompressionAlgorithm,
val save: Boolean)

View file

@ -373,6 +373,7 @@
<string name="warning_database_revoked">Access to the file revoked by the file manager, close the database and reopen it from its location.</string>
<string name="warning_exact_alarm">You have not allowed the app to use an exact alarm. As a result, the features requiring a timer will not be done with an exact time.</string>
<string name="warning_keyfile_integrity">The hash of the file is not guaranteed because Android can change its data on the fly. Change the file extension to .bin for correct integrity.</string>
<string name="merge_success">Merge successfully completed</string>
<string name="permission">Permission</string>
<string name="version_label">Version %1$s</string>
<string name="build_label">Build %1$s</string>