From 151a5a7e73a24b71ca1b32933041f566466b533e Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Wed, 24 Mar 2021 18:08:11 +0100 Subject: [PATCH] Select Twofish with KDB database --- .../kunzisoft/keepass/database/element/Database.kt | 3 --- .../database/element/database/DatabaseKDB.kt | 1 + .../database/file/output/DatabaseOutputKDB.kt | 6 +++--- ...ptionAlgorithmPreferenceDialogFragmentCompat.kt | 14 ++++++-------- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/kunzisoft/keepass/database/element/Database.kt b/app/src/main/java/com/kunzisoft/keepass/database/element/Database.kt index 2ef80fc93..7c70cf018 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/element/Database.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/element/Database.kt @@ -238,9 +238,6 @@ class Database { val allowNoMasterKey: Boolean get() = mDatabaseKDBX != null - val allowEncryptionAlgorithmModification: Boolean - get() = availableEncryptionAlgorithms.size > 1 - fun getEncryptionAlgorithmName(): String { return mDatabaseKDB?.encryptionAlgorithm?.toString() ?: mDatabaseKDBX?.encryptionAlgorithm?.toString() diff --git a/app/src/main/java/com/kunzisoft/keepass/database/element/database/DatabaseKDB.kt b/app/src/main/java/com/kunzisoft/keepass/database/element/database/DatabaseKDB.kt index ff8282bd2..73dd14155 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/element/database/DatabaseKDB.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/element/database/DatabaseKDB.kt @@ -77,6 +77,7 @@ class DatabaseKDB : DatabaseVersioned() { get() { val list = ArrayList() list.add(EncryptionAlgorithm.AESRijndael) + list.add(EncryptionAlgorithm.Twofish) return list } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/file/output/DatabaseOutputKDB.kt b/app/src/main/java/com/kunzisoft/keepass/database/file/output/DatabaseOutputKDB.kt index 390c68a5f..af52bd05d 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/file/output/DatabaseOutputKDB.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/file/output/DatabaseOutputKDB.kt @@ -105,11 +105,11 @@ class DatabaseOutputKDB(private val mDatabaseKDB: DatabaseKDB, header.signature2 = DatabaseHeaderKDB.DBSIG_2 header.flags = DatabaseHeaderKDB.FLAG_SHA2 - when { - mDatabaseKDB.encryptionAlgorithm === EncryptionAlgorithm.AESRijndael -> { + when (mDatabaseKDB.encryptionAlgorithm) { + EncryptionAlgorithm.AESRijndael -> { header.flags = UnsignedInt(header.flags.toKotlinInt() or DatabaseHeaderKDB.FLAG_RIJNDAEL.toKotlinInt()) } - mDatabaseKDB.encryptionAlgorithm === EncryptionAlgorithm.Twofish -> { + EncryptionAlgorithm.Twofish -> { header.flags = UnsignedInt(header.flags.toKotlinInt() or DatabaseHeaderKDB.FLAG_TWOFISH.toKotlinInt()) } else -> throw DatabaseOutputException("Unsupported algorithm.") diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preferencedialogfragment/DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat.kt b/app/src/main/java/com/kunzisoft/keepass/settings/preferencedialogfragment/DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat.kt index caba06881..a63c3b770 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/preferencedialogfragment/DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat.kt +++ b/app/src/main/java/com/kunzisoft/keepass/settings/preferencedialogfragment/DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat.kt @@ -58,15 +58,13 @@ class DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat if (positiveResult) { database?.let { database -> - if (database.allowEncryptionAlgorithmModification) { - if (algorithmSelected != null) { - val newAlgorithm = algorithmSelected - val oldAlgorithm = database.encryptionAlgorithm - database.encryptionAlgorithm = newAlgorithm + if (algorithmSelected != null) { + val newAlgorithm = algorithmSelected + val oldAlgorithm = database.encryptionAlgorithm + database.encryptionAlgorithm = newAlgorithm - if (oldAlgorithm != null && newAlgorithm != null) - mProgressDatabaseTaskProvider?.startDatabaseSaveEncryption(oldAlgorithm, newAlgorithm, mDatabaseAutoSaveEnable) - } + if (oldAlgorithm != null && newAlgorithm != null) + mProgressDatabaseTaskProvider?.startDatabaseSaveEncryption(oldAlgorithm, newAlgorithm, mDatabaseAutoSaveEnable) } } }