mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Fix reloading database
This commit is contained in:
@@ -55,6 +55,7 @@ class LoadDatabaseRunnable(private val context: Context,
|
|||||||
mReadonly,
|
mReadonly,
|
||||||
context.contentResolver,
|
context.contentResolver,
|
||||||
UriUtil.getBinaryDir(context),
|
UriUtil.getBinaryDir(context),
|
||||||
|
Database.LoadedKey.generateNewCipherKey(),
|
||||||
mFixDuplicateUUID,
|
mFixDuplicateUUID,
|
||||||
progressTaskUpdater)
|
progressTaskUpdater)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,10 @@ class ReloadDatabaseRunnable(private val context: Context,
|
|||||||
private val mLoadDatabaseResult: ((Result) -> Unit)?)
|
private val mLoadDatabaseResult: ((Result) -> Unit)?)
|
||||||
: ActionRunnable() {
|
: ActionRunnable() {
|
||||||
|
|
||||||
|
private var tempCipherKey: Database.LoadedKey? = null
|
||||||
|
|
||||||
override fun onStartRun() {
|
override fun onStartRun() {
|
||||||
|
tempCipherKey = mDatabase.loadedCipherKey
|
||||||
// Clear before we load
|
// Clear before we load
|
||||||
mDatabase.clear(UriUtil.getBinaryDir(context))
|
mDatabase.clear(UriUtil.getBinaryDir(context))
|
||||||
}
|
}
|
||||||
@@ -42,6 +45,7 @@ class ReloadDatabaseRunnable(private val context: Context,
|
|||||||
try {
|
try {
|
||||||
mDatabase.reloadData(context.contentResolver,
|
mDatabase.reloadData(context.contentResolver,
|
||||||
UriUtil.getBinaryDir(context),
|
UriUtil.getBinaryDir(context),
|
||||||
|
tempCipherKey ?: Database.LoadedKey.generateNewCipherKey(),
|
||||||
progressTaskUpdater)
|
progressTaskUpdater)
|
||||||
} catch (e: LoadDatabaseException) {
|
} catch (e: LoadDatabaseException) {
|
||||||
setError(e)
|
setError(e)
|
||||||
@@ -51,6 +55,7 @@ class ReloadDatabaseRunnable(private val context: Context,
|
|||||||
// Register the current time to init the lock timer
|
// Register the current time to init the lock timer
|
||||||
PreferencesUtil.saveCurrentTime(context)
|
PreferencesUtil.saveCurrentTime(context)
|
||||||
} else {
|
} else {
|
||||||
|
tempCipherKey = null
|
||||||
mDatabase.clearAndClose(UriUtil.getBinaryDir(context))
|
mDatabase.clearAndClose(UriUtil.getBinaryDir(context))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -411,6 +411,7 @@ class Database {
|
|||||||
readOnly: Boolean,
|
readOnly: Boolean,
|
||||||
contentResolver: ContentResolver,
|
contentResolver: ContentResolver,
|
||||||
cacheDirectory: File,
|
cacheDirectory: File,
|
||||||
|
tempCipherKey: LoadedKey,
|
||||||
fixDuplicateUUID: Boolean,
|
fixDuplicateUUID: Boolean,
|
||||||
progressTaskUpdater: ProgressTaskUpdater?) {
|
progressTaskUpdater: ProgressTaskUpdater?) {
|
||||||
|
|
||||||
@@ -435,7 +436,7 @@ class Database {
|
|||||||
.openDatabase(databaseInputStream,
|
.openDatabase(databaseInputStream,
|
||||||
mainCredential.masterPassword,
|
mainCredential.masterPassword,
|
||||||
keyFileInputStream,
|
keyFileInputStream,
|
||||||
LoadedKey.generateNewCipherKey(),
|
tempCipherKey,
|
||||||
progressTaskUpdater,
|
progressTaskUpdater,
|
||||||
fixDuplicateUUID)
|
fixDuplicateUUID)
|
||||||
},
|
},
|
||||||
@@ -444,7 +445,7 @@ class Database {
|
|||||||
.openDatabase(databaseInputStream,
|
.openDatabase(databaseInputStream,
|
||||||
mainCredential.masterPassword,
|
mainCredential.masterPassword,
|
||||||
keyFileInputStream,
|
keyFileInputStream,
|
||||||
LoadedKey.generateNewCipherKey(),
|
tempCipherKey,
|
||||||
progressTaskUpdater,
|
progressTaskUpdater,
|
||||||
fixDuplicateUUID)
|
fixDuplicateUUID)
|
||||||
}
|
}
|
||||||
@@ -464,6 +465,7 @@ class Database {
|
|||||||
@Throws(LoadDatabaseException::class)
|
@Throws(LoadDatabaseException::class)
|
||||||
fun reloadData(contentResolver: ContentResolver,
|
fun reloadData(contentResolver: ContentResolver,
|
||||||
cacheDirectory: File,
|
cacheDirectory: File,
|
||||||
|
tempCipherKey: LoadedKey,
|
||||||
progressTaskUpdater: ProgressTaskUpdater?) {
|
progressTaskUpdater: ProgressTaskUpdater?) {
|
||||||
|
|
||||||
// Retrieve the stream from the old database URI
|
// Retrieve the stream from the old database URI
|
||||||
@@ -474,12 +476,14 @@ class Database {
|
|||||||
DatabaseInputKDB(cacheDirectory)
|
DatabaseInputKDB(cacheDirectory)
|
||||||
.openDatabase(databaseInputStream,
|
.openDatabase(databaseInputStream,
|
||||||
masterKey,
|
masterKey,
|
||||||
|
tempCipherKey,
|
||||||
progressTaskUpdater)
|
progressTaskUpdater)
|
||||||
},
|
},
|
||||||
{ databaseInputStream ->
|
{ databaseInputStream ->
|
||||||
DatabaseInputKDBX(cacheDirectory)
|
DatabaseInputKDBX(cacheDirectory)
|
||||||
.openDatabase(databaseInputStream,
|
.openDatabase(databaseInputStream,
|
||||||
masterKey,
|
masterKey,
|
||||||
|
tempCipherKey,
|
||||||
progressTaskUpdater)
|
progressTaskUpdater)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -38,19 +38,6 @@ abstract class DatabaseInput<PwDb : DatabaseVersioned<*, *, *, *>>
|
|||||||
*
|
*
|
||||||
* @throws LoadDatabaseException on database error (contains IO exceptions)
|
* @throws LoadDatabaseException on database error (contains IO exceptions)
|
||||||
*/
|
*/
|
||||||
@Throws(LoadDatabaseException::class)
|
|
||||||
abstract fun openDatabase(databaseInputStream: InputStream,
|
|
||||||
password: String?,
|
|
||||||
keyfileInputStream: InputStream?,
|
|
||||||
progressTaskUpdater: ProgressTaskUpdater?,
|
|
||||||
fixDuplicateUUID: Boolean = false): PwDb
|
|
||||||
|
|
||||||
|
|
||||||
@Throws(LoadDatabaseException::class)
|
|
||||||
abstract fun openDatabase(databaseInputStream: InputStream,
|
|
||||||
masterKey: ByteArray,
|
|
||||||
progressTaskUpdater: ProgressTaskUpdater?,
|
|
||||||
fixDuplicateUUID: Boolean = false): PwDb
|
|
||||||
|
|
||||||
@Throws(LoadDatabaseException::class)
|
@Throws(LoadDatabaseException::class)
|
||||||
abstract fun openDatabase(databaseInputStream: InputStream,
|
abstract fun openDatabase(databaseInputStream: InputStream,
|
||||||
|
|||||||
@@ -51,28 +51,6 @@ class DatabaseInputKDB(cacheDirectory: File)
|
|||||||
|
|
||||||
private lateinit var mDatabase: DatabaseKDB
|
private lateinit var mDatabase: DatabaseKDB
|
||||||
|
|
||||||
@Throws(LoadDatabaseException::class)
|
|
||||||
override fun openDatabase(databaseInputStream: InputStream,
|
|
||||||
password: String?,
|
|
||||||
keyfileInputStream: InputStream?,
|
|
||||||
progressTaskUpdater: ProgressTaskUpdater?,
|
|
||||||
fixDuplicateUUID: Boolean): DatabaseKDB {
|
|
||||||
return openDatabase(databaseInputStream, progressTaskUpdater, fixDuplicateUUID) {
|
|
||||||
mDatabase.retrieveMasterKey(password, keyfileInputStream)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Throws(LoadDatabaseException::class)
|
|
||||||
override fun openDatabase(databaseInputStream: InputStream,
|
|
||||||
masterKey: ByteArray,
|
|
||||||
progressTaskUpdater: ProgressTaskUpdater?,
|
|
||||||
fixDuplicateUUID: Boolean): DatabaseKDB {
|
|
||||||
return openDatabase(databaseInputStream, progressTaskUpdater, fixDuplicateUUID) {
|
|
||||||
mDatabase.masterKey = masterKey
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Throws(LoadDatabaseException::class)
|
@Throws(LoadDatabaseException::class)
|
||||||
override fun openDatabase(databaseInputStream: InputStream,
|
override fun openDatabase(databaseInputStream: InputStream,
|
||||||
password: String?,
|
password: String?,
|
||||||
|
|||||||
@@ -94,27 +94,6 @@ class DatabaseInputKDBX(cacheDirectory: File)
|
|||||||
private var entryCustomDataKey: String? = null
|
private var entryCustomDataKey: String? = null
|
||||||
private var entryCustomDataValue: String? = null
|
private var entryCustomDataValue: String? = null
|
||||||
|
|
||||||
@Throws(LoadDatabaseException::class)
|
|
||||||
override fun openDatabase(databaseInputStream: InputStream,
|
|
||||||
password: String?,
|
|
||||||
keyfileInputStream: InputStream?,
|
|
||||||
progressTaskUpdater: ProgressTaskUpdater?,
|
|
||||||
fixDuplicateUUID: Boolean): DatabaseKDBX {
|
|
||||||
return openDatabase(databaseInputStream, progressTaskUpdater, fixDuplicateUUID) {
|
|
||||||
mDatabase.retrieveMasterKey(password, keyfileInputStream)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Throws(LoadDatabaseException::class)
|
|
||||||
override fun openDatabase(databaseInputStream: InputStream,
|
|
||||||
masterKey: ByteArray,
|
|
||||||
progressTaskUpdater: ProgressTaskUpdater?,
|
|
||||||
fixDuplicateUUID: Boolean): DatabaseKDBX {
|
|
||||||
return openDatabase(databaseInputStream, progressTaskUpdater, fixDuplicateUUID) {
|
|
||||||
mDatabase.masterKey = masterKey
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Throws(LoadDatabaseException::class)
|
@Throws(LoadDatabaseException::class)
|
||||||
override fun openDatabase(databaseInputStream: InputStream,
|
override fun openDatabase(databaseInputStream: InputStream,
|
||||||
password: String?,
|
password: String?,
|
||||||
|
|||||||
Reference in New Issue
Block a user