mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-05 16:22:31 -08:00
Open database with challenge response in service
This commit is contained in:
1 parent
19bc2444bc
commit
a5e53d872b
18 files changed
+288
-151
No files matched your search
@@ -55,11 +55,11 @@ import com.kunzisoft.keepass.autofill.AutofillComponent
|
||||
import com.kunzisoft.keepass.autofill.AutofillHelper
|
||||
import com.kunzisoft.keepass.biometric.AdvancedUnlockFragment
|
||||
import com.kunzisoft.keepass.biometric.AdvancedUnlockManager
|
||||
import com.kunzisoft.keepass.database.action.DatabaseTaskProvider
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.exception.DuplicateUuidDatabaseException
|
||||
import com.kunzisoft.keepass.database.exception.FileNotFoundDatabaseException
|
||||
import com.kunzisoft.keepass.education.PasswordActivityEducation
|
||||
import com.kunzisoft.keepass.hardware.HardwareKey
|
||||
import com.kunzisoft.keepass.hardware.HardwareKeyResponseHelper
|
||||
import com.kunzisoft.keepass.model.*
|
||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_LOAD_TASK
|
||||
@@ -103,16 +103,20 @@ class MainCredentialActivity : DatabaseModeActivity(), AdvancedUnlockFragment.Bu
|
||||
private var mRememberKeyFile: Boolean = false
|
||||
private var mExternalFileHelper: ExternalFileHelper? = null
|
||||
|
||||
private var mHardwareKeyResponseHelper: HardwareKeyResponseHelper? = null
|
||||
|
||||
private var mReadOnly: Boolean = false
|
||||
private var mForceReadOnly: Boolean = false
|
||||
|
||||
private var mHardwareKeyResponseHelper = HardwareKeyResponseHelper(this)
|
||||
|
||||
private var mAutofillActivityResultLauncher: ActivityResultLauncher<Intent>? =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
AutofillHelper.buildActivityResultLauncher(this)
|
||||
else null
|
||||
|
||||
override fun initializeDatabaseTaskProvider(): DatabaseTaskProvider {
|
||||
return DatabaseTaskProvider(this, mHardwareKeyResponseHelper)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
@@ -150,35 +154,6 @@ class MainCredentialActivity : DatabaseModeActivity(), AdvancedUnlockFragment.Bu
|
||||
loadDatabase()
|
||||
}
|
||||
|
||||
// Build elements to manage hardware key
|
||||
mHardwareKeyResponseHelper = HardwareKeyResponseHelper(this)
|
||||
mHardwareKeyResponseHelper?.buildHardwareKeyResponse { responseData, _ ->
|
||||
mainCredentialView?.validateCredential(responseData)
|
||||
}
|
||||
mainCredentialView?.onRequestHardwareKeyResponse = { hardwareKey ->
|
||||
try {
|
||||
when (hardwareKey) {
|
||||
HardwareKey.CHALLENGE_RESPONSE_YUBIKEY -> {
|
||||
mDatabaseFileUri?.let { databaseUri ->
|
||||
mHardwareKeyResponseHelper?.launchChallengeForResponse(databaseUri)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
// TODO other algorithm
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Unable to retrieve the challenge response", e)
|
||||
e.message?.let { message ->
|
||||
Snackbar.make(
|
||||
coordinatorLayout,
|
||||
message,
|
||||
Snackbar.LENGTH_LONG
|
||||
).asError().show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If is a view intent
|
||||
getUriFromIntent(intent)
|
||||
|
||||
|
||||
+3
-12
@@ -36,7 +36,6 @@ import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.helpers.ExternalFileHelper
|
||||
import com.kunzisoft.keepass.activities.helpers.setOpenDocumentClickListener
|
||||
import com.kunzisoft.keepass.hardware.HardwareKey
|
||||
import com.kunzisoft.keepass.hardware.HardwareKeyResponseHelper
|
||||
import com.kunzisoft.keepass.model.MainCredential
|
||||
import com.kunzisoft.keepass.password.PasswordEntropy
|
||||
import com.kunzisoft.keepass.utils.UriUtil
|
||||
@@ -50,7 +49,6 @@ class SetMainCredentialDialogFragment : DatabaseDialogFragment() {
|
||||
private var mMasterPassword: String? = null
|
||||
private var mKeyFileUri: Uri? = null
|
||||
private var mHardwareKey: HardwareKey? = null
|
||||
private var mChallengeResponse: ByteArray? = null
|
||||
|
||||
private lateinit var rootView: View
|
||||
|
||||
@@ -74,8 +72,6 @@ class SetMainCredentialDialogFragment : DatabaseDialogFragment() {
|
||||
private var mNoKeyConfirmationDialog: AlertDialog? = null
|
||||
private var mEmptyKeyFileConfirmationDialog: AlertDialog? = null
|
||||
|
||||
private var mHardwareKeyResponseHelper: HardwareKeyResponseHelper? = null
|
||||
|
||||
private var mAllowNoMasterKey: Boolean = false
|
||||
|
||||
private val passwordTextWatcher = object : TextWatcher {
|
||||
@@ -180,7 +176,7 @@ class SetMainCredentialDialogFragment : DatabaseDialogFragment() {
|
||||
|
||||
mMasterPassword = ""
|
||||
mKeyFileUri = null
|
||||
mChallengeResponse = null
|
||||
mHardwareKey = null
|
||||
|
||||
if (verifyHardwareKey()) {
|
||||
approveMainCredential()
|
||||
@@ -219,16 +215,11 @@ class SetMainCredentialDialogFragment : DatabaseDialogFragment() {
|
||||
}
|
||||
}
|
||||
|
||||
fun setChallengeResponse(response: ByteArray?) {
|
||||
mChallengeResponse = response
|
||||
approveMainCredential()
|
||||
}
|
||||
|
||||
private fun retrieveMainCredential(): MainCredential {
|
||||
val masterPassword = if (passwordCheckBox.isChecked) mMasterPassword else null
|
||||
val keyFileUri = if (keyFileCheckBox.isChecked) mKeyFileUri else null
|
||||
val hardwareKeyData = if (hardwareKeyCheckBox.isChecked) mChallengeResponse else null
|
||||
return MainCredential(masterPassword, keyFileUri, hardwareKeyData)
|
||||
val hardwareKey = if (hardwareKeyCheckBox.isChecked) mHardwareKey else null
|
||||
return MainCredential(masterPassword, keyFileUri, hardwareKey)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
||||
@@ -20,7 +20,7 @@ abstract class DatabaseActivity: StylishActivity(), DatabaseRetrieval {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
mDatabaseTaskProvider = DatabaseTaskProvider(this)
|
||||
mDatabaseTaskProvider = initializeDatabaseTaskProvider()
|
||||
|
||||
mDatabaseTaskProvider?.onDatabaseRetrieved = { database ->
|
||||
val databaseWasReloaded = database?.wasReloaded == true
|
||||
@@ -36,6 +36,10 @@ abstract class DatabaseActivity: StylishActivity(), DatabaseRetrieval {
|
||||
}
|
||||
}
|
||||
|
||||
open fun initializeDatabaseTaskProvider(): DatabaseTaskProvider {
|
||||
return DatabaseTaskProvider(this)
|
||||
}
|
||||
|
||||
override fun onDatabaseRetrieved(database: Database?) {
|
||||
mDatabase = database
|
||||
mDatabaseViewModel.defineDatabase(database)
|
||||
|
||||
+6
-4
@@ -24,14 +24,15 @@ import android.net.Uri
|
||||
import com.kunzisoft.keepass.app.database.CipherDatabaseAction
|
||||
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.hardware.HardwareKey
|
||||
import com.kunzisoft.keepass.model.MainCredential
|
||||
import com.kunzisoft.keepass.utils.UriUtil
|
||||
|
||||
open class AssignMainCredentialInDatabaseRunnable (
|
||||
context: Context,
|
||||
database: Database,
|
||||
protected val mDatabaseUri: Uri,
|
||||
protected val mMainCredential: MainCredential)
|
||||
protected val mMainCredential: MainCredential,
|
||||
protected val mChallengeResponseRetriever: (HardwareKey?, ByteArray?) -> ByteArray?)
|
||||
: SaveDatabaseRunnable(context, database, true) {
|
||||
|
||||
private var mBackupKey: ByteArray? = null
|
||||
@@ -39,10 +40,11 @@ open class AssignMainCredentialInDatabaseRunnable (
|
||||
override fun onStartRun() {
|
||||
// Set key
|
||||
try {
|
||||
// TODO Move in assign master key
|
||||
mBackupKey = ByteArray(database.masterKey.size)
|
||||
System.arraycopy(database.masterKey, 0, mBackupKey!!, 0, mBackupKey!!.size)
|
||||
database.masterKey.copyInto(mBackupKey!!)
|
||||
|
||||
database.assignMasterKey(context.contentResolver, mMainCredential)
|
||||
database.assignMasterKey(context.contentResolver, mMainCredential, mChallengeResponseRetriever)
|
||||
} catch (e: Exception) {
|
||||
erase(mBackupKey)
|
||||
setError(e)
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.net.Uri
|
||||
import android.util.Log
|
||||
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.hardware.HardwareKey
|
||||
import com.kunzisoft.keepass.model.MainCredential
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
|
||||
@@ -34,8 +35,9 @@ class CreateDatabaseRunnable(context: Context,
|
||||
private val rootName: String,
|
||||
private val templateGroupName: String?,
|
||||
mainCredential: MainCredential,
|
||||
challengeResponseRetriever: (HardwareKey?, ByteArray?) -> ByteArray?,
|
||||
private val createDatabaseResult: ((Result) -> Unit)?)
|
||||
: AssignMainCredentialInDatabaseRunnable(context, mDatabase, databaseUri, mainCredential) {
|
||||
: AssignMainCredentialInDatabaseRunnable(context, mDatabase, databaseUri, mainCredential, challengeResponseRetriever) {
|
||||
|
||||
override fun onStartRun() {
|
||||
try {
|
||||
|
||||
@@ -42,6 +42,8 @@ import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.hardware.HardwareKey
|
||||
import com.kunzisoft.keepass.hardware.HardwareKeyResponseHelper
|
||||
import com.kunzisoft.keepass.model.CipherEncryptDatabase
|
||||
import com.kunzisoft.keepass.model.MainCredential
|
||||
import com.kunzisoft.keepass.model.SnapFileDatabaseInfo
|
||||
@@ -82,7 +84,7 @@ import com.kunzisoft.keepass.tasks.ProgressTaskDialogFragment
|
||||
import com.kunzisoft.keepass.tasks.ProgressTaskDialogFragment.Companion.PROGRESS_TASK_DIALOG_TAG
|
||||
import com.kunzisoft.keepass.utils.DATABASE_START_TASK_ACTION
|
||||
import com.kunzisoft.keepass.utils.DATABASE_STOP_TASK_ACTION
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.*
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@@ -111,11 +113,36 @@ class DatabaseTaskProvider {
|
||||
private var progressTaskDialogFragment: ProgressTaskDialogFragment? = null
|
||||
private var databaseChangedDialogFragment: DatabaseChangedDialogFragment? = null
|
||||
|
||||
constructor(activity: FragmentActivity) {
|
||||
// To manage hardware key challenge response
|
||||
private var mHardwareKeyResponseHelper: HardwareKeyResponseHelper? = null
|
||||
|
||||
private var mChallengeResponseData: ByteArray? = null
|
||||
private var mCancelChallengeResponse: Boolean = false
|
||||
|
||||
constructor(activity: FragmentActivity,
|
||||
hardwareKeyResponseHelper: HardwareKeyResponseHelper? = null) {
|
||||
this.activity = activity
|
||||
this.context = activity
|
||||
this.intentDatabaseTask = Intent(activity.applicationContext,
|
||||
DatabaseTaskNotificationService::class.java)
|
||||
|
||||
if (hardwareKeyResponseHelper != null) {
|
||||
this.mHardwareKeyResponseHelper = hardwareKeyResponseHelper
|
||||
this.mHardwareKeyResponseHelper?.buildHardwareKeyResponse { responseData, _ ->
|
||||
// TODO Verify database
|
||||
mChallengeResponseData = responseData ?: ByteArray(0)
|
||||
respondToChallengeIfAllowed()
|
||||
}
|
||||
this.requestChallengeListener = object: DatabaseTaskNotificationService.RequestChallengeListener {
|
||||
override fun onChallengeResponseRequested(hardwareKey: HardwareKey?, seed: ByteArray?) {
|
||||
mHardwareKeyResponseHelper?.launchChallengeForResponse(hardwareKey, seed)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// It's not a credential screen, cancel the challenge response
|
||||
mCancelChallengeResponse = true
|
||||
cancelChallengeResponseIfAllowed()
|
||||
}
|
||||
}
|
||||
|
||||
constructor(service: Service) {
|
||||
@@ -181,6 +208,26 @@ class DatabaseTaskProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private var requestChallengeListener: DatabaseTaskNotificationService.RequestChallengeListener? = null
|
||||
|
||||
private fun respondToChallengeIfAllowed() {
|
||||
// To wait binder and response
|
||||
mBinder?.let { binder ->
|
||||
mChallengeResponseData?.let { responseData ->
|
||||
binder.getService().respondToChallenge(responseData)
|
||||
mChallengeResponseData = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun cancelChallengeResponseIfAllowed() {
|
||||
mBinder?.let { binder ->
|
||||
if (mCancelChallengeResponse) {
|
||||
binder.getService().cancelChallengeResponse()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun startDialog(titleId: Int? = null,
|
||||
messageId: Int? = null,
|
||||
warningId: Int? = null) {
|
||||
@@ -226,25 +273,41 @@ class DatabaseTaskProvider {
|
||||
serviceConnection = object : ServiceConnection {
|
||||
override fun onServiceConnected(name: ComponentName?, serviceBinder: IBinder?) {
|
||||
mBinder = (serviceBinder as DatabaseTaskNotificationService.ActionTaskBinder?)?.apply {
|
||||
addDatabaseListener(databaseListener)
|
||||
addDatabaseFileInfoListener(databaseInfoListener)
|
||||
addActionTaskListener(actionTaskListener)
|
||||
addServiceListeners(this)
|
||||
getService().checkDatabase()
|
||||
getService().checkDatabaseInfo()
|
||||
getService().checkAction()
|
||||
}
|
||||
respondToChallengeIfAllowed()
|
||||
cancelChallengeResponseIfAllowed()
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName?) {
|
||||
mBinder?.removeActionTaskListener(actionTaskListener)
|
||||
mBinder?.removeDatabaseFileInfoListener(databaseInfoListener)
|
||||
mBinder?.removeDatabaseListener(databaseListener)
|
||||
removeServiceListeners(mBinder)
|
||||
mBinder = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addServiceListeners(service: DatabaseTaskNotificationService.ActionTaskBinder?) {
|
||||
service?.addDatabaseListener(databaseListener)
|
||||
service?.addDatabaseFileInfoListener(databaseInfoListener)
|
||||
service?.addActionTaskListener(actionTaskListener)
|
||||
requestChallengeListener?.let {
|
||||
service?.addRequestChallengeListener(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeServiceListeners(service: DatabaseTaskNotificationService.ActionTaskBinder?) {
|
||||
service?.removeActionTaskListener(actionTaskListener)
|
||||
service?.removeDatabaseFileInfoListener(databaseInfoListener)
|
||||
service?.removeDatabaseListener(databaseListener)
|
||||
requestChallengeListener?.let {
|
||||
service?.removeRequestChallengeListener(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindService() {
|
||||
initServiceConnection()
|
||||
serviceConnection?.let {
|
||||
@@ -262,10 +325,6 @@ class DatabaseTaskProvider {
|
||||
serviceConnection = null
|
||||
}
|
||||
|
||||
fun isBinded(): Boolean {
|
||||
return mBinder != null
|
||||
}
|
||||
|
||||
fun registerProgressTask() {
|
||||
stopDialog()
|
||||
|
||||
@@ -299,9 +358,7 @@ class DatabaseTaskProvider {
|
||||
fun unregisterProgressTask() {
|
||||
stopDialog()
|
||||
|
||||
mBinder?.removeActionTaskListener(actionTaskListener)
|
||||
mBinder?.removeDatabaseFileInfoListener(databaseInfoListener)
|
||||
mBinder?.removeDatabaseListener(databaseListener)
|
||||
removeServiceListeners(mBinder)
|
||||
mBinder = null
|
||||
|
||||
unBindService()
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.binary.BinaryData
|
||||
import com.kunzisoft.keepass.database.exception.LoadDatabaseException
|
||||
import com.kunzisoft.keepass.hardware.HardwareKey
|
||||
import com.kunzisoft.keepass.model.CipherEncryptDatabase
|
||||
import com.kunzisoft.keepass.model.MainCredential
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
@@ -37,6 +38,7 @@ class LoadDatabaseRunnable(private val context: Context,
|
||||
private val mDatabase: Database,
|
||||
private val mDatabaseUri: Uri,
|
||||
private val mMainCredential: MainCredential,
|
||||
private val mChallengeResponseRetriever: (hardwareKey: HardwareKey?, seed: ByteArray?) -> ByteArray?,
|
||||
private val mReadonly: Boolean,
|
||||
private val mCipherEncryptDatabase: CipherEncryptDatabase?,
|
||||
private val mFixDuplicateUUID: Boolean,
|
||||
@@ -55,6 +57,7 @@ class LoadDatabaseRunnable(private val context: Context,
|
||||
context.contentResolver,
|
||||
mDatabaseUri,
|
||||
mMainCredential,
|
||||
mChallengeResponseRetriever,
|
||||
mReadonly,
|
||||
UriUtil.getBinaryDir(context),
|
||||
{ memoryWanted ->
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.net.Uri
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.binary.BinaryData
|
||||
import com.kunzisoft.keepass.database.exception.LoadDatabaseException
|
||||
import com.kunzisoft.keepass.hardware.HardwareKey
|
||||
import com.kunzisoft.keepass.model.MainCredential
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
import com.kunzisoft.keepass.tasks.ActionRunnable
|
||||
@@ -33,6 +34,7 @@ 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() {
|
||||
@@ -47,6 +49,7 @@ class MergeDatabaseRunnable(private val context: Context,
|
||||
context.contentResolver,
|
||||
mDatabaseToMergeUri,
|
||||
mDatabaseToMergeMainCredential,
|
||||
mDatabaseToMergeChallengeResponseRetriever,
|
||||
{ memoryWanted ->
|
||||
BinaryData.canMemoryBeAllocatedInRAM(context, memoryWanted)
|
||||
},
|
||||
|
||||
@@ -54,6 +54,7 @@ import com.kunzisoft.keepass.database.file.output.DatabaseOutputKDBX
|
||||
import com.kunzisoft.keepass.database.merge.DatabaseKDBXMerger
|
||||
import com.kunzisoft.keepass.database.search.SearchHelper
|
||||
import com.kunzisoft.keepass.database.search.SearchParameters
|
||||
import com.kunzisoft.keepass.hardware.HardwareKey
|
||||
import com.kunzisoft.keepass.icons.IconDrawableFactory
|
||||
import com.kunzisoft.keepass.model.MainCredential
|
||||
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater
|
||||
@@ -388,6 +389,9 @@ class Database {
|
||||
dataModifiedSinceLastLoading = true
|
||||
}
|
||||
|
||||
val transformSeed: ByteArray?
|
||||
get() = mDatabaseKDB?.transformSeed ?: mDatabaseKDBX?.transformSeed
|
||||
|
||||
var rootGroup: Group?
|
||||
get() {
|
||||
mDatabaseKDB?.rootGroup?.let {
|
||||
@@ -577,6 +581,7 @@ class Database {
|
||||
contentResolver: ContentResolver,
|
||||
databaseUri: Uri,
|
||||
mainCredential: MainCredential,
|
||||
challengeResponseRetriever: (HardwareKey?, ByteArray?) -> ByteArray?,
|
||||
readOnly: Boolean,
|
||||
cacheDirectory: File,
|
||||
isRAMSufficient: (memoryWanted: Long) -> Boolean,
|
||||
@@ -601,11 +606,11 @@ class Database {
|
||||
DatabaseInputKDB(databaseKDB)
|
||||
.openDatabase(databaseInputStream,
|
||||
progressTaskUpdater
|
||||
) {
|
||||
) { seed ->
|
||||
databaseKDB.retrieveMasterKey(
|
||||
mainCredential.masterPassword,
|
||||
getKeyFileData(contentResolver, mainCredential.keyFileUri),
|
||||
mainCredential.hardwareKeyData
|
||||
challengeResponseRetriever.invoke(mainCredential.hardwareKey, seed)
|
||||
)
|
||||
}
|
||||
setDatabaseKDB(databaseKDB)
|
||||
@@ -618,11 +623,11 @@ class Database {
|
||||
DatabaseInputKDBX(databaseKDBX).apply {
|
||||
setMethodToCheckIfRAMIsSufficient(isRAMSufficient)
|
||||
openDatabase(databaseInputStream,
|
||||
progressTaskUpdater) {
|
||||
progressTaskUpdater) { seed ->
|
||||
databaseKDBX.retrieveMasterKey(
|
||||
mainCredential.masterPassword,
|
||||
getKeyFileData(contentResolver, mainCredential.keyFileUri),
|
||||
mainCredential.hardwareKeyData
|
||||
challengeResponseRetriever.invoke(mainCredential.hardwareKey, seed)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -648,6 +653,7 @@ class Database {
|
||||
contentResolver: ContentResolver,
|
||||
databaseToMergeUri: Uri?,
|
||||
databaseToMergeMainCredential: MainCredential?,
|
||||
databaseToMergeChallengeResponseRetriever: (HardwareKey?, ByteArray?) -> ByteArray?,
|
||||
isRAMSufficient: (memoryWanted: Long) -> Boolean,
|
||||
progressTaskUpdater: ProgressTaskUpdater?
|
||||
) {
|
||||
@@ -667,7 +673,7 @@ class Database {
|
||||
{ databaseInputStream ->
|
||||
val databaseToMergeKDB = DatabaseKDB()
|
||||
DatabaseInputKDB(databaseToMergeKDB)
|
||||
.openDatabase(databaseInputStream, progressTaskUpdater) {
|
||||
.openDatabase(databaseInputStream, progressTaskUpdater) { seed ->
|
||||
if (databaseToMergeMainCredential != null) {
|
||||
databaseToMergeKDB.retrieveMasterKey(
|
||||
databaseToMergeMainCredential.masterPassword,
|
||||
@@ -675,10 +681,12 @@ class Database {
|
||||
contentResolver,
|
||||
databaseToMergeMainCredential.keyFileUri,
|
||||
),
|
||||
databaseToMergeMainCredential.hardwareKeyData
|
||||
databaseToMergeChallengeResponseRetriever
|
||||
.invoke(databaseToMergeMainCredential.hardwareKey, seed)
|
||||
)
|
||||
} else {
|
||||
databaseToMergeKDB.masterKey = masterKey
|
||||
databaseToMergeKDB.transformSeed = transformSeed
|
||||
}
|
||||
}
|
||||
setDatabaseKDB(databaseToMergeKDB)
|
||||
@@ -687,7 +695,7 @@ class Database {
|
||||
val databaseToMergeKDBX = DatabaseKDBX()
|
||||
DatabaseInputKDBX(databaseToMergeKDBX).apply {
|
||||
setMethodToCheckIfRAMIsSufficient(isRAMSufficient)
|
||||
openDatabase(databaseInputStream, progressTaskUpdater) {
|
||||
openDatabase(databaseInputStream, progressTaskUpdater) { seed ->
|
||||
if (databaseToMergeMainCredential != null) {
|
||||
databaseToMergeKDBX.retrieveMasterKey(
|
||||
databaseToMergeMainCredential.masterPassword,
|
||||
@@ -695,10 +703,12 @@ class Database {
|
||||
contentResolver,
|
||||
databaseToMergeMainCredential.keyFileUri
|
||||
),
|
||||
databaseToMergeMainCredential.hardwareKeyData
|
||||
databaseToMergeChallengeResponseRetriever
|
||||
.invoke(databaseToMergeMainCredential.hardwareKey, seed)
|
||||
)
|
||||
} else {
|
||||
databaseToMergeKDBX.masterKey = masterKey
|
||||
databaseToMergeKDBX.transformSeed = transformSeed
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -756,6 +766,7 @@ class Database {
|
||||
DatabaseInputKDB(databaseKDB)
|
||||
.openDatabase(databaseInputStream, progressTaskUpdater) {
|
||||
databaseKDB.masterKey = masterKey
|
||||
databaseKDB.transformSeed = transformSeed
|
||||
}
|
||||
setDatabaseKDB(databaseKDB)
|
||||
},
|
||||
@@ -768,6 +779,7 @@ class Database {
|
||||
setMethodToCheckIfRAMIsSufficient(isRAMSufficient)
|
||||
openDatabase(databaseInputStream, progressTaskUpdater) {
|
||||
databaseKDBX.masterKey = masterKey
|
||||
databaseKDBX.transformSeed = transformSeed
|
||||
}
|
||||
}
|
||||
setDatabaseKDBX(databaseKDBX)
|
||||
@@ -880,14 +892,14 @@ class Database {
|
||||
try {
|
||||
outputStream = UriUtil.getUriOutputStream(contentResolver, saveUri)
|
||||
outputStream?.let { definedOutputStream ->
|
||||
// TODO seed
|
||||
val databaseOutput =
|
||||
mDatabaseKDB?.let { DatabaseOutputKDB(it, definedOutputStream) }
|
||||
?: mDatabaseKDBX?.let {
|
||||
DatabaseOutputKDBX(
|
||||
it,
|
||||
definedOutputStream
|
||||
)
|
||||
}
|
||||
mDatabaseKDB?.let {
|
||||
DatabaseOutputKDB(it, definedOutputStream)
|
||||
}
|
||||
?: mDatabaseKDBX?.let {
|
||||
DatabaseOutputKDBX(it, definedOutputStream)
|
||||
}
|
||||
databaseOutput?.output()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
@@ -959,17 +971,18 @@ class Database {
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun assignMasterKey(contentResolver: ContentResolver,
|
||||
mainCredential: MainCredential) {
|
||||
mainCredential: MainCredential,
|
||||
challengeResponseRetriever: (HardwareKey?, ByteArray?) -> ByteArray?) {
|
||||
val keyFileData = getKeyFileData(contentResolver, mainCredential.keyFileUri)
|
||||
mDatabaseKDB?.retrieveMasterKey(
|
||||
mainCredential.masterPassword,
|
||||
keyFileData,
|
||||
mainCredential.hardwareKeyData
|
||||
challengeResponseRetriever.invoke(mainCredential.hardwareKey, mDatabaseKDB?.transformSeed)
|
||||
)
|
||||
mDatabaseKDBX?.retrieveMasterKey(
|
||||
mainCredential.masterPassword,
|
||||
keyFileData,
|
||||
mainCredential.hardwareKeyData
|
||||
challengeResponseRetriever.invoke(mainCredential.hardwareKey, mDatabaseKDBX?.transformSeed)
|
||||
)
|
||||
mDatabaseKDBX?.keyLastChanged = DateInstant()
|
||||
}
|
||||
|
||||
@@ -61,6 +61,8 @@ abstract class DatabaseVersioned<
|
||||
var finalKey: ByteArray? = null
|
||||
protected set
|
||||
|
||||
var transformSeed: ByteArray? = null
|
||||
|
||||
abstract val version: String
|
||||
abstract val defaultFileExtension: String
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@ class InvalidCredentialsDatabaseException : LoadDatabaseException {
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.invalid_credentials
|
||||
constructor() : super()
|
||||
constructor(string: String) : super(string)
|
||||
constructor(exception: Throwable) : super(exception)
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ abstract class DatabaseInput<D : DatabaseVersioned<*, *, *, *>> (protected var m
|
||||
@Throws(LoadDatabaseException::class)
|
||||
abstract fun openDatabase(databaseInputStream: InputStream,
|
||||
progressTaskUpdater: ProgressTaskUpdater?,
|
||||
assignMasterKey: (() -> Unit)): D
|
||||
assignMasterKey: ((seed: ByteArray?) -> Unit)): D
|
||||
|
||||
protected fun startKeyTimer(progressTaskUpdater: ProgressTaskUpdater?) {
|
||||
progressTaskUpdater?.updateMessage(R.string.retrieving_db_key)
|
||||
|
||||
@@ -50,7 +50,7 @@ class DatabaseInputKDB(database: DatabaseKDB)
|
||||
@Throws(LoadDatabaseException::class)
|
||||
override fun openDatabase(databaseInputStream: InputStream,
|
||||
progressTaskUpdater: ProgressTaskUpdater?,
|
||||
assignMasterKey: (() -> Unit)): DatabaseKDB {
|
||||
assignMasterKey: ((seed: ByteArray?) -> Unit)): DatabaseKDB {
|
||||
|
||||
try {
|
||||
startKeyTimer(progressTaskUpdater)
|
||||
@@ -76,7 +76,8 @@ class DatabaseInputKDB(database: DatabaseKDB)
|
||||
throw VersionDatabaseException()
|
||||
}
|
||||
|
||||
assignMasterKey.invoke()
|
||||
mDatabase.transformSeed = header.transformSeed
|
||||
assignMasterKey.invoke(header.transformSeed)
|
||||
|
||||
// Select algorithm
|
||||
when {
|
||||
|
||||
@@ -46,6 +46,7 @@ import com.kunzisoft.keepass.stream.HashedBlockInputStream
|
||||
import com.kunzisoft.keepass.stream.HmacBlockInputStream
|
||||
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater
|
||||
import com.kunzisoft.keepass.utils.*
|
||||
import kotlinx.coroutines.yield
|
||||
import org.xmlpull.v1.XmlPullParser
|
||||
import org.xmlpull.v1.XmlPullParserException
|
||||
import org.xmlpull.v1.XmlPullParserFactory
|
||||
@@ -102,7 +103,7 @@ class DatabaseInputKDBX(database: DatabaseKDBX)
|
||||
@Throws(LoadDatabaseException::class)
|
||||
override fun openDatabase(databaseInputStream: InputStream,
|
||||
progressTaskUpdater: ProgressTaskUpdater?,
|
||||
assignMasterKey: (() -> Unit)): DatabaseKDBX {
|
||||
assignMasterKey: ((seed: ByteArray?) -> Unit)): DatabaseKDBX {
|
||||
try {
|
||||
startKeyTimer(progressTaskUpdater)
|
||||
|
||||
@@ -114,7 +115,9 @@ class DatabaseInputKDBX(database: DatabaseKDBX)
|
||||
hashOfHeader = headerAndHash.hash
|
||||
val pbHeader = headerAndHash.header
|
||||
|
||||
assignMasterKey.invoke()
|
||||
val transformSeed = header.transformSeed
|
||||
mDatabase.transformSeed = transformSeed
|
||||
assignMasterKey.invoke(transformSeed)
|
||||
mDatabase.makeFinalKey(header.masterSeed)
|
||||
|
||||
stopKeyTimer()
|
||||
|
||||
@@ -2,16 +2,15 @@ package com.kunzisoft.keepass.hardware
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.ActivityResult
|
||||
import androidx.activity.result.ActivityResultCallback
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
|
||||
class HardwareKeyResponseHelper {
|
||||
|
||||
@@ -30,17 +29,19 @@ class HardwareKeyResponseHelper {
|
||||
this.fragment = context
|
||||
}
|
||||
|
||||
fun buildHardwareKeyResponse(onChallengeResponded: ((challengeResponse:ByteArray?,
|
||||
extra: Bundle?) -> Unit)?) {
|
||||
fun buildHardwareKeyResponse(onChallengeResponded: (challengeResponse: ByteArray?,
|
||||
extra: Bundle?) -> Unit) {
|
||||
val resultCallback = ActivityResultCallback<ActivityResult> { result ->
|
||||
Log.d(TAG, "resultCode from ykdroid: " + result.resultCode)
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
val challengeResponse: ByteArray? = result.data?.getByteArrayExtra("response")
|
||||
Log.d(TAG, "Response: " + challengeResponse.contentToString())
|
||||
challengeResponse?.let {
|
||||
onChallengeResponded?.invoke(challengeResponse,
|
||||
result.data?.getBundleExtra(EXTRA_BUNDLE_KEY))
|
||||
}
|
||||
onChallengeResponded.invoke(challengeResponse,
|
||||
result.data?.getBundleExtra(EXTRA_BUNDLE_KEY))
|
||||
} else {
|
||||
Log.e(TAG, "Response error")
|
||||
onChallengeResponded.invoke(null,
|
||||
result.data?.getBundleExtra(EXTRA_BUNDLE_KEY))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,19 +58,40 @@ class HardwareKeyResponseHelper {
|
||||
}
|
||||
}
|
||||
|
||||
fun launchChallengeForResponse(databaseUri: Uri, extra: Bundle? = null) {
|
||||
fun launchChallengeForResponse(hardwareKey: HardwareKey?, seed: ByteArray?) {
|
||||
try {
|
||||
fragment?.context?.contentResolver ?: activity?.contentResolver ?.let { contentResolver ->
|
||||
Database.getTransformSeed(contentResolver, databaseUri) { seed ->
|
||||
when (hardwareKey) {
|
||||
HardwareKey.CHALLENGE_RESPONSE_YUBIKEY -> {
|
||||
// Transform the seed before sending
|
||||
var challenge: ByteArray? = null
|
||||
if (seed != null) {
|
||||
challenge = ByteArray(64)
|
||||
seed.copyInto(challenge, 0, 0, 32)
|
||||
challenge.fill(32, 32, 64)
|
||||
}
|
||||
// Send to the driver
|
||||
getChallengeResponseResultLauncher?.launch(Intent(YKDROID_CHALLENGE_RESPONSE_INTENT).apply {
|
||||
putExtra(YKDROID_SEED_KEY, seed)
|
||||
putExtra(EXTRA_BUNDLE_KEY, extra)
|
||||
putExtra(YKDROID_SEED_KEY, challenge)
|
||||
})
|
||||
Log.d(TAG, "Challenge sent : " + seed.contentToString())
|
||||
Log.d(TAG, "Challenge sent : " + challenge.contentToString())
|
||||
}
|
||||
else -> {
|
||||
// TODO other algorithm
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Could not launch challenge for response", e)
|
||||
Log.e(
|
||||
TAG,
|
||||
"Unable to retrieve the challenge response",
|
||||
e
|
||||
)
|
||||
e.message?.let { message ->
|
||||
Toast.makeText(
|
||||
activity,
|
||||
message,
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,32 +21,24 @@ package com.kunzisoft.keepass.model
|
||||
import android.net.Uri
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.hardware.HardwareKey
|
||||
import com.kunzisoft.keepass.utils.readEnum
|
||||
import com.kunzisoft.keepass.utils.writeEnum
|
||||
|
||||
data class MainCredential(var masterPassword: String? = null,
|
||||
var keyFileUri: Uri? = null,
|
||||
var hardwareKeyData: ByteArray? = null): Parcelable {
|
||||
var hardwareKey: HardwareKey? = null): Parcelable {
|
||||
|
||||
constructor(parcel: Parcel) : this() {
|
||||
masterPassword = parcel.readString()
|
||||
keyFileUri = parcel.readParcelable(Uri::class.java.classLoader)
|
||||
val hardwareKeyDataLength = parcel.readInt()
|
||||
if (hardwareKeyDataLength >= 0) {
|
||||
hardwareKeyData = ByteArray(hardwareKeyDataLength)
|
||||
parcel.readByteArray(hardwareKeyData!!)
|
||||
} else {
|
||||
hardwareKeyData = null
|
||||
}
|
||||
hardwareKey = parcel.readEnum<HardwareKey>()
|
||||
}
|
||||
|
||||
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||
parcel.writeString(masterPassword)
|
||||
parcel.writeParcelable(keyFileUri, flags)
|
||||
if (hardwareKeyData != null) {
|
||||
parcel.writeInt(hardwareKeyData!!.size)
|
||||
parcel.writeByteArray(hardwareKeyData)
|
||||
} else {
|
||||
parcel.writeInt(-1)
|
||||
}
|
||||
parcel.writeEnum(hardwareKey)
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
@@ -61,10 +53,7 @@ data class MainCredential(var masterPassword: String? = null,
|
||||
|
||||
if (masterPassword != other.masterPassword) return false
|
||||
if (keyFileUri != other.keyFileUri) return false
|
||||
if (hardwareKeyData != null) {
|
||||
if (other.hardwareKeyData == null) return false
|
||||
if (!hardwareKeyData.contentEquals(other.hardwareKeyData)) return false
|
||||
} else if (other.hardwareKeyData != null) return false
|
||||
if (hardwareKey != other.hardwareKey) return false
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -72,7 +61,7 @@ data class MainCredential(var masterPassword: String? = null,
|
||||
override fun hashCode(): Int {
|
||||
var result = masterPassword?.hashCode() ?: 0
|
||||
result = 31 * result + (keyFileUri?.hashCode() ?: 0)
|
||||
result = 31 * result + (hardwareKeyData?.contentHashCode() ?: 0)
|
||||
result = 31 * result + (hardwareKey?.hashCode() ?: 0)
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
+90
-13
@@ -41,6 +41,8 @@ import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.database.exception.InvalidCredentialsDatabaseException
|
||||
import com.kunzisoft.keepass.hardware.HardwareKey
|
||||
import com.kunzisoft.keepass.model.CipherEncryptDatabase
|
||||
import com.kunzisoft.keepass.model.MainCredential
|
||||
import com.kunzisoft.keepass.model.SnapFileDatabaseInfo
|
||||
@@ -53,6 +55,7 @@ import com.kunzisoft.keepass.utils.LOCK_ACTION
|
||||
import com.kunzisoft.keepass.utils.closeDatabase
|
||||
import com.kunzisoft.keepass.viewmodels.FileDatabaseInfo
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import java.util.*
|
||||
|
||||
open class DatabaseTaskNotificationService : LockNotificationService(), ProgressTaskUpdater {
|
||||
@@ -63,10 +66,14 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
||||
|
||||
private val mainScope = CoroutineScope(Dispatchers.Main)
|
||||
|
||||
private var mDatabaseListeners = LinkedList<DatabaseListener>()
|
||||
private var mDatabaseInfoListeners = LinkedList<DatabaseInfoListener>()
|
||||
private var mDatabaseListeners = mutableListOf<DatabaseListener>()
|
||||
private var mDatabaseInfoListeners = mutableListOf<DatabaseInfoListener>()
|
||||
private var mActionTaskBinder = ActionTaskBinder()
|
||||
private var mActionTaskListeners = LinkedList<ActionTaskListener>()
|
||||
private var mActionTaskListeners = mutableListOf<ActionTaskListener>()
|
||||
// Channel to connect asynchronously a listener or a response
|
||||
private var mRequestChallengeListenerChannel = Channel<RequestChallengeListener?>(0)
|
||||
private var mResponseChallengeChannel = Channel<ByteArray?>(0)
|
||||
|
||||
private var mActionRunning = false
|
||||
private var mTaskRemovedRequested = false
|
||||
private var mCreationState = false
|
||||
@@ -76,6 +83,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
||||
private var mMessageId: Int? = null
|
||||
private var mWarningId: Int? = null
|
||||
|
||||
|
||||
override fun retrieveChannelId(): String {
|
||||
return CHANNEL_DATABASE_ID
|
||||
}
|
||||
@@ -114,6 +122,23 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
||||
fun removeActionTaskListener(actionTaskListener: ActionTaskListener) {
|
||||
mActionTaskListeners.remove(actionTaskListener)
|
||||
}
|
||||
|
||||
fun addRequestChallengeListener(requestChallengeListener: RequestChallengeListener) {
|
||||
mainScope.launch {
|
||||
if (!mRequestChallengeListenerChannel.isEmpty) {
|
||||
mRequestChallengeListenerChannel.cancel(CancellationException("Challenge already requested"))
|
||||
mRequestChallengeListenerChannel = Channel(0)
|
||||
} else {
|
||||
mRequestChallengeListenerChannel.send(requestChallengeListener)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun removeRequestChallengeListener(requestChallengeListener: RequestChallengeListener) {
|
||||
mainScope.launch {
|
||||
//mRequestChallengeListenerChannel.cancel()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface DatabaseListener {
|
||||
@@ -131,6 +156,10 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
||||
fun onStopAction(database: Database, actionTask: String, result: ActionRunnable.Result)
|
||||
}
|
||||
|
||||
interface RequestChallengeListener {
|
||||
fun onChallengeResponseRequested(hardwareKey: HardwareKey?, seed: ByteArray?)
|
||||
}
|
||||
|
||||
fun checkDatabase() {
|
||||
mDatabaseListeners.forEach { databaseListener ->
|
||||
databaseListener.onDatabaseRetrieved(mDatabase)
|
||||
@@ -203,6 +232,26 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
||||
}
|
||||
}
|
||||
|
||||
fun respondToChallenge(response: ByteArray) {
|
||||
mainScope.launch {
|
||||
if (response.isEmpty()) {
|
||||
mResponseChallengeChannel.cancel(CancellationException(("Unable to get the response from challenge")))
|
||||
mResponseChallengeChannel = Channel(0)
|
||||
} else {
|
||||
mResponseChallengeChannel.send(response)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun cancelChallengeResponse() {
|
||||
mainScope.launch {
|
||||
mRequestChallengeListenerChannel.cancel()
|
||||
mRequestChallengeListenerChannel = Channel(0)
|
||||
mResponseChallengeChannel.cancel()
|
||||
mResponseChallengeChannel = Channel(0)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBind(intent: Intent): IBinder? {
|
||||
super.onBind(intent)
|
||||
return mActionTaskBinder
|
||||
@@ -539,6 +588,22 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
||||
super.onTaskRemoved(rootIntent)
|
||||
}
|
||||
|
||||
private fun retrieveResponseFromChallenge(hardwareKey: HardwareKey?,
|
||||
seed: ByteArray?): ByteArray? {
|
||||
if (hardwareKey == null || seed == null)
|
||||
return null
|
||||
// Request a challenge - response
|
||||
var response: ByteArray?
|
||||
runBlocking {
|
||||
// Send the request
|
||||
val challengeResponseRequestListener = mRequestChallengeListenerChannel.receive()
|
||||
challengeResponseRequestListener?.onChallengeResponseRequested(hardwareKey, seed)
|
||||
// Wait the response
|
||||
response = mResponseChallengeChannel.receive()
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
private fun buildDatabaseCreateActionTask(intent: Intent, database: Database): ActionRunnable? {
|
||||
|
||||
if (intent.hasExtra(DATABASE_URI_KEY)
|
||||
@@ -558,7 +623,10 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
||||
getString(R.string.database_default_name),
|
||||
getString(R.string.database),
|
||||
getString(R.string.template_group_name),
|
||||
mainCredential
|
||||
mainCredential,
|
||||
{ hardwareKey, seed ->
|
||||
retrieveResponseFromChallenge(hardwareKey, seed)
|
||||
}
|
||||
) { result ->
|
||||
result.data = Bundle().apply {
|
||||
putParcelable(DATABASE_URI_KEY, databaseUri)
|
||||
@@ -589,14 +657,17 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
||||
mCreationState = false
|
||||
|
||||
return LoadDatabaseRunnable(
|
||||
this,
|
||||
database,
|
||||
databaseUri,
|
||||
mainCredential,
|
||||
readOnly,
|
||||
cipherEncryptDatabase,
|
||||
intent.getBooleanExtra(FIX_DUPLICATE_UUID_KEY, false),
|
||||
this
|
||||
this,
|
||||
database,
|
||||
databaseUri,
|
||||
mainCredential,
|
||||
{ hardwareKey, seed ->
|
||||
retrieveResponseFromChallenge(hardwareKey, seed)
|
||||
},
|
||||
readOnly,
|
||||
cipherEncryptDatabase,
|
||||
intent.getBooleanExtra(FIX_DUPLICATE_UUID_KEY, false),
|
||||
this
|
||||
) { result ->
|
||||
// Add each info to reload database after thrown duplicate UUID exception
|
||||
result.data = Bundle().apply {
|
||||
@@ -626,6 +697,9 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
||||
database,
|
||||
databaseToMergeUri,
|
||||
databaseToMergeMainCredential,
|
||||
{ hardwareKey, seed ->
|
||||
retrieveResponseFromChallenge(hardwareKey, seed)
|
||||
},
|
||||
this
|
||||
) { result ->
|
||||
// No need to add each info to reload database
|
||||
@@ -652,7 +726,10 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
||||
AssignMainCredentialInDatabaseRunnable(this,
|
||||
database,
|
||||
databaseUri,
|
||||
intent.getParcelableExtra(MAIN_CREDENTIAL_KEY) ?: MainCredential()
|
||||
intent.getParcelableExtra(MAIN_CREDENTIAL_KEY) ?: MainCredential(),
|
||||
{ hardwareKey, seed ->
|
||||
retrieveResponseFromChallenge(hardwareKey, seed)
|
||||
}
|
||||
)
|
||||
} else {
|
||||
null
|
||||
|
||||
@@ -30,12 +30,14 @@ import android.view.KeyEvent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.*
|
||||
import android.widget.CompoundButton
|
||||
import android.widget.EditText
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.helpers.ExternalFileHelper
|
||||
import com.kunzisoft.keepass.activities.helpers.setOpenDocumentClickListener
|
||||
import com.kunzisoft.keepass.hardware.HardwareKey
|
||||
import com.kunzisoft.keepass.model.CredentialStorage
|
||||
import com.kunzisoft.keepass.model.MainCredential
|
||||
|
||||
@@ -55,9 +57,6 @@ class MainCredentialView @JvmOverloads constructor(context: Context,
|
||||
var onKeyFileChecked: (CompoundButton.OnCheckedChangeListener)? = null
|
||||
var onHardwareKeyChecked: (CompoundButton.OnCheckedChangeListener)? = null
|
||||
var onValidateListener: (() -> Unit)? = null
|
||||
var onRequestHardwareKeyResponse: ((HardwareKey)-> Unit)? = null
|
||||
|
||||
private var mChallengeResponse: ByteArray? = null
|
||||
|
||||
private var mCredentialStorage: CredentialStorage = CredentialStorage.PASSWORD
|
||||
|
||||
@@ -119,15 +118,8 @@ class MainCredentialView @JvmOverloads constructor(context: Context,
|
||||
}
|
||||
}
|
||||
|
||||
fun validateCredential(hardwareKeyData: ByteArray? = null) {
|
||||
val hardwareKey = hardwareKeySelectionView.hardwareKey
|
||||
if (hardwareKeyData == null && checkboxHardwareView.isChecked) {
|
||||
onRequestHardwareKeyResponse?.invoke(hardwareKey)
|
||||
} else {
|
||||
mChallengeResponse = hardwareKeyData
|
||||
onValidateListener?.invoke()
|
||||
mChallengeResponse = null
|
||||
}
|
||||
fun validateCredential() {
|
||||
onValidateListener?.invoke()
|
||||
}
|
||||
|
||||
fun populatePasswordTextView(text: String?) {
|
||||
@@ -170,8 +162,8 @@ class MainCredentialView @JvmOverloads constructor(context: Context,
|
||||
passwordTextView.text?.toString() else null
|
||||
this.keyFileUri = if (checkboxKeyFileView.isChecked)
|
||||
keyFileSelectionView.uri else null
|
||||
this.hardwareKeyData = if (checkboxHardwareView.isChecked)
|
||||
mChallengeResponse else null
|
||||
this.hardwareKey = if (checkboxHardwareView.isChecked)
|
||||
hardwareKeySelectionView.hardwareKey else null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user