mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Compare commits
92 Commits
2.5.0.0bet
...
2.5.0.0bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d7e24816a | ||
|
|
f5e02ec63f | ||
|
|
ed1f4ebace | ||
|
|
8b9fc30a6d | ||
|
|
e42933d786 | ||
|
|
e9531e4edd | ||
|
|
0cd9cd294d | ||
|
|
b03fb12fca | ||
|
|
b7b2e8dc4e | ||
|
|
96568abc51 | ||
|
|
a180688858 | ||
|
|
2590067558 | ||
|
|
b5499238f7 | ||
|
|
cc5b96f539 | ||
|
|
32343dc937 | ||
|
|
1e71dd3031 | ||
|
|
ebf6f6a52a | ||
|
|
6bf6d661af | ||
|
|
fe16879f35 | ||
|
|
ead384d1bb | ||
|
|
1ebdc0bacd | ||
|
|
8eca8cdd53 | ||
|
|
24c61b1b37 | ||
|
|
ea18cc7166 | ||
|
|
387c499829 | ||
|
|
339470dd6e | ||
|
|
02d1089dbc | ||
|
|
1bc0932cec | ||
|
|
76cc2739c8 | ||
|
|
b23908aec2 | ||
|
|
6b1b8c0f7b | ||
|
|
06320a7eba | ||
|
|
fc02145d0c | ||
|
|
5360738775 | ||
|
|
0957df752a | ||
|
|
fe56d06b5d | ||
|
|
f4955b16cd | ||
|
|
07692ba73d | ||
|
|
64ac3e8f32 | ||
|
|
8013d3109a | ||
|
|
be6f01dc99 | ||
|
|
30f7779ec6 | ||
|
|
6b5823ca70 | ||
|
|
d4a09ed569 | ||
|
|
84fe409c4b | ||
|
|
51d90891ad | ||
|
|
b1fa06099c | ||
|
|
fa9d8ad6ad | ||
|
|
6703d7b451 | ||
|
|
73afd44d9c | ||
|
|
93cb93bb9b | ||
|
|
82902cff71 | ||
|
|
3657f7e54c | ||
|
|
a57a2f738d | ||
|
|
b93592d703 | ||
|
|
fd288e624b | ||
|
|
095fa3f6ef | ||
|
|
b1f6c578ad | ||
|
|
1bc991bfcb | ||
|
|
02feb478e8 | ||
|
|
c2df79f0c9 | ||
|
|
ef13965747 | ||
|
|
13421601de | ||
|
|
5a9b46c4b5 | ||
|
|
6268642097 | ||
|
|
12eadbc092 | ||
|
|
c9475d1dc2 | ||
|
|
56805defb6 | ||
|
|
477a784201 | ||
|
|
f54bac15c9 | ||
|
|
ae28ebe701 | ||
|
|
f16adf00da | ||
|
|
d17699f6f7 | ||
|
|
8afcf043ee | ||
|
|
dda9d034aa | ||
|
|
652bad51b4 | ||
|
|
4d2ccc0789 | ||
|
|
0e1c21e0f4 | ||
|
|
8d3f58b2cc | ||
|
|
be78905d85 | ||
|
|
b3f232c840 | ||
|
|
075a16c1c3 | ||
|
|
18a13e6266 | ||
|
|
7149bdbc3a | ||
|
|
9a4c4aa9bf | ||
|
|
2b32cab9d1 | ||
|
|
66611db261 | ||
|
|
fdc2095b42 | ||
|
|
2f9cab0da2 | ||
|
|
bd0d474751 | ||
|
|
cca0ab2669 | ||
|
|
6a69a7f416 |
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -38,7 +38,7 @@ If applicable, add screenshots to help explain your problem.
|
||||
**Android (please complete the following information):**
|
||||
- Device: [e.g. GalaxyS8]
|
||||
- Version: [e.g. 8.1]
|
||||
- Browser: [e.g. Chrome]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
- Browser for Autofill: [e.g. Chrome version X]
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
KeepassDX (2.5.0.0beta25)
|
||||
* Setting for Recycle Bin
|
||||
* Fix Recycle bin issues
|
||||
* Fix TOTP
|
||||
* Fix infinite save
|
||||
* Fix update group
|
||||
* Fix OOM
|
||||
|
||||
KeepassDX (2.5.0.0beta24)
|
||||
* Add OTP (HOTP / TOTP)
|
||||
* Add settings (Color, Security, Master Key)
|
||||
|
||||
@@ -6,14 +6,13 @@ apply plugin: 'kotlin-kapt'
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
buildToolsVersion '28.0.3'
|
||||
ndkVersion "20.1.5948944"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.kunzisoft.keepass"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 28
|
||||
versionCode = 24
|
||||
versionName = "2.5.0.0beta24"
|
||||
versionCode = 25
|
||||
versionName = "2.5.0.0beta25"
|
||||
multiDexEnabled true
|
||||
|
||||
testApplicationId = "com.kunzisoft.keepass.tests"
|
||||
@@ -28,7 +27,6 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled = false
|
||||
@@ -109,8 +107,6 @@ dependencies {
|
||||
implementation 'org.apache.commons:commons-io:1.3.2'
|
||||
// Apache Commons Codec
|
||||
implementation 'commons-codec:commons-codec:1.11'
|
||||
// Base64
|
||||
implementation 'biz.source_code:base64coder:2010-12-19'
|
||||
// Icon pack
|
||||
implementation project(path: ':icon-pack-classic')
|
||||
implementation project(path: ':icon-pack-material')
|
||||
|
||||
@@ -27,12 +27,11 @@ import java.util.Random
|
||||
|
||||
import junit.framework.TestCase
|
||||
|
||||
import com.kunzisoft.keepass.database.element.PwDate
|
||||
import com.kunzisoft.keepass.stream.LEDataInputStream
|
||||
import com.kunzisoft.keepass.stream.LEDataOutputStream
|
||||
import com.kunzisoft.keepass.utils.Types
|
||||
import com.kunzisoft.keepass.utils.DatabaseInputOutputUtils
|
||||
|
||||
class TypesTest : TestCase() {
|
||||
class DatabaseInputOutputUtilsTest : TestCase() {
|
||||
|
||||
fun testReadWriteLongZero() {
|
||||
testReadWriteLong(0.toByte())
|
||||
@@ -155,8 +154,8 @@ class TypesTest : TestCase() {
|
||||
|
||||
setArray(orig, value, 0, 1)
|
||||
|
||||
val one = Types.readUByte(orig, 0)
|
||||
Types.writeUByte(one, dest, 0)
|
||||
val one = DatabaseInputOutputUtils.readUByte(orig, 0)
|
||||
DatabaseInputOutputUtils.writeUByte(one, dest, 0)
|
||||
|
||||
assertArrayEquals(orig, dest)
|
||||
|
||||
@@ -168,27 +167,31 @@ class TypesTest : TestCase() {
|
||||
val expected = Calendar.getInstance()
|
||||
expected.set(2008, 1, 2, 3, 4, 5)
|
||||
|
||||
val buf = PwDate.writeTime(expected.time, cal)
|
||||
val actual = Calendar.getInstance()
|
||||
actual.time = PwDate.readTime(buf, 0, cal)
|
||||
DatabaseInputOutputUtils.writeCDate(expected.time, cal)?.let { buf ->
|
||||
actual.time = DatabaseInputOutputUtils.readCDate(buf, 0, cal).date
|
||||
}
|
||||
|
||||
assertEquals("Year mismatch: ", 2008, actual.get(Calendar.YEAR))
|
||||
assertEquals("Month mismatch: ", 1, actual.get(Calendar.MONTH))
|
||||
assertEquals("Day mismatch: ", 1, actual.get(Calendar.DAY_OF_MONTH))
|
||||
assertEquals("Day mismatch: ", 2, actual.get(Calendar.DAY_OF_MONTH))
|
||||
assertEquals("Hour mismatch: ", 3, actual.get(Calendar.HOUR_OF_DAY))
|
||||
assertEquals("Minute mismatch: ", 4, actual.get(Calendar.MINUTE))
|
||||
assertEquals("Second mismatch: ", 5, actual.get(Calendar.SECOND))
|
||||
}
|
||||
|
||||
fun testUUID() {
|
||||
val rnd = Random()
|
||||
val bUUID = ByteArray(16)
|
||||
rnd.nextBytes(bUUID)
|
||||
Random().nextBytes(bUUID)
|
||||
|
||||
val uuid = Types.bytestoUUID(bUUID)
|
||||
val eUUID = Types.UUIDtoBytes(uuid)
|
||||
val uuid = DatabaseInputOutputUtils.bytesToUuid(bUUID)
|
||||
val eUUID = DatabaseInputOutputUtils.uuidToBytes(uuid)
|
||||
|
||||
val lUUID = LEDataInputStream.readUuid(bUUID, 0)
|
||||
val leUUID = DatabaseInputOutputUtils.uuidToBytes(lUUID)
|
||||
|
||||
assertArrayEquals("UUID match failed", bUUID, eUUID)
|
||||
assertArrayEquals("UUID match failed", bUUID, leUUID)
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
@@ -200,7 +203,7 @@ class TypesTest : TestCase() {
|
||||
|
||||
val bos = ByteArrayOutputStream()
|
||||
val leos = LEDataOutputStream(bos)
|
||||
leos.writeLong(Types.ULONG_MAX_VALUE)
|
||||
leos.writeLong(DatabaseInputOutputUtils.ULONG_MAX_VALUE)
|
||||
leos.close()
|
||||
|
||||
val uLongMax = bos.toByteArray()
|
||||
@@ -21,17 +21,18 @@ package com.kunzisoft.keepass.tests
|
||||
|
||||
import junit.framework.TestCase
|
||||
|
||||
import com.kunzisoft.keepass.database.element.PwDate
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
import com.kunzisoft.keepass.utils.DatabaseInputOutputUtils
|
||||
import org.junit.Assert
|
||||
|
||||
class PwDateTest : TestCase() {
|
||||
|
||||
fun testDate() {
|
||||
val jDate = PwDate(System.currentTimeMillis())
|
||||
val intermediate = PwDate(jDate)
|
||||
val cDate = PwDate(intermediate.byteArrayDate!!, 0)
|
||||
val jDate = DateInstant(System.currentTimeMillis())
|
||||
val intermediate = DateInstant(jDate)
|
||||
val cDate = DatabaseInputOutputUtils.readCDate(DatabaseInputOutputUtils.writeCDate(intermediate.date)!!, 0)
|
||||
|
||||
Assert.assertTrue("jDate and intermediate not equal", jDate == intermediate)
|
||||
Assert.assertTrue("jDate and cDate not equal", cDate == jDate)
|
||||
Assert.assertTrue("jDate $jDate and cDate $cDate not equal", cDate == jDate)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
android:allowBackup="true"
|
||||
android:fullBackupContent="@xml/backup"
|
||||
android:backupAgent="com.kunzisoft.keepass.backup.SettingsBackupAgent"
|
||||
android:largeHeap="true"
|
||||
android:theme="@style/KeepassDXStyle.Night">
|
||||
<!-- TODO backup API Key -->
|
||||
<meta-data
|
||||
|
||||
@@ -38,8 +38,8 @@ import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.helpers.ReadOnlyHelper
|
||||
import com.kunzisoft.keepass.activities.lock.LockingHideActivity
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.EntryVersioned
|
||||
import com.kunzisoft.keepass.database.element.PwNodeId
|
||||
import com.kunzisoft.keepass.database.element.Entry
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.education.EntryActivityEducation
|
||||
import com.kunzisoft.keepass.icons.assignDatabaseIcon
|
||||
import com.kunzisoft.keepass.magikeyboard.MagikIME
|
||||
@@ -64,7 +64,7 @@ class EntryActivity : LockingHideActivity() {
|
||||
|
||||
private var mDatabase: Database? = null
|
||||
|
||||
private var mEntry: EntryVersioned? = null
|
||||
private var mEntry: Entry? = null
|
||||
private var mIsHistory: Boolean = false
|
||||
|
||||
private var mShowPassword: Boolean = false
|
||||
@@ -115,7 +115,7 @@ class EntryActivity : LockingHideActivity() {
|
||||
|
||||
// Get Entry from UUID
|
||||
try {
|
||||
val keyEntry: PwNodeId<UUID> = intent.getParcelableExtra(KEY_ENTRY)
|
||||
val keyEntry: NodeId<UUID> = intent.getParcelableExtra(KEY_ENTRY)
|
||||
mEntry = mDatabase?.getEntryById(keyEntry)
|
||||
} catch (e: ClassCastException) {
|
||||
Log.e(TAG, "Unable to retrieve the entry key")
|
||||
@@ -158,7 +158,7 @@ class EntryActivity : LockingHideActivity() {
|
||||
firstLaunchOfActivity = false
|
||||
}
|
||||
|
||||
private fun fillEntryDataInContentsView(entry: EntryVersioned) {
|
||||
private fun fillEntryDataInContentsView(entry: Entry) {
|
||||
|
||||
val database = Database.getInstance()
|
||||
database.startManageEntry(entry)
|
||||
@@ -298,6 +298,8 @@ class EntryActivity : LockingHideActivity() {
|
||||
}
|
||||
|
||||
database.stopManageEntry(entry)
|
||||
|
||||
entryContentsView?.refreshHistory()
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
@@ -327,9 +329,9 @@ class EntryActivity : LockingHideActivity() {
|
||||
val inflater = menuInflater
|
||||
MenuUtil.contributionMenuInflater(inflater, menu)
|
||||
inflater.inflate(R.menu.entry, menu)
|
||||
inflater.inflate(R.menu.database_lock, menu)
|
||||
|
||||
inflater.inflate(R.menu.database, menu)
|
||||
if (mReadOnly) {
|
||||
menu.findItem(R.id.menu_save_database)?.isVisible = false
|
||||
menu.findItem(R.id.menu_edit)?.isVisible = false
|
||||
}
|
||||
|
||||
@@ -398,21 +400,18 @@ class EntryActivity : LockingHideActivity() {
|
||||
MenuUtil.onContributionItemSelected(this)
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.menu_toggle_pass -> {
|
||||
mShowPassword = !mShowPassword
|
||||
changeShowPasswordIcon(item)
|
||||
entryContentsView?.setHiddenPasswordStyle(!mShowPassword)
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.menu_edit -> {
|
||||
mEntry?.let {
|
||||
EntryEditActivity.launch(this@EntryActivity, it)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.menu_goto_url -> {
|
||||
var url: String = mEntry?.url ?: ""
|
||||
|
||||
@@ -422,18 +421,17 @@ class EntryActivity : LockingHideActivity() {
|
||||
}
|
||||
|
||||
UriUtil.gotoUrl(this, url)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.menu_lock -> {
|
||||
lockAndExit()
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.menu_save_database -> {
|
||||
mProgressDialogThread?.startDatabaseSave(!mReadOnly)
|
||||
}
|
||||
android.R.id.home -> finish() // close this activity and return to preview activity (if there is any)
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
@@ -455,7 +453,7 @@ class EntryActivity : LockingHideActivity() {
|
||||
const val KEY_ENTRY = "KEY_ENTRY"
|
||||
const val KEY_ENTRY_HISTORY_POSITION = "KEY_ENTRY_HISTORY_POSITION"
|
||||
|
||||
fun launch(activity: Activity, entry: EntryVersioned, readOnly: Boolean, historyPosition: Int? = null) {
|
||||
fun launch(activity: Activity, entry: Entry, readOnly: Boolean, historyPosition: Int? = null) {
|
||||
if (TimeoutHelper.checkTimeAndLockIfTimeout(activity)) {
|
||||
val intent = Intent(activity, EntryActivity::class.java)
|
||||
intent.putExtra(KEY_ENTRY, entry.nodeId)
|
||||
|
||||
@@ -33,8 +33,9 @@ import com.kunzisoft.keepass.activities.dialogs.SetOTPDialogFragment
|
||||
import com.kunzisoft.keepass.activities.dialogs.GeneratePasswordDialogFragment
|
||||
import com.kunzisoft.keepass.activities.dialogs.IconPickerDialogFragment
|
||||
import com.kunzisoft.keepass.activities.lock.LockingHideActivity
|
||||
import com.kunzisoft.keepass.database.action.ProgressDialogThread
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.education.EntryEditActivityEducation
|
||||
import com.kunzisoft.keepass.notifications.ClipboardEntryNotificationService
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_CREATE_ENTRY_TASK
|
||||
@@ -56,10 +57,10 @@ class EntryEditActivity : LockingHideActivity(),
|
||||
private var mDatabase: Database? = null
|
||||
|
||||
// Refs of an entry and group in database, are not modifiable
|
||||
private var mEntry: EntryVersioned? = null
|
||||
private var mParent: GroupVersioned? = null
|
||||
private var mEntry: Entry? = null
|
||||
private var mParent: Group? = null
|
||||
// New or copy of mEntry in the database to be modifiable
|
||||
private var mNewEntry: EntryVersioned? = null
|
||||
private var mNewEntry: Entry? = null
|
||||
private var mIsNew: Boolean = false
|
||||
|
||||
// Views
|
||||
@@ -67,9 +68,6 @@ class EntryEditActivity : LockingHideActivity(),
|
||||
private var entryEditContentsView: EntryEditContentsView? = null
|
||||
private var saveView: View? = null
|
||||
|
||||
// Dialog thread
|
||||
private var progressDialogThread: ProgressDialogThread? = null
|
||||
|
||||
// Education
|
||||
private var entryEditActivityEducation: EntryEditActivityEducation? = null
|
||||
|
||||
@@ -98,7 +96,7 @@ class EntryEditActivity : LockingHideActivity(),
|
||||
mDatabase = Database.getInstance()
|
||||
|
||||
// Entry is retrieve, it's an entry to update
|
||||
intent.getParcelableExtra<PwNodeId<UUID>>(KEY_ENTRY)?.let {
|
||||
intent.getParcelableExtra<NodeId<UUID>>(KEY_ENTRY)?.let {
|
||||
mIsNew = false
|
||||
// Create an Entry copy to modify from the database entry
|
||||
mEntry = mDatabase?.getEntryById(it)
|
||||
@@ -118,7 +116,7 @@ class EntryEditActivity : LockingHideActivity(),
|
||||
|| !savedInstanceState.containsKey(KEY_NEW_ENTRY)) {
|
||||
mEntry?.let { entry ->
|
||||
// Create a copy to modify
|
||||
mNewEntry = EntryVersioned(entry).also { newEntry ->
|
||||
mNewEntry = Entry(entry).also { newEntry ->
|
||||
// WARNING Remove the parent to keep memory with parcelable
|
||||
newEntry.removeParent()
|
||||
}
|
||||
@@ -127,7 +125,7 @@ class EntryEditActivity : LockingHideActivity(),
|
||||
}
|
||||
|
||||
// Parent is retrieve, it's a new entry to create
|
||||
intent.getParcelableExtra<PwNodeId<*>>(KEY_PARENT)?.let {
|
||||
intent.getParcelableExtra<NodeId<*>>(KEY_PARENT)?.let {
|
||||
mIsNew = true
|
||||
// Create an empty new entry
|
||||
if (savedInstanceState == null
|
||||
@@ -176,7 +174,7 @@ class EntryEditActivity : LockingHideActivity(),
|
||||
entryEditActivityEducation = EntryEditActivityEducation(this)
|
||||
|
||||
// Create progress dialog
|
||||
progressDialogThread = ProgressDialogThread(this) { actionTask, result ->
|
||||
mProgressDialogThread?.onActionFinish = { actionTask, result ->
|
||||
when (actionTask) {
|
||||
ACTION_DATABASE_CREATE_ENTRY_TASK,
|
||||
ACTION_DATABASE_UPDATE_ENTRY_TASK -> {
|
||||
@@ -187,7 +185,7 @@ class EntryEditActivity : LockingHideActivity(),
|
||||
}
|
||||
}
|
||||
|
||||
private fun populateViewsWithEntry(newEntry: EntryVersioned) {
|
||||
private fun populateViewsWithEntry(newEntry: Entry) {
|
||||
// Don't start the field reference manager, we want to see the raw ref
|
||||
mDatabase?.stopManageEntry(newEntry)
|
||||
|
||||
@@ -209,7 +207,7 @@ class EntryEditActivity : LockingHideActivity(),
|
||||
}
|
||||
}
|
||||
|
||||
private fun populateEntryWithViews(newEntry: EntryVersioned) {
|
||||
private fun populateEntryWithViews(newEntry: Entry) {
|
||||
|
||||
mDatabase?.startManageEntry(newEntry)
|
||||
|
||||
@@ -231,7 +229,7 @@ class EntryEditActivity : LockingHideActivity(),
|
||||
mDatabase?.stopManageEntry(newEntry)
|
||||
}
|
||||
|
||||
private fun temporarilySaveAndShowSelectedIcon(icon: PwIcon) {
|
||||
private fun temporarilySaveAndShowSelectedIcon(icon: IconImage) {
|
||||
mNewEntry?.icon = icon
|
||||
mDatabase?.drawFactory?.let { iconDrawFactory ->
|
||||
entryEditContentsView?.setIcon(iconDrawFactory, icon)
|
||||
@@ -265,26 +263,26 @@ class EntryEditActivity : LockingHideActivity(),
|
||||
// WARNING Add the parent previously deleted
|
||||
newEntry.parent = mEntry?.parent
|
||||
// Build info
|
||||
newEntry.lastAccessTime = PwDate()
|
||||
newEntry.lastModificationTime = PwDate()
|
||||
newEntry.lastAccessTime = DateInstant()
|
||||
newEntry.lastModificationTime = DateInstant()
|
||||
|
||||
populateEntryWithViews(newEntry)
|
||||
|
||||
// Open a progress dialog and save entry
|
||||
if (mIsNew) {
|
||||
mParent?.let { parent ->
|
||||
progressDialogThread?.startDatabaseCreateEntry(
|
||||
mProgressDialogThread?.startDatabaseCreateEntry(
|
||||
newEntry,
|
||||
parent,
|
||||
!mReadOnly
|
||||
!mReadOnly && mAutoSaveEnable
|
||||
)
|
||||
}
|
||||
} else {
|
||||
mEntry?.let { oldEntry ->
|
||||
progressDialogThread?.startDatabaseUpdateEntry(
|
||||
mProgressDialogThread?.startDatabaseUpdateEntry(
|
||||
oldEntry,
|
||||
newEntry,
|
||||
!mReadOnly
|
||||
!mReadOnly && mAutoSaveEnable
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -292,25 +290,16 @@ class EntryEditActivity : LockingHideActivity(),
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
progressDialogThread?.registerProgressTask()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
progressDialogThread?.unregisterProgressTask()
|
||||
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
super.onCreateOptionsMenu(menu)
|
||||
|
||||
val inflater = menuInflater
|
||||
inflater.inflate(R.menu.database_lock, menu)
|
||||
inflater.inflate(R.menu.database, menu)
|
||||
// Save database not needed here
|
||||
menu.findItem(R.id.menu_save_database)?.isVisible = false
|
||||
MenuUtil.contributionMenuInflater(inflater, menu)
|
||||
inflater.inflate(R.menu.edit_entry, menu)
|
||||
if (mDatabase?.allowOTP == true)
|
||||
inflater.inflate(R.menu.entry_otp, menu)
|
||||
|
||||
entryEditActivityEducation?.let {
|
||||
Handler().post { performedNextEducation(it) }
|
||||
@@ -351,12 +340,13 @@ class EntryEditActivity : LockingHideActivity(),
|
||||
lockAndExit()
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.menu_save_database -> {
|
||||
mProgressDialogThread?.startDatabaseSave(!mReadOnly)
|
||||
}
|
||||
R.id.menu_contribute -> {
|
||||
MenuUtil.onContributionItemSelected(this)
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.menu_add_otp -> {
|
||||
// Retrieve the current otpElement if exists
|
||||
// and open the dialog to set up the OTP
|
||||
@@ -364,7 +354,6 @@ class EntryEditActivity : LockingHideActivity(),
|
||||
.show(supportFragmentManager, "addOTPDialog")
|
||||
return true
|
||||
}
|
||||
|
||||
android.R.id.home -> finish()
|
||||
}
|
||||
|
||||
@@ -452,7 +441,7 @@ class EntryEditActivity : LockingHideActivity(),
|
||||
* @param activity from activity
|
||||
* @param pwEntry Entry to update
|
||||
*/
|
||||
fun launch(activity: Activity, pwEntry: EntryVersioned) {
|
||||
fun launch(activity: Activity, pwEntry: Entry) {
|
||||
if (TimeoutHelper.checkTimeAndLockIfTimeout(activity)) {
|
||||
val intent = Intent(activity, EntryEditActivity::class.java)
|
||||
intent.putExtra(KEY_ENTRY, pwEntry.nodeId)
|
||||
@@ -466,7 +455,7 @@ class EntryEditActivity : LockingHideActivity(),
|
||||
* @param activity from activity
|
||||
* @param pwGroup Group who will contains new entry
|
||||
*/
|
||||
fun launch(activity: Activity, pwGroup: GroupVersioned) {
|
||||
fun launch(activity: Activity, pwGroup: Group) {
|
||||
if (TimeoutHelper.checkTimeAndLockIfTimeout(activity)) {
|
||||
val intent = Intent(activity, EntryEditActivity::class.java)
|
||||
intent.putExtra(KEY_PARENT, pwGroup.nodeId)
|
||||
|
||||
@@ -76,7 +76,7 @@ class FileDatabaseSelectActivity : StylishActivity(),
|
||||
|
||||
private var mOpenFileHelper: OpenFileHelper? = null
|
||||
|
||||
private var progressDialogThread: ProgressDialogThread? = null
|
||||
private var mProgressDialogThread: ProgressDialogThread? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -163,13 +163,15 @@ class FileDatabaseSelectActivity : StylishActivity(),
|
||||
}
|
||||
|
||||
// Attach the dialog thread to this activity
|
||||
progressDialogThread = ProgressDialogThread(this) { actionTask, _ ->
|
||||
when (actionTask) {
|
||||
ACTION_DATABASE_CREATE_TASK -> {
|
||||
// TODO Check
|
||||
// mAdapterDatabaseHistory?.notifyDataSetChanged()
|
||||
// updateFileListVisibility()
|
||||
GroupActivity.launch(this)
|
||||
mProgressDialogThread = ProgressDialogThread(this).apply {
|
||||
onActionFinish = { actionTask, _ ->
|
||||
when (actionTask) {
|
||||
ACTION_DATABASE_CREATE_TASK -> {
|
||||
// TODO Check
|
||||
// mAdapterDatabaseHistory?.notifyDataSetChanged()
|
||||
// updateFileListVisibility()
|
||||
GroupActivity.launch(this@FileDatabaseSelectActivity)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -296,12 +298,12 @@ class FileDatabaseSelectActivity : StylishActivity(),
|
||||
}
|
||||
|
||||
// Register progress task
|
||||
progressDialogThread?.registerProgressTask()
|
||||
mProgressDialogThread?.registerProgressTask()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
// Unregister progress task
|
||||
progressDialogThread?.unregisterProgressTask()
|
||||
mProgressDialogThread?.unregisterProgressTask()
|
||||
|
||||
super.onPause()
|
||||
}
|
||||
@@ -329,7 +331,7 @@ class FileDatabaseSelectActivity : StylishActivity(),
|
||||
mDatabaseFileUri?.let { databaseUri ->
|
||||
|
||||
// Create the new database
|
||||
progressDialogThread?.startDatabaseCreate(
|
||||
mProgressDialogThread?.startDatabaseCreate(
|
||||
databaseUri,
|
||||
masterPasswordChecked,
|
||||
masterPassword,
|
||||
|
||||
@@ -42,18 +42,18 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.dialogs.GroupEditDialogFragment
|
||||
import com.kunzisoft.keepass.activities.dialogs.IconPickerDialogFragment
|
||||
import com.kunzisoft.keepass.activities.dialogs.ReadOnlyDialog
|
||||
import com.kunzisoft.keepass.activities.dialogs.SortDialogFragment
|
||||
import com.kunzisoft.keepass.activities.dialogs.*
|
||||
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
|
||||
import com.kunzisoft.keepass.activities.helpers.ReadOnlyHelper
|
||||
import com.kunzisoft.keepass.activities.lock.LockingActivity
|
||||
import com.kunzisoft.keepass.adapters.SearchEntryCursorAdapter
|
||||
import com.kunzisoft.keepass.autofill.AutofillHelper
|
||||
import com.kunzisoft.keepass.database.SortNodeEnum
|
||||
import com.kunzisoft.keepass.database.action.ProgressDialogThread
|
||||
import com.kunzisoft.keepass.database.element.SortNodeEnum
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
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.education.GroupActivityEducation
|
||||
import com.kunzisoft.keepass.icons.assignDatabaseIcon
|
||||
import com.kunzisoft.keepass.magikeyboard.MagikIME
|
||||
@@ -77,6 +77,7 @@ class GroupActivity : LockingActivity(),
|
||||
IconPickerDialogFragment.IconPickerListener,
|
||||
ListNodesFragment.NodeClickListener,
|
||||
ListNodesFragment.NodesActionMenuListener,
|
||||
DeleteNodesDialogFragment.DeleteNodeListener,
|
||||
ListNodesFragment.OnScrollListener,
|
||||
SortDialogFragment.SortSelectionListener {
|
||||
|
||||
@@ -96,14 +97,10 @@ class GroupActivity : LockingActivity(),
|
||||
private var mListNodesFragment: ListNodesFragment? = null
|
||||
private var mCurrentGroupIsASearch: Boolean = false
|
||||
|
||||
private var progressDialogThread: ProgressDialogThread? = null
|
||||
|
||||
// Nodes
|
||||
private var mRootGroup: GroupVersioned? = null
|
||||
private var mCurrentGroup: GroupVersioned? = null
|
||||
private var mOldGroupToUpdate: GroupVersioned? = null
|
||||
// TODO private var mNodeToCopy: NodeVersioned? = null
|
||||
// TODO private var mNodeToMove: NodeVersioned? = null
|
||||
private var mRootGroup: Group? = null
|
||||
private var mCurrentGroup: Group? = null
|
||||
private var mOldGroupToUpdate: Group? = null
|
||||
|
||||
private var mSearchSuggestionAdapter: SearchEntryCursorAdapter? = null
|
||||
|
||||
@@ -134,14 +131,6 @@ class GroupActivity : LockingActivity(),
|
||||
toolbar?.title = ""
|
||||
setSupportActionBar(toolbar)
|
||||
|
||||
/*
|
||||
toolbarAction?.setNavigationOnClickListener {
|
||||
toolbarAction?.collapse()
|
||||
mNodeToCopy = null
|
||||
mNodeToMove = null
|
||||
}
|
||||
*/
|
||||
|
||||
// Focus view to reinitialize timeout
|
||||
resetAppTimeoutWhenViewFocusedOrChanged(addNodeButtonView)
|
||||
|
||||
@@ -207,13 +196,13 @@ class GroupActivity : LockingActivity(),
|
||||
mSearchSuggestionAdapter = SearchEntryCursorAdapter(this, database)
|
||||
|
||||
// Init dialog thread
|
||||
progressDialogThread = ProgressDialogThread(this) { actionTask, result ->
|
||||
mProgressDialogThread?.onActionFinish = { actionTask, result ->
|
||||
|
||||
var oldNodes: List<NodeVersioned> = ArrayList()
|
||||
var oldNodes: List<Node> = ArrayList()
|
||||
result.data?.getBundle(OLD_NODES_KEY)?.let { oldNodesBundle ->
|
||||
oldNodes = getListNodesFromBundle(database, oldNodesBundle)
|
||||
}
|
||||
var newNodes: List<NodeVersioned> = ArrayList()
|
||||
var newNodes: List<Node> = ArrayList()
|
||||
result.data?.getBundle(NEW_NODES_KEY)?.let { newNodesBundle ->
|
||||
newNodes = getListNodesFromBundle(database, newNodesBundle)
|
||||
}
|
||||
@@ -234,24 +223,23 @@ class GroupActivity : LockingActivity(),
|
||||
ACTION_DATABASE_DELETE_NODES_TASK -> {
|
||||
if (result.isSuccess) {
|
||||
|
||||
// Rebuild all the list the avoid bug when delete node from db sort
|
||||
if (PreferencesUtil.getListSort(this@GroupActivity) == SortNodeEnum.DB) {
|
||||
mListNodesFragment?.rebuildList()
|
||||
} else {
|
||||
// Use the old Nodes / entries unchanged with the old parent
|
||||
mListNodesFragment?.removeNodes(oldNodes)
|
||||
}
|
||||
// Rebuild all the list to avoid bug when delete node from sort
|
||||
mListNodesFragment?.rebuildList()
|
||||
|
||||
// Add trash in views list if it doesn't exists
|
||||
if (database.isRecycleBinEnabled) {
|
||||
val recycleBin = database.recycleBin
|
||||
if (mCurrentGroup != null && recycleBin != null
|
||||
&& mCurrentGroup!!.parent == null
|
||||
&& mCurrentGroup != recycleBin) {
|
||||
if (mListNodesFragment?.contains(recycleBin) == true)
|
||||
val currentGroup = mCurrentGroup
|
||||
if (currentGroup != null && recycleBin != null
|
||||
&& currentGroup != recycleBin) {
|
||||
// Recycle bin already here, simply update it
|
||||
if (mListNodesFragment?.contains(recycleBin) == true) {
|
||||
mListNodesFragment?.updateNode(recycleBin)
|
||||
else
|
||||
}
|
||||
// Recycle bin not here, verify if parents are similar to add it
|
||||
else if (currentGroup == recycleBin.parent) {
|
||||
mListNodesFragment?.addNode(recycleBin)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -259,9 +247,11 @@ class GroupActivity : LockingActivity(),
|
||||
}
|
||||
|
||||
if (!result.isSuccess) {
|
||||
result.exception?.errorId?.let { errorId ->
|
||||
coordinatorLayout?.let { coordinatorLayout ->
|
||||
coordinatorLayout?.let { coordinatorLayout ->
|
||||
result.exception?.errorId?.let { errorId ->
|
||||
Snackbar.make(coordinatorLayout, errorId, Snackbar.LENGTH_LONG).asError().show()
|
||||
} ?: result.message?.let { message ->
|
||||
Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG).asError().show()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -291,7 +281,7 @@ class GroupActivity : LockingActivity(),
|
||||
}
|
||||
}
|
||||
|
||||
private fun openSearchGroup(group: GroupVersioned?) {
|
||||
private fun openSearchGroup(group: Group?) {
|
||||
// Delete the previous search fragment
|
||||
val searchFragment = supportFragmentManager.findFragmentByTag(SEARCH_FRAGMENT_TAG)
|
||||
if (searchFragment != null) {
|
||||
@@ -303,11 +293,11 @@ class GroupActivity : LockingActivity(),
|
||||
openGroup(group, true)
|
||||
}
|
||||
|
||||
private fun openChildGroup(group: GroupVersioned) {
|
||||
private fun openChildGroup(group: Group) {
|
||||
openGroup(group, false)
|
||||
}
|
||||
|
||||
private fun openGroup(group: GroupVersioned?, isASearch: Boolean) {
|
||||
private fun openGroup(group: Group?, isASearch: Boolean) {
|
||||
// Check TimeoutHelper
|
||||
TimeoutHelper.checkTimeAndLockIfTimeoutOrResetTimeout(this) {
|
||||
// Open a group in a new fragment
|
||||
@@ -347,7 +337,7 @@ class GroupActivity : LockingActivity(),
|
||||
super.onSaveInstanceState(outState)
|
||||
}
|
||||
|
||||
private fun retrieveCurrentGroup(intent: Intent, savedInstanceState: Bundle?): GroupVersioned? {
|
||||
private fun retrieveCurrentGroup(intent: Intent, savedInstanceState: Bundle?): Group? {
|
||||
|
||||
// Force read only if the database is like that
|
||||
mReadOnly = mDatabase?.isReadOnly == true || mReadOnly
|
||||
@@ -358,7 +348,7 @@ class GroupActivity : LockingActivity(),
|
||||
}
|
||||
// else a real group
|
||||
else {
|
||||
var pwGroupId: PwNodeId<*>? = null
|
||||
var pwGroupId: NodeId<*>? = null
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(GROUP_ID_KEY)) {
|
||||
pwGroupId = savedInstanceState.getParcelable(GROUP_ID_KEY)
|
||||
} else {
|
||||
@@ -367,7 +357,7 @@ class GroupActivity : LockingActivity(),
|
||||
}
|
||||
|
||||
Log.w(TAG, "Creating tree view")
|
||||
val currentGroup: GroupVersioned?
|
||||
val currentGroup: Group?
|
||||
currentGroup = if (pwGroupId == null) {
|
||||
mRootGroup
|
||||
} else {
|
||||
@@ -470,16 +460,16 @@ class GroupActivity : LockingActivity(),
|
||||
addNodeButtonView?.hideButtonOnScrollListener(dy)
|
||||
}
|
||||
|
||||
override fun onNodeClick(node: NodeVersioned) {
|
||||
override fun onNodeClick(node: Node) {
|
||||
when (node.type) {
|
||||
Type.GROUP -> try {
|
||||
openChildGroup(node as GroupVersioned)
|
||||
openChildGroup(node as Group)
|
||||
} catch (e: ClassCastException) {
|
||||
Log.e(TAG, "Node can't be cast in Group")
|
||||
}
|
||||
|
||||
Type.ENTRY -> try {
|
||||
val entryVersioned = node as EntryVersioned
|
||||
val entryVersioned = node as Entry
|
||||
EntrySelectionHelper.doEntrySelectionAction(intent,
|
||||
{
|
||||
EntryActivity.launch(this@GroupActivity, entryVersioned, mReadOnly)
|
||||
@@ -517,7 +507,7 @@ class GroupActivity : LockingActivity(),
|
||||
actionNodeMode = null
|
||||
}
|
||||
|
||||
override fun onNodeSelected(nodes: List<NodeVersioned>): Boolean {
|
||||
override fun onNodeSelected(nodes: List<Node>): Boolean {
|
||||
if (nodes.isNotEmpty()) {
|
||||
if (actionNodeMode == null || toolbarAction?.getSupportActionModeCallback() == null) {
|
||||
mListNodesFragment?.actionNodesCallback(nodes, this)?.let {
|
||||
@@ -532,34 +522,34 @@ class GroupActivity : LockingActivity(),
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOpenMenuClick(node: NodeVersioned): Boolean {
|
||||
override fun onOpenMenuClick(node: Node): Boolean {
|
||||
finishNodeAction()
|
||||
onNodeClick(node)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onEditMenuClick(node: NodeVersioned): Boolean {
|
||||
override fun onEditMenuClick(node: Node): Boolean {
|
||||
finishNodeAction()
|
||||
when (node.type) {
|
||||
Type.GROUP -> {
|
||||
mOldGroupToUpdate = node as GroupVersioned
|
||||
mOldGroupToUpdate = node as Group
|
||||
GroupEditDialogFragment.build(mOldGroupToUpdate!!)
|
||||
.show(supportFragmentManager,
|
||||
GroupEditDialogFragment.TAG_CREATE_GROUP)
|
||||
}
|
||||
Type.ENTRY -> EntryEditActivity.launch(this@GroupActivity, node as EntryVersioned)
|
||||
Type.ENTRY -> EntryEditActivity.launch(this@GroupActivity, node as Entry)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onCopyMenuClick(nodes: List<NodeVersioned>): Boolean {
|
||||
override fun onCopyMenuClick(nodes: List<Node>): Boolean {
|
||||
actionNodeMode?.invalidate()
|
||||
|
||||
// Nothing here fragment calls onPasteMenuClick internally
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onMoveMenuClick(nodes: List<NodeVersioned>): Boolean {
|
||||
override fun onMoveMenuClick(nodes: List<Node>): Boolean {
|
||||
actionNodeMode?.invalidate()
|
||||
|
||||
// Nothing here fragment calls onPasteMenuClick internally
|
||||
@@ -567,56 +557,88 @@ class GroupActivity : LockingActivity(),
|
||||
}
|
||||
|
||||
override fun onPasteMenuClick(pasteMode: ListNodesFragment.PasteMode?,
|
||||
nodes: List<NodeVersioned>): Boolean {
|
||||
when (pasteMode) {
|
||||
ListNodesFragment.PasteMode.PASTE_FROM_COPY -> {
|
||||
// Copy
|
||||
mCurrentGroup?.let { newParent ->
|
||||
progressDialogThread?.startDatabaseCopyNodes(
|
||||
nodes,
|
||||
newParent,
|
||||
!mReadOnly
|
||||
)
|
||||
nodes: List<Node>): Boolean {
|
||||
// Move or copy only if allowed (in root if allowed)
|
||||
if (mCurrentGroup != mDatabase?.rootGroup
|
||||
|| mDatabase?.rootCanContainsEntry() == true) {
|
||||
|
||||
when (pasteMode) {
|
||||
ListNodesFragment.PasteMode.PASTE_FROM_COPY -> {
|
||||
// Copy
|
||||
mCurrentGroup?.let { newParent ->
|
||||
mProgressDialogThread?.startDatabaseCopyNodes(
|
||||
nodes,
|
||||
newParent,
|
||||
!mReadOnly && mAutoSaveEnable
|
||||
)
|
||||
}
|
||||
}
|
||||
ListNodesFragment.PasteMode.PASTE_FROM_MOVE -> {
|
||||
// Move
|
||||
mCurrentGroup?.let { newParent ->
|
||||
mProgressDialogThread?.startDatabaseMoveNodes(
|
||||
nodes,
|
||||
newParent,
|
||||
!mReadOnly && mAutoSaveEnable
|
||||
)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
ListNodesFragment.PasteMode.PASTE_FROM_MOVE -> {
|
||||
// Move
|
||||
mCurrentGroup?.let { newParent ->
|
||||
progressDialogThread?.startDatabaseMoveNodes(
|
||||
nodes,
|
||||
newParent,
|
||||
!mReadOnly
|
||||
)
|
||||
}
|
||||
} else {
|
||||
coordinatorLayout?.let { coordinatorLayout ->
|
||||
Snackbar.make(coordinatorLayout,
|
||||
R.string.error_copy_entry_here,
|
||||
Snackbar.LENGTH_LONG).asError().show()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
finishNodeAction()
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onDeleteMenuClick(nodes: List<NodeVersioned>): Boolean {
|
||||
progressDialogThread?.startDatabaseDeleteNodes(
|
||||
nodes,
|
||||
!mReadOnly
|
||||
)
|
||||
override fun onDeleteMenuClick(nodes: List<Node>): Boolean {
|
||||
val database = mDatabase
|
||||
|
||||
// If recycle bin enabled, ensure it exists
|
||||
if (database != null && database.isRecycleBinEnabled) {
|
||||
database.ensureRecycleBinExists(resources)
|
||||
}
|
||||
|
||||
// If recycle bin enabled and not in recycle bin, move in recycle bin
|
||||
if (database != null
|
||||
&& database.isRecycleBinEnabled
|
||||
&& database.recycleBin != mCurrentGroup) {
|
||||
mProgressDialogThread?.startDatabaseDeleteNodes(
|
||||
nodes,
|
||||
!mReadOnly && mAutoSaveEnable
|
||||
)
|
||||
}
|
||||
// else open the dialog to confirm deletion
|
||||
else {
|
||||
DeleteNodesDialogFragment.getInstance(nodes)
|
||||
.show(supportFragmentManager, "deleteNodesDialogFragment")
|
||||
}
|
||||
finishNodeAction()
|
||||
return true
|
||||
}
|
||||
|
||||
override fun permanentlyDeleteNodes(nodes: List<Node>) {
|
||||
mProgressDialogThread?.startDatabaseDeleteNodes(
|
||||
nodes,
|
||||
!mReadOnly && mAutoSaveEnable
|
||||
)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
// Refresh the elements
|
||||
assignGroupViewElements()
|
||||
// Refresh suggestions to change preferences
|
||||
mSearchSuggestionAdapter?.reInit(this)
|
||||
|
||||
progressDialogThread?.registerProgressTask()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
progressDialogThread?.unregisterProgressTask()
|
||||
|
||||
super.onPause()
|
||||
|
||||
finishNodeAction()
|
||||
@@ -626,12 +648,21 @@ class GroupActivity : LockingActivity(),
|
||||
|
||||
val inflater = menuInflater
|
||||
inflater.inflate(R.menu.search, menu)
|
||||
inflater.inflate(R.menu.database_lock, menu)
|
||||
inflater.inflate(R.menu.database, menu)
|
||||
if (mReadOnly) {
|
||||
menu.findItem(R.id.menu_save_database)?.isVisible = false
|
||||
}
|
||||
if (!mSelectionMode) {
|
||||
inflater.inflate(R.menu.default_menu, menu)
|
||||
MenuUtil.contributionMenuInflater(inflater, menu)
|
||||
}
|
||||
|
||||
// Menu for recycle bin
|
||||
if (mDatabase?.isRecycleBinEnabled == true
|
||||
&& mDatabase?.recycleBin == mCurrentGroup) {
|
||||
inflater.inflate(R.menu.recycle_bin, menu)
|
||||
}
|
||||
|
||||
// Get the SearchView and set the searchable configuration
|
||||
val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager
|
||||
|
||||
@@ -740,6 +771,17 @@ class GroupActivity : LockingActivity(),
|
||||
lockAndExit()
|
||||
return true
|
||||
}
|
||||
R.id.menu_save_database -> {
|
||||
mProgressDialogThread?.startDatabaseSave(!mReadOnly)
|
||||
return true
|
||||
}
|
||||
R.id.menu_empty_recycle_bin -> {
|
||||
mCurrentGroup?.getChildren()?.let { listChildren ->
|
||||
// Automatically delete all elements
|
||||
onDeleteMenuClick(listChildren)
|
||||
}
|
||||
return true
|
||||
}
|
||||
else -> {
|
||||
// Check the time lock before launching settings
|
||||
MenuUtil.onDefaultMenuOptionsItemSelected(this, item, mReadOnly, true)
|
||||
@@ -750,7 +792,7 @@ class GroupActivity : LockingActivity(),
|
||||
|
||||
override fun approveEditGroup(action: GroupEditDialogFragment.EditGroupDialogAction?,
|
||||
name: String?,
|
||||
icon: PwIcon?) {
|
||||
icon: IconImage?) {
|
||||
|
||||
if (name != null && name.isNotEmpty() && icon != null) {
|
||||
when (action) {
|
||||
@@ -764,28 +806,33 @@ class GroupActivity : LockingActivity(),
|
||||
// Not really needed here because added in runnable but safe
|
||||
newGroup.parent = currentGroup
|
||||
|
||||
progressDialogThread?.startDatabaseCreateGroup(
|
||||
newGroup, currentGroup, !mReadOnly)
|
||||
mProgressDialogThread?.startDatabaseCreateGroup(
|
||||
newGroup,
|
||||
currentGroup,
|
||||
!mReadOnly && mAutoSaveEnable
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
GroupEditDialogFragment.EditGroupDialogAction.UPDATE -> {
|
||||
// If update add new elements
|
||||
mOldGroupToUpdate?.let { oldGroupToUpdate ->
|
||||
GroupVersioned(oldGroupToUpdate).let { updateGroup ->
|
||||
val updateGroup = Group(oldGroupToUpdate).let { updateGroup ->
|
||||
updateGroup.apply {
|
||||
// WARNING remove parent and children to keep memory
|
||||
removeParent()
|
||||
removeChildren() // TODO concurrent exception
|
||||
removeChildren()
|
||||
|
||||
title = name
|
||||
this.icon = icon // TODO custom icon
|
||||
}
|
||||
|
||||
// If group updated save it in the database
|
||||
progressDialogThread?.startDatabaseUpdateGroup(
|
||||
oldGroupToUpdate, updateGroup, !mReadOnly)
|
||||
}
|
||||
// If group updated save it in the database
|
||||
mProgressDialogThread?.startDatabaseUpdateGroup(
|
||||
oldGroupToUpdate,
|
||||
updateGroup,
|
||||
!mReadOnly && mAutoSaveEnable
|
||||
)
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
@@ -795,7 +842,7 @@ class GroupActivity : LockingActivity(),
|
||||
|
||||
override fun cancelEditGroup(action: GroupEditDialogFragment.EditGroupDialogAction?,
|
||||
name: String?,
|
||||
icon: PwIcon?) {
|
||||
icon: IconImage?) {
|
||||
// Do nothing here
|
||||
}
|
||||
|
||||
@@ -906,7 +953,7 @@ class GroupActivity : LockingActivity(),
|
||||
private const val SEARCH_FRAGMENT_TAG = "SEARCH_FRAGMENT_TAG"
|
||||
private const val OLD_GROUP_TO_UPDATE_KEY = "OLD_GROUP_TO_UPDATE_KEY"
|
||||
|
||||
private fun buildAndLaunchIntent(context: Context, group: GroupVersioned?, readOnly: Boolean,
|
||||
private fun buildAndLaunchIntent(context: Context, group: Group?, readOnly: Boolean,
|
||||
intentBuildLauncher: (Intent) -> Unit) {
|
||||
val checkTime = if (context is Activity)
|
||||
TimeoutHelper.checkTimeAndLockIfTimeout(context)
|
||||
|
||||
@@ -18,16 +18,16 @@ import androidx.appcompat.view.ActionMode
|
||||
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.adapters.NodeAdapter
|
||||
import com.kunzisoft.keepass.database.SortNodeEnum
|
||||
import com.kunzisoft.keepass.database.element.GroupVersioned
|
||||
import com.kunzisoft.keepass.database.element.NodeVersioned
|
||||
import com.kunzisoft.keepass.database.element.SortNodeEnum
|
||||
import com.kunzisoft.keepass.database.element.Group
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
import com.kunzisoft.keepass.activities.dialogs.SortDialogFragment
|
||||
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
import com.kunzisoft.keepass.activities.stylish.StylishFragment
|
||||
import com.kunzisoft.keepass.activities.helpers.ReadOnlyHelper
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.Type
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import java.util.*
|
||||
|
||||
class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionListener {
|
||||
@@ -36,7 +36,7 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
private var onScrollListener: OnScrollListener? = null
|
||||
|
||||
private var listView: RecyclerView? = null
|
||||
var mainGroup: GroupVersioned? = null
|
||||
var mainGroup: Group? = null
|
||||
private set
|
||||
private var mAdapter: NodeAdapter? = null
|
||||
|
||||
@@ -44,8 +44,8 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
private set
|
||||
var nodeActionPasteMode: PasteMode = PasteMode.UNDEFINED
|
||||
private set
|
||||
private val listActionNodes = LinkedList<NodeVersioned>()
|
||||
private val listPasteNodes = LinkedList<NodeVersioned>()
|
||||
private val listActionNodes = LinkedList<Node>()
|
||||
private val listPasteNodes = LinkedList<Node>()
|
||||
|
||||
private var notFoundView: View? = null
|
||||
private var isASearchResult: Boolean = false
|
||||
@@ -103,7 +103,7 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
mAdapter = NodeAdapter(context)
|
||||
mAdapter?.apply {
|
||||
setOnNodeClickListener(object : NodeAdapter.NodeClickCallback {
|
||||
override fun onNodeClick(node: NodeVersioned) {
|
||||
override fun onNodeClick(node: Node) {
|
||||
if (nodeActionSelectionMode) {
|
||||
if (listActionNodes.contains(node)) {
|
||||
// Remove selected item if already selected
|
||||
@@ -120,7 +120,7 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNodeLongClick(node: NodeVersioned): Boolean {
|
||||
override fun onNodeLongClick(node: Node): Boolean {
|
||||
if (nodeActionPasteMode == PasteMode.UNDEFINED) {
|
||||
// Select the first item after a long click
|
||||
if (!listActionNodes.contains(node))
|
||||
@@ -228,8 +228,7 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
R.id.menu_sort -> {
|
||||
context?.let { context ->
|
||||
val sortDialogFragment: SortDialogFragment =
|
||||
if (Database.getInstance().allowRecycleBin
|
||||
&& Database.getInstance().isRecycleBinEnabled) {
|
||||
if (Database.getInstance().isRecycleBinEnabled) {
|
||||
SortDialogFragment.getInstance(
|
||||
PreferencesUtil.getListSort(context),
|
||||
PreferencesUtil.getAscendingSort(context),
|
||||
@@ -251,7 +250,7 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
}
|
||||
}
|
||||
|
||||
fun actionNodesCallback(nodes: List<NodeVersioned>,
|
||||
fun actionNodesCallback(nodes: List<Node>,
|
||||
menuListener: NodesActionMenuListener?) : ActionMode.Callback {
|
||||
|
||||
return object : ActionMode.Callback {
|
||||
@@ -276,7 +275,8 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
// Open and Edit for a single item
|
||||
if (nodes.size == 1) {
|
||||
// Edition
|
||||
if (readOnly || nodes[0] == database.recycleBin) {
|
||||
if (readOnly
|
||||
|| (database.isRecycleBinEnabled && nodes[0] == database.recycleBin)) {
|
||||
menu?.removeItem(R.id.menu_edit)
|
||||
}
|
||||
} else {
|
||||
@@ -287,7 +287,6 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
// Copy and Move (not for groups)
|
||||
if (readOnly
|
||||
|| isASearchResult
|
||||
|| nodes.any { it == database.recycleBin }
|
||||
|| nodes.any { it.type == Type.GROUP }) {
|
||||
// TODO COPY For Group
|
||||
menu?.removeItem(R.id.menu_copy)
|
||||
@@ -295,7 +294,8 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
}
|
||||
|
||||
// Deletion
|
||||
if (readOnly || nodes.any { it == database.recycleBin }) {
|
||||
if (readOnly
|
||||
|| (database.isRecycleBinEnabled && nodes.any { it == database.recycleBin })) {
|
||||
menu?.removeItem(R.id.menu_delete)
|
||||
}
|
||||
}
|
||||
@@ -354,7 +354,7 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
EntryEditActivity.ADD_OR_UPDATE_ENTRY_REQUEST_CODE -> {
|
||||
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE
|
||||
|| resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
|
||||
data?.getParcelableExtra<NodeVersioned>(EntryEditActivity.ADD_OR_UPDATE_ENTRY_KEY)?.let { newNode ->
|
||||
data?.getParcelableExtra<Node>(EntryEditActivity.ADD_OR_UPDATE_ENTRY_KEY)?.let { newNode ->
|
||||
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE)
|
||||
mAdapter?.addNode(newNode)
|
||||
if (resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
|
||||
@@ -369,31 +369,31 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
}
|
||||
}
|
||||
|
||||
fun contains(node: NodeVersioned): Boolean {
|
||||
fun contains(node: Node): Boolean {
|
||||
return mAdapter?.contains(node) ?: false
|
||||
}
|
||||
|
||||
fun addNode(newNode: NodeVersioned) {
|
||||
fun addNode(newNode: Node) {
|
||||
mAdapter?.addNode(newNode)
|
||||
}
|
||||
|
||||
fun addNodes(newNodes: List<NodeVersioned>) {
|
||||
fun addNodes(newNodes: List<Node>) {
|
||||
mAdapter?.addNodes(newNodes)
|
||||
}
|
||||
|
||||
fun updateNode(oldNode: NodeVersioned, newNode: NodeVersioned? = null) {
|
||||
fun updateNode(oldNode: Node, newNode: Node? = null) {
|
||||
mAdapter?.updateNode(oldNode, newNode ?: oldNode)
|
||||
}
|
||||
|
||||
fun updateNodes(oldNodes: List<NodeVersioned>, newNodes: List<NodeVersioned>) {
|
||||
fun updateNodes(oldNodes: List<Node>, newNodes: List<Node>) {
|
||||
mAdapter?.updateNodes(oldNodes, newNodes)
|
||||
}
|
||||
|
||||
fun removeNode(pwNode: NodeVersioned) {
|
||||
fun removeNode(pwNode: Node) {
|
||||
mAdapter?.removeNode(pwNode)
|
||||
}
|
||||
|
||||
fun removeNodes(nodes: List<NodeVersioned>) {
|
||||
fun removeNodes(nodes: List<Node>) {
|
||||
mAdapter?.removeNodes(nodes)
|
||||
}
|
||||
|
||||
@@ -409,20 +409,20 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
* Callback listener to redefine to do an action when a node is click
|
||||
*/
|
||||
interface NodeClickListener {
|
||||
fun onNodeClick(node: NodeVersioned)
|
||||
fun onNodeSelected(nodes: List<NodeVersioned>): Boolean
|
||||
fun onNodeClick(node: Node)
|
||||
fun onNodeSelected(nodes: List<Node>): Boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu listener to redefine to do an action in menu
|
||||
*/
|
||||
interface NodesActionMenuListener {
|
||||
fun onOpenMenuClick(node: NodeVersioned): Boolean
|
||||
fun onEditMenuClick(node: NodeVersioned): Boolean
|
||||
fun onCopyMenuClick(nodes: List<NodeVersioned>): Boolean
|
||||
fun onMoveMenuClick(nodes: List<NodeVersioned>): Boolean
|
||||
fun onDeleteMenuClick(nodes: List<NodeVersioned>): Boolean
|
||||
fun onPasteMenuClick(pasteMode: PasteMode?, nodes: List<NodeVersioned>): Boolean
|
||||
fun onOpenMenuClick(node: Node): Boolean
|
||||
fun onEditMenuClick(node: Node): Boolean
|
||||
fun onCopyMenuClick(nodes: List<Node>): Boolean
|
||||
fun onMoveMenuClick(nodes: List<Node>): Boolean
|
||||
fun onDeleteMenuClick(nodes: List<Node>): Boolean
|
||||
fun onPasteMenuClick(pasteMode: PasteMode?, nodes: List<Node>): Boolean
|
||||
}
|
||||
|
||||
enum class PasteMode {
|
||||
@@ -447,7 +447,7 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
private const val GROUP_KEY = "GROUP_KEY"
|
||||
private const val IS_SEARCH = "IS_SEARCH"
|
||||
|
||||
fun newInstance(group: GroupVersioned?, readOnly: Boolean, isASearch: Boolean): ListNodesFragment {
|
||||
fun newInstance(group: Group?, readOnly: Boolean, isASearch: Boolean): ListNodesFragment {
|
||||
val bundle = Bundle()
|
||||
if (group != null) {
|
||||
bundle.putParcelable(GROUP_KEY, group)
|
||||
|
||||
@@ -58,7 +58,7 @@ import com.kunzisoft.keepass.autofill.AutofillHelper
|
||||
import com.kunzisoft.keepass.biometric.AdvancedUnlockedManager
|
||||
import com.kunzisoft.keepass.database.action.ProgressDialogThread
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.exception.LoadDatabaseDuplicateUuidException
|
||||
import com.kunzisoft.keepass.database.exception.DuplicateUuidDatabaseException
|
||||
import com.kunzisoft.keepass.education.PasswordActivityEducation
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_LOAD_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.CIPHER_ENTITY_KEY
|
||||
@@ -101,7 +101,7 @@ class PasswordActivity : StylishActivity() {
|
||||
|
||||
private var readOnly: Boolean = false
|
||||
|
||||
private var progressDialogThread: ProgressDialogThread? = null
|
||||
private var mProgressDialogThread: ProgressDialogThread? = null
|
||||
|
||||
private var advancedUnlockedManager: AdvancedUnlockedManager? = null
|
||||
|
||||
@@ -163,69 +163,71 @@ class PasswordActivity : StylishActivity() {
|
||||
enableOrNotTheConfirmationButton()
|
||||
}
|
||||
|
||||
progressDialogThread = ProgressDialogThread(this) { actionTask, result ->
|
||||
when (actionTask) {
|
||||
ACTION_DATABASE_LOAD_TASK -> {
|
||||
// Recheck biometric if error
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (PreferencesUtil.isBiometricUnlockEnable(this@PasswordActivity)) {
|
||||
// Stay with the same mode and init it
|
||||
advancedUnlockedManager?.initBiometricMode()
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the password in view in all cases
|
||||
removePassword()
|
||||
|
||||
if (result.isSuccess) {
|
||||
launchGroupActivity()
|
||||
} else {
|
||||
var resultError = ""
|
||||
val resultException = result.exception
|
||||
val resultMessage = result.message
|
||||
|
||||
if (resultException != null) {
|
||||
resultError = resultException.getLocalizedMessage(resources)
|
||||
|
||||
// Relaunch loading if we need to fix UUID
|
||||
if (resultException is LoadDatabaseDuplicateUuidException) {
|
||||
showLoadDatabaseDuplicateUuidMessage {
|
||||
|
||||
var databaseUri: Uri? = null
|
||||
var masterPassword: String? = null
|
||||
var keyFileUri: Uri? = null
|
||||
var readOnly = true
|
||||
var cipherEntity: CipherDatabaseEntity? = null
|
||||
|
||||
result.data?.let { resultData ->
|
||||
databaseUri = resultData.getParcelable(DATABASE_URI_KEY)
|
||||
masterPassword = resultData.getString(MASTER_PASSWORD_KEY)
|
||||
keyFileUri = resultData.getParcelable(KEY_FILE_KEY)
|
||||
readOnly = resultData.getBoolean(READ_ONLY_KEY)
|
||||
cipherEntity = resultData.getParcelable(CIPHER_ENTITY_KEY)
|
||||
}
|
||||
|
||||
databaseUri?.let { databaseFileUri ->
|
||||
showProgressDialogAndLoadDatabase(
|
||||
databaseFileUri,
|
||||
masterPassword,
|
||||
keyFileUri,
|
||||
readOnly,
|
||||
cipherEntity,
|
||||
true)
|
||||
}
|
||||
}
|
||||
mProgressDialogThread = ProgressDialogThread(this).apply {
|
||||
onActionFinish = { actionTask, result ->
|
||||
when (actionTask) {
|
||||
ACTION_DATABASE_LOAD_TASK -> {
|
||||
// Recheck biometric if error
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (PreferencesUtil.isBiometricUnlockEnable(this@PasswordActivity)) {
|
||||
// Stay with the same mode and init it
|
||||
advancedUnlockedManager?.initBiometricMode()
|
||||
}
|
||||
}
|
||||
|
||||
// Show error message
|
||||
if (resultMessage != null && resultMessage.isNotEmpty()) {
|
||||
resultError = "$resultError $resultMessage"
|
||||
// Remove the password in view in all cases
|
||||
removePassword()
|
||||
|
||||
if (result.isSuccess) {
|
||||
launchGroupActivity()
|
||||
} else {
|
||||
var resultError = ""
|
||||
val resultException = result.exception
|
||||
val resultMessage = result.message
|
||||
|
||||
if (resultException != null) {
|
||||
resultError = resultException.getLocalizedMessage(resources)
|
||||
|
||||
// Relaunch loading if we need to fix UUID
|
||||
if (resultException is DuplicateUuidDatabaseException) {
|
||||
showLoadDatabaseDuplicateUuidMessage {
|
||||
|
||||
var databaseUri: Uri? = null
|
||||
var masterPassword: String? = null
|
||||
var keyFileUri: Uri? = null
|
||||
var readOnly = true
|
||||
var cipherEntity: CipherDatabaseEntity? = null
|
||||
|
||||
result.data?.let { resultData ->
|
||||
databaseUri = resultData.getParcelable(DATABASE_URI_KEY)
|
||||
masterPassword = resultData.getString(MASTER_PASSWORD_KEY)
|
||||
keyFileUri = resultData.getParcelable(KEY_FILE_KEY)
|
||||
readOnly = resultData.getBoolean(READ_ONLY_KEY)
|
||||
cipherEntity = resultData.getParcelable(CIPHER_ENTITY_KEY)
|
||||
}
|
||||
|
||||
databaseUri?.let { databaseFileUri ->
|
||||
showProgressDialogAndLoadDatabase(
|
||||
databaseFileUri,
|
||||
masterPassword,
|
||||
keyFileUri,
|
||||
readOnly,
|
||||
cipherEntity,
|
||||
true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Show error message
|
||||
if (resultMessage != null && resultMessage.isNotEmpty()) {
|
||||
resultError = "$resultError $resultMessage"
|
||||
}
|
||||
Log.e(TAG, resultError, resultException)
|
||||
Snackbar.make(activity_password_coordinator_layout,
|
||||
resultError,
|
||||
Snackbar.LENGTH_LONG).asError().show()
|
||||
}
|
||||
Log.e(TAG, resultError, resultException)
|
||||
Snackbar.make(activity_password_coordinator_layout,
|
||||
resultError,
|
||||
Snackbar.LENGTH_LONG).asError().show()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -272,7 +274,7 @@ class PasswordActivity : StylishActivity() {
|
||||
// For check shutdown
|
||||
super.onResume()
|
||||
|
||||
progressDialogThread?.registerProgressTask()
|
||||
mProgressDialogThread?.registerProgressTask()
|
||||
|
||||
initUriFromIntent()
|
||||
}
|
||||
@@ -399,7 +401,7 @@ class PasswordActivity : StylishActivity() {
|
||||
}
|
||||
})
|
||||
}
|
||||
advancedUnlockedManager?.initBiometric()
|
||||
advancedUnlockedManager?.checkBiometricAvailability()
|
||||
biometricInitialize = true
|
||||
} else {
|
||||
advancedUnlockedManager?.destroy()
|
||||
@@ -459,7 +461,7 @@ class PasswordActivity : StylishActivity() {
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
progressDialogThread?.unregisterProgressTask()
|
||||
mProgressDialogThread?.unregisterProgressTask()
|
||||
|
||||
super.onPause()
|
||||
}
|
||||
@@ -527,7 +529,7 @@ class PasswordActivity : StylishActivity() {
|
||||
readOnly: Boolean,
|
||||
cipherDatabaseEntity: CipherDatabaseEntity?,
|
||||
fixDuplicateUUID: Boolean) {
|
||||
progressDialogThread?.startDatabaseLoad(
|
||||
mProgressDialogThread?.startDatabaseLoad(
|
||||
databaseUri,
|
||||
password,
|
||||
keyFile,
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2019 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.activities.dialogs
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.getBundleFromListNodes
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.getListNodesFromBundle
|
||||
|
||||
class DeleteNodesDialogFragment : DialogFragment() {
|
||||
|
||||
private var mNodesToDelete: List<Node> = ArrayList()
|
||||
private var mListener: DeleteNodeListener? = null
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
try {
|
||||
mListener = context as DeleteNodeListener
|
||||
} catch (e: ClassCastException) {
|
||||
throw ClassCastException(context.toString()
|
||||
+ " must implement " + DeleteNodeListener::class.java.name)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
|
||||
arguments?.apply {
|
||||
if (containsKey(DatabaseTaskNotificationService.GROUPS_ID_KEY)
|
||||
&& containsKey(DatabaseTaskNotificationService.ENTRIES_ID_KEY)) {
|
||||
mNodesToDelete = getListNodesFromBundle(Database.getInstance(), this)
|
||||
}
|
||||
} ?: savedInstanceState?.apply {
|
||||
if (containsKey(DatabaseTaskNotificationService.GROUPS_ID_KEY)
|
||||
&& containsKey(DatabaseTaskNotificationService.ENTRIES_ID_KEY)) {
|
||||
mNodesToDelete = getListNodesFromBundle(Database.getInstance(), savedInstanceState)
|
||||
}
|
||||
}
|
||||
activity?.let { activity ->
|
||||
// Use the Builder class for convenient dialog construction
|
||||
val builder = AlertDialog.Builder(activity)
|
||||
|
||||
builder.setMessage(getString(R.string.warning_permanently_delete_nodes))
|
||||
builder.setPositiveButton(android.R.string.yes) { _, _ ->
|
||||
mListener?.permanentlyDeleteNodes(mNodesToDelete)
|
||||
}
|
||||
builder.setNegativeButton(android.R.string.no) { _, _ -> dismiss() }
|
||||
// Create the AlertDialog object and return it
|
||||
return builder.create()
|
||||
}
|
||||
return super.onCreateDialog(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putAll(getBundleFromListNodes(mNodesToDelete))
|
||||
}
|
||||
|
||||
interface DeleteNodeListener {
|
||||
fun permanentlyDeleteNodes(nodes: List<Node>)
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getInstance(nodesToDelete: List<Node>): DeleteNodesDialogFragment {
|
||||
return DeleteNodesDialogFragment().apply {
|
||||
arguments = getBundleFromListNodes(nodesToDelete)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,8 +33,8 @@ import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.dialogs.GroupEditDialogFragment.EditGroupDialogAction.CREATION
|
||||
import com.kunzisoft.keepass.activities.dialogs.GroupEditDialogFragment.EditGroupDialogAction.UPDATE
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.GroupVersioned
|
||||
import com.kunzisoft.keepass.database.element.PwIcon
|
||||
import com.kunzisoft.keepass.database.element.Group
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.icons.assignDatabaseIcon
|
||||
|
||||
class GroupEditDialogFragment : DialogFragment(), IconPickerDialogFragment.IconPickerListener {
|
||||
@@ -45,7 +45,7 @@ class GroupEditDialogFragment : DialogFragment(), IconPickerDialogFragment.IconP
|
||||
|
||||
private var editGroupDialogAction: EditGroupDialogAction? = null
|
||||
private var nameGroup: String? = null
|
||||
private var iconGroup: PwIcon? = null
|
||||
private var iconGroup: IconImage? = null
|
||||
|
||||
private var nameTextLayoutView: TextInputLayout? = null
|
||||
private var nameTextView: TextView? = null
|
||||
@@ -186,8 +186,8 @@ class GroupEditDialogFragment : DialogFragment(), IconPickerDialogFragment.IconP
|
||||
}
|
||||
|
||||
interface EditGroupListener {
|
||||
fun approveEditGroup(action: EditGroupDialogAction?, name: String?, icon: PwIcon?)
|
||||
fun cancelEditGroup(action: EditGroupDialogAction?, name: String?, icon: PwIcon?)
|
||||
fun approveEditGroup(action: EditGroupDialogAction?, name: String?, icon: IconImage?)
|
||||
fun cancelEditGroup(action: EditGroupDialogAction?, name: String?, icon: IconImage?)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -206,7 +206,7 @@ class GroupEditDialogFragment : DialogFragment(), IconPickerDialogFragment.IconP
|
||||
return fragment
|
||||
}
|
||||
|
||||
fun build(group: GroupVersioned): GroupEditDialogFragment {
|
||||
fun build(group: Group): GroupEditDialogFragment {
|
||||
val bundle = Bundle()
|
||||
bundle.putString(KEY_NAME, group.title)
|
||||
bundle.putParcelable(KEY_ICON, group.icon)
|
||||
|
||||
@@ -35,7 +35,7 @@ import android.widget.GridView
|
||||
import android.widget.ImageView
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.stylish.StylishActivity
|
||||
import com.kunzisoft.keepass.database.element.PwIconStandard
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
|
||||
import com.kunzisoft.keepass.icons.IconPack
|
||||
import com.kunzisoft.keepass.icons.IconPackChooser
|
||||
|
||||
@@ -72,7 +72,7 @@ class IconPickerDialogFragment : DialogFragment() {
|
||||
|
||||
currIconGridView.setOnItemClickListener { _, _, position, _ ->
|
||||
val bundle = Bundle()
|
||||
bundle.putParcelable(KEY_ICON_STANDARD, PwIconStandard(position))
|
||||
bundle.putParcelable(KEY_ICON_STANDARD, IconImageStandard(position))
|
||||
iconPickerListener?.iconPicked(bundle)
|
||||
dismiss()
|
||||
}
|
||||
@@ -128,7 +128,7 @@ class IconPickerDialogFragment : DialogFragment() {
|
||||
|
||||
private const val KEY_ICON_STANDARD = "KEY_ICON_STANDARD"
|
||||
|
||||
fun getIconStandardFromBundle(bundle: Bundle): PwIconStandard? {
|
||||
fun getIconStandardFromBundle(bundle: Bundle): IconImageStandard? {
|
||||
return bundle.getParcelable(KEY_ICON_STANDARD)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.kunzisoft.keepass.otp.OtpElement.Companion.MIN_TOTP_PERIOD
|
||||
import com.kunzisoft.keepass.otp.OtpTokenType
|
||||
import com.kunzisoft.keepass.otp.OtpType
|
||||
import com.kunzisoft.keepass.otp.TokenCalculator
|
||||
import java.util.*
|
||||
|
||||
class SetOTPDialogFragment : DialogFragment() {
|
||||
|
||||
@@ -246,7 +247,7 @@ class SetOTPDialogFragment : DialogFragment() {
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
s?.toString()?.let { userString ->
|
||||
try {
|
||||
mOtpElement.setBase32Secret(userString)
|
||||
mOtpElement.setBase32Secret(userString.toUpperCase(Locale.ENGLISH))
|
||||
otpSecretContainer?.error = null
|
||||
} catch (exception: Exception) {
|
||||
otpSecretContainer?.error = getString(R.string.error_otp_secret_key)
|
||||
|
||||
@@ -29,7 +29,7 @@ import android.view.View
|
||||
import android.widget.CompoundButton
|
||||
import android.widget.RadioGroup
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.SortNodeEnum
|
||||
import com.kunzisoft.keepass.database.element.SortNodeEnum
|
||||
|
||||
class SortDialogFragment : DialogFragment() {
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import android.view.ViewGroup
|
||||
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
|
||||
import com.kunzisoft.keepass.activities.helpers.ReadOnlyHelper
|
||||
import com.kunzisoft.keepass.activities.stylish.StylishActivity
|
||||
import com.kunzisoft.keepass.database.action.ProgressDialogThread
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.notifications.KeyboardEntryNotificationService
|
||||
import com.kunzisoft.keepass.magikeyboard.MagikIME
|
||||
@@ -63,6 +64,10 @@ abstract class LockingActivity : StylishActivity() {
|
||||
return field || mSelectionMode
|
||||
}
|
||||
protected var mSelectionMode: Boolean = false
|
||||
protected var mAutoSaveEnable: Boolean = true
|
||||
|
||||
var mProgressDialogThread: ProgressDialogThread? = null
|
||||
private set
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -86,6 +91,8 @@ abstract class LockingActivity : StylishActivity() {
|
||||
|
||||
mExitLock = false
|
||||
mReadOnly = ReadOnlyHelper.retrieveReadOnlyFromInstanceStateOrIntent(savedInstanceState, intent)
|
||||
|
||||
mProgressDialogThread = ProgressDialogThread(this)
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
@@ -101,8 +108,13 @@ abstract class LockingActivity : StylishActivity() {
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
mProgressDialogThread?.registerProgressTask()
|
||||
|
||||
// To refresh when back to normal workflow from selection workflow
|
||||
mSelectionMode = EntrySelectionHelper.retrieveEntrySelectionModeFromIntent(intent)
|
||||
mAutoSaveEnable = PreferencesUtil.isAutoSaveDatabaseEnabled(this)
|
||||
|
||||
invalidateOptionsMenu()
|
||||
|
||||
if (mTimeoutEnable) {
|
||||
// End activity if database not loaded
|
||||
@@ -119,8 +131,6 @@ abstract class LockingActivity : StylishActivity() {
|
||||
if (!mExitLock)
|
||||
TimeoutHelper.recordTime(this)
|
||||
}
|
||||
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
@@ -130,6 +140,8 @@ abstract class LockingActivity : StylishActivity() {
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
mProgressDialogThread?.unregisterProgressTask()
|
||||
|
||||
super.onPause()
|
||||
|
||||
if (mTimeoutEnable) {
|
||||
|
||||
@@ -7,13 +7,13 @@ import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.element.EntryVersioned
|
||||
import com.kunzisoft.keepass.database.element.Entry
|
||||
|
||||
class EntryHistoryAdapter(val context: Context) : RecyclerView.Adapter<EntryHistoryAdapter.EntryHistoryViewHolder>() {
|
||||
|
||||
private val inflater: LayoutInflater = LayoutInflater.from(context)
|
||||
var entryHistoryList: MutableList<EntryVersioned> = ArrayList()
|
||||
var onItemClickListener: ((item: EntryVersioned, position: Int)->Unit)? = null
|
||||
var entryHistoryList: MutableList<Entry> = ArrayList()
|
||||
var onItemClickListener: ((item: Entry, position: Int)->Unit)? = null
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EntryHistoryViewHolder {
|
||||
return EntryHistoryViewHolder(inflater.inflate(R.layout.item_list_entry_history, parent, false))
|
||||
|
||||
@@ -34,8 +34,10 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.SortedList
|
||||
import androidx.recyclerview.widget.SortedListAdapterCallback
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.SortNodeEnum
|
||||
import com.kunzisoft.keepass.database.element.SortNodeEnum
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.icons.assignDatabaseIcon
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
import java.util.*
|
||||
@@ -48,7 +50,7 @@ class NodeAdapter
|
||||
(private val context: Context)
|
||||
: RecyclerView.Adapter<NodeAdapter.NodeViewHolder>() {
|
||||
|
||||
private val nodeSortedList: SortedList<NodeVersioned>
|
||||
private val nodeSortedList: SortedList<Node>
|
||||
private val inflater: LayoutInflater = LayoutInflater.from(context)
|
||||
|
||||
private var calculateViewTypeTextSize = Array(2) { true} // number of view type
|
||||
@@ -65,7 +67,7 @@ class NodeAdapter
|
||||
private var showUserNames: Boolean = true
|
||||
private var showNumberEntries: Boolean = true
|
||||
|
||||
private var actionNodesList = LinkedList<NodeVersioned>()
|
||||
private var actionNodesList = LinkedList<Node>()
|
||||
private var nodeClickCallback: NodeClickCallback? = null
|
||||
|
||||
private val mDatabase: Database
|
||||
@@ -83,18 +85,18 @@ class NodeAdapter
|
||||
init {
|
||||
assignPreferences()
|
||||
|
||||
this.nodeSortedList = SortedList(NodeVersioned::class.java, object : SortedListAdapterCallback<NodeVersioned>(this) {
|
||||
override fun compare(item1: NodeVersioned, item2: NodeVersioned): Int {
|
||||
this.nodeSortedList = SortedList(Node::class.java, object : SortedListAdapterCallback<Node>(this) {
|
||||
override fun compare(item1: Node, item2: Node): Int {
|
||||
return listSort.getNodeComparator(ascendingSort, groupsBeforeSort, recycleBinBottomSort).compare(item1, item2)
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: NodeVersioned, newItem: NodeVersioned): Boolean {
|
||||
override fun areContentsTheSame(oldItem: Node, newItem: Node): Boolean {
|
||||
return oldItem.type == newItem.type
|
||||
&& oldItem.title == newItem.title
|
||||
&& oldItem.icon == newItem.icon
|
||||
}
|
||||
|
||||
override fun areItemsTheSame(item1: NodeVersioned, item2: NodeVersioned): Boolean {
|
||||
override fun areItemsTheSame(item1: Node, item2: Node): Boolean {
|
||||
return item1 == item2
|
||||
}
|
||||
})
|
||||
@@ -133,7 +135,7 @@ class NodeAdapter
|
||||
/**
|
||||
* Rebuild the list by clear and build children from the group
|
||||
*/
|
||||
fun rebuildList(group: GroupVersioned) {
|
||||
fun rebuildList(group: Group) {
|
||||
this.nodeSortedList.clear()
|
||||
assignPreferences()
|
||||
try {
|
||||
@@ -145,7 +147,7 @@ class NodeAdapter
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun contains(node: NodeVersioned): Boolean {
|
||||
fun contains(node: Node): Boolean {
|
||||
return nodeSortedList.indexOf(node) != SortedList.INVALID_POSITION
|
||||
}
|
||||
|
||||
@@ -153,7 +155,7 @@ class NodeAdapter
|
||||
* Add a node to the list
|
||||
* @param node Node to add
|
||||
*/
|
||||
fun addNode(node: NodeVersioned) {
|
||||
fun addNode(node: Node) {
|
||||
nodeSortedList.add(node)
|
||||
}
|
||||
|
||||
@@ -161,7 +163,7 @@ class NodeAdapter
|
||||
* Add nodes to the list
|
||||
* @param nodes Nodes to add
|
||||
*/
|
||||
fun addNodes(nodes: List<NodeVersioned>) {
|
||||
fun addNodes(nodes: List<Node>) {
|
||||
nodeSortedList.addAll(nodes)
|
||||
}
|
||||
|
||||
@@ -169,7 +171,7 @@ class NodeAdapter
|
||||
* Remove a node in the list
|
||||
* @param node Node to delete
|
||||
*/
|
||||
fun removeNode(node: NodeVersioned) {
|
||||
fun removeNode(node: Node) {
|
||||
nodeSortedList.remove(node)
|
||||
}
|
||||
|
||||
@@ -177,7 +179,7 @@ class NodeAdapter
|
||||
* Remove nodes in the list
|
||||
* @param nodes Nodes to delete
|
||||
*/
|
||||
fun removeNodes(nodes: List<NodeVersioned>) {
|
||||
fun removeNodes(nodes: List<Node>) {
|
||||
nodes.forEach { node ->
|
||||
nodeSortedList.remove(node)
|
||||
}
|
||||
@@ -209,7 +211,7 @@ class NodeAdapter
|
||||
* @param oldNode Node before the update
|
||||
* @param newNode Node after the update
|
||||
*/
|
||||
fun updateNode(oldNode: NodeVersioned, newNode: NodeVersioned) {
|
||||
fun updateNode(oldNode: Node, newNode: Node) {
|
||||
nodeSortedList.beginBatchedUpdates()
|
||||
nodeSortedList.remove(oldNode)
|
||||
nodeSortedList.add(newNode)
|
||||
@@ -221,7 +223,7 @@ class NodeAdapter
|
||||
* @param oldNodes Nodes before the update
|
||||
* @param newNodes Node after the update
|
||||
*/
|
||||
fun updateNodes(oldNodes: List<NodeVersioned>, newNodes: List<NodeVersioned>) {
|
||||
fun updateNodes(oldNodes: List<Node>, newNodes: List<Node>) {
|
||||
nodeSortedList.beginBatchedUpdates()
|
||||
oldNodes.forEach { oldNode ->
|
||||
nodeSortedList.remove(oldNode)
|
||||
@@ -230,11 +232,11 @@ class NodeAdapter
|
||||
nodeSortedList.endBatchedUpdates()
|
||||
}
|
||||
|
||||
fun notifyNodeChanged(node: NodeVersioned) {
|
||||
fun notifyNodeChanged(node: Node) {
|
||||
notifyItemChanged(nodeSortedList.indexOf(node))
|
||||
}
|
||||
|
||||
fun setActionNodes(actionNodes: List<NodeVersioned>) {
|
||||
fun setActionNodes(actionNodes: List<Node>) {
|
||||
this.actionNodesList.apply {
|
||||
clear()
|
||||
addAll(actionNodes)
|
||||
@@ -315,7 +317,7 @@ class NodeAdapter
|
||||
paintFlags and Paint.STRIKE_THRU_TEXT_FLAG
|
||||
visibility = View.GONE
|
||||
if (subNode.type == Type.ENTRY) {
|
||||
val entry = subNode as EntryVersioned
|
||||
val entry = subNode as Entry
|
||||
|
||||
mDatabase.startManageEntry(entry)
|
||||
|
||||
@@ -336,7 +338,7 @@ class NodeAdapter
|
||||
if (subNode.type == Type.GROUP) {
|
||||
if (showNumberEntries) {
|
||||
holder.numberChildren?.apply {
|
||||
text = (subNode as GroupVersioned).getChildEntries(true).size.toString()
|
||||
text = (subNode as Group).getChildEntries(true).size.toString()
|
||||
setTextSize(textSizeUnit, numberChildrenTextSize)
|
||||
visibility = View.VISIBLE
|
||||
}
|
||||
@@ -361,8 +363,8 @@ class NodeAdapter
|
||||
* Callback listener to redefine to do an action when a node is click
|
||||
*/
|
||||
interface NodeClickCallback {
|
||||
fun onNodeClick(node: NodeVersioned)
|
||||
fun onNodeLongClick(node: NodeVersioned): Boolean
|
||||
fun onNodeClick(node: Node)
|
||||
fun onNodeLongClick(node: Node): Boolean
|
||||
}
|
||||
|
||||
class NodeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
|
||||
@@ -22,7 +22,6 @@ package com.kunzisoft.keepass.adapters
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.graphics.Color
|
||||
import androidx.cursoradapter.widget.CursorAdapter
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -31,8 +30,8 @@ import android.widget.TextView
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.cursor.EntryCursor
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.EntryVersioned
|
||||
import com.kunzisoft.keepass.database.element.PwIcon
|
||||
import com.kunzisoft.keepass.database.element.Entry
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.icons.assignDatabaseIcon
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
import java.util.*
|
||||
@@ -76,7 +75,7 @@ class SearchEntryCursorAdapter(context: Context, private val database: Database)
|
||||
val uuid = UUID(cursor.getLong(cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_UUID_MOST_SIGNIFICANT_BITS)),
|
||||
cursor.getLong(cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_UUID_LEAST_SIGNIFICANT_BITS)))
|
||||
val iconFactory = database.iconFactory
|
||||
var icon: PwIcon = iconFactory.getIcon(
|
||||
var icon: IconImage = iconFactory.getIcon(
|
||||
UUID(cursor.getLong(cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_ICON_CUSTOM_UUID_MOST_SIGNIFICANT_BITS)),
|
||||
cursor.getLong(cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_ICON_CUSTOM_UUID_LEAST_SIGNIFICANT_BITS))))
|
||||
if (icon.isUnknown) {
|
||||
@@ -94,7 +93,7 @@ class SearchEntryCursorAdapter(context: Context, private val database: Database)
|
||||
viewHolder.imageViewIcon?.assignDatabaseIcon(database.drawFactory, icon, iconColor)
|
||||
|
||||
// Assign title
|
||||
val showTitle = EntryVersioned.getVisualTitle(false, title, username, url, uuid.toString())
|
||||
val showTitle = Entry.getVisualTitle(false, title, username, url, uuid.toString())
|
||||
viewHolder.textViewTitle?.text = showTitle
|
||||
if (displayUsername && username.isNotEmpty()) {
|
||||
viewHolder.textViewSubTitle?.text = String.format("(%s)", username)
|
||||
@@ -113,8 +112,8 @@ class SearchEntryCursorAdapter(context: Context, private val database: Database)
|
||||
return database.searchEntries(constraint.toString())
|
||||
}
|
||||
|
||||
fun getEntryFromPosition(position: Int): EntryVersioned? {
|
||||
var pwEntry: EntryVersioned? = null
|
||||
fun getEntryFromPosition(position: Int): Entry? {
|
||||
var pwEntry: Entry? = null
|
||||
|
||||
val cursor = this.cursor
|
||||
if (cursor.moveToFirst() && cursor.move(position)) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.view.MenuInflater
|
||||
import android.widget.CompoundButton
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.biometric.BiometricConstants
|
||||
import androidx.biometric.BiometricManager
|
||||
import androidx.biometric.BiometricPrompt
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
@@ -36,65 +37,59 @@ class AdvancedUnlockedManager(var context: FragmentActivity,
|
||||
|
||||
private var cipherDatabaseAction = CipherDatabaseAction.getInstance(context.applicationContext)
|
||||
|
||||
// fingerprint related code here
|
||||
fun initBiometric() {
|
||||
|
||||
// Check if fingerprint well init (be called the first time the fingerprint is configured
|
||||
// and the activity still active)
|
||||
if (biometricUnlockDatabaseHelper == null || !biometricUnlockDatabaseHelper!!.isBiometricInitialized) {
|
||||
biometricUnlockDatabaseHelper = BiometricUnlockDatabaseHelper(context)
|
||||
// callback for fingerprint findings
|
||||
biometricUnlockDatabaseHelper?.biometricUnlockCallback = this
|
||||
biometricUnlockDatabaseHelper?.authenticationCallback = biometricAuthenticationCallback
|
||||
}
|
||||
|
||||
init {
|
||||
// Add a check listener to change fingerprint mode
|
||||
checkboxPasswordView?.setOnCheckedChangeListener { compoundButton, checked ->
|
||||
|
||||
checkBiometricAvailability()
|
||||
|
||||
// Add old listener to enable the button, only be call here because of onCheckedChange bug
|
||||
onCheckedPasswordChangeListener?.onCheckedChanged(compoundButton, checked)
|
||||
}
|
||||
|
||||
checkBiometricAvailability()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun checkBiometricAvailability() {
|
||||
/**
|
||||
* Check biometric availability and change the current mode depending of device's state
|
||||
*/
|
||||
fun checkBiometricAvailability() {
|
||||
|
||||
// fingerprint not supported (by API level or hardware) so keep option hidden
|
||||
// biometric not supported (by API level or hardware) so keep option hidden
|
||||
// or manually disable
|
||||
val biometricCanAuthenticate = BiometricManager.from(context).canAuthenticate()
|
||||
|
||||
if (!PreferencesUtil.isBiometricUnlockEnable(context)
|
||||
|| biometricCanAuthenticate == BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE
|
||||
|| biometricCanAuthenticate == BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE) {
|
||||
|
||||
toggleMode(Mode.UNAVAILABLE)
|
||||
|
||||
} else {
|
||||
|
||||
// fingerprint is available but not configured, show icon but in disabled state with some information
|
||||
// biometric is available but not configured, show icon but in disabled state with some information
|
||||
if (biometricCanAuthenticate == BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED) {
|
||||
|
||||
toggleMode(Mode.NOT_CONFIGURED)
|
||||
|
||||
toggleMode(Mode.BIOMETRIC_NOT_CONFIGURED)
|
||||
} else {
|
||||
if (checkboxPasswordView?.isChecked == true) {
|
||||
// listen for encryption
|
||||
toggleMode(Mode.STORE)
|
||||
// Check if fingerprint well init (be called the first time the fingerprint is configured
|
||||
// and the activity still active)
|
||||
if (biometricUnlockDatabaseHelper?.isKeyManagerInitialized != true) {
|
||||
biometricUnlockDatabaseHelper = BiometricUnlockDatabaseHelper(context)
|
||||
// callback for fingerprint findings
|
||||
biometricUnlockDatabaseHelper?.biometricUnlockCallback = this
|
||||
biometricUnlockDatabaseHelper?.authenticationCallback = biometricAuthenticationCallback
|
||||
}
|
||||
// Recheck to change the mode
|
||||
if (biometricUnlockDatabaseHelper?.isKeyManagerInitialized != true) {
|
||||
toggleMode(Mode.KEY_MANAGER_UNAVAILABLE)
|
||||
} else {
|
||||
cipherDatabaseAction.containsCipherDatabase(databaseFileUri) { containsCipher ->
|
||||
|
||||
// fingerprint available but no stored password found yet for this DB so show info don't listen
|
||||
toggleMode( if (containsCipher) {
|
||||
// listen for decryption
|
||||
Mode.OPEN
|
||||
} else {
|
||||
// wait for typing
|
||||
Mode.WAIT_CREDENTIAL
|
||||
})
|
||||
if (checkboxPasswordView?.isChecked == true) {
|
||||
// listen for encryption
|
||||
toggleMode(Mode.STORE_CREDENTIAL)
|
||||
} else {
|
||||
cipherDatabaseAction.containsCipherDatabase(databaseFileUri) { containsCipher ->
|
||||
// biometric available but no stored password found yet for this DB so show info don't listen
|
||||
toggleMode( if (containsCipher) {
|
||||
// listen for decryption
|
||||
Mode.EXTRACT_CREDENTIAL
|
||||
} else {
|
||||
// wait for typing
|
||||
Mode.WAIT_CREDENTIAL
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,17 +124,15 @@ class AdvancedUnlockedManager(var context: FragmentActivity,
|
||||
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
|
||||
context.runOnUiThread {
|
||||
when (biometricMode) {
|
||||
Mode.UNAVAILABLE -> {
|
||||
}
|
||||
Mode.NOT_CONFIGURED -> {
|
||||
}
|
||||
Mode.WAIT_CREDENTIAL -> {
|
||||
}
|
||||
Mode.STORE -> {
|
||||
Mode.UNAVAILABLE -> {}
|
||||
Mode.BIOMETRIC_NOT_CONFIGURED -> {}
|
||||
Mode.KEY_MANAGER_UNAVAILABLE -> {}
|
||||
Mode.WAIT_CREDENTIAL -> {}
|
||||
Mode.STORE_CREDENTIAL -> {
|
||||
// newly store the entered password in encrypted way
|
||||
biometricUnlockDatabaseHelper?.encryptData(passwordView?.text.toString())
|
||||
}
|
||||
Mode.OPEN -> {
|
||||
Mode.EXTRACT_CREDENTIAL -> {
|
||||
// retrieve the encrypted value from preferences
|
||||
cipherDatabaseAction.getCipherDatabase(databaseFileUri) {
|
||||
it?.encryptedValue?.let { value ->
|
||||
@@ -155,7 +148,7 @@ class AdvancedUnlockedManager(var context: FragmentActivity,
|
||||
private fun initNotAvailable() {
|
||||
showFingerPrintViews(false)
|
||||
|
||||
advancedUnlockInfoView?.setIconViewClickListener(null)
|
||||
advancedUnlockInfoView?.setIconViewClickListener(false, null)
|
||||
}
|
||||
|
||||
private fun initNotConfigured() {
|
||||
@@ -163,7 +156,17 @@ class AdvancedUnlockedManager(var context: FragmentActivity,
|
||||
setAdvancedUnlockedTitleView(R.string.configure_biometric)
|
||||
setAdvancedUnlockedMessageView("")
|
||||
|
||||
advancedUnlockInfoView?.setIconViewClickListener {
|
||||
advancedUnlockInfoView?.setIconViewClickListener(false) {
|
||||
context.startActivity(Intent(Settings.ACTION_SECURITY_SETTINGS))
|
||||
}
|
||||
}
|
||||
|
||||
private fun initKeyManagerNotAvailable() {
|
||||
showFingerPrintViews(true)
|
||||
setAdvancedUnlockedTitleView(R.string.keystore_not_accessible)
|
||||
setAdvancedUnlockedMessageView("")
|
||||
|
||||
advancedUnlockInfoView?.setIconViewClickListener(false) {
|
||||
context.startActivity(Intent(Settings.ACTION_SECURITY_SETTINGS))
|
||||
}
|
||||
}
|
||||
@@ -173,7 +176,11 @@ class AdvancedUnlockedManager(var context: FragmentActivity,
|
||||
setAdvancedUnlockedTitleView(R.string.no_credentials_stored)
|
||||
setAdvancedUnlockedMessageView("")
|
||||
|
||||
advancedUnlockInfoView?.setIconViewClickListener(null)
|
||||
advancedUnlockInfoView?.setIconViewClickListener(false) {
|
||||
biometricAuthenticationCallback.onAuthenticationError(
|
||||
BiometricConstants.ERROR_UNABLE_TO_PROCESS
|
||||
, context.getString(R.string.credential_before_click_biometric_button))
|
||||
}
|
||||
}
|
||||
|
||||
private fun openBiometricPrompt(biometricPrompt: BiometricPrompt?,
|
||||
@@ -235,10 +242,11 @@ class AdvancedUnlockedManager(var context: FragmentActivity,
|
||||
fun initBiometricMode() {
|
||||
when (biometricMode) {
|
||||
Mode.UNAVAILABLE -> initNotAvailable()
|
||||
Mode.NOT_CONFIGURED -> initNotConfigured()
|
||||
Mode.BIOMETRIC_NOT_CONFIGURED -> initNotConfigured()
|
||||
Mode.KEY_MANAGER_UNAVAILABLE -> initKeyManagerNotAvailable()
|
||||
Mode.WAIT_CREDENTIAL -> initWaitData()
|
||||
Mode.STORE -> initEncryptData()
|
||||
Mode.OPEN -> initDecryptData()
|
||||
Mode.STORE_CREDENTIAL -> initEncryptData()
|
||||
Mode.EXTRACT_CREDENTIAL -> initDecryptData()
|
||||
}
|
||||
// Show fingerprint key deletion
|
||||
context.invalidateOptionsMenu()
|
||||
@@ -255,7 +263,7 @@ class AdvancedUnlockedManager(var context: FragmentActivity,
|
||||
if (!addBiometricMenuInProgress) {
|
||||
addBiometricMenuInProgress = true
|
||||
cipherDatabaseAction.containsCipherDatabase(databaseFileUri) {
|
||||
if ((biometricMode != Mode.UNAVAILABLE && biometricMode != Mode.NOT_CONFIGURED)
|
||||
if ((biometricMode != Mode.UNAVAILABLE && biometricMode != Mode.BIOMETRIC_NOT_CONFIGURED)
|
||||
&& it) {
|
||||
menuInflater.inflate(R.menu.advanced_unlock, menu)
|
||||
addBiometricMenuInProgress = false
|
||||
@@ -267,7 +275,7 @@ class AdvancedUnlockedManager(var context: FragmentActivity,
|
||||
fun deleteEntryKey() {
|
||||
biometricUnlockDatabaseHelper?.deleteEntryKey()
|
||||
cipherDatabaseAction.deleteByDatabaseUri(databaseFileUri)
|
||||
biometricMode = Mode.NOT_CONFIGURED
|
||||
biometricMode = Mode.BIOMETRIC_NOT_CONFIGURED
|
||||
checkBiometricAvailability()
|
||||
}
|
||||
|
||||
@@ -313,7 +321,7 @@ class AdvancedUnlockedManager(var context: FragmentActivity,
|
||||
}
|
||||
|
||||
enum class Mode {
|
||||
UNAVAILABLE, NOT_CONFIGURED, WAIT_CREDENTIAL, STORE, OPEN
|
||||
UNAVAILABLE, BIOMETRIC_NOT_CONFIGURED, KEY_MANAGER_UNAVAILABLE, WAIT_CREDENTIAL, STORE_CREDENTIAL, EXTRACT_CREDENTIAL
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -52,13 +52,14 @@ class BiometricUnlockDatabaseHelper(private val context: FragmentActivity) {
|
||||
private var keyguardManager: KeyguardManager? = null
|
||||
private var cryptoObject: BiometricPrompt.CryptoObject? = null
|
||||
|
||||
private var isBiometricInit = false
|
||||
private var isKeyManagerInit = false
|
||||
var authenticationCallback: BiometricPrompt.AuthenticationCallback? = null
|
||||
var biometricUnlockCallback: BiometricUnlockCallback? = null
|
||||
|
||||
private val promptInfoStoreCredential = BiometricPrompt.PromptInfo.Builder().apply {
|
||||
setTitle(context.getString(R.string.biometric_prompt_store_credential_title))
|
||||
setDescription(context.getString(R.string.biometric_prompt_store_credential_message))
|
||||
setConfirmationRequired(true)
|
||||
// TODO device credential
|
||||
/*
|
||||
if (keyguardManager?.isDeviceSecure == true)
|
||||
@@ -70,7 +71,8 @@ class BiometricUnlockDatabaseHelper(private val context: FragmentActivity) {
|
||||
|
||||
private val promptInfoExtractCredential = BiometricPrompt.PromptInfo.Builder().apply {
|
||||
setTitle(context.getString(R.string.biometric_prompt_extract_credential_title))
|
||||
setDescription(context.getString(R.string.biometric_prompt_extract_credential_message))
|
||||
//setDescription(context.getString(R.string.biometric_prompt_extract_credential_message))
|
||||
setConfirmationRequired(false)
|
||||
// TODO device credential
|
||||
/*
|
||||
if (keyguardManager?.isDeviceSecure == true)
|
||||
@@ -80,18 +82,18 @@ class BiometricUnlockDatabaseHelper(private val context: FragmentActivity) {
|
||||
setNegativeButtonText(context.getString(android.R.string.cancel))
|
||||
}.build()
|
||||
|
||||
val isBiometricInitialized: Boolean
|
||||
val isKeyManagerInitialized: Boolean
|
||||
get() {
|
||||
if (!isBiometricInit) {
|
||||
if (!isKeyManagerInit) {
|
||||
biometricUnlockCallback?.onBiometricException(Exception("Biometric not initialized"))
|
||||
}
|
||||
return isBiometricInit
|
||||
return isKeyManagerInit
|
||||
}
|
||||
|
||||
init {
|
||||
if (BiometricManager.from(context).canAuthenticate() != BiometricManager.BIOMETRIC_SUCCESS) {
|
||||
// really not much to do when no fingerprint support found
|
||||
isBiometricInit = false
|
||||
isKeyManagerInit = false
|
||||
} else {
|
||||
this.keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||
|
||||
@@ -103,17 +105,19 @@ class BiometricUnlockDatabaseHelper(private val context: FragmentActivity) {
|
||||
+ BIOMETRIC_BLOCKS_MODES + "/"
|
||||
+ BIOMETRIC_ENCRYPTION_PADDING)
|
||||
this.cryptoObject = BiometricPrompt.CryptoObject(cipher!!)
|
||||
isBiometricInit = true
|
||||
isKeyManagerInit = (keyStore != null
|
||||
&& keyGenerator != null
|
||||
&& cipher != null)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Unable to initialize the keystore", e)
|
||||
isBiometricInit = false
|
||||
isKeyManagerInit = false
|
||||
biometricUnlockCallback?.onBiometricException(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSecretKey(): SecretKey? {
|
||||
if (!isBiometricInitialized) {
|
||||
if (!isKeyManagerInitialized) {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
@@ -155,7 +159,7 @@ class BiometricUnlockDatabaseHelper(private val context: FragmentActivity) {
|
||||
: (biometricPrompt: BiometricPrompt?,
|
||||
cryptoObject: BiometricPrompt.CryptoObject?,
|
||||
promptInfo: BiometricPrompt.PromptInfo)->Unit) {
|
||||
if (!isBiometricInitialized) {
|
||||
if (!isKeyManagerInitialized) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
@@ -176,11 +180,10 @@ class BiometricUnlockDatabaseHelper(private val context: FragmentActivity) {
|
||||
Log.e(TAG, "Unable to initialize encrypt data", e)
|
||||
biometricUnlockCallback?.onBiometricException(e)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun encryptData(value: String) {
|
||||
if (!isBiometricInitialized) {
|
||||
if (!isKeyManagerInitialized) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
@@ -197,14 +200,13 @@ class BiometricUnlockDatabaseHelper(private val context: FragmentActivity) {
|
||||
Log.e(TAG, "Unable to encrypt data", e)
|
||||
biometricUnlockCallback?.onBiometricException(e)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun initDecryptData(ivSpecValue: String, actionIfCypherInit
|
||||
: (biometricPrompt: BiometricPrompt?,
|
||||
cryptoObject: BiometricPrompt.CryptoObject?,
|
||||
promptInfo: BiometricPrompt.PromptInfo)->Unit) {
|
||||
if (!isBiometricInitialized) {
|
||||
if (!isKeyManagerInitialized) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
@@ -229,11 +231,10 @@ class BiometricUnlockDatabaseHelper(private val context: FragmentActivity) {
|
||||
Log.e(TAG, "Unable to initialize decrypt data", e)
|
||||
biometricUnlockCallback?.onBiometricException(e)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun decryptData(encryptedValue: String) {
|
||||
if (!isBiometricInitialized) {
|
||||
if (!isKeyManagerInitialized) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
@@ -249,7 +250,6 @@ class BiometricUnlockDatabaseHelper(private val context: FragmentActivity) {
|
||||
Log.e(TAG, "Unable to decrypt data", e)
|
||||
biometricUnlockCallback?.onBiometricException(e)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun deleteEntryKey() {
|
||||
|
||||
@@ -20,43 +20,44 @@
|
||||
package com.kunzisoft.keepass.biometric
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Animatable2
|
||||
import android.graphics.drawable.AnimatedVectorDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import android.widget.ImageView
|
||||
import androidx.vectordrawable.graphics.drawable.Animatable2Compat
|
||||
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
|
||||
|
||||
import com.kunzisoft.keepass.R
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
class FingerPrintAnimatedVector(context: Context, imageView: ImageView) {
|
||||
|
||||
private val scanFingerprint: AnimatedVectorDrawable =
|
||||
context.getDrawable(R.drawable.scan_fingerprint) as AnimatedVectorDrawable
|
||||
private val scanFingerprint: AnimatedVectorDrawableCompat? =
|
||||
AnimatedVectorDrawableCompat.create(context, R.drawable.scan_fingerprint)
|
||||
|
||||
init {
|
||||
imageView.setImageDrawable(scanFingerprint)
|
||||
}
|
||||
|
||||
private var animationCallback = object : Animatable2.AnimationCallback() {
|
||||
private var animationCallback = object : Animatable2Compat.AnimationCallback() {
|
||||
override fun onAnimationEnd(drawable: Drawable) {
|
||||
if (!scanFingerprint.isRunning)
|
||||
scanFingerprint.start()
|
||||
imageView.post {
|
||||
scanFingerprint?.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun startScan() {
|
||||
scanFingerprint.registerAnimationCallback(animationCallback)
|
||||
scanFingerprint?.registerAnimationCallback(animationCallback)
|
||||
|
||||
if (!scanFingerprint.isRunning)
|
||||
scanFingerprint.start()
|
||||
if (scanFingerprint?.isRunning != true)
|
||||
scanFingerprint?.start()
|
||||
}
|
||||
|
||||
fun stopScan() {
|
||||
scanFingerprint.unregisterAnimationCallback(animationCallback)
|
||||
scanFingerprint?.unregisterAnimationCallback(animationCallback)
|
||||
|
||||
if (scanFingerprint.isRunning)
|
||||
if (scanFingerprint?.isRunning == true)
|
||||
scanFingerprint.stop()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ package com.kunzisoft.keepass.crypto.engine
|
||||
|
||||
|
||||
import com.kunzisoft.keepass.crypto.CipherFactory
|
||||
import com.kunzisoft.keepass.database.element.PwEncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.utils.Types
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.utils.DatabaseInputOutputUtils
|
||||
import java.security.InvalidAlgorithmParameterException
|
||||
import java.security.InvalidKeyException
|
||||
import java.security.NoSuchAlgorithmException
|
||||
@@ -41,13 +41,13 @@ class AesEngine : CipherEngine() {
|
||||
return cipher
|
||||
}
|
||||
|
||||
override fun getPwEncryptionAlgorithm(): PwEncryptionAlgorithm {
|
||||
return PwEncryptionAlgorithm.AESRijndael
|
||||
override fun getPwEncryptionAlgorithm(): EncryptionAlgorithm {
|
||||
return EncryptionAlgorithm.AESRijndael
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
val CIPHER_UUID: UUID = Types.bytestoUUID(
|
||||
val CIPHER_UUID: UUID = DatabaseInputOutputUtils.bytesToUuid(
|
||||
byteArrayOf(0x31.toByte(), 0xC1.toByte(), 0xF2.toByte(), 0xE6.toByte(), 0xBF.toByte(), 0x71.toByte(), 0x43.toByte(), 0x50.toByte(), 0xBE.toByte(), 0x58.toByte(), 0x05.toByte(), 0x21.toByte(), 0x6A.toByte(), 0xFC.toByte(), 0x5A.toByte(), 0xFF.toByte()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.engine
|
||||
|
||||
import com.kunzisoft.keepass.database.element.PwEncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.utils.Types
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.utils.DatabaseInputOutputUtils
|
||||
import org.spongycastle.jce.provider.BouncyCastleProvider
|
||||
import java.security.InvalidAlgorithmParameterException
|
||||
import java.security.InvalidKeyException
|
||||
@@ -44,13 +44,13 @@ class ChaCha20Engine : CipherEngine() {
|
||||
return cipher
|
||||
}
|
||||
|
||||
override fun getPwEncryptionAlgorithm(): PwEncryptionAlgorithm {
|
||||
return PwEncryptionAlgorithm.ChaCha20
|
||||
override fun getPwEncryptionAlgorithm(): EncryptionAlgorithm {
|
||||
return EncryptionAlgorithm.ChaCha20
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
val CIPHER_UUID: UUID = Types.bytestoUUID(
|
||||
val CIPHER_UUID: UUID = DatabaseInputOutputUtils.bytesToUuid(
|
||||
byteArrayOf(0xD6.toByte(), 0x03.toByte(), 0x8A.toByte(), 0x2B.toByte(), 0x8B.toByte(), 0x6F.toByte(), 0x4C.toByte(), 0xB5.toByte(), 0xA5.toByte(), 0x24.toByte(), 0x33.toByte(), 0x9A.toByte(), 0x31.toByte(), 0xDB.toByte(), 0xB5.toByte(), 0x9A.toByte()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.engine
|
||||
|
||||
import com.kunzisoft.keepass.database.element.PwEncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
|
||||
import java.security.InvalidAlgorithmParameterException
|
||||
import java.security.InvalidKeyException
|
||||
@@ -46,6 +46,6 @@ abstract class CipherEngine {
|
||||
return getCipher(opmode, key, IV, false)
|
||||
}
|
||||
|
||||
abstract fun getPwEncryptionAlgorithm(): PwEncryptionAlgorithm
|
||||
abstract fun getPwEncryptionAlgorithm(): EncryptionAlgorithm
|
||||
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
package com.kunzisoft.keepass.crypto.engine
|
||||
|
||||
import com.kunzisoft.keepass.crypto.CipherFactory
|
||||
import com.kunzisoft.keepass.database.element.PwEncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.utils.Types
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.utils.DatabaseInputOutputUtils
|
||||
|
||||
import java.security.InvalidAlgorithmParameterException
|
||||
import java.security.InvalidKeyException
|
||||
@@ -47,13 +47,13 @@ class TwofishEngine : CipherEngine() {
|
||||
return cipher
|
||||
}
|
||||
|
||||
override fun getPwEncryptionAlgorithm(): PwEncryptionAlgorithm {
|
||||
return PwEncryptionAlgorithm.Twofish
|
||||
override fun getPwEncryptionAlgorithm(): EncryptionAlgorithm {
|
||||
return EncryptionAlgorithm.Twofish
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
val CIPHER_UUID: UUID = Types.bytestoUUID(
|
||||
val CIPHER_UUID: UUID = DatabaseInputOutputUtils.bytesToUuid(
|
||||
byteArrayOf(0xAD.toByte(), 0x68.toByte(), 0xF2.toByte(), 0x9F.toByte(), 0x57.toByte(), 0x6F.toByte(), 0x4B.toByte(), 0xB9.toByte(), 0xA3.toByte(), 0x6A.toByte(), 0xD4.toByte(), 0x7A.toByte(), 0xF9.toByte(), 0x65.toByte(), 0x34.toByte(), 0x6C.toByte()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.content.res.Resources
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.crypto.CryptoUtil
|
||||
import com.kunzisoft.keepass.crypto.finalkey.FinalKeyFactory
|
||||
import com.kunzisoft.keepass.utils.Types
|
||||
import com.kunzisoft.keepass.utils.DatabaseInputOutputUtils
|
||||
import java.io.IOException
|
||||
import java.security.SecureRandom
|
||||
import java.util.*
|
||||
@@ -32,7 +32,7 @@ class AesKdf internal constructor() : KdfEngine() {
|
||||
|
||||
override val defaultParameters: KdfParameters
|
||||
get() {
|
||||
return KdfParameters(uuid).apply {
|
||||
return KdfParameters(uuid!!).apply {
|
||||
setParamUUID()
|
||||
setUInt32(PARAM_ROUNDS, DEFAULT_ROUNDS.toLong())
|
||||
}
|
||||
@@ -88,7 +88,7 @@ class AesKdf internal constructor() : KdfEngine() {
|
||||
|
||||
private const val DEFAULT_ROUNDS = 6000
|
||||
|
||||
val CIPHER_UUID: UUID = Types.bytestoUUID(
|
||||
val CIPHER_UUID: UUID = DatabaseInputOutputUtils.bytesToUuid(
|
||||
byteArrayOf(0xC9.toByte(),
|
||||
0xD9.toByte(),
|
||||
0xF3.toByte(),
|
||||
|
||||
@@ -21,7 +21,7 @@ package com.kunzisoft.keepass.crypto.keyDerivation
|
||||
|
||||
import android.content.res.Resources
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.utils.Types
|
||||
import com.kunzisoft.keepass.utils.DatabaseInputOutputUtils
|
||||
import java.io.IOException
|
||||
import java.security.SecureRandom
|
||||
import java.util.*
|
||||
@@ -30,7 +30,7 @@ class Argon2Kdf internal constructor() : KdfEngine() {
|
||||
|
||||
override val defaultParameters: KdfParameters
|
||||
get() {
|
||||
val p = KdfParameters(uuid)
|
||||
val p = KdfParameters(uuid!!)
|
||||
|
||||
p.setParamUUID()
|
||||
p.setUInt32(PARAM_PARALLELISM, DEFAULT_PARALLELISM)
|
||||
@@ -126,7 +126,7 @@ class Argon2Kdf internal constructor() : KdfEngine() {
|
||||
|
||||
companion object {
|
||||
|
||||
val CIPHER_UUID: UUID = Types.bytestoUUID(
|
||||
val CIPHER_UUID: UUID = DatabaseInputOutputUtils.bytesToUuid(
|
||||
byteArrayOf(0xEF.toByte(),
|
||||
0x63.toByte(),
|
||||
0x6D.toByte(),
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.keyDerivation;
|
||||
|
||||
import com.kunzisoft.keepass.utils.VariantDictionary;
|
||||
import com.kunzisoft.keepass.stream.LEDataInputStream;
|
||||
import com.kunzisoft.keepass.stream.LEDataOutputStream;
|
||||
import com.kunzisoft.keepass.utils.Types;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class KdfParameters extends VariantDictionary {
|
||||
|
||||
private UUID kdfUUID;
|
||||
|
||||
private static final String ParamUUID = "$UUID";
|
||||
|
||||
KdfParameters(UUID uuid) {
|
||||
kdfUUID = uuid;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return kdfUUID;
|
||||
}
|
||||
|
||||
protected void setParamUUID() {
|
||||
setByteArray(ParamUUID, Types.UUIDtoBytes(kdfUUID));
|
||||
}
|
||||
|
||||
public static KdfParameters deserialize(byte[] data) throws IOException {
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(data);
|
||||
LEDataInputStream lis = new LEDataInputStream(bis);
|
||||
|
||||
VariantDictionary d = VariantDictionary.deserialize(lis);
|
||||
if (d == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
UUID uuid = Types.bytestoUUID(d.getByteArray(ParamUUID));
|
||||
|
||||
KdfParameters kdfP = new KdfParameters(uuid);
|
||||
kdfP.copyTo(d);
|
||||
return kdfP;
|
||||
}
|
||||
|
||||
public static byte[] serialize(KdfParameters kdf) throws IOException {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
LEDataOutputStream los = new LEDataOutputStream(bos);
|
||||
|
||||
KdfParameters.serialize(kdf, los);
|
||||
|
||||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.keyDerivation
|
||||
|
||||
import com.kunzisoft.keepass.utils.VariantDictionary
|
||||
import com.kunzisoft.keepass.stream.LEDataInputStream
|
||||
import com.kunzisoft.keepass.stream.LEDataOutputStream
|
||||
import com.kunzisoft.keepass.utils.DatabaseInputOutputUtils
|
||||
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.IOException
|
||||
import java.util.UUID
|
||||
|
||||
class KdfParameters internal constructor(val uuid: UUID) : VariantDictionary() {
|
||||
|
||||
fun setParamUUID() {
|
||||
setByteArray(PARAM_UUID, DatabaseInputOutputUtils.uuidToBytes(uuid))
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private const val PARAM_UUID = "\$UUID"
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun deserialize(data: ByteArray): KdfParameters? {
|
||||
val bis = ByteArrayInputStream(data)
|
||||
val lis = LEDataInputStream(bis)
|
||||
|
||||
val d = deserialize(lis) ?: return null
|
||||
|
||||
val uuid = DatabaseInputOutputUtils.bytesToUuid(d.getByteArray(PARAM_UUID))
|
||||
|
||||
val kdfP = KdfParameters(uuid)
|
||||
kdfP.copyTo(d)
|
||||
return kdfP
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun serialize(kdf: KdfParameters): ByteArray {
|
||||
val bos = ByteArrayOutputStream()
|
||||
val los = LEDataOutputStream(bos)
|
||||
|
||||
serialize(kdf, los)
|
||||
|
||||
return bos.toByteArray()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,9 +32,8 @@ open class AssignPasswordInDatabaseRunnable (
|
||||
withMasterPassword: Boolean,
|
||||
masterPassword: String?,
|
||||
withKeyFile: Boolean,
|
||||
keyFile: Uri?,
|
||||
save: Boolean)
|
||||
: SaveDatabaseRunnable(context, database, save) {
|
||||
keyFile: Uri?)
|
||||
: SaveDatabaseRunnable(context, database, true) {
|
||||
|
||||
private var mMasterPassword: String? = null
|
||||
protected var mKeyFile: Uri? = null
|
||||
@@ -59,7 +58,7 @@ open class AssignPasswordInDatabaseRunnable (
|
||||
database.retrieveMasterKey(mMasterPassword, uriInputStream)
|
||||
} catch (e: Exception) {
|
||||
erase(mBackupKey)
|
||||
setError(e.message)
|
||||
setError(e)
|
||||
}
|
||||
|
||||
super.onStartRun()
|
||||
|
||||
@@ -28,24 +28,25 @@ import com.kunzisoft.keepass.database.element.Database
|
||||
class CreateDatabaseRunnable(context: Context,
|
||||
private val mDatabase: Database,
|
||||
databaseUri: Uri,
|
||||
private val databaseName: String,
|
||||
private val rootName: String,
|
||||
withMasterPassword: Boolean,
|
||||
masterPassword: String?,
|
||||
withKeyFile: Boolean,
|
||||
keyFile: Uri?,
|
||||
save: Boolean)
|
||||
: AssignPasswordInDatabaseRunnable(context, mDatabase, databaseUri, withMasterPassword, masterPassword, withKeyFile, keyFile, save) {
|
||||
keyFile: Uri?)
|
||||
: AssignPasswordInDatabaseRunnable(context, mDatabase, databaseUri, withMasterPassword, masterPassword, withKeyFile, keyFile) {
|
||||
|
||||
override fun onStartRun() {
|
||||
try {
|
||||
// Create new database record
|
||||
mDatabase.apply {
|
||||
createData(mDatabaseUri)
|
||||
createData(mDatabaseUri, databaseName, rootName)
|
||||
// Set Database state
|
||||
loaded = true
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
mDatabase.closeAndClear()
|
||||
setError(e.message)
|
||||
setError(e)
|
||||
}
|
||||
|
||||
super.onStartRun()
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.kunzisoft.keepass.app.database.CipherDatabaseAction
|
||||
import com.kunzisoft.keepass.app.database.CipherDatabaseEntity
|
||||
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.exception.LoadDatabaseDuplicateUuidException
|
||||
import com.kunzisoft.keepass.database.exception.DuplicateUuidDatabaseException
|
||||
import com.kunzisoft.keepass.database.exception.LoadDatabaseException
|
||||
import com.kunzisoft.keepass.notifications.DatabaseOpenNotificationService
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
@@ -62,7 +62,7 @@ class LoadDatabaseRunnable(private val context: Context,
|
||||
mFixDuplicateUUID,
|
||||
progressTaskUpdater)
|
||||
}
|
||||
catch (e: LoadDatabaseDuplicateUuidException) {
|
||||
catch (e: DuplicateUuidDatabaseException) {
|
||||
mDuplicateUuidAction?.invoke(result)
|
||||
setError(e)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,11 @@ import androidx.fragment.app.FragmentActivity
|
||||
import com.kunzisoft.keepass.app.database.CipherDatabaseEntity
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
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.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_ASSIGN_PASSWORD_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_COPY_NODES_TASK
|
||||
@@ -20,18 +25,19 @@ import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Compa
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_DELETE_NODES_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_LOAD_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_MOVE_NODES_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_COLOR_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_COMPRESSION_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_DEFAULT_USERNAME_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_DESCRIPTION_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_ENCRYPTION_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_ITERATIONS_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_KEY_DERIVATION_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_MAX_HISTORY_ITEMS_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_MAX_HISTORY_SIZE_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_MEMORY_USAGE_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_NAME_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_PARALLELISM_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_COLOR_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_COMPRESSION_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_DEFAULT_USERNAME_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_DESCRIPTION_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_ENCRYPTION_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_ITERATIONS_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_KEY_DERIVATION_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_MAX_HISTORY_ITEMS_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_MAX_HISTORY_SIZE_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_MEMORY_USAGE_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_NAME_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_PARALLELISM_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_ENTRY_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_GROUP_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.getBundleFromListNodes
|
||||
@@ -44,10 +50,10 @@ import com.kunzisoft.keepass.utils.DATABASE_STOP_TASK_ACTION
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class ProgressDialogThread(private val activity: FragmentActivity) {
|
||||
|
||||
class ProgressDialogThread(private val activity: FragmentActivity,
|
||||
var onActionFinish: (actionTask: String,
|
||||
result: ActionRunnable.Result) -> Unit) {
|
||||
var onActionFinish: ((actionTask: String,
|
||||
result: ActionRunnable.Result) -> Unit)? = null
|
||||
|
||||
private var intentDatabaseTask = Intent(activity, DatabaseTaskNotificationService::class.java)
|
||||
|
||||
@@ -68,7 +74,7 @@ class ProgressDialogThread(private val activity: FragmentActivity,
|
||||
}
|
||||
|
||||
override fun onStopAction(actionTask: String, result: ActionRunnable.Result) {
|
||||
onActionFinish.invoke(actionTask, result)
|
||||
onActionFinish?.invoke(actionTask, result)
|
||||
// Remove the progress task
|
||||
ProgressTaskDialogFragment.stop(activity)
|
||||
TimeoutHelper.releaseTemporarilyDisableTimeoutAndLockIfTimeout(activity)
|
||||
@@ -250,8 +256,8 @@ class ProgressDialogThread(private val activity: FragmentActivity,
|
||||
----
|
||||
*/
|
||||
|
||||
fun startDatabaseCreateGroup(newGroup: GroupVersioned,
|
||||
parent: GroupVersioned,
|
||||
fun startDatabaseCreateGroup(newGroup: Group,
|
||||
parent: Group,
|
||||
save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putParcelable(DatabaseTaskNotificationService.GROUP_KEY, newGroup)
|
||||
@@ -261,8 +267,8 @@ class ProgressDialogThread(private val activity: FragmentActivity,
|
||||
, ACTION_DATABASE_CREATE_GROUP_TASK)
|
||||
}
|
||||
|
||||
fun startDatabaseUpdateGroup(oldGroup: GroupVersioned,
|
||||
groupToUpdate: GroupVersioned,
|
||||
fun startDatabaseUpdateGroup(oldGroup: Group,
|
||||
groupToUpdate: Group,
|
||||
save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putParcelable(DatabaseTaskNotificationService.GROUP_ID_KEY, oldGroup.nodeId)
|
||||
@@ -272,8 +278,8 @@ class ProgressDialogThread(private val activity: FragmentActivity,
|
||||
, ACTION_DATABASE_UPDATE_GROUP_TASK)
|
||||
}
|
||||
|
||||
fun startDatabaseCreateEntry(newEntry: EntryVersioned,
|
||||
parent: GroupVersioned,
|
||||
fun startDatabaseCreateEntry(newEntry: Entry,
|
||||
parent: Group,
|
||||
save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putParcelable(DatabaseTaskNotificationService.ENTRY_KEY, newEntry)
|
||||
@@ -283,8 +289,8 @@ class ProgressDialogThread(private val activity: FragmentActivity,
|
||||
, ACTION_DATABASE_CREATE_ENTRY_TASK)
|
||||
}
|
||||
|
||||
fun startDatabaseUpdateEntry(oldEntry: EntryVersioned,
|
||||
entryToUpdate: EntryVersioned,
|
||||
fun startDatabaseUpdateEntry(oldEntry: Entry,
|
||||
entryToUpdate: Entry,
|
||||
save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putParcelable(DatabaseTaskNotificationService.ENTRY_ID_KEY, oldEntry.nodeId)
|
||||
@@ -295,20 +301,20 @@ class ProgressDialogThread(private val activity: FragmentActivity,
|
||||
}
|
||||
|
||||
private fun startDatabaseActionListNodes(actionTask: String,
|
||||
nodesPaste: List<NodeVersioned>,
|
||||
newParent: GroupVersioned?,
|
||||
nodesPaste: List<Node>,
|
||||
newParent: Group?,
|
||||
save: Boolean) {
|
||||
val groupsIdToCopy = ArrayList<PwNodeId<*>>()
|
||||
val entriesIdToCopy = ArrayList<PwNodeId<UUID>>()
|
||||
val groupsIdToCopy = ArrayList<NodeId<*>>()
|
||||
val entriesIdToCopy = ArrayList<NodeId<UUID>>()
|
||||
nodesPaste.forEach { nodeVersioned ->
|
||||
when (nodeVersioned.type) {
|
||||
Type.GROUP -> {
|
||||
(nodeVersioned as GroupVersioned).nodeId?.let { groupId ->
|
||||
(nodeVersioned as Group).nodeId?.let { groupId ->
|
||||
groupsIdToCopy.add(groupId)
|
||||
}
|
||||
}
|
||||
Type.ENTRY -> {
|
||||
entriesIdToCopy.add((nodeVersioned as EntryVersioned).nodeId)
|
||||
entriesIdToCopy.add((nodeVersioned as Entry).nodeId)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,19 +331,19 @@ class ProgressDialogThread(private val activity: FragmentActivity,
|
||||
, actionTask)
|
||||
}
|
||||
|
||||
fun startDatabaseCopyNodes(nodesToCopy: List<NodeVersioned>,
|
||||
newParent: GroupVersioned,
|
||||
fun startDatabaseCopyNodes(nodesToCopy: List<Node>,
|
||||
newParent: Group,
|
||||
save: Boolean) {
|
||||
startDatabaseActionListNodes(ACTION_DATABASE_COPY_NODES_TASK, nodesToCopy, newParent, save)
|
||||
}
|
||||
|
||||
fun startDatabaseMoveNodes(nodesToMove: List<NodeVersioned>,
|
||||
newParent: GroupVersioned,
|
||||
fun startDatabaseMoveNodes(nodesToMove: List<Node>,
|
||||
newParent: Group,
|
||||
save: Boolean) {
|
||||
startDatabaseActionListNodes(ACTION_DATABASE_MOVE_NODES_TASK, nodesToMove, newParent, save)
|
||||
}
|
||||
|
||||
fun startDatabaseDeleteNodes(nodesToDelete: List<NodeVersioned>,
|
||||
fun startDatabaseDeleteNodes(nodesToDelete: List<Node>,
|
||||
save: Boolean) {
|
||||
startDatabaseActionListNodes(ACTION_DATABASE_DELETE_NODES_TASK, nodesToDelete, null, save)
|
||||
}
|
||||
@@ -349,66 +355,80 @@ class ProgressDialogThread(private val activity: FragmentActivity,
|
||||
*/
|
||||
|
||||
fun startDatabaseSaveName(oldName: String,
|
||||
newName: String) {
|
||||
newName: String,
|
||||
save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putString(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldName)
|
||||
putString(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newName)
|
||||
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
|
||||
}
|
||||
, ACTION_DATABASE_SAVE_NAME_TASK)
|
||||
, ACTION_DATABASE_UPDATE_NAME_TASK)
|
||||
}
|
||||
|
||||
fun startDatabaseSaveDescription(oldDescription: String,
|
||||
newDescription: String) {
|
||||
newDescription: String,
|
||||
save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putString(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldDescription)
|
||||
putString(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newDescription)
|
||||
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
|
||||
}
|
||||
, ACTION_DATABASE_SAVE_DESCRIPTION_TASK)
|
||||
, ACTION_DATABASE_UPDATE_DESCRIPTION_TASK)
|
||||
}
|
||||
|
||||
fun startDatabaseSaveDefaultUsername(oldDefaultUsername: String,
|
||||
newDefaultUsername: String) {
|
||||
newDefaultUsername: String,
|
||||
save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putString(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldDefaultUsername)
|
||||
putString(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newDefaultUsername)
|
||||
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
|
||||
}
|
||||
, ACTION_DATABASE_SAVE_DEFAULT_USERNAME_TASK)
|
||||
, ACTION_DATABASE_UPDATE_DEFAULT_USERNAME_TASK)
|
||||
}
|
||||
|
||||
fun startDatabaseSaveColor(oldColor: String,
|
||||
newColor: String) {
|
||||
newColor: String,
|
||||
save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putString(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldColor)
|
||||
putString(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newColor)
|
||||
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
|
||||
}
|
||||
, ACTION_DATABASE_SAVE_COLOR_TASK)
|
||||
, ACTION_DATABASE_UPDATE_COLOR_TASK)
|
||||
}
|
||||
|
||||
fun startDatabaseSaveCompression(oldCompression: PwCompressionAlgorithm,
|
||||
newCompression: PwCompressionAlgorithm) {
|
||||
fun startDatabaseSaveCompression(oldCompression: CompressionAlgorithm,
|
||||
newCompression: CompressionAlgorithm,
|
||||
save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldCompression)
|
||||
putSerializable(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newCompression)
|
||||
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
|
||||
}
|
||||
, ACTION_DATABASE_SAVE_COMPRESSION_TASK)
|
||||
, ACTION_DATABASE_UPDATE_COMPRESSION_TASK)
|
||||
}
|
||||
|
||||
fun startDatabaseSaveMaxHistoryItems(oldMaxHistoryItems: Int,
|
||||
newMaxHistoryItems: Int) {
|
||||
newMaxHistoryItems: Int,
|
||||
save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putInt(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldMaxHistoryItems)
|
||||
putInt(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newMaxHistoryItems)
|
||||
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
|
||||
}
|
||||
, ACTION_DATABASE_SAVE_MAX_HISTORY_ITEMS_TASK)
|
||||
, ACTION_DATABASE_UPDATE_MAX_HISTORY_ITEMS_TASK)
|
||||
}
|
||||
|
||||
fun startDatabaseSaveMaxHistorySize(oldMaxHistorySize: Long,
|
||||
newMaxHistorySize: Long) {
|
||||
newMaxHistorySize: Long,
|
||||
save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putLong(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldMaxHistorySize)
|
||||
putLong(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newMaxHistorySize)
|
||||
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
|
||||
}
|
||||
, ACTION_DATABASE_SAVE_MAX_HISTORY_SIZE_TASK)
|
||||
, ACTION_DATABASE_UPDATE_MAX_HISTORY_SIZE_TASK)
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -417,48 +437,68 @@ class ProgressDialogThread(private val activity: FragmentActivity,
|
||||
-------------------
|
||||
*/
|
||||
|
||||
fun startDatabaseSaveEncryption(oldEncryption: PwEncryptionAlgorithm,
|
||||
newEncryption: PwEncryptionAlgorithm) {
|
||||
fun startDatabaseSaveEncryption(oldEncryption: EncryptionAlgorithm,
|
||||
newEncryption: EncryptionAlgorithm,
|
||||
save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldEncryption)
|
||||
putSerializable(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newEncryption)
|
||||
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
|
||||
}
|
||||
, ACTION_DATABASE_SAVE_ENCRYPTION_TASK)
|
||||
, ACTION_DATABASE_UPDATE_ENCRYPTION_TASK)
|
||||
}
|
||||
|
||||
fun startDatabaseSaveKeyDerivation(oldKeyDerivation: KdfEngine,
|
||||
newKeyDerivation: KdfEngine) {
|
||||
newKeyDerivation: KdfEngine,
|
||||
save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldKeyDerivation)
|
||||
putSerializable(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newKeyDerivation)
|
||||
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
|
||||
}
|
||||
, ACTION_DATABASE_SAVE_KEY_DERIVATION_TASK)
|
||||
, ACTION_DATABASE_UPDATE_KEY_DERIVATION_TASK)
|
||||
}
|
||||
|
||||
fun startDatabaseSaveIterations(oldIterations: Long,
|
||||
newIterations: Long) {
|
||||
newIterations: Long,
|
||||
save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putLong(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldIterations)
|
||||
putLong(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newIterations)
|
||||
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
|
||||
}
|
||||
, ACTION_DATABASE_SAVE_ITERATIONS_TASK)
|
||||
, ACTION_DATABASE_UPDATE_ITERATIONS_TASK)
|
||||
}
|
||||
|
||||
fun startDatabaseSaveMemoryUsage(oldMemoryUsage: Long,
|
||||
newMemoryUsage: Long) {
|
||||
newMemoryUsage: Long,
|
||||
save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putLong(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldMemoryUsage)
|
||||
putLong(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newMemoryUsage)
|
||||
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
|
||||
}
|
||||
, ACTION_DATABASE_SAVE_MEMORY_USAGE_TASK)
|
||||
, ACTION_DATABASE_UPDATE_MEMORY_USAGE_TASK)
|
||||
}
|
||||
|
||||
fun startDatabaseSaveParallelism(oldParallelism: Int,
|
||||
newParallelism: Int) {
|
||||
newParallelism: Int,
|
||||
save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putInt(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldParallelism)
|
||||
putInt(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newParallelism)
|
||||
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
|
||||
}
|
||||
, ACTION_DATABASE_SAVE_PARALLELISM_TASK)
|
||||
, ACTION_DATABASE_UPDATE_PARALLELISM_TASK)
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Database without parameter
|
||||
*/
|
||||
fun startDatabaseSave(save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
|
||||
}
|
||||
, ACTION_DATABASE_SAVE)
|
||||
}
|
||||
}
|
||||
@@ -21,9 +21,8 @@ package com.kunzisoft.keepass.database.action
|
||||
|
||||
import android.content.Context
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.exception.DatabaseOutputException
|
||||
import com.kunzisoft.keepass.database.exception.DatabaseException
|
||||
import com.kunzisoft.keepass.tasks.ActionRunnable
|
||||
import java.io.IOException
|
||||
|
||||
open class SaveDatabaseRunnable(protected var context: Context,
|
||||
protected var database: Database,
|
||||
@@ -38,10 +37,8 @@ open class SaveDatabaseRunnable(protected var context: Context,
|
||||
if (saveDatabase && result.isSuccess) {
|
||||
try {
|
||||
database.saveData(context.contentResolver)
|
||||
} catch (e: IOException) {
|
||||
setError(e.message)
|
||||
} catch (e: DatabaseOutputException) {
|
||||
setError(e.message)
|
||||
} catch (e: DatabaseException) {
|
||||
setError(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2019 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.action
|
||||
|
||||
import android.content.Context
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
|
||||
class UpdateCompressionBinariesDatabaseRunnable (
|
||||
context: Context,
|
||||
database: Database,
|
||||
private val oldCompressionAlgorithm: CompressionAlgorithm,
|
||||
private val newCompressionAlgorithm: CompressionAlgorithm,
|
||||
saveDatabase: Boolean)
|
||||
: SaveDatabaseRunnable(context, database, saveDatabase) {
|
||||
|
||||
override fun onStartRun() {
|
||||
// Set new compression
|
||||
if (database.allowDataCompression) {
|
||||
try {
|
||||
database.apply {
|
||||
updateDataBinaryCompression(oldCompressionAlgorithm, newCompressionAlgorithm)
|
||||
compressionAlgorithm = newCompressionAlgorithm
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
setError(e)
|
||||
}
|
||||
}
|
||||
|
||||
super.onStartRun()
|
||||
}
|
||||
|
||||
override fun onFinishRun() {
|
||||
super.onFinishRun()
|
||||
|
||||
if (database.allowDataCompression) {
|
||||
if (!result.isSuccess) {
|
||||
try {
|
||||
database.apply {
|
||||
compressionAlgorithm = oldCompressionAlgorithm
|
||||
updateDataBinaryCompression(newCompressionAlgorithm, oldCompressionAlgorithm)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
setError(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,15 +21,15 @@ package com.kunzisoft.keepass.database.action.node
|
||||
|
||||
import android.content.Context
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.EntryVersioned
|
||||
import com.kunzisoft.keepass.database.element.GroupVersioned
|
||||
import com.kunzisoft.keepass.database.element.NodeVersioned
|
||||
import com.kunzisoft.keepass.database.element.Entry
|
||||
import com.kunzisoft.keepass.database.element.Group
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
|
||||
class AddEntryRunnable constructor(
|
||||
context: Context,
|
||||
database: Database,
|
||||
private val mNewEntry: EntryVersioned,
|
||||
private val mParent: GroupVersioned,
|
||||
private val mNewEntry: Entry,
|
||||
private val mParent: Group,
|
||||
save: Boolean,
|
||||
afterActionNodesFinish: AfterActionNodesFinish?)
|
||||
: ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save) {
|
||||
@@ -47,8 +47,8 @@ class AddEntryRunnable constructor(
|
||||
}
|
||||
}
|
||||
|
||||
val oldNodesReturn = ArrayList<NodeVersioned>()
|
||||
val newNodesReturn = ArrayList<NodeVersioned>()
|
||||
val oldNodesReturn = ArrayList<Node>()
|
||||
val newNodesReturn = ArrayList<Node>()
|
||||
newNodesReturn.add(mNewEntry)
|
||||
return ActionNodesValues(oldNodesReturn, newNodesReturn)
|
||||
}
|
||||
|
||||
@@ -21,14 +21,14 @@ package com.kunzisoft.keepass.database.action.node
|
||||
|
||||
import android.content.Context
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.GroupVersioned
|
||||
import com.kunzisoft.keepass.database.element.NodeVersioned
|
||||
import com.kunzisoft.keepass.database.element.Group
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
|
||||
class AddGroupRunnable constructor(
|
||||
context: Context,
|
||||
database: Database,
|
||||
private val mNewGroup: GroupVersioned,
|
||||
private val mParent: GroupVersioned,
|
||||
private val mNewGroup: Group,
|
||||
private val mParent: Group,
|
||||
save: Boolean,
|
||||
afterActionNodesFinish: AfterActionNodesFinish?)
|
||||
: ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save) {
|
||||
@@ -44,8 +44,8 @@ class AddGroupRunnable constructor(
|
||||
database.removeGroupFrom(mNewGroup, mParent)
|
||||
}
|
||||
|
||||
val oldNodesReturn = ArrayList<NodeVersioned>()
|
||||
val newNodesReturn = ArrayList<NodeVersioned>()
|
||||
val oldNodesReturn = ArrayList<Node>()
|
||||
val newNodesReturn = ArrayList<Node>()
|
||||
newNodesReturn.add(mNewGroup)
|
||||
return ActionNodesValues(oldNodesReturn, newNodesReturn)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.action.node
|
||||
|
||||
import com.kunzisoft.keepass.database.element.NodeVersioned
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
import com.kunzisoft.keepass.tasks.ActionRunnable
|
||||
|
||||
/**
|
||||
@@ -30,7 +30,7 @@ import com.kunzisoft.keepass.tasks.ActionRunnable
|
||||
* - Move : @param oldNodes empty, @param newNodes NodesToMove
|
||||
* - Update : @param oldNodes NodesToUpdate, @param newNodes NodesUpdated
|
||||
*/
|
||||
class ActionNodesValues(val oldNodes: List<NodeVersioned>, val newNodes: List<NodeVersioned>)
|
||||
class ActionNodesValues(val oldNodes: List<Node>, val newNodes: List<Node>)
|
||||
|
||||
abstract class AfterActionNodesFinish {
|
||||
abstract fun onActionNodesFinish(result: ActionRunnable.Result, actionNodesValues: ActionNodesValues)
|
||||
|
||||
@@ -22,19 +22,21 @@ package com.kunzisoft.keepass.database.action.node
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.database.exception.CopyDatabaseEntryException
|
||||
import com.kunzisoft.keepass.database.exception.CopyDatabaseGroupException
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.database.exception.CopyEntryDatabaseException
|
||||
import com.kunzisoft.keepass.database.exception.CopyGroupDatabaseException
|
||||
|
||||
class CopyNodesRunnable constructor(
|
||||
context: Context,
|
||||
database: Database,
|
||||
private val mNodesToCopy: List<NodeVersioned>,
|
||||
private val mNewParent: GroupVersioned,
|
||||
private val mNodesToCopy: List<Node>,
|
||||
private val mNewParent: Group,
|
||||
save: Boolean,
|
||||
afterActionNodesFinish: AfterActionNodesFinish?)
|
||||
: ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save) {
|
||||
|
||||
private var mEntriesCopied = ArrayList<EntryVersioned>()
|
||||
private var mEntriesCopied = ArrayList<Entry>()
|
||||
|
||||
override fun nodeAction() {
|
||||
|
||||
@@ -42,7 +44,7 @@ class CopyNodesRunnable constructor(
|
||||
when (currentNode.type) {
|
||||
Type.GROUP -> {
|
||||
Log.e(TAG, "Copy not allowed for group")// Only finish thread
|
||||
setError(CopyDatabaseGroupException())
|
||||
setError(CopyGroupDatabaseException())
|
||||
break@foreachNode
|
||||
}
|
||||
Type.ENTRY -> {
|
||||
@@ -51,18 +53,18 @@ class CopyNodesRunnable constructor(
|
||||
// Update entry with new values
|
||||
mNewParent.touch(modified = false, touchParents = true)
|
||||
|
||||
val entryCopied = database.copyEntryTo(currentNode as EntryVersioned, mNewParent)
|
||||
val entryCopied = database.copyEntryTo(currentNode as Entry, mNewParent)
|
||||
if (entryCopied != null) {
|
||||
entryCopied.touch(modified = true, touchParents = true)
|
||||
mEntriesCopied.add(entryCopied)
|
||||
} else {
|
||||
Log.e(TAG, "Unable to create a copy of the entry")
|
||||
setError(CopyDatabaseEntryException())
|
||||
setError(CopyEntryDatabaseException())
|
||||
break@foreachNode
|
||||
}
|
||||
} else {
|
||||
// Only finish thread
|
||||
setError(CopyDatabaseEntryException())
|
||||
setError(CopyEntryDatabaseException())
|
||||
break@foreachNode
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,18 +21,20 @@ package com.kunzisoft.keepass.database.action.node
|
||||
|
||||
import android.content.Context
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
|
||||
class DeleteNodesRunnable(context: Context,
|
||||
database: Database,
|
||||
private val mNodesToDelete: List<NodeVersioned>,
|
||||
private val mNodesToDelete: List<Node>,
|
||||
save: Boolean,
|
||||
afterActionNodesFinish: AfterActionNodesFinish)
|
||||
: ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save) {
|
||||
|
||||
private var mParent: GroupVersioned? = null
|
||||
private var mParent: Group? = null
|
||||
private var mCanRecycle: Boolean = false
|
||||
|
||||
private var mNodesToDeleteBackup = ArrayList<NodeVersioned>()
|
||||
private var mNodesToDeleteBackup = ArrayList<Node>()
|
||||
|
||||
override fun nodeAction() {
|
||||
|
||||
@@ -43,7 +45,7 @@ class DeleteNodesRunnable(context: Context,
|
||||
when (currentNode.type) {
|
||||
Type.GROUP -> {
|
||||
// Create a copy to keep the old ref and remove it visually
|
||||
mNodesToDeleteBackup.add(GroupVersioned(currentNode as GroupVersioned))
|
||||
mNodesToDeleteBackup.add(Group(currentNode as Group))
|
||||
// Remove Node from parent
|
||||
mCanRecycle = database.canRecycle(currentNode)
|
||||
if (mCanRecycle) {
|
||||
@@ -54,7 +56,7 @@ class DeleteNodesRunnable(context: Context,
|
||||
}
|
||||
Type.ENTRY -> {
|
||||
// Create a copy to keep the old ref and remove it visually
|
||||
mNodesToDeleteBackup.add(EntryVersioned(currentNode as EntryVersioned))
|
||||
mNodesToDeleteBackup.add(Entry(currentNode as Entry))
|
||||
// Remove Node from parent
|
||||
mCanRecycle = database.canRecycle(currentNode)
|
||||
if (mCanRecycle) {
|
||||
@@ -74,10 +76,10 @@ class DeleteNodesRunnable(context: Context,
|
||||
mNodesToDeleteBackup.forEach { backupNode ->
|
||||
when (backupNode.type) {
|
||||
Type.GROUP -> {
|
||||
database.undoRecycle(backupNode as GroupVersioned, it)
|
||||
database.undoRecycle(backupNode as Group, it)
|
||||
}
|
||||
Type.ENTRY -> {
|
||||
database.undoRecycle(backupNode as EntryVersioned, it)
|
||||
database.undoRecycle(backupNode as Entry, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,20 +22,21 @@ package com.kunzisoft.keepass.database.action.node
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.database.exception.LoadDatabaseException
|
||||
import com.kunzisoft.keepass.database.exception.MoveDatabaseEntryException
|
||||
import com.kunzisoft.keepass.database.exception.MoveDatabaseGroupException
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.database.exception.EntryDatabaseException
|
||||
import com.kunzisoft.keepass.database.exception.MoveGroupDatabaseException
|
||||
|
||||
class MoveNodesRunnable constructor(
|
||||
context: Context,
|
||||
database: Database,
|
||||
private val mNodesToMove: List<NodeVersioned>,
|
||||
private val mNewParent: GroupVersioned,
|
||||
private val mNodesToMove: List<Node>,
|
||||
private val mNewParent: Group,
|
||||
save: Boolean,
|
||||
afterActionNodesFinish: AfterActionNodesFinish?)
|
||||
: ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save) {
|
||||
|
||||
private var mOldParent: GroupVersioned? = null
|
||||
private var mOldParent: Group? = null
|
||||
|
||||
override fun nodeAction() {
|
||||
|
||||
@@ -45,7 +46,7 @@ class MoveNodesRunnable constructor(
|
||||
|
||||
when (nodeToMove.type) {
|
||||
Type.GROUP -> {
|
||||
val groupToMove = nodeToMove as GroupVersioned
|
||||
val groupToMove = nodeToMove as Group
|
||||
// Move group in new parent if not in the current group
|
||||
if (groupToMove != mNewParent
|
||||
&& !mNewParent.isContainedIn(groupToMove)) {
|
||||
@@ -53,12 +54,12 @@ class MoveNodesRunnable constructor(
|
||||
database.moveGroupTo(groupToMove, mNewParent)
|
||||
} else {
|
||||
// Only finish thread
|
||||
setError(MoveDatabaseGroupException())
|
||||
setError(MoveGroupDatabaseException())
|
||||
break@foreachNode
|
||||
}
|
||||
}
|
||||
Type.ENTRY -> {
|
||||
val entryToMove = nodeToMove as EntryVersioned
|
||||
val entryToMove = nodeToMove as Entry
|
||||
// Move only if the parent change
|
||||
if (mOldParent != mNewParent
|
||||
// and root can contains entry
|
||||
@@ -67,7 +68,7 @@ class MoveNodesRunnable constructor(
|
||||
database.moveEntryTo(entryToMove, mNewParent)
|
||||
} else {
|
||||
// Only finish thread
|
||||
setError(MoveDatabaseEntryException())
|
||||
setError(EntryDatabaseException())
|
||||
break@foreachNode
|
||||
}
|
||||
}
|
||||
@@ -83,8 +84,8 @@ class MoveNodesRunnable constructor(
|
||||
if (mOldParent != null &&
|
||||
mOldParent != nodeToMove.parent) {
|
||||
when (nodeToMove.type) {
|
||||
Type.GROUP -> database.moveGroupTo(nodeToMove as GroupVersioned, mOldParent!!)
|
||||
Type.ENTRY -> database.moveEntryTo(nodeToMove as EntryVersioned, mOldParent!!)
|
||||
Type.GROUP -> database.moveGroupTo(nodeToMove as Group, mOldParent!!)
|
||||
Type.ENTRY -> database.moveEntryTo(nodeToMove as Entry, mOldParent!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database
|
||||
package com.kunzisoft.keepass.database.action.node
|
||||
|
||||
|
||||
/** "Delegate" class for operating on each group when traversing all of
|
||||
@@ -21,20 +21,20 @@ package com.kunzisoft.keepass.database.action.node
|
||||
|
||||
import android.content.Context
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.EntryVersioned
|
||||
import com.kunzisoft.keepass.database.element.NodeVersioned
|
||||
import com.kunzisoft.keepass.database.element.Entry
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
|
||||
class UpdateEntryRunnable constructor(
|
||||
context: Context,
|
||||
database: Database,
|
||||
private val mOldEntry: EntryVersioned,
|
||||
private val mNewEntry: EntryVersioned,
|
||||
private val mOldEntry: Entry,
|
||||
private val mNewEntry: Entry,
|
||||
save: Boolean,
|
||||
afterActionNodesFinish: AfterActionNodesFinish?)
|
||||
: ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save) {
|
||||
|
||||
// Keep backup of original values in case save fails
|
||||
private var mBackupEntryHistory: EntryVersioned = EntryVersioned(mOldEntry)
|
||||
private var mBackupEntryHistory: Entry = Entry(mOldEntry)
|
||||
|
||||
override fun nodeAction() {
|
||||
// WARNING : Re attribute parent removed in entry edit activity to save memory
|
||||
@@ -45,8 +45,8 @@ class UpdateEntryRunnable constructor(
|
||||
mNewEntry.touch(modified = true, touchParents = true)
|
||||
|
||||
// Create an entry history (an entry history don't have history)
|
||||
mOldEntry.addEntryToHistory(EntryVersioned(mBackupEntryHistory, copyHistory = false))
|
||||
database.removeOldestHistory(mOldEntry)
|
||||
mOldEntry.addEntryToHistory(Entry(mBackupEntryHistory, copyHistory = false))
|
||||
database.removeOldestEntryHistory(mOldEntry)
|
||||
|
||||
// Only change data in index
|
||||
database.updateEntry(mOldEntry)
|
||||
@@ -59,9 +59,9 @@ class UpdateEntryRunnable constructor(
|
||||
database.updateEntry(mOldEntry)
|
||||
}
|
||||
|
||||
val oldNodesReturn = ArrayList<NodeVersioned>()
|
||||
val oldNodesReturn = ArrayList<Node>()
|
||||
oldNodesReturn.add(mBackupEntryHistory)
|
||||
val newNodesReturn = ArrayList<NodeVersioned>()
|
||||
val newNodesReturn = ArrayList<Node>()
|
||||
newNodesReturn.add(mOldEntry)
|
||||
return ActionNodesValues(oldNodesReturn, newNodesReturn)
|
||||
}
|
||||
|
||||
@@ -21,20 +21,20 @@ package com.kunzisoft.keepass.database.action.node
|
||||
|
||||
import android.content.Context
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.GroupVersioned
|
||||
import com.kunzisoft.keepass.database.element.NodeVersioned
|
||||
import com.kunzisoft.keepass.database.element.Group
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
|
||||
class UpdateGroupRunnable constructor(
|
||||
context: Context,
|
||||
database: Database,
|
||||
private val mOldGroup: GroupVersioned,
|
||||
private val mNewGroup: GroupVersioned,
|
||||
private val mOldGroup: Group,
|
||||
private val mNewGroup: Group,
|
||||
save: Boolean,
|
||||
afterActionNodesFinish: AfterActionNodesFinish?)
|
||||
: ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save) {
|
||||
|
||||
// Keep backup of original values in case save fails
|
||||
private val mBackupGroup: GroupVersioned = GroupVersioned(mOldGroup)
|
||||
private val mBackupGroup: Group = Group(mOldGroup)
|
||||
|
||||
override fun nodeAction() {
|
||||
// WARNING : Re attribute parent and children removed in group activity to save memory
|
||||
@@ -56,9 +56,9 @@ class UpdateGroupRunnable constructor(
|
||||
database.updateGroup(mOldGroup)
|
||||
}
|
||||
|
||||
val oldNodesReturn = ArrayList<NodeVersioned>()
|
||||
val oldNodesReturn = ArrayList<Node>()
|
||||
oldNodesReturn.add(mBackupGroup)
|
||||
val newNodesReturn = ArrayList<NodeVersioned>()
|
||||
val newNodesReturn = ArrayList<Node>()
|
||||
newNodesReturn.add(mOldGroup)
|
||||
return ActionNodesValues(oldNodesReturn, newNodesReturn)
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ package com.kunzisoft.keepass.database.cursor
|
||||
|
||||
import android.database.MatrixCursor
|
||||
import android.provider.BaseColumns
|
||||
import com.kunzisoft.keepass.database.element.PwEntry
|
||||
import com.kunzisoft.keepass.database.element.PwIconFactory
|
||||
import com.kunzisoft.keepass.database.element.PwNodeId
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryVersioned
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageFactory
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
|
||||
abstract class EntryCursor<EntryId, PwEntryV : PwEntry<*, EntryId, *, *>> : MatrixCursor(arrayOf(
|
||||
abstract class EntryCursor<EntryId, PwEntryV : EntryVersioned<*, EntryId, *, *>> : MatrixCursor(arrayOf(
|
||||
_ID,
|
||||
COLUMN_INDEX_UUID_MOST_SIGNIFICANT_BITS,
|
||||
COLUMN_INDEX_UUID_LEAST_SIGNIFICANT_BITS,
|
||||
@@ -24,9 +24,9 @@ abstract class EntryCursor<EntryId, PwEntryV : PwEntry<*, EntryId, *, *>> : Matr
|
||||
|
||||
abstract fun addEntry(entry: PwEntryV)
|
||||
|
||||
abstract fun getPwNodeId(): PwNodeId<EntryId>
|
||||
abstract fun getPwNodeId(): NodeId<EntryId>
|
||||
|
||||
open fun populateEntry(pwEntry: PwEntryV, iconFactory: PwIconFactory) {
|
||||
open fun populateEntry(pwEntry: PwEntryV, iconFactory: IconImageFactory) {
|
||||
pwEntry.nodeId = getPwNodeId()
|
||||
pwEntry.title = getString(getColumnIndex(COLUMN_INDEX_TITLE))
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
package com.kunzisoft.keepass.database.cursor
|
||||
|
||||
import com.kunzisoft.keepass.database.element.PwDatabase
|
||||
import com.kunzisoft.keepass.database.element.PwEntryV3
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseVersioned
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryKDB
|
||||
|
||||
class EntryCursorV3 : EntryCursorUUID<PwEntryV3>() {
|
||||
class EntryCursorKDB : EntryCursorUUID<EntryKDB>() {
|
||||
|
||||
override fun addEntry(entry: PwEntryV3) {
|
||||
override fun addEntry(entry: EntryKDB) {
|
||||
addRow(arrayOf(
|
||||
entryId,
|
||||
entry.id.mostSignificantBits,
|
||||
entry.id.leastSignificantBits,
|
||||
entry.title,
|
||||
entry.icon.iconId,
|
||||
PwDatabase.UUID_ZERO.mostSignificantBits,
|
||||
PwDatabase.UUID_ZERO.leastSignificantBits,
|
||||
DatabaseVersioned.UUID_ZERO.mostSignificantBits,
|
||||
DatabaseVersioned.UUID_ZERO.leastSignificantBits,
|
||||
entry.username,
|
||||
entry.password,
|
||||
entry.url,
|
||||
@@ -1,15 +1,15 @@
|
||||
package com.kunzisoft.keepass.database.cursor
|
||||
|
||||
import com.kunzisoft.keepass.database.element.PwEntryV4
|
||||
import com.kunzisoft.keepass.database.element.PwIconFactory
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryKDBX
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageFactory
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
class EntryCursorV4 : EntryCursorUUID<PwEntryV4>() {
|
||||
class EntryCursorKDBX : EntryCursorUUID<EntryKDBX>() {
|
||||
|
||||
private val extraFieldCursor: ExtraFieldCursor = ExtraFieldCursor()
|
||||
|
||||
override fun addEntry(entry: PwEntryV4) {
|
||||
override fun addEntry(entry: EntryKDBX) {
|
||||
addRow(arrayOf(
|
||||
entryId,
|
||||
entry.id.mostSignificantBits,
|
||||
@@ -31,7 +31,7 @@ class EntryCursorV4 : EntryCursorUUID<PwEntryV4>() {
|
||||
entryId++
|
||||
}
|
||||
|
||||
override fun populateEntry(pwEntry: PwEntryV4, iconFactory: PwIconFactory) {
|
||||
override fun populateEntry(pwEntry: EntryKDBX, iconFactory: IconImageFactory) {
|
||||
super.populateEntry(pwEntry, iconFactory)
|
||||
|
||||
// Retrieve custom icon
|
||||
@@ -1,14 +1,14 @@
|
||||
package com.kunzisoft.keepass.database.cursor
|
||||
|
||||
import com.kunzisoft.keepass.database.element.PwEntry
|
||||
import com.kunzisoft.keepass.database.element.PwNodeId
|
||||
import com.kunzisoft.keepass.database.element.PwNodeIdUUID
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryVersioned
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
||||
import java.util.*
|
||||
|
||||
abstract class EntryCursorUUID<EntryV: PwEntry<*, UUID, *, *>>: EntryCursor<UUID, EntryV>() {
|
||||
abstract class EntryCursorUUID<EntryV: EntryVersioned<*, UUID, *, *>>: EntryCursor<UUID, EntryV>() {
|
||||
|
||||
override fun getPwNodeId(): PwNodeId<UUID> {
|
||||
return PwNodeIdUUID(
|
||||
override fun getPwNodeId(): NodeId<UUID> {
|
||||
return NodeIdUUID(
|
||||
UUID(getLong(getColumnIndex(COLUMN_INDEX_UUID_MOST_SIGNIFICANT_BITS)),
|
||||
getLong(getColumnIndex(COLUMN_INDEX_UUID_LEAST_SIGNIFICANT_BITS))))
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.kunzisoft.keepass.database.cursor
|
||||
import android.database.MatrixCursor
|
||||
import android.provider.BaseColumns
|
||||
|
||||
import com.kunzisoft.keepass.database.element.PwEntryV4
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryKDBX
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
|
||||
class ExtraFieldCursor : MatrixCursor(arrayOf(
|
||||
@@ -22,7 +22,7 @@ class ExtraFieldCursor : MatrixCursor(arrayOf(
|
||||
fieldId++
|
||||
}
|
||||
|
||||
fun populateExtraFieldInEntry(pwEntry: PwEntryV4) {
|
||||
fun populateExtraFieldInEntry(pwEntry: EntryKDBX) {
|
||||
pwEntry.putExtraField(getString(getColumnIndex(COLUMN_LABEL)),
|
||||
ProtectedString(getInt(getColumnIndex(COLUMN_PROTECTION)) > 0,
|
||||
getString(getColumnIndex(COLUMN_VALUE))))
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright 2019 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import androidx.core.os.ConfigurationCompat
|
||||
import java.util.*
|
||||
|
||||
class DateInstant : Parcelable {
|
||||
|
||||
private var jDate: Date = Date()
|
||||
|
||||
val date: Date
|
||||
get() = jDate
|
||||
|
||||
constructor(source: DateInstant) {
|
||||
this.jDate = Date(source.jDate.time)
|
||||
}
|
||||
|
||||
constructor(date: Date) {
|
||||
jDate = Date(date.time)
|
||||
}
|
||||
|
||||
constructor(millis: Long) {
|
||||
jDate = Date(millis)
|
||||
}
|
||||
|
||||
constructor() {
|
||||
jDate = Date()
|
||||
}
|
||||
|
||||
protected constructor(parcel: Parcel) {
|
||||
jDate = parcel.readSerializable() as Date
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
fun getDateTimeString(resources: Resources): String {
|
||||
return Companion.getDateTimeString(resources, this.date)
|
||||
}
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||
dest.writeSerializable(date)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) {
|
||||
return true
|
||||
}
|
||||
if (other == null) {
|
||||
return false
|
||||
}
|
||||
if (javaClass != other.javaClass) {
|
||||
return false
|
||||
}
|
||||
|
||||
val date = other as DateInstant
|
||||
return isSameDate(jDate, date.jDate)
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return jDate.hashCode()
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return jDate.toString()
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
val NEVER_EXPIRE = neverExpire
|
||||
|
||||
private val neverExpire: DateInstant
|
||||
get() {
|
||||
val cal = Calendar.getInstance()
|
||||
cal.set(Calendar.YEAR, 2999)
|
||||
cal.set(Calendar.MONTH, 11)
|
||||
cal.set(Calendar.DAY_OF_MONTH, 28)
|
||||
cal.set(Calendar.HOUR, 23)
|
||||
cal.set(Calendar.MINUTE, 59)
|
||||
cal.set(Calendar.SECOND, 59)
|
||||
|
||||
return DateInstant(cal.time)
|
||||
}
|
||||
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<DateInstant> = object : Parcelable.Creator<DateInstant> {
|
||||
override fun createFromParcel(parcel: Parcel): DateInstant {
|
||||
return DateInstant(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<DateInstant?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
|
||||
private fun isSameDate(d1: Date?, d2: Date?): Boolean {
|
||||
val cal1 = Calendar.getInstance()
|
||||
cal1.time = d1
|
||||
cal1.set(Calendar.MILLISECOND, 0)
|
||||
|
||||
val cal2 = Calendar.getInstance()
|
||||
cal2.time = d2
|
||||
cal2.set(Calendar.MILLISECOND, 0)
|
||||
|
||||
return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
|
||||
cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH) &&
|
||||
cal1.get(Calendar.DAY_OF_MONTH) == cal2.get(Calendar.DAY_OF_MONTH) &&
|
||||
cal1.get(Calendar.HOUR) == cal2.get(Calendar.HOUR) &&
|
||||
cal1.get(Calendar.MINUTE) == cal2.get(Calendar.MINUTE) &&
|
||||
cal1.get(Calendar.SECOND) == cal2.get(Calendar.SECOND)
|
||||
|
||||
}
|
||||
|
||||
fun getDateTimeString(resources: Resources, date: Date): String {
|
||||
return java.text.DateFormat.getDateTimeInstance(
|
||||
java.text.DateFormat.MEDIUM,
|
||||
java.text.DateFormat.MEDIUM,
|
||||
ConfigurationCompat.getLocales(resources.configuration)[0])
|
||||
.format(date)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,12 +19,13 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseVersioned
|
||||
import java.util.Date
|
||||
import java.util.UUID
|
||||
|
||||
class PwDeletedObject {
|
||||
class DeletedObject {
|
||||
|
||||
var uuid: UUID = PwDatabase.UUID_ZERO
|
||||
var uuid: UUID = DatabaseVersioned.UUID_ZERO
|
||||
var deletionTime: Date? = null
|
||||
get() = if (field == null) {
|
||||
Date(System.currentTimeMillis())
|
||||
@@ -43,7 +44,7 @@ class PwDeletedObject {
|
||||
return true
|
||||
if (other == null)
|
||||
return false
|
||||
if (other !is PwDeletedObject)
|
||||
if (other !is DeletedObject)
|
||||
return false
|
||||
return uuid == other.uuid
|
||||
}
|
||||
@@ -0,0 +1,406 @@
|
||||
package com.kunzisoft.keepass.database.element
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseKDBX
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryKDB
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryKDBX
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryVersionedInterface
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageCustom
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
import com.kunzisoft.keepass.model.EntryInfo
|
||||
import com.kunzisoft.keepass.model.Field
|
||||
import com.kunzisoft.keepass.otp.OtpElement
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class Entry : Node, EntryVersionedInterface<Group> {
|
||||
|
||||
var entryKDB: EntryKDB? = null
|
||||
private set
|
||||
var entryKDBX: EntryKDBX? = null
|
||||
private set
|
||||
|
||||
fun updateWith(entry: Entry, copyHistory: Boolean = true) {
|
||||
entry.entryKDB?.let {
|
||||
this.entryKDB?.updateWith(it)
|
||||
}
|
||||
entry.entryKDBX?.let {
|
||||
this.entryKDBX?.updateWith(it, copyHistory)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this constructor to copy an Entry with exact same values
|
||||
*/
|
||||
constructor(entry: Entry, copyHistory: Boolean = true) {
|
||||
if (entry.entryKDB != null) {
|
||||
this.entryKDB = EntryKDB()
|
||||
}
|
||||
if (entry.entryKDBX != null) {
|
||||
this.entryKDBX = EntryKDBX()
|
||||
}
|
||||
updateWith(entry, copyHistory)
|
||||
}
|
||||
|
||||
constructor(entry: EntryKDB) {
|
||||
this.entryKDBX = null
|
||||
this.entryKDB = entry
|
||||
}
|
||||
|
||||
constructor(entry: EntryKDBX) {
|
||||
this.entryKDB = null
|
||||
this.entryKDBX = entry
|
||||
}
|
||||
|
||||
constructor(parcel: Parcel) {
|
||||
entryKDB = parcel.readParcelable(EntryKDB::class.java.classLoader)
|
||||
entryKDBX = parcel.readParcelable(EntryKDBX::class.java.classLoader)
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||
dest.writeParcelable(entryKDB, flags)
|
||||
dest.writeParcelable(entryKDBX, flags)
|
||||
}
|
||||
|
||||
override var nodeId: NodeId<UUID>
|
||||
get() = entryKDBX?.nodeId ?: entryKDB?.nodeId ?: NodeIdUUID()
|
||||
set(value) {
|
||||
entryKDB?.nodeId = value
|
||||
entryKDBX?.nodeId = value
|
||||
}
|
||||
|
||||
override var title: String
|
||||
get() = entryKDB?.title ?: entryKDBX?.title ?: ""
|
||||
set(value) {
|
||||
entryKDB?.title = value
|
||||
entryKDBX?.title = value
|
||||
}
|
||||
|
||||
override var icon: IconImage
|
||||
get() {
|
||||
return entryKDB?.icon ?: entryKDBX?.icon ?: IconImageStandard()
|
||||
}
|
||||
set(value) {
|
||||
entryKDB?.icon = value
|
||||
entryKDBX?.icon = value
|
||||
}
|
||||
|
||||
override val type: Type
|
||||
get() = Type.ENTRY
|
||||
|
||||
override var parent: Group?
|
||||
get() {
|
||||
entryKDB?.parent?.let {
|
||||
return Group(it)
|
||||
}
|
||||
entryKDBX?.parent?.let {
|
||||
return Group(it)
|
||||
}
|
||||
return null
|
||||
}
|
||||
set(value) {
|
||||
entryKDB?.parent = value?.groupKDB
|
||||
entryKDBX?.parent = value?.groupKDBX
|
||||
}
|
||||
|
||||
override fun containsParent(): Boolean {
|
||||
return entryKDB?.containsParent() ?: entryKDBX?.containsParent() ?: false
|
||||
}
|
||||
|
||||
override fun afterAssignNewParent() {
|
||||
entryKDBX?.afterChangeParent()
|
||||
}
|
||||
|
||||
override fun touch(modified: Boolean, touchParents: Boolean) {
|
||||
entryKDB?.touch(modified, touchParents)
|
||||
entryKDBX?.touch(modified, touchParents)
|
||||
}
|
||||
|
||||
override fun isContainedIn(container: Group): Boolean {
|
||||
var contained: Boolean? = false
|
||||
container.groupKDB?.let {
|
||||
contained = entryKDB?.isContainedIn(it)
|
||||
}
|
||||
container.groupKDBX?.let {
|
||||
contained = entryKDBX?.isContainedIn(it)
|
||||
}
|
||||
return contained ?: false
|
||||
}
|
||||
|
||||
override var creationTime: DateInstant
|
||||
get() = entryKDB?.creationTime ?: entryKDBX?.creationTime ?: DateInstant()
|
||||
set(value) {
|
||||
entryKDB?.creationTime = value
|
||||
entryKDBX?.creationTime = value
|
||||
}
|
||||
|
||||
override var lastModificationTime: DateInstant
|
||||
get() = entryKDB?.lastModificationTime ?: entryKDBX?.lastModificationTime ?: DateInstant()
|
||||
set(value) {
|
||||
entryKDB?.lastModificationTime = value
|
||||
entryKDBX?.lastModificationTime = value
|
||||
}
|
||||
|
||||
override var lastAccessTime: DateInstant
|
||||
get() = entryKDB?.lastAccessTime ?: entryKDBX?.lastAccessTime ?: DateInstant()
|
||||
set(value) {
|
||||
entryKDB?.lastAccessTime = value
|
||||
entryKDBX?.lastAccessTime = value
|
||||
}
|
||||
|
||||
override var expiryTime: DateInstant
|
||||
get() = entryKDB?.expiryTime ?: entryKDBX?.expiryTime ?: DateInstant()
|
||||
set(value) {
|
||||
entryKDB?.expiryTime = value
|
||||
entryKDBX?.expiryTime = value
|
||||
}
|
||||
|
||||
override var expires: Boolean
|
||||
get() = entryKDB?.expires ?: entryKDBX?.expires ?: false
|
||||
set(value) {
|
||||
entryKDB?.expires = value
|
||||
entryKDBX?.expires = value
|
||||
}
|
||||
|
||||
override val isCurrentlyExpires: Boolean
|
||||
get() = entryKDB?.isCurrentlyExpires ?: entryKDBX?.isCurrentlyExpires ?: false
|
||||
|
||||
override var username: String
|
||||
get() = entryKDB?.username ?: entryKDBX?.username ?: ""
|
||||
set(value) {
|
||||
entryKDB?.username = value
|
||||
entryKDBX?.username = value
|
||||
}
|
||||
|
||||
override var password: String
|
||||
get() = entryKDB?.password ?: entryKDBX?.password ?: ""
|
||||
set(value) {
|
||||
entryKDB?.password = value
|
||||
entryKDBX?.password = value
|
||||
}
|
||||
|
||||
override var url: String
|
||||
get() = entryKDB?.url ?: entryKDBX?.url ?: ""
|
||||
set(value) {
|
||||
entryKDB?.url = value
|
||||
entryKDBX?.url = value
|
||||
}
|
||||
|
||||
override var notes: String
|
||||
get() = entryKDB?.notes ?: entryKDBX?.notes ?: ""
|
||||
set(value) {
|
||||
entryKDB?.notes = value
|
||||
entryKDBX?.notes = value
|
||||
}
|
||||
|
||||
private fun isTan(): Boolean {
|
||||
return title == PMS_TAN_ENTRY && username.isNotEmpty()
|
||||
}
|
||||
|
||||
fun getVisualTitle(): String {
|
||||
return getVisualTitle(isTan(),
|
||||
title,
|
||||
username,
|
||||
url,
|
||||
nodeId.toString())
|
||||
}
|
||||
|
||||
/*
|
||||
------------
|
||||
KDB Methods
|
||||
------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* If it's a node with only meta information like Meta-info SYSTEM Database Color
|
||||
* @return false by default, true if it's a meta stream
|
||||
*/
|
||||
val isMetaStream: Boolean
|
||||
get() = entryKDB?.isMetaStream ?: false
|
||||
|
||||
/*
|
||||
------------
|
||||
KDBX Methods
|
||||
------------
|
||||
*/
|
||||
|
||||
var iconCustom: IconImageCustom
|
||||
get() = entryKDBX?.iconCustom ?: IconImageCustom.UNKNOWN_ICON
|
||||
set(value) {
|
||||
entryKDBX?.iconCustom = value
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve custom fields to show, key is the label, value is the value of field (protected or not)
|
||||
* @return Map of label/value
|
||||
*/
|
||||
val customFields: HashMap<String, ProtectedString>
|
||||
get() = entryKDBX?.customFields ?: HashMap()
|
||||
|
||||
/**
|
||||
* To redefine if version of entry allow custom field,
|
||||
* @return true if entry allows custom field
|
||||
*/
|
||||
fun allowCustomFields(): Boolean {
|
||||
return entryKDBX?.allowCustomFields() ?: false
|
||||
}
|
||||
|
||||
fun removeAllFields() {
|
||||
entryKDBX?.removeAllFields()
|
||||
}
|
||||
|
||||
/**
|
||||
* Update or add an extra field to the list (standard or custom)
|
||||
* @param label Label of field, must be unique
|
||||
* @param value Value of field
|
||||
*/
|
||||
fun putExtraField(label: String, value: ProtectedString) {
|
||||
entryKDBX?.putExtraField(label, value)
|
||||
}
|
||||
|
||||
fun getOtpElement(): OtpElement? {
|
||||
return OtpEntryFields.parseFields { key ->
|
||||
customFields[key]?.toString()
|
||||
}
|
||||
}
|
||||
|
||||
fun startToManageFieldReferences(db: DatabaseKDBX) {
|
||||
entryKDBX?.startToManageFieldReferences(db)
|
||||
}
|
||||
|
||||
fun stopToManageFieldReferences() {
|
||||
entryKDBX?.stopToManageFieldReferences()
|
||||
}
|
||||
|
||||
fun getHistory(): ArrayList<Entry> {
|
||||
val history = ArrayList<Entry>()
|
||||
val entryV4History = entryKDBX?.history ?: ArrayList()
|
||||
for (entryHistory in entryV4History) {
|
||||
history.add(Entry(entryHistory))
|
||||
}
|
||||
return history
|
||||
}
|
||||
|
||||
fun addEntryToHistory(entry: Entry) {
|
||||
entry.entryKDBX?.let {
|
||||
entryKDBX?.addEntryToHistory(it)
|
||||
}
|
||||
}
|
||||
|
||||
fun removeAllHistory() {
|
||||
entryKDBX?.removeAllHistory()
|
||||
}
|
||||
|
||||
fun removeOldestEntryFromHistory() {
|
||||
entryKDBX?.removeOldestEntryFromHistory()
|
||||
}
|
||||
|
||||
fun getSize(): Long {
|
||||
return entryKDBX?.size ?: 0L
|
||||
}
|
||||
|
||||
fun containsCustomData(): Boolean {
|
||||
return entryKDBX?.containsCustomData() ?: false
|
||||
}
|
||||
|
||||
/*
|
||||
------------
|
||||
Converter
|
||||
------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Retrieve generated entry info,
|
||||
* Remove parameter fields and add auto generated elements in auto custom fields
|
||||
*/
|
||||
fun getEntryInfo(database: Database?, raw: Boolean = false): EntryInfo {
|
||||
val entryInfo = EntryInfo()
|
||||
if (raw)
|
||||
database?.stopManageEntry(this)
|
||||
else
|
||||
database?.startManageEntry(this)
|
||||
entryInfo.id = nodeId.toString()
|
||||
entryInfo.title = title
|
||||
entryInfo.username = username
|
||||
entryInfo.password = password
|
||||
entryInfo.url = url
|
||||
entryInfo.notes = notes
|
||||
for (entry in customFields.entries) {
|
||||
entryInfo.customFields.add(
|
||||
Field(entry.key, entry.value))
|
||||
}
|
||||
// Add otpElement to generate token
|
||||
entryInfo.otpModel = getOtpElement()?.otpModel
|
||||
// Replace parameter fields by generated OTP fields
|
||||
entryInfo.customFields = OtpEntryFields.generateAutoFields(entryInfo.customFields)
|
||||
if (!raw)
|
||||
database?.stopManageEntry(this)
|
||||
return entryInfo
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as Entry
|
||||
|
||||
if (entryKDB != other.entryKDB) return false
|
||||
if (entryKDBX != other.entryKDBX) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = entryKDB?.hashCode() ?: 0
|
||||
result = 31 * result + (entryKDBX?.hashCode() ?: 0)
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<Entry> {
|
||||
override fun createFromParcel(parcel: Parcel): Entry {
|
||||
return Entry(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<Entry?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
|
||||
const val PMS_TAN_ENTRY = "<TAN>"
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* Get the display title from an entry, <br></br>
|
||||
* [.startManageEntry] and [.stopManageEntry] must be called
|
||||
* before and after [.getVisualTitle]
|
||||
*/
|
||||
fun getVisualTitle(isTan: Boolean, title: String, userName: String, url: String, id: String): String {
|
||||
return if (isTan) {
|
||||
"$PMS_TAN_ENTRY $userName"
|
||||
} else {
|
||||
if (title.isEmpty())
|
||||
if (userName.isEmpty())
|
||||
if (url.isEmpty())
|
||||
id
|
||||
else
|
||||
url
|
||||
else
|
||||
userName
|
||||
else
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,395 +0,0 @@
|
||||
package com.kunzisoft.keepass.database.element
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
import com.kunzisoft.keepass.model.EntryInfo
|
||||
import com.kunzisoft.keepass.model.Field
|
||||
import com.kunzisoft.keepass.otp.OtpElement
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class EntryVersioned : NodeVersioned, PwEntryInterface<GroupVersioned> {
|
||||
|
||||
var pwEntryV3: PwEntryV3? = null
|
||||
private set
|
||||
var pwEntryV4: PwEntryV4? = null
|
||||
private set
|
||||
|
||||
fun updateWith(entry: EntryVersioned, copyHistory: Boolean = true) {
|
||||
entry.pwEntryV3?.let {
|
||||
this.pwEntryV3?.updateWith(it)
|
||||
}
|
||||
entry.pwEntryV4?.let {
|
||||
this.pwEntryV4?.updateWith(it, copyHistory)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this constructor to copy an Entry with exact same values
|
||||
*/
|
||||
constructor(entry: EntryVersioned, copyHistory: Boolean = true) {
|
||||
if (entry.pwEntryV3 != null) {
|
||||
this.pwEntryV3 = PwEntryV3()
|
||||
}
|
||||
if (entry.pwEntryV4 != null) {
|
||||
this.pwEntryV4 = PwEntryV4()
|
||||
}
|
||||
updateWith(entry, copyHistory)
|
||||
}
|
||||
|
||||
constructor(entry: PwEntryV3) {
|
||||
this.pwEntryV4 = null
|
||||
this.pwEntryV3 = entry
|
||||
}
|
||||
|
||||
constructor(entry: PwEntryV4) {
|
||||
this.pwEntryV3 = null
|
||||
this.pwEntryV4 = entry
|
||||
}
|
||||
|
||||
constructor(parcel: Parcel) {
|
||||
pwEntryV3 = parcel.readParcelable(PwEntryV3::class.java.classLoader)
|
||||
pwEntryV4 = parcel.readParcelable(PwEntryV4::class.java.classLoader)
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||
dest.writeParcelable(pwEntryV3, flags)
|
||||
dest.writeParcelable(pwEntryV4, flags)
|
||||
}
|
||||
|
||||
override var nodeId: PwNodeId<UUID>
|
||||
get() = pwEntryV4?.nodeId ?: pwEntryV3?.nodeId ?: PwNodeIdUUID()
|
||||
set(value) {
|
||||
pwEntryV3?.nodeId = value
|
||||
pwEntryV4?.nodeId = value
|
||||
}
|
||||
|
||||
override var title: String
|
||||
get() = pwEntryV3?.title ?: pwEntryV4?.title ?: ""
|
||||
set(value) {
|
||||
pwEntryV3?.title = value
|
||||
pwEntryV4?.title = value
|
||||
}
|
||||
|
||||
override var icon: PwIcon
|
||||
get() {
|
||||
return pwEntryV3?.icon ?: pwEntryV4?.icon ?: PwIconStandard()
|
||||
}
|
||||
set(value) {
|
||||
pwEntryV3?.icon = value
|
||||
pwEntryV4?.icon = value
|
||||
}
|
||||
|
||||
override val type: Type
|
||||
get() = Type.ENTRY
|
||||
|
||||
override var parent: GroupVersioned?
|
||||
get() {
|
||||
pwEntryV3?.parent?.let {
|
||||
return GroupVersioned(it)
|
||||
}
|
||||
pwEntryV4?.parent?.let {
|
||||
return GroupVersioned(it)
|
||||
}
|
||||
return null
|
||||
}
|
||||
set(value) {
|
||||
pwEntryV3?.parent = value?.pwGroupV3
|
||||
pwEntryV4?.parent = value?.pwGroupV4
|
||||
}
|
||||
|
||||
override fun containsParent(): Boolean {
|
||||
return pwEntryV3?.containsParent() ?: pwEntryV4?.containsParent() ?: false
|
||||
}
|
||||
|
||||
override fun afterAssignNewParent() {
|
||||
pwEntryV4?.afterChangeParent()
|
||||
}
|
||||
|
||||
override fun touch(modified: Boolean, touchParents: Boolean) {
|
||||
pwEntryV3?.touch(modified, touchParents)
|
||||
pwEntryV4?.touch(modified, touchParents)
|
||||
}
|
||||
|
||||
override fun isContainedIn(container: GroupVersioned): Boolean {
|
||||
var contained: Boolean? = false
|
||||
container.pwGroupV3?.let {
|
||||
contained = pwEntryV3?.isContainedIn(it)
|
||||
}
|
||||
container.pwGroupV4?.let {
|
||||
contained = pwEntryV4?.isContainedIn(it)
|
||||
}
|
||||
return contained ?: false
|
||||
}
|
||||
|
||||
override var creationTime: PwDate
|
||||
get() = pwEntryV3?.creationTime ?: pwEntryV4?.creationTime ?: PwDate()
|
||||
set(value) {
|
||||
pwEntryV3?.creationTime = value
|
||||
pwEntryV4?.creationTime = value
|
||||
}
|
||||
|
||||
override var lastModificationTime: PwDate
|
||||
get() = pwEntryV3?.lastModificationTime ?: pwEntryV4?.lastModificationTime ?: PwDate()
|
||||
set(value) {
|
||||
pwEntryV3?.lastModificationTime = value
|
||||
pwEntryV4?.lastModificationTime = value
|
||||
}
|
||||
|
||||
override var lastAccessTime: PwDate
|
||||
get() = pwEntryV3?.lastAccessTime ?: pwEntryV4?.lastAccessTime ?: PwDate()
|
||||
set(value) {
|
||||
pwEntryV3?.lastAccessTime = value
|
||||
pwEntryV4?.lastAccessTime = value
|
||||
}
|
||||
|
||||
override var expiryTime: PwDate
|
||||
get() = pwEntryV3?.expiryTime ?: pwEntryV4?.expiryTime ?: PwDate()
|
||||
set(value) {
|
||||
pwEntryV3?.expiryTime = value
|
||||
pwEntryV4?.expiryTime = value
|
||||
}
|
||||
|
||||
override var expires: Boolean
|
||||
get() = pwEntryV3?.expires ?: pwEntryV4?.expires ?: false
|
||||
set(value) {
|
||||
pwEntryV3?.expires = value
|
||||
pwEntryV4?.expires = value
|
||||
}
|
||||
|
||||
override val isCurrentlyExpires: Boolean
|
||||
get() = pwEntryV3?.isCurrentlyExpires ?: pwEntryV4?.isCurrentlyExpires ?: false
|
||||
|
||||
override var username: String
|
||||
get() = pwEntryV3?.username ?: pwEntryV4?.username ?: ""
|
||||
set(value) {
|
||||
pwEntryV3?.username = value
|
||||
pwEntryV4?.username = value
|
||||
}
|
||||
|
||||
override var password: String
|
||||
get() = pwEntryV3?.password ?: pwEntryV4?.password ?: ""
|
||||
set(value) {
|
||||
pwEntryV3?.password = value
|
||||
pwEntryV4?.password = value
|
||||
}
|
||||
|
||||
override var url: String
|
||||
get() = pwEntryV3?.url ?: pwEntryV4?.url ?: ""
|
||||
set(value) {
|
||||
pwEntryV3?.url = value
|
||||
pwEntryV4?.url = value
|
||||
}
|
||||
|
||||
override var notes: String
|
||||
get() = pwEntryV3?.notes ?: pwEntryV4?.notes ?: ""
|
||||
set(value) {
|
||||
pwEntryV3?.notes = value
|
||||
pwEntryV4?.notes = value
|
||||
}
|
||||
|
||||
private fun isTan(): Boolean {
|
||||
return title == PMS_TAN_ENTRY && username.isNotEmpty()
|
||||
}
|
||||
|
||||
fun getVisualTitle(): String {
|
||||
return getVisualTitle(isTan(),
|
||||
title,
|
||||
username,
|
||||
url,
|
||||
nodeId.toString())
|
||||
}
|
||||
|
||||
/*
|
||||
------------
|
||||
V3 Methods
|
||||
------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* If it's a node with only meta information like Meta-info SYSTEM Database Color
|
||||
* @return false by default, true if it's a meta stream
|
||||
*/
|
||||
val isMetaStream: Boolean
|
||||
get() = pwEntryV3?.isMetaStream ?: false
|
||||
|
||||
/*
|
||||
------------
|
||||
V4 Methods
|
||||
------------
|
||||
*/
|
||||
|
||||
var iconCustom: PwIconCustom
|
||||
get() = pwEntryV4?.iconCustom ?: PwIconCustom.UNKNOWN_ICON
|
||||
set(value) {
|
||||
pwEntryV4?.iconCustom = value
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve custom fields to show, key is the label, value is the value of field (protected or not)
|
||||
* @return Map of label/value
|
||||
*/
|
||||
val customFields: HashMap<String, ProtectedString>
|
||||
get() = pwEntryV4?.customFields ?: HashMap()
|
||||
|
||||
/**
|
||||
* To redefine if version of entry allow custom field,
|
||||
* @return true if entry allows custom field
|
||||
*/
|
||||
fun allowCustomFields(): Boolean {
|
||||
return pwEntryV4?.allowCustomFields() ?: false
|
||||
}
|
||||
|
||||
fun removeAllFields() {
|
||||
pwEntryV4?.removeAllFields()
|
||||
}
|
||||
|
||||
/**
|
||||
* Update or add an extra field to the list (standard or custom)
|
||||
* @param label Label of field, must be unique
|
||||
* @param value Value of field
|
||||
*/
|
||||
fun putExtraField(label: String, value: ProtectedString) {
|
||||
pwEntryV4?.putExtraField(label, value)
|
||||
}
|
||||
|
||||
fun getOtpElement(): OtpElement? {
|
||||
return OtpEntryFields.parseFields { key ->
|
||||
customFields[key]?.toString()
|
||||
}
|
||||
}
|
||||
|
||||
fun startToManageFieldReferences(db: PwDatabaseV4) {
|
||||
pwEntryV4?.startToManageFieldReferences(db)
|
||||
}
|
||||
|
||||
fun stopToManageFieldReferences() {
|
||||
pwEntryV4?.stopToManageFieldReferences()
|
||||
}
|
||||
|
||||
fun getHistory(): ArrayList<EntryVersioned> {
|
||||
val history = ArrayList<EntryVersioned>()
|
||||
val entryV4History = pwEntryV4?.history ?: ArrayList()
|
||||
for (entryHistory in entryV4History) {
|
||||
history.add(EntryVersioned(entryHistory))
|
||||
}
|
||||
return history
|
||||
}
|
||||
|
||||
fun addEntryToHistory(entry: EntryVersioned) {
|
||||
entry.pwEntryV4?.let {
|
||||
pwEntryV4?.addEntryToHistory(it)
|
||||
}
|
||||
}
|
||||
|
||||
fun removeAllHistory() {
|
||||
pwEntryV4?.removeAllHistory()
|
||||
}
|
||||
|
||||
fun removeOldestEntryFromHistory() {
|
||||
pwEntryV4?.removeOldestEntryFromHistory()
|
||||
}
|
||||
|
||||
fun getSize(): Long {
|
||||
return pwEntryV4?.size ?: 0L
|
||||
}
|
||||
|
||||
fun containsCustomData(): Boolean {
|
||||
return pwEntryV4?.containsCustomData() ?: false
|
||||
}
|
||||
|
||||
/*
|
||||
------------
|
||||
Converter
|
||||
------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Retrieve generated entry info,
|
||||
* Remove parameter fields and add auto generated elements in auto custom fields
|
||||
*/
|
||||
fun getEntryInfo(database: Database?, raw: Boolean = false): EntryInfo {
|
||||
val entryInfo = EntryInfo()
|
||||
if (raw)
|
||||
database?.stopManageEntry(this)
|
||||
else
|
||||
database?.startManageEntry(this)
|
||||
entryInfo.id = nodeId.toString()
|
||||
entryInfo.title = title
|
||||
entryInfo.username = username
|
||||
entryInfo.password = password
|
||||
entryInfo.url = url
|
||||
entryInfo.notes = notes
|
||||
for (entry in customFields.entries) {
|
||||
entryInfo.customFields.add(
|
||||
Field(entry.key, entry.value))
|
||||
}
|
||||
// Add otpElement to generate token
|
||||
entryInfo.otpModel = getOtpElement()?.otpModel
|
||||
// Replace parameter fields by generated OTP fields
|
||||
entryInfo.customFields = OtpEntryFields.generateAutoFields(entryInfo.customFields)
|
||||
if (!raw)
|
||||
database?.stopManageEntry(this)
|
||||
return entryInfo
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as EntryVersioned
|
||||
|
||||
if (pwEntryV3 != other.pwEntryV3) return false
|
||||
if (pwEntryV4 != other.pwEntryV4) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = pwEntryV3?.hashCode() ?: 0
|
||||
result = 31 * result + (pwEntryV4?.hashCode() ?: 0)
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<EntryVersioned> {
|
||||
override fun createFromParcel(parcel: Parcel): EntryVersioned {
|
||||
return EntryVersioned(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<EntryVersioned?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
|
||||
const val PMS_TAN_ENTRY = "<TAN>"
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* Get the display title from an entry, <br></br>
|
||||
* [.startManageEntry] and [.stopManageEntry] must be called
|
||||
* before and after [.getVisualTitle]
|
||||
*/
|
||||
fun getVisualTitle(isTan: Boolean, title: String, userName: String, url: String, id: String): String {
|
||||
return if (isTan) {
|
||||
"$PMS_TAN_ENTRY $userName"
|
||||
} else {
|
||||
if (title.isEmpty())
|
||||
if (userName.isEmpty())
|
||||
if (url.isEmpty())
|
||||
id
|
||||
else
|
||||
url
|
||||
else
|
||||
userName
|
||||
else
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
package com.kunzisoft.keepass.database.element
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.group.GroupKDB
|
||||
import com.kunzisoft.keepass.database.element.group.GroupKDBX
|
||||
import com.kunzisoft.keepass.database.element.group.GroupVersionedInterface
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
|
||||
import com.kunzisoft.keepass.database.element.node.*
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class Group : Node, GroupVersionedInterface<Group, Entry> {
|
||||
|
||||
var groupKDB: GroupKDB? = null
|
||||
private set
|
||||
var groupKDBX: GroupKDBX? = null
|
||||
private set
|
||||
|
||||
fun updateWith(group: Group) {
|
||||
group.groupKDB?.let {
|
||||
this.groupKDB?.updateWith(it)
|
||||
}
|
||||
group.groupKDBX?.let {
|
||||
this.groupKDBX?.updateWith(it)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this constructor to copy a Group
|
||||
*/
|
||||
constructor(group: Group) {
|
||||
if (group.groupKDB != null) {
|
||||
if (this.groupKDB == null)
|
||||
this.groupKDB = GroupKDB()
|
||||
}
|
||||
if (group.groupKDBX != null) {
|
||||
if (this.groupKDBX == null)
|
||||
this.groupKDBX = GroupKDBX()
|
||||
}
|
||||
updateWith(group)
|
||||
}
|
||||
|
||||
constructor(group: GroupKDB) {
|
||||
this.groupKDBX = null
|
||||
this.groupKDB = group
|
||||
}
|
||||
|
||||
constructor(group: GroupKDBX) {
|
||||
this.groupKDB = null
|
||||
this.groupKDBX = group
|
||||
}
|
||||
|
||||
constructor(parcel: Parcel) {
|
||||
groupKDB = parcel.readParcelable(GroupKDB::class.java.classLoader)
|
||||
groupKDBX = parcel.readParcelable(GroupKDBX::class.java.classLoader)
|
||||
}
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<Group> {
|
||||
override fun createFromParcel(parcel: Parcel): Group {
|
||||
return Group(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<Group?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||
dest.writeParcelable(groupKDB, flags)
|
||||
dest.writeParcelable(groupKDBX, flags)
|
||||
}
|
||||
|
||||
override val nodeId: NodeId<*>?
|
||||
get() = groupKDBX?.nodeId ?: groupKDB?.nodeId
|
||||
|
||||
override var title: String
|
||||
get() = groupKDB?.title ?: groupKDBX?.title ?: ""
|
||||
set(value) {
|
||||
groupKDB?.title = value
|
||||
groupKDBX?.title = value
|
||||
}
|
||||
|
||||
override var icon: IconImage
|
||||
get() = groupKDB?.icon ?: groupKDBX?.icon ?: IconImageStandard()
|
||||
set(value) {
|
||||
groupKDB?.icon = value
|
||||
groupKDBX?.icon = value
|
||||
}
|
||||
|
||||
override val type: Type
|
||||
get() = Type.GROUP
|
||||
|
||||
override var parent: Group?
|
||||
get() {
|
||||
groupKDB?.parent?.let {
|
||||
return Group(it)
|
||||
}
|
||||
groupKDBX?.parent?.let {
|
||||
return Group(it)
|
||||
}
|
||||
return null
|
||||
}
|
||||
set(value) {
|
||||
groupKDB?.parent = value?.groupKDB
|
||||
groupKDBX?.parent = value?.groupKDBX
|
||||
}
|
||||
|
||||
override fun containsParent(): Boolean {
|
||||
return groupKDB?.containsParent() ?: groupKDBX?.containsParent() ?: false
|
||||
}
|
||||
|
||||
override fun afterAssignNewParent() {
|
||||
groupKDB?.afterAssignNewParent()
|
||||
groupKDBX?.afterAssignNewParent()
|
||||
}
|
||||
|
||||
fun addChildrenFrom(group: Group) {
|
||||
group.groupKDB?.getChildEntries()?.forEach { entryToAdd ->
|
||||
groupKDB?.addChildEntry(entryToAdd)
|
||||
}
|
||||
group.groupKDB?.getChildGroups()?.forEach { groupToAdd ->
|
||||
groupKDB?.addChildGroup(groupToAdd)
|
||||
}
|
||||
|
||||
group.groupKDBX?.getChildEntries()?.forEach { entryToAdd ->
|
||||
groupKDBX?.addChildEntry(entryToAdd)
|
||||
}
|
||||
group.groupKDBX?.getChildGroups()?.forEach { groupToAdd ->
|
||||
groupKDBX?.addChildGroup(groupToAdd)
|
||||
}
|
||||
}
|
||||
|
||||
override fun touch(modified: Boolean, touchParents: Boolean) {
|
||||
groupKDB?.touch(modified, touchParents)
|
||||
groupKDBX?.touch(modified, touchParents)
|
||||
}
|
||||
|
||||
override fun isContainedIn(container: Group): Boolean {
|
||||
var contained: Boolean? = null
|
||||
container.groupKDB?.let {
|
||||
contained = groupKDB?.isContainedIn(it)
|
||||
}
|
||||
container.groupKDBX?.let {
|
||||
contained = groupKDBX?.isContainedIn(it)
|
||||
}
|
||||
return contained ?: false
|
||||
}
|
||||
|
||||
override var creationTime: DateInstant
|
||||
get() = groupKDB?.creationTime ?: groupKDBX?.creationTime ?: DateInstant()
|
||||
set(value) {
|
||||
groupKDB?.creationTime = value
|
||||
groupKDBX?.creationTime = value
|
||||
}
|
||||
|
||||
override var lastModificationTime: DateInstant
|
||||
get() = groupKDB?.lastModificationTime ?: groupKDBX?.lastModificationTime ?: DateInstant()
|
||||
set(value) {
|
||||
groupKDB?.lastModificationTime = value
|
||||
groupKDBX?.lastModificationTime = value
|
||||
}
|
||||
|
||||
override var lastAccessTime: DateInstant
|
||||
get() = groupKDB?.lastAccessTime ?: groupKDBX?.lastAccessTime ?: DateInstant()
|
||||
set(value) {
|
||||
groupKDB?.lastAccessTime = value
|
||||
groupKDBX?.lastAccessTime = value
|
||||
}
|
||||
|
||||
override var expiryTime: DateInstant
|
||||
get() = groupKDB?.expiryTime ?: groupKDBX?.expiryTime ?: DateInstant()
|
||||
set(value) {
|
||||
groupKDB?.expiryTime = value
|
||||
groupKDBX?.expiryTime = value
|
||||
}
|
||||
|
||||
override var expires: Boolean
|
||||
get() = groupKDB?.expires ?: groupKDBX?.expires ?: false
|
||||
set(value) {
|
||||
groupKDB?.expires = value
|
||||
groupKDBX?.expires = value
|
||||
}
|
||||
|
||||
override val isCurrentlyExpires: Boolean
|
||||
get() = groupKDB?.isCurrentlyExpires ?: groupKDBX?.isCurrentlyExpires ?: false
|
||||
|
||||
override fun getChildGroups(): MutableList<Group> {
|
||||
val children = ArrayList<Group>()
|
||||
|
||||
groupKDB?.getChildGroups()?.forEach {
|
||||
children.add(Group(it))
|
||||
}
|
||||
groupKDBX?.getChildGroups()?.forEach {
|
||||
children.add(Group(it))
|
||||
}
|
||||
|
||||
return children
|
||||
}
|
||||
|
||||
override fun getChildEntries(): MutableList<Entry> {
|
||||
return getChildEntries(false)
|
||||
}
|
||||
|
||||
fun getChildEntries(withoutMetaStream: Boolean): MutableList<Entry> {
|
||||
val children = ArrayList<Entry>()
|
||||
|
||||
groupKDB?.getChildEntries()?.forEach {
|
||||
val entryToAddAsChild = Entry(it)
|
||||
if (!withoutMetaStream || (withoutMetaStream && !entryToAddAsChild.isMetaStream))
|
||||
children.add(entryToAddAsChild)
|
||||
}
|
||||
groupKDBX?.getChildEntries()?.forEach {
|
||||
children.add(Entry(it))
|
||||
}
|
||||
|
||||
return children
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter MetaStream entries and return children
|
||||
* @return List of direct children (one level below) as NodeVersioned
|
||||
*/
|
||||
fun getChildren(withoutMetaStream: Boolean = true): List<Node> {
|
||||
val children = ArrayList<Node>()
|
||||
children.addAll(getChildGroups())
|
||||
|
||||
groupKDB?.let {
|
||||
children.addAll(getChildEntries(withoutMetaStream))
|
||||
}
|
||||
groupKDBX?.let {
|
||||
// No MetasStream in V4
|
||||
children.addAll(getChildEntries(withoutMetaStream))
|
||||
}
|
||||
|
||||
return children
|
||||
}
|
||||
|
||||
override fun addChildGroup(group: Group) {
|
||||
group.groupKDB?.let {
|
||||
groupKDB?.addChildGroup(it)
|
||||
}
|
||||
group.groupKDBX?.let {
|
||||
groupKDBX?.addChildGroup(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun addChildEntry(entry: Entry) {
|
||||
entry.entryKDB?.let {
|
||||
groupKDB?.addChildEntry(it)
|
||||
}
|
||||
entry.entryKDBX?.let {
|
||||
groupKDBX?.addChildEntry(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun removeChildGroup(group: Group) {
|
||||
group.groupKDB?.let {
|
||||
groupKDB?.removeChildGroup(it)
|
||||
}
|
||||
group.groupKDBX?.let {
|
||||
groupKDBX?.removeChildGroup(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun removeChildEntry(entry: Entry) {
|
||||
entry.entryKDB?.let {
|
||||
groupKDB?.removeChildEntry(it)
|
||||
}
|
||||
entry.entryKDBX?.let {
|
||||
groupKDBX?.removeChildEntry(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun removeChildren() {
|
||||
groupKDB?.removeChildren()
|
||||
groupKDBX?.removeChildren()
|
||||
}
|
||||
|
||||
override fun allowAddEntryIfIsRoot(): Boolean {
|
||||
return groupKDB?.allowAddEntryIfIsRoot() ?: groupKDBX?.allowAddEntryIfIsRoot() ?: false
|
||||
}
|
||||
|
||||
/*
|
||||
------------
|
||||
KDB Methods
|
||||
------------
|
||||
*/
|
||||
|
||||
var nodeIdKDB: NodeId<Int>
|
||||
get() = groupKDB?.nodeId ?: NodeIdInt()
|
||||
set(value) { groupKDB?.nodeId = value }
|
||||
|
||||
fun setNodeId(id: NodeIdInt) {
|
||||
groupKDB?.nodeId = id
|
||||
}
|
||||
|
||||
fun getLevel(): Int {
|
||||
return groupKDB?.level ?: -1
|
||||
}
|
||||
|
||||
fun setLevel(level: Int) {
|
||||
groupKDB?.level = level
|
||||
}
|
||||
|
||||
/*
|
||||
------------
|
||||
KDBX Methods
|
||||
------------
|
||||
*/
|
||||
|
||||
var nodeIdKDBX: NodeId<UUID>
|
||||
get() = groupKDBX?.nodeId ?: NodeIdUUID()
|
||||
set(value) { groupKDBX?.nodeId = value }
|
||||
|
||||
fun setNodeId(id: NodeIdUUID) {
|
||||
groupKDBX?.nodeId = id
|
||||
}
|
||||
|
||||
fun setEnableAutoType(enableAutoType: Boolean?) {
|
||||
groupKDBX?.enableAutoType = enableAutoType
|
||||
}
|
||||
|
||||
fun setEnableSearching(enableSearching: Boolean?) {
|
||||
groupKDBX?.enableSearching = enableSearching
|
||||
}
|
||||
|
||||
fun setExpanded(expanded: Boolean) {
|
||||
groupKDBX?.isExpanded = expanded
|
||||
}
|
||||
|
||||
fun containsCustomData(): Boolean {
|
||||
return groupKDBX?.containsCustomData() ?: false
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as Group
|
||||
|
||||
if (groupKDB != other.groupKDB) return false
|
||||
if (groupKDBX != other.groupKDBX) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = groupKDB?.hashCode() ?: 0
|
||||
result = 31 * result + (groupKDBX?.hashCode() ?: 0)
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -1,363 +0,0 @@
|
||||
package com.kunzisoft.keepass.database.element
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class GroupVersioned : NodeVersioned, PwGroupInterface<GroupVersioned, EntryVersioned> {
|
||||
|
||||
var pwGroupV3: PwGroupV3? = null
|
||||
private set
|
||||
var pwGroupV4: PwGroupV4? = null
|
||||
private set
|
||||
|
||||
fun updateWith(group: GroupVersioned) {
|
||||
group.pwGroupV3?.let {
|
||||
this.pwGroupV3?.updateWith(it)
|
||||
}
|
||||
group.pwGroupV4?.let {
|
||||
this.pwGroupV4?.updateWith(it)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this constructor to copy a Group
|
||||
*/
|
||||
constructor(group: GroupVersioned) {
|
||||
if (group.pwGroupV3 != null) {
|
||||
if (this.pwGroupV3 == null)
|
||||
this.pwGroupV3 = PwGroupV3()
|
||||
}
|
||||
if (group.pwGroupV4 != null) {
|
||||
if (this.pwGroupV4 == null)
|
||||
this.pwGroupV4 = PwGroupV4()
|
||||
}
|
||||
updateWith(group)
|
||||
}
|
||||
|
||||
constructor(group: PwGroupV3) {
|
||||
this.pwGroupV4 = null
|
||||
this.pwGroupV3 = group
|
||||
}
|
||||
|
||||
constructor(group: PwGroupV4) {
|
||||
this.pwGroupV3 = null
|
||||
this.pwGroupV4 = group
|
||||
}
|
||||
|
||||
constructor(parcel: Parcel) {
|
||||
pwGroupV3 = parcel.readParcelable(PwGroupV3::class.java.classLoader)
|
||||
pwGroupV4 = parcel.readParcelable(PwGroupV4::class.java.classLoader)
|
||||
}
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<GroupVersioned> {
|
||||
override fun createFromParcel(parcel: Parcel): GroupVersioned {
|
||||
return GroupVersioned(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<GroupVersioned?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||
dest.writeParcelable(pwGroupV3, flags)
|
||||
dest.writeParcelable(pwGroupV4, flags)
|
||||
}
|
||||
|
||||
override val nodeId: PwNodeId<*>?
|
||||
get() = pwGroupV4?.nodeId ?: pwGroupV3?.nodeId
|
||||
|
||||
override var title: String
|
||||
get() = pwGroupV3?.title ?: pwGroupV4?.title ?: ""
|
||||
set(value) {
|
||||
pwGroupV3?.title = value
|
||||
pwGroupV4?.title = value
|
||||
}
|
||||
|
||||
override var icon: PwIcon
|
||||
get() = pwGroupV3?.icon ?: pwGroupV4?.icon ?: PwIconStandard()
|
||||
set(value) {
|
||||
pwGroupV3?.icon = value
|
||||
pwGroupV4?.icon = value
|
||||
}
|
||||
|
||||
override val type: Type
|
||||
get() = Type.GROUP
|
||||
|
||||
override var parent: GroupVersioned?
|
||||
get() {
|
||||
pwGroupV3?.parent?.let {
|
||||
return GroupVersioned(it)
|
||||
}
|
||||
pwGroupV4?.parent?.let {
|
||||
return GroupVersioned(it)
|
||||
}
|
||||
return null
|
||||
}
|
||||
set(value) {
|
||||
pwGroupV3?.parent = value?.pwGroupV3
|
||||
pwGroupV4?.parent = value?.pwGroupV4
|
||||
}
|
||||
|
||||
override fun containsParent(): Boolean {
|
||||
return pwGroupV3?.containsParent() ?: pwGroupV4?.containsParent() ?: false
|
||||
}
|
||||
|
||||
override fun afterAssignNewParent() {
|
||||
pwGroupV3?.afterAssignNewParent()
|
||||
pwGroupV4?.afterAssignNewParent()
|
||||
}
|
||||
|
||||
fun addChildrenFrom(group: GroupVersioned) {
|
||||
group.pwGroupV3?.getChildEntries()?.forEach { entryToAdd ->
|
||||
pwGroupV3?.addChildEntry(entryToAdd)
|
||||
}
|
||||
group.pwGroupV3?.getChildGroups()?.forEach { groupToAdd ->
|
||||
pwGroupV3?.addChildGroup(groupToAdd)
|
||||
}
|
||||
|
||||
group.pwGroupV4?.getChildEntries()?.forEach { entryToAdd ->
|
||||
pwGroupV4?.addChildEntry(entryToAdd)
|
||||
}
|
||||
group.pwGroupV4?.getChildGroups()?.forEach { groupToAdd ->
|
||||
pwGroupV4?.addChildGroup(groupToAdd)
|
||||
}
|
||||
}
|
||||
|
||||
fun removeChildren() {
|
||||
pwGroupV3?.getChildEntries()?.forEach { entryToRemove ->
|
||||
pwGroupV3?.removeChildEntry(entryToRemove)
|
||||
}
|
||||
pwGroupV3?.getChildGroups()?.forEach { groupToRemove ->
|
||||
pwGroupV3?.removeChildGroup(groupToRemove)
|
||||
}
|
||||
|
||||
pwGroupV4?.getChildEntries()?.forEach { entryToRemove ->
|
||||
pwGroupV4?.removeChildEntry(entryToRemove)
|
||||
}
|
||||
pwGroupV4?.getChildGroups()?.forEach { groupToRemove ->
|
||||
pwGroupV4?.removeChildGroup(groupToRemove)
|
||||
}
|
||||
}
|
||||
|
||||
override fun touch(modified: Boolean, touchParents: Boolean) {
|
||||
pwGroupV3?.touch(modified, touchParents)
|
||||
pwGroupV4?.touch(modified, touchParents)
|
||||
}
|
||||
|
||||
override fun isContainedIn(container: GroupVersioned): Boolean {
|
||||
var contained: Boolean? = null
|
||||
container.pwGroupV3?.let {
|
||||
contained = pwGroupV3?.isContainedIn(it)
|
||||
}
|
||||
container.pwGroupV4?.let {
|
||||
contained = pwGroupV4?.isContainedIn(it)
|
||||
}
|
||||
return contained ?: false
|
||||
}
|
||||
|
||||
override var creationTime: PwDate
|
||||
get() = pwGroupV3?.creationTime ?: pwGroupV4?.creationTime ?: PwDate()
|
||||
set(value) {
|
||||
pwGroupV3?.creationTime = value
|
||||
pwGroupV4?.creationTime = value
|
||||
}
|
||||
|
||||
override var lastModificationTime: PwDate
|
||||
get() = pwGroupV3?.lastModificationTime ?: pwGroupV4?.lastModificationTime ?: PwDate()
|
||||
set(value) {
|
||||
pwGroupV3?.lastModificationTime = value
|
||||
pwGroupV4?.lastModificationTime = value
|
||||
}
|
||||
|
||||
override var lastAccessTime: PwDate
|
||||
get() = pwGroupV3?.lastAccessTime ?: pwGroupV4?.lastAccessTime ?: PwDate()
|
||||
set(value) {
|
||||
pwGroupV3?.lastAccessTime = value
|
||||
pwGroupV4?.lastAccessTime = value
|
||||
}
|
||||
|
||||
override var expiryTime: PwDate
|
||||
get() = pwGroupV3?.expiryTime ?: pwGroupV4?.expiryTime ?: PwDate()
|
||||
set(value) {
|
||||
pwGroupV3?.expiryTime = value
|
||||
pwGroupV4?.expiryTime = value
|
||||
}
|
||||
|
||||
override var expires: Boolean
|
||||
get() = pwGroupV3?.expires ?: pwGroupV4?.expires ?: false
|
||||
set(value) {
|
||||
pwGroupV3?.expires = value
|
||||
pwGroupV4?.expires = value
|
||||
}
|
||||
|
||||
override val isCurrentlyExpires: Boolean
|
||||
get() = pwGroupV3?.isCurrentlyExpires ?: pwGroupV4?.isCurrentlyExpires ?: false
|
||||
|
||||
override fun getChildGroups(): MutableList<GroupVersioned> {
|
||||
val children = ArrayList<GroupVersioned>()
|
||||
|
||||
pwGroupV3?.getChildGroups()?.forEach {
|
||||
children.add(GroupVersioned(it))
|
||||
}
|
||||
pwGroupV4?.getChildGroups()?.forEach {
|
||||
children.add(GroupVersioned(it))
|
||||
}
|
||||
|
||||
return children
|
||||
}
|
||||
|
||||
override fun getChildEntries(): MutableList<EntryVersioned> {
|
||||
return getChildEntries(false)
|
||||
}
|
||||
|
||||
fun getChildEntries(withoutMetaStream: Boolean): MutableList<EntryVersioned> {
|
||||
val children = ArrayList<EntryVersioned>()
|
||||
|
||||
pwGroupV3?.getChildEntries()?.forEach {
|
||||
val entryToAddAsChild = EntryVersioned(it)
|
||||
if (!withoutMetaStream || (withoutMetaStream && !entryToAddAsChild.isMetaStream))
|
||||
children.add(entryToAddAsChild)
|
||||
}
|
||||
pwGroupV4?.getChildEntries()?.forEach {
|
||||
children.add(EntryVersioned(it))
|
||||
}
|
||||
|
||||
return children
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter MetaStream entries and return children
|
||||
* @return List of direct children (one level below) as PwNode
|
||||
*/
|
||||
fun getChildren(withoutMetaStream: Boolean = true): List<NodeVersioned> {
|
||||
val children = ArrayList<NodeVersioned>()
|
||||
children.addAll(getChildGroups())
|
||||
|
||||
pwGroupV3?.let {
|
||||
children.addAll(getChildEntries(withoutMetaStream))
|
||||
}
|
||||
pwGroupV4?.let {
|
||||
// No MetasStream in V4
|
||||
children.addAll(getChildEntries(withoutMetaStream))
|
||||
}
|
||||
|
||||
return children
|
||||
}
|
||||
|
||||
override fun addChildGroup(group: GroupVersioned) {
|
||||
group.pwGroupV3?.let {
|
||||
pwGroupV3?.addChildGroup(it)
|
||||
}
|
||||
group.pwGroupV4?.let {
|
||||
pwGroupV4?.addChildGroup(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun addChildEntry(entry: EntryVersioned) {
|
||||
entry.pwEntryV3?.let {
|
||||
pwGroupV3?.addChildEntry(it)
|
||||
}
|
||||
entry.pwEntryV4?.let {
|
||||
pwGroupV4?.addChildEntry(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun removeChildGroup(group: GroupVersioned) {
|
||||
group.pwGroupV3?.let {
|
||||
pwGroupV3?.removeChildGroup(it)
|
||||
}
|
||||
group.pwGroupV4?.let {
|
||||
pwGroupV4?.removeChildGroup(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun removeChildEntry(entry: EntryVersioned) {
|
||||
entry.pwEntryV3?.let {
|
||||
pwGroupV3?.removeChildEntry(it)
|
||||
}
|
||||
entry.pwEntryV4?.let {
|
||||
pwGroupV4?.removeChildEntry(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun allowAddEntryIfIsRoot(): Boolean {
|
||||
return pwGroupV3?.allowAddEntryIfIsRoot() ?: pwGroupV4?.allowAddEntryIfIsRoot() ?: false
|
||||
}
|
||||
|
||||
/*
|
||||
------------
|
||||
V3 Methods
|
||||
------------
|
||||
*/
|
||||
|
||||
var nodeIdV3: PwNodeId<Int>
|
||||
get() = pwGroupV3?.nodeId ?: PwNodeIdInt()
|
||||
set(value) { pwGroupV3?.nodeId = value }
|
||||
|
||||
fun setNodeId(id: PwNodeIdInt) {
|
||||
pwGroupV3?.nodeId = id
|
||||
}
|
||||
|
||||
fun getLevel(): Int {
|
||||
return pwGroupV3?.level ?: -1
|
||||
}
|
||||
|
||||
fun setLevel(level: Int) {
|
||||
pwGroupV3?.level = level
|
||||
}
|
||||
|
||||
/*
|
||||
------------
|
||||
V4 Methods
|
||||
------------
|
||||
*/
|
||||
|
||||
var nodeIdV4: PwNodeId<UUID>
|
||||
get() = pwGroupV4?.nodeId ?: PwNodeIdUUID()
|
||||
set(value) { pwGroupV4?.nodeId = value }
|
||||
|
||||
fun setNodeId(id: PwNodeIdUUID) {
|
||||
pwGroupV4?.nodeId = id
|
||||
}
|
||||
|
||||
fun setEnableAutoType(enableAutoType: Boolean?) {
|
||||
pwGroupV4?.enableAutoType = enableAutoType
|
||||
}
|
||||
|
||||
fun setEnableSearching(enableSearching: Boolean?) {
|
||||
pwGroupV4?.enableSearching = enableSearching
|
||||
}
|
||||
|
||||
fun setExpanded(expanded: Boolean) {
|
||||
pwGroupV4?.isExpanded = expanded
|
||||
}
|
||||
|
||||
fun containsCustomData(): Boolean {
|
||||
return pwGroupV4?.containsCustomData() ?: false
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as GroupVersioned
|
||||
|
||||
if (pwGroupV3 != other.pwGroupV3) return false
|
||||
if (pwGroupV4 != other.pwGroupV4) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = pwGroupV3?.hashCode() ?: 0
|
||||
result = 31 * result + (pwGroupV4?.hashCode() ?: 0)
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -1,275 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import androidx.core.os.ConfigurationCompat
|
||||
import com.kunzisoft.keepass.utils.Types
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Converting from the C Date format to the Java data format is
|
||||
* expensive when done for every record at once.
|
||||
*/
|
||||
class PwDate : Parcelable {
|
||||
|
||||
private var jDate: Date = Date()
|
||||
private var jDateBuilt = false
|
||||
@Transient
|
||||
private var cDate: ByteArray? = null
|
||||
@Transient
|
||||
private var cDateBuilt = false
|
||||
|
||||
val date: Date
|
||||
get() {
|
||||
if (!jDateBuilt) {
|
||||
jDate = readTime(cDate, 0, calendar)
|
||||
jDateBuilt = true
|
||||
}
|
||||
|
||||
return jDate
|
||||
}
|
||||
|
||||
val byteArrayDate: ByteArray?
|
||||
get() {
|
||||
if (!cDateBuilt) {
|
||||
cDate = writeTime(jDate, calendar)
|
||||
cDateBuilt = true
|
||||
}
|
||||
|
||||
return cDate
|
||||
}
|
||||
|
||||
constructor(buf: ByteArray, offset: Int) {
|
||||
cDate = ByteArray(DATE_SIZE)
|
||||
System.arraycopy(buf, offset, cDate!!, 0, DATE_SIZE)
|
||||
cDateBuilt = true
|
||||
}
|
||||
|
||||
constructor(source: PwDate) {
|
||||
this.jDate = Date(source.jDate.time)
|
||||
this.jDateBuilt = source.jDateBuilt
|
||||
|
||||
if (source.cDate != null) {
|
||||
val dateLength = source.cDate!!.size
|
||||
this.cDate = ByteArray(dateLength)
|
||||
System.arraycopy(source.cDate!!, 0, this.cDate!!, 0, dateLength)
|
||||
}
|
||||
this.cDateBuilt = source.cDateBuilt
|
||||
}
|
||||
|
||||
constructor(date: Date) {
|
||||
jDate = Date(date.time)
|
||||
jDateBuilt = true
|
||||
}
|
||||
|
||||
constructor(millis: Long) {
|
||||
jDate = Date(millis)
|
||||
jDateBuilt = true
|
||||
}
|
||||
|
||||
constructor() {
|
||||
jDate = Date()
|
||||
jDateBuilt = true
|
||||
}
|
||||
|
||||
protected constructor(parcel: Parcel) {
|
||||
jDate = parcel.readSerializable() as Date
|
||||
jDateBuilt = parcel.readByte().toInt() != 0
|
||||
cDateBuilt = false
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
fun getDateTimeString(resources: Resources): String {
|
||||
return Companion.getDateTimeString(resources, this.date)
|
||||
}
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||
dest.writeSerializable(date)
|
||||
dest.writeByte((if (jDateBuilt) 1 else 0).toByte())
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) {
|
||||
return true
|
||||
}
|
||||
if (other == null) {
|
||||
return false
|
||||
}
|
||||
if (javaClass != other.javaClass) {
|
||||
return false
|
||||
}
|
||||
|
||||
val date = other as PwDate?
|
||||
return if (cDateBuilt && date!!.cDateBuilt) {
|
||||
Arrays.equals(cDate, date.cDate)
|
||||
} else if (jDateBuilt && date!!.jDateBuilt) {
|
||||
isSameDate(jDate, date.jDate)
|
||||
} else if (cDateBuilt && date!!.jDateBuilt) {
|
||||
Arrays.equals(date.byteArrayDate, cDate)
|
||||
} else {
|
||||
isSameDate(date!!.date, jDate)
|
||||
}
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = jDate.hashCode()
|
||||
result = 31 * result + jDateBuilt.hashCode()
|
||||
result = 31 * result + (cDate?.contentHashCode() ?: 0)
|
||||
result = 31 * result + cDateBuilt.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private const val DATE_SIZE = 5
|
||||
|
||||
private var mCalendar: Calendar? = null
|
||||
|
||||
val NEVER_EXPIRE = neverExpire
|
||||
|
||||
private val calendar: Calendar?
|
||||
get() {
|
||||
if (mCalendar == null) {
|
||||
mCalendar = Calendar.getInstance()
|
||||
}
|
||||
return mCalendar
|
||||
}
|
||||
|
||||
private val neverExpire: PwDate
|
||||
get() {
|
||||
val cal = Calendar.getInstance()
|
||||
cal.set(Calendar.YEAR, 2999)
|
||||
cal.set(Calendar.MONTH, 11)
|
||||
cal.set(Calendar.DAY_OF_MONTH, 28)
|
||||
cal.set(Calendar.HOUR, 23)
|
||||
cal.set(Calendar.MINUTE, 59)
|
||||
cal.set(Calendar.SECOND, 59)
|
||||
|
||||
return PwDate(cal.time)
|
||||
}
|
||||
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<PwDate> = object : Parcelable.Creator<PwDate> {
|
||||
override fun createFromParcel(parcel: Parcel): PwDate {
|
||||
return PwDate(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<PwDate?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack date from 5 byte format. The five bytes at 'offset' are unpacked
|
||||
* to a java.util.Date instance.
|
||||
*/
|
||||
fun readTime(buf: ByteArray?, offset: Int, calendar: Calendar?): Date {
|
||||
var time = calendar
|
||||
val dw1 = Types.readUByte(buf!!, offset)
|
||||
val dw2 = Types.readUByte(buf, offset + 1)
|
||||
val dw3 = Types.readUByte(buf, offset + 2)
|
||||
val dw4 = Types.readUByte(buf, offset + 3)
|
||||
val dw5 = Types.readUByte(buf, offset + 4)
|
||||
|
||||
// Unpack 5 byte structure to date and time
|
||||
val year = dw1 shl 6 or (dw2 shr 2)
|
||||
val month = dw2 and 0x00000003 shl 2 or (dw3 shr 6)
|
||||
|
||||
val day = dw3 shr 1 and 0x0000001F
|
||||
val hour = dw3 and 0x00000001 shl 4 or (dw4 shr 4)
|
||||
val minute = dw4 and 0x0000000F shl 2 or (dw5 shr 6)
|
||||
val second = dw5 and 0x0000003F
|
||||
|
||||
if (time == null) {
|
||||
time = Calendar.getInstance()
|
||||
}
|
||||
// File format is a 1 based month, java Calendar uses a zero based month
|
||||
// File format is a 1 based day, java Calendar uses a 1 based day
|
||||
time!!.set(year, month - 1, day, hour, minute, second)
|
||||
|
||||
return time.time
|
||||
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun writeTime(date: Date?, calendar: Calendar? = null): ByteArray? {
|
||||
var cal = calendar
|
||||
if (date == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
val buf = ByteArray(5)
|
||||
if (cal == null) {
|
||||
cal = Calendar.getInstance()
|
||||
}
|
||||
cal!!.time = date
|
||||
|
||||
val year = cal.get(Calendar.YEAR)
|
||||
// File format is a 1 based month, java Calendar uses a zero based month
|
||||
val month = cal.get(Calendar.MONTH) + 1
|
||||
// File format is a 0 based day, java Calendar uses a 1 based day
|
||||
val day = cal.get(Calendar.DAY_OF_MONTH) - 1
|
||||
val hour = cal.get(Calendar.HOUR_OF_DAY)
|
||||
val minute = cal.get(Calendar.MINUTE)
|
||||
val second = cal.get(Calendar.SECOND)
|
||||
|
||||
buf[0] = Types.writeUByte(year shr 6 and 0x0000003F)
|
||||
buf[1] = Types.writeUByte(year and 0x0000003F shl 2 or (month shr 2 and 0x00000003))
|
||||
buf[2] = (month and 0x00000003 shl 6
|
||||
or (day and 0x0000001F shl 1) or (hour shr 4 and 0x00000001)).toByte()
|
||||
buf[3] = (hour and 0x0000000F shl 4 or (minute shr 2 and 0x0000000F)).toByte()
|
||||
buf[4] = (minute and 0x00000003 shl 6 or (second and 0x0000003F)).toByte()
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
private fun isSameDate(d1: Date?, d2: Date?): Boolean {
|
||||
val cal1 = Calendar.getInstance()
|
||||
cal1.time = d1
|
||||
cal1.set(Calendar.MILLISECOND, 0)
|
||||
|
||||
val cal2 = Calendar.getInstance()
|
||||
cal2.time = d2
|
||||
cal2.set(Calendar.MILLISECOND, 0)
|
||||
|
||||
return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
|
||||
cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH) &&
|
||||
cal1.get(Calendar.DAY_OF_MONTH) == cal2.get(Calendar.DAY_OF_MONTH) &&
|
||||
cal1.get(Calendar.HOUR) == cal2.get(Calendar.HOUR) &&
|
||||
cal1.get(Calendar.MINUTE) == cal2.get(Calendar.MINUTE) &&
|
||||
cal1.get(Calendar.SECOND) == cal2.get(Calendar.SECOND)
|
||||
|
||||
}
|
||||
|
||||
fun getDateTimeString(resources: Resources, date: Date): String {
|
||||
return java.text.DateFormat.getDateTimeInstance(
|
||||
java.text.DateFormat.MEDIUM,
|
||||
java.text.DateFormat.MEDIUM,
|
||||
ConfigurationCompat.getLocales(resources.configuration)[0])
|
||||
.format(date)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.kunzisoft.keepass.database.element
|
||||
|
||||
import android.os.Parcel
|
||||
import java.util.*
|
||||
|
||||
abstract class PwEntry
|
||||
<
|
||||
GroupId,
|
||||
EntryId,
|
||||
ParentGroup: PwGroup<GroupId, EntryId, ParentGroup, Entry>,
|
||||
Entry: PwEntry<GroupId, EntryId, ParentGroup, Entry>
|
||||
>
|
||||
: PwNode<EntryId, ParentGroup, Entry>, PwEntryInterface<ParentGroup> {
|
||||
|
||||
constructor() : super()
|
||||
|
||||
constructor(parcel: Parcel) : super(parcel)
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.kunzisoft.keepass.database.element
|
||||
|
||||
interface PwEntryInterface<ParentGroup> : PwNodeInterface<ParentGroup> {
|
||||
|
||||
var username: String
|
||||
|
||||
var password: String
|
||||
|
||||
var url: String
|
||||
|
||||
var notes: String
|
||||
}
|
||||
@@ -18,18 +18,16 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kunzisoft.keepass.database
|
||||
package com.kunzisoft.keepass.database.element
|
||||
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.EntryVersioned
|
||||
import com.kunzisoft.keepass.database.element.NodeVersioned
|
||||
import com.kunzisoft.keepass.database.element.Type
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import java.util.*
|
||||
|
||||
enum class SortNodeEnum {
|
||||
DB, TITLE, USERNAME, CREATION_TIME, LAST_MODIFY_TIME, LAST_ACCESS_TIME;
|
||||
|
||||
fun getNodeComparator(ascending: Boolean, groupsBefore: Boolean, recycleBinBottom: Boolean): Comparator<NodeVersioned> {
|
||||
fun getNodeComparator(ascending: Boolean, groupsBefore: Boolean, recycleBinBottom: Boolean): Comparator<Node> {
|
||||
return when (this) {
|
||||
DB -> NodeNaturalComparator(ascending, groupsBefore, false) // Force false because natural order contains recycle bin
|
||||
TITLE -> NodeTitleComparator(ascending, groupsBefore, recycleBinBottom)
|
||||
@@ -40,11 +38,11 @@ enum class SortNodeEnum {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class NodeComparator(var ascending: Boolean, var groupsBefore: Boolean, var recycleBinBottom: Boolean) : Comparator<NodeVersioned> {
|
||||
abstract class NodeComparator(var ascending: Boolean, var groupsBefore: Boolean, var recycleBinBottom: Boolean) : Comparator<Node> {
|
||||
|
||||
abstract fun compareBySpecificOrder(object1: NodeVersioned, object2: NodeVersioned): Int
|
||||
abstract fun compareBySpecificOrder(object1: Node, object2: Node): Int
|
||||
|
||||
private fun specificOrderOrHashIfEquals(object1: NodeVersioned, object2: NodeVersioned): Int {
|
||||
private fun specificOrderOrHashIfEquals(object1: Node, object2: Node): Int {
|
||||
val specificOrderComp = compareBySpecificOrder(object1, object2)
|
||||
|
||||
return if (specificOrderComp == 0) {
|
||||
@@ -52,20 +50,20 @@ enum class SortNodeEnum {
|
||||
} else if (!ascending) -specificOrderComp else specificOrderComp // If descending, revert
|
||||
}
|
||||
|
||||
override fun compare(object1: NodeVersioned,object2: NodeVersioned): Int {
|
||||
override fun compare(object1: Node, object2: Node): Int {
|
||||
if (object1 == object2)
|
||||
return 0
|
||||
|
||||
if (object1.type == Type.GROUP) {
|
||||
return if (object2.type == Type.GROUP) {
|
||||
// RecycleBin at end of groups
|
||||
if (recycleBinBottom) {
|
||||
if (Database.getInstance().recycleBin == object1)
|
||||
val database = Database.getInstance()
|
||||
if (database.isRecycleBinEnabled && recycleBinBottom) {
|
||||
if (database.recycleBin == object1)
|
||||
return 1
|
||||
if (Database.getInstance().recycleBin == object2)
|
||||
if (database.recycleBin == object2)
|
||||
return -1
|
||||
}
|
||||
|
||||
specificOrderOrHashIfEquals(object1, object2)
|
||||
} else if (object2.type == Type.ENTRY) {
|
||||
if (groupsBefore)
|
||||
@@ -99,7 +97,7 @@ enum class SortNodeEnum {
|
||||
class NodeNaturalComparator(ascending: Boolean, groupsBefore: Boolean, recycleBinBottom: Boolean)
|
||||
: NodeComparator(ascending, groupsBefore, recycleBinBottom) {
|
||||
|
||||
override fun compareBySpecificOrder(object1: NodeVersioned, object2: NodeVersioned): Int {
|
||||
override fun compareBySpecificOrder(object1: Node, object2: Node): Int {
|
||||
return object1.nodePositionInParent.compareTo(object2.nodePositionInParent)
|
||||
}
|
||||
}
|
||||
@@ -110,7 +108,7 @@ enum class SortNodeEnum {
|
||||
class NodeTitleComparator(ascending: Boolean, groupsBefore: Boolean, recycleBinBottom: Boolean)
|
||||
: NodeComparator(ascending, groupsBefore, recycleBinBottom) {
|
||||
|
||||
override fun compareBySpecificOrder(object1: NodeVersioned, object2: NodeVersioned): Int {
|
||||
override fun compareBySpecificOrder(object1: Node, object2: Node): Int {
|
||||
return object1.title.compareTo(object2.title, ignoreCase = true)
|
||||
}
|
||||
}
|
||||
@@ -121,11 +119,11 @@ enum class SortNodeEnum {
|
||||
class NodeUsernameComparator(ascending: Boolean, groupsBefore: Boolean, recycleBinBottom: Boolean)
|
||||
: NodeComparator(ascending, groupsBefore, recycleBinBottom) {
|
||||
|
||||
override fun compareBySpecificOrder(object1: NodeVersioned, object2: NodeVersioned): Int {
|
||||
override fun compareBySpecificOrder(object1: Node, object2: Node): Int {
|
||||
if (object1.type == Type.ENTRY && object2.type == Type.ENTRY) {
|
||||
// To get username if it's a ref
|
||||
return (object1 as EntryVersioned).getEntryInfo(Database.getInstance()).username
|
||||
.compareTo((object2 as EntryVersioned).getEntryInfo(Database.getInstance()).username,
|
||||
return (object1 as Entry).getEntryInfo(Database.getInstance()).username
|
||||
.compareTo((object2 as Entry).getEntryInfo(Database.getInstance()).username,
|
||||
ignoreCase = true)
|
||||
}
|
||||
return NodeTitleComparator(ascending, groupsBefore, recycleBinBottom).compare(object1, object2)
|
||||
@@ -138,7 +136,7 @@ enum class SortNodeEnum {
|
||||
class NodeCreationComparator(ascending: Boolean, groupsBefore: Boolean, recycleBinBottom: Boolean)
|
||||
: NodeComparator(ascending, groupsBefore, recycleBinBottom) {
|
||||
|
||||
override fun compareBySpecificOrder(object1: NodeVersioned, object2: NodeVersioned): Int {
|
||||
override fun compareBySpecificOrder(object1: Node, object2: Node): Int {
|
||||
return object1.creationTime.date
|
||||
.compareTo(object2.creationTime.date)
|
||||
}
|
||||
@@ -150,7 +148,7 @@ enum class SortNodeEnum {
|
||||
class NodeLastModificationComparator(ascending: Boolean, groupsBefore: Boolean, recycleBinBottom: Boolean)
|
||||
: NodeComparator(ascending, groupsBefore, recycleBinBottom) {
|
||||
|
||||
override fun compareBySpecificOrder(object1: NodeVersioned, object2: NodeVersioned): Int {
|
||||
override fun compareBySpecificOrder(object1: Node, object2: Node): Int {
|
||||
return object1.lastModificationTime.date
|
||||
.compareTo(object2.lastModificationTime.date)
|
||||
}
|
||||
@@ -162,7 +160,7 @@ enum class SortNodeEnum {
|
||||
class NodeLastAccessComparator(ascending: Boolean, groupsBefore: Boolean, recycleBinBottom: Boolean)
|
||||
: NodeComparator(ascending, groupsBefore, recycleBinBottom) {
|
||||
|
||||
override fun compareBySpecificOrder(object1: NodeVersioned, object2: NodeVersioned): Int {
|
||||
override fun compareBySpecificOrder(object1: Node, object2: Node): Int {
|
||||
return object1.lastAccessTime.date
|
||||
.compareTo(object2.lastAccessTime.date)
|
||||
}
|
||||
@@ -17,28 +17,30 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.database
|
||||
|
||||
import android.util.SparseArray
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedBinary
|
||||
import com.kunzisoft.keepass.database.element.security.BinaryAttachment
|
||||
import java.io.IOException
|
||||
|
||||
class BinaryPool {
|
||||
private val pool = SparseArray<ProtectedBinary>()
|
||||
private val pool = SparseArray<BinaryAttachment>()
|
||||
|
||||
operator fun get(key: Int): ProtectedBinary? {
|
||||
operator fun get(key: Int): BinaryAttachment? {
|
||||
return pool[key]
|
||||
}
|
||||
|
||||
fun put(key: Int, value: ProtectedBinary) {
|
||||
fun put(key: Int, value: BinaryAttachment) {
|
||||
pool.put(key, value)
|
||||
}
|
||||
|
||||
fun doForEachBinary(action: (key: Int, binary: ProtectedBinary) -> Unit) {
|
||||
fun doForEachBinary(action: (key: Int, binary: BinaryAttachment) -> Unit) {
|
||||
for (i in 0 until pool.size()) {
|
||||
action.invoke(i, pool.get(pool.keyAt(i)))
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun clear() {
|
||||
doForEachBinary { _, binary ->
|
||||
binary.clear()
|
||||
@@ -46,9 +48,10 @@ class BinaryPool {
|
||||
pool.clear()
|
||||
}
|
||||
|
||||
fun add(protectedBinary: ProtectedBinary) {
|
||||
if (findKey(protectedBinary) != -1) return
|
||||
pool.put(findUnusedKey(), protectedBinary)
|
||||
fun add(fileBinary: BinaryAttachment) {
|
||||
if (findKey(fileBinary) == null) {
|
||||
pool.put(findUnusedKey(), fileBinary)
|
||||
}
|
||||
}
|
||||
|
||||
fun findUnusedKey(): Int {
|
||||
@@ -58,10 +61,10 @@ class BinaryPool {
|
||||
return unusedKey
|
||||
}
|
||||
|
||||
fun findKey(pb: ProtectedBinary): Int {
|
||||
fun findKey(pb: BinaryAttachment): Int? {
|
||||
for (i in 0 until pool.size()) {
|
||||
if (pool.get(pool.keyAt(i)) == pb) return i
|
||||
}
|
||||
return -1
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -17,20 +17,33 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.database
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.utils.ObjectNameResource
|
||||
import com.kunzisoft.keepass.utils.readEnum
|
||||
import com.kunzisoft.keepass.utils.writeEnum
|
||||
|
||||
|
||||
// Note: We can get away with using int's to store unsigned 32-bit ints
|
||||
// since we won't do arithmetic on these values (also unlikely to
|
||||
// reach negative ids).
|
||||
enum class PwCompressionAlgorithm : ObjectNameResource {
|
||||
enum class CompressionAlgorithm : ObjectNameResource, Parcelable {
|
||||
|
||||
None,
|
||||
GZip;
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||
dest.writeEnum(this)
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getName(resources: Resources): String {
|
||||
return when (this) {
|
||||
None -> resources.getString(R.string.compression_none)
|
||||
@@ -38,4 +51,14 @@ enum class PwCompressionAlgorithm : ObjectNameResource {
|
||||
}
|
||||
}
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<CompressionAlgorithm> {
|
||||
override fun createFromParcel(parcel: Parcel): CompressionAlgorithm {
|
||||
return parcel.readEnum<CompressionAlgorithm>() ?: None
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<CompressionAlgorithm?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,11 +17,17 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.database
|
||||
|
||||
import com.kunzisoft.keepass.crypto.finalkey.FinalKeyFactory
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryKDB
|
||||
import com.kunzisoft.keepass.database.element.group.GroupKDB
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdInt
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
||||
import com.kunzisoft.keepass.database.element.node.NodeVersioned
|
||||
import com.kunzisoft.keepass.stream.NullOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
@@ -31,10 +37,12 @@ import java.security.NoSuchAlgorithmException
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class PwDatabaseV3 : PwDatabase<Int, UUID, PwGroupV3, PwEntryV3>() {
|
||||
class DatabaseKDB : DatabaseVersioned<Int, UUID, GroupKDB, EntryKDB>() {
|
||||
|
||||
private var numKeyEncRounds: Int = 0
|
||||
|
||||
var backupGroupId: Int = BACKUP_FOLDER_UNDEFINED_ID
|
||||
|
||||
private var kdfListV3: MutableList<KdfEngine> = ArrayList()
|
||||
|
||||
override val version: String
|
||||
@@ -44,22 +52,32 @@ class PwDatabaseV3 : PwDatabase<Int, UUID, PwGroupV3, PwEntryV3>() {
|
||||
kdfListV3.add(KdfFactory.aesKdf)
|
||||
}
|
||||
|
||||
private fun getGroupById(groupId: Int): GroupKDB? {
|
||||
if (groupId == -1)
|
||||
return null
|
||||
return getGroupById(NodeIdInt(groupId))
|
||||
}
|
||||
|
||||
// Retrieve backup group in index
|
||||
val backupGroup: GroupKDB?
|
||||
get() = if (backupGroupId == BACKUP_FOLDER_UNDEFINED_ID) null else getGroupById(backupGroupId)
|
||||
|
||||
override val kdfEngine: KdfEngine?
|
||||
get() = kdfListV3[0]
|
||||
|
||||
override val kdfAvailableList: List<KdfEngine>
|
||||
get() = kdfListV3
|
||||
|
||||
override val availableEncryptionAlgorithms: List<PwEncryptionAlgorithm>
|
||||
override val availableEncryptionAlgorithms: List<EncryptionAlgorithm>
|
||||
get() {
|
||||
val list = ArrayList<PwEncryptionAlgorithm>()
|
||||
list.add(PwEncryptionAlgorithm.AESRijndael)
|
||||
val list = ArrayList<EncryptionAlgorithm>()
|
||||
list.add(EncryptionAlgorithm.AESRijndael)
|
||||
return list
|
||||
}
|
||||
|
||||
val rootGroups: List<PwGroupV3>
|
||||
val rootGroups: List<GroupKDB>
|
||||
get() {
|
||||
val kids = ArrayList<PwGroupV3>()
|
||||
val kids = ArrayList<GroupKDB>()
|
||||
doForEachGroupInIndex { group ->
|
||||
if (group.level == 0)
|
||||
kids.add(group)
|
||||
@@ -81,7 +99,7 @@ class PwDatabaseV3 : PwDatabase<Int, UUID, PwGroupV3, PwEntryV3>() {
|
||||
}
|
||||
|
||||
init {
|
||||
algorithm = PwEncryptionAlgorithm.AESRijndael
|
||||
algorithm = EncryptionAlgorithm.AESRijndael
|
||||
numKeyEncRounds = DEFAULT_ENCRYPTION_ROUNDS
|
||||
}
|
||||
|
||||
@@ -90,10 +108,10 @@ class PwDatabaseV3 : PwDatabase<Int, UUID, PwGroupV3, PwEntryV3>() {
|
||||
*
|
||||
* @return new tree id
|
||||
*/
|
||||
override fun newGroupId(): PwNodeIdInt {
|
||||
var newId: PwNodeIdInt
|
||||
override fun newGroupId(): NodeIdInt {
|
||||
var newId: NodeIdInt
|
||||
do {
|
||||
newId = PwNodeIdInt()
|
||||
newId = NodeIdInt()
|
||||
} while (isGroupIdUsed(newId))
|
||||
|
||||
return newId
|
||||
@@ -104,10 +122,10 @@ class PwDatabaseV3 : PwDatabase<Int, UUID, PwGroupV3, PwEntryV3>() {
|
||||
*
|
||||
* @return new tree id
|
||||
*/
|
||||
override fun newEntryId(): PwNodeIdUUID {
|
||||
var newId: PwNodeIdUUID
|
||||
override fun newEntryId(): NodeIdUUID {
|
||||
var newId: NodeIdUUID
|
||||
do {
|
||||
newId = PwNodeIdUUID()
|
||||
newId = NodeIdUUID()
|
||||
} while (isEntryIdUsed(newId))
|
||||
|
||||
return newId
|
||||
@@ -152,12 +170,12 @@ class PwDatabaseV3 : PwDatabase<Int, UUID, PwGroupV3, PwEntryV3>() {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun createGroup(): PwGroupV3 {
|
||||
return PwGroupV3()
|
||||
override fun createGroup(): GroupKDB {
|
||||
return GroupKDB()
|
||||
}
|
||||
|
||||
override fun createEntry(): PwEntryV3 {
|
||||
return PwEntryV3()
|
||||
override fun createEntry(): EntryKDB {
|
||||
return EntryKDB()
|
||||
}
|
||||
|
||||
override fun rootCanContainsEntry(): Boolean {
|
||||
@@ -168,10 +186,16 @@ class PwDatabaseV3 : PwDatabase<Int, UUID, PwGroupV3, PwEntryV3>() {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun isBackup(group: PwGroupV3): Boolean {
|
||||
var currentGroup: PwGroupV3? = group
|
||||
override fun isInRecycleBin(group: GroupKDB): Boolean {
|
||||
var currentGroup: GroupKDB? = group
|
||||
|
||||
if (currentGroup == backupGroup)
|
||||
return true
|
||||
|
||||
while (currentGroup != null) {
|
||||
if (currentGroup.level == 0 && currentGroup.title.equals("Backup", ignoreCase = true)) {
|
||||
if (currentGroup.level == 0
|
||||
&& currentGroup.title.equals(BACKUP_FOLDER_TITLE, ignoreCase = true)) {
|
||||
backupGroupId = currentGroup.id
|
||||
return true
|
||||
}
|
||||
currentGroup = currentGroup.parent
|
||||
@@ -179,8 +203,68 @@ class PwDatabaseV3 : PwDatabase<Int, UUID, PwGroupV3, PwEntryV3>() {
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the recycle bin tree exists, if enabled and create it
|
||||
* if it doesn't exist
|
||||
*/
|
||||
fun ensureRecycleBinExists() {
|
||||
rootGroups.forEach { currentGroup ->
|
||||
if (currentGroup.level == 0
|
||||
&& currentGroup.title.equals(BACKUP_FOLDER_TITLE, ignoreCase = true)) {
|
||||
backupGroupId = currentGroup.id
|
||||
}
|
||||
}
|
||||
|
||||
if (backupGroup == null) {
|
||||
// Create recycle bin
|
||||
val recycleBinGroup = createGroup().apply {
|
||||
title = BACKUP_FOLDER_TITLE
|
||||
icon = iconFactory.trashIcon
|
||||
}
|
||||
addGroupTo(recycleBinGroup, rootGroup)
|
||||
backupGroupId = recycleBinGroup.id
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Define if a Node must be delete or recycle when remove action is called
|
||||
* @param node Node to remove
|
||||
* @return true if node can be recycle, false elsewhere
|
||||
*/
|
||||
fun canRecycle(node: NodeVersioned<*, GroupKDB, EntryKDB>): Boolean {
|
||||
// TODO #394 Backup pw3
|
||||
return true
|
||||
}
|
||||
|
||||
fun recycle(group: GroupKDB) {
|
||||
ensureRecycleBinExists()
|
||||
removeGroupFrom(group, group.parent)
|
||||
addGroupTo(group, backupGroup)
|
||||
group.afterAssignNewParent()
|
||||
}
|
||||
|
||||
fun recycle(entry: EntryKDB) {
|
||||
ensureRecycleBinExists()
|
||||
removeEntryFrom(entry, entry.parent)
|
||||
addEntryTo(entry, backupGroup)
|
||||
entry.afterAssignNewParent()
|
||||
}
|
||||
|
||||
fun undoRecycle(group: GroupKDB, origParent: GroupKDB) {
|
||||
removeGroupFrom(group, backupGroup)
|
||||
addGroupTo(group, origParent)
|
||||
}
|
||||
|
||||
fun undoRecycle(entry: EntryKDB, origParent: GroupKDB) {
|
||||
removeEntryFrom(entry, backupGroup)
|
||||
addEntryTo(entry, origParent)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val BACKUP_FOLDER_TITLE = "Backup"
|
||||
private const val BACKUP_FOLDER_UNDEFINED_ID = -1
|
||||
|
||||
private const val DEFAULT_ENCRYPTION_ROUNDS = 300
|
||||
|
||||
/**
|
||||
@@ -17,17 +17,30 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.database
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.util.Base64
|
||||
import android.util.Log
|
||||
import biz.source_code.base64Coder.Base64Coder
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.crypto.CryptoUtil
|
||||
import com.kunzisoft.keepass.crypto.engine.AesEngine
|
||||
import com.kunzisoft.keepass.crypto.engine.CipherEngine
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.*
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfParameters
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseKDB.Companion.BACKUP_FOLDER_TITLE
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryKDBX
|
||||
import com.kunzisoft.keepass.database.element.group.GroupKDBX
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageCustom
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
||||
import com.kunzisoft.keepass.database.element.node.NodeVersioned
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.security.MemoryProtectionConfig
|
||||
import com.kunzisoft.keepass.database.exception.UnknownKDF
|
||||
import com.kunzisoft.keepass.database.file.DatabaseHeaderKDBX.Companion.FILE_VERSION_32_3
|
||||
import com.kunzisoft.keepass.database.file.DatabaseHeaderKDBX.Companion.FILE_VERSION_32_4
|
||||
import com.kunzisoft.keepass.utils.VariantDictionary
|
||||
import org.w3c.dom.Node
|
||||
import org.w3c.dom.Text
|
||||
@@ -41,29 +54,30 @@ import javax.xml.parsers.DocumentBuilderFactory
|
||||
import javax.xml.parsers.ParserConfigurationException
|
||||
|
||||
|
||||
class PwDatabaseV4 : PwDatabase<UUID, UUID, PwGroupV4, PwEntryV4> {
|
||||
class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
|
||||
|
||||
var hmacKey: ByteArray? = null
|
||||
private set
|
||||
var dataCipher = AesEngine.CIPHER_UUID
|
||||
private var dataEngine: CipherEngine = AesEngine()
|
||||
var compressionAlgorithm = PwCompressionAlgorithm.GZip
|
||||
var compressionAlgorithm = CompressionAlgorithm.GZip
|
||||
var kdfParameters: KdfParameters? = null
|
||||
private var kdfV4List: MutableList<KdfEngine> = ArrayList()
|
||||
private var kdfList: MutableList<KdfEngine> = ArrayList()
|
||||
private var numKeyEncRounds: Long = 0
|
||||
var publicCustomData = VariantDictionary()
|
||||
|
||||
var name = "KeePass DX database"
|
||||
var nameChanged = PwDate()
|
||||
var kdbxVersion: Long = 0
|
||||
var name = ""
|
||||
var nameChanged = DateInstant()
|
||||
// TODO change setting date
|
||||
var settingsChanged = PwDate()
|
||||
var settingsChanged = DateInstant()
|
||||
var description = ""
|
||||
var descriptionChanged = PwDate()
|
||||
var descriptionChanged = DateInstant()
|
||||
var defaultUserName = ""
|
||||
var defaultUserNameChanged = PwDate()
|
||||
var defaultUserNameChanged = DateInstant()
|
||||
|
||||
// TODO date
|
||||
var keyLastChanged = PwDate()
|
||||
var keyLastChanged = DateInstant()
|
||||
var keyChangeRecDays: Long = -1
|
||||
var keyChangeForceDays: Long = 1
|
||||
var isKeyChangeForceOnce = false
|
||||
@@ -78,57 +92,68 @@ class PwDatabaseV4 : PwDatabase<UUID, UUID, PwGroupV4, PwEntryV4> {
|
||||
var recycleBinUUID: UUID = UUID_ZERO
|
||||
var recycleBinChanged = Date()
|
||||
var entryTemplatesGroup = UUID_ZERO
|
||||
var entryTemplatesGroupChanged = PwDate()
|
||||
var entryTemplatesGroupChanged = DateInstant()
|
||||
var historyMaxItems = DEFAULT_HISTORY_MAX_ITEMS
|
||||
var historyMaxSize = DEFAULT_HISTORY_MAX_SIZE
|
||||
var lastSelectedGroupUUID = UUID_ZERO
|
||||
var lastTopVisibleGroupUUID = UUID_ZERO
|
||||
var memoryProtection = MemoryProtectionConfig()
|
||||
val deletedObjects = ArrayList<PwDeletedObject>()
|
||||
val customIcons = ArrayList<PwIconCustom>()
|
||||
val deletedObjects = ArrayList<DeletedObject>()
|
||||
val customIcons = ArrayList<IconImageCustom>()
|
||||
val customData = HashMap<String, String>()
|
||||
|
||||
var binPool = BinaryPool()
|
||||
var binaryPool = BinaryPool()
|
||||
|
||||
var localizedAppName = "KeePassDX" // TODO resource
|
||||
var localizedAppName = "KeePassDX"
|
||||
|
||||
init {
|
||||
kdfV4List.add(KdfFactory.aesKdf)
|
||||
kdfV4List.add(KdfFactory.argon2Kdf)
|
||||
kdfList.add(KdfFactory.aesKdf)
|
||||
kdfList.add(KdfFactory.argon2Kdf)
|
||||
}
|
||||
|
||||
constructor()
|
||||
|
||||
constructor(databaseName: String) {
|
||||
val groupV4 = createGroup().apply {
|
||||
title = databaseName
|
||||
/**
|
||||
* Create a new database with a root group
|
||||
*/
|
||||
constructor(databaseName: String, rootName: String) {
|
||||
name = databaseName
|
||||
val group = createGroup().apply {
|
||||
title = rootName
|
||||
icon = iconFactory.folderIcon
|
||||
}
|
||||
rootGroup = groupV4
|
||||
addGroupIndex(groupV4)
|
||||
rootGroup = group
|
||||
addGroupIndex(group)
|
||||
}
|
||||
|
||||
override val version: String
|
||||
get() = "KeePass 2"
|
||||
get() {
|
||||
val kdbxStringVersion = when(kdbxVersion) {
|
||||
FILE_VERSION_32_3 -> "3.1"
|
||||
FILE_VERSION_32_4 -> "4.0"
|
||||
else -> "UNKNOWN"
|
||||
}
|
||||
return "KeePass 2 - KDBX$kdbxStringVersion"
|
||||
}
|
||||
|
||||
override val kdfEngine: KdfEngine?
|
||||
get() = try {
|
||||
getEngineV4(kdfParameters)
|
||||
getEngineKDBX4(kdfParameters)
|
||||
} catch (unknownKDF: UnknownKDF) {
|
||||
Log.i(TAG, "Unable to retrieve KDF engine", unknownKDF)
|
||||
null
|
||||
}
|
||||
|
||||
override val kdfAvailableList: List<KdfEngine>
|
||||
get() = kdfV4List
|
||||
get() = kdfList
|
||||
|
||||
@Throws(UnknownKDF::class)
|
||||
fun getEngineV4(kdfParameters: KdfParameters?): KdfEngine {
|
||||
fun getEngineKDBX4(kdfParameters: KdfParameters?): KdfEngine {
|
||||
val unknownKDFException = UnknownKDF()
|
||||
if (kdfParameters == null) {
|
||||
throw unknownKDFException
|
||||
}
|
||||
for (engine in kdfV4List) {
|
||||
for (engine in kdfList) {
|
||||
if (engine.uuid == kdfParameters.uuid) {
|
||||
return engine
|
||||
}
|
||||
@@ -136,20 +161,53 @@ class PwDatabaseV4 : PwDatabase<UUID, UUID, PwGroupV4, PwEntryV4> {
|
||||
throw unknownKDFException
|
||||
}
|
||||
|
||||
val availableCompressionAlgorithms: List<PwCompressionAlgorithm>
|
||||
val availableCompressionAlgorithms: List<CompressionAlgorithm>
|
||||
get() {
|
||||
val list = ArrayList<PwCompressionAlgorithm>()
|
||||
list.add(PwCompressionAlgorithm.None)
|
||||
list.add(PwCompressionAlgorithm.GZip)
|
||||
val list = ArrayList<CompressionAlgorithm>()
|
||||
list.add(CompressionAlgorithm.None)
|
||||
list.add(CompressionAlgorithm.GZip)
|
||||
return list
|
||||
}
|
||||
|
||||
override val availableEncryptionAlgorithms: List<PwEncryptionAlgorithm>
|
||||
fun changeBinaryCompression(oldCompression: CompressionAlgorithm,
|
||||
newCompression: CompressionAlgorithm) {
|
||||
binaryPool.doForEachBinary { key, binary ->
|
||||
|
||||
try {
|
||||
when (oldCompression) {
|
||||
CompressionAlgorithm.None -> {
|
||||
when (newCompression) {
|
||||
CompressionAlgorithm.None -> {
|
||||
}
|
||||
CompressionAlgorithm.GZip -> {
|
||||
// To compress, create a new binary with file
|
||||
binary.compress()
|
||||
}
|
||||
}
|
||||
}
|
||||
CompressionAlgorithm.GZip -> {
|
||||
when (newCompression) {
|
||||
CompressionAlgorithm.None -> {
|
||||
// To decompress, create a new binary with file
|
||||
binary.decompress()
|
||||
}
|
||||
CompressionAlgorithm.GZip -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Unable to change compression for $key")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override val availableEncryptionAlgorithms: List<EncryptionAlgorithm>
|
||||
get() {
|
||||
val list = ArrayList<PwEncryptionAlgorithm>()
|
||||
list.add(PwEncryptionAlgorithm.AESRijndael)
|
||||
list.add(PwEncryptionAlgorithm.Twofish)
|
||||
list.add(PwEncryptionAlgorithm.ChaCha20)
|
||||
val list = ArrayList<EncryptionAlgorithm>()
|
||||
list.add(EncryptionAlgorithm.AESRijndael)
|
||||
list.add(EncryptionAlgorithm.Twofish)
|
||||
list.add(EncryptionAlgorithm.ChaCha20)
|
||||
return list
|
||||
}
|
||||
|
||||
@@ -197,31 +255,31 @@ class PwDatabaseV4 : PwDatabase<UUID, UUID, PwGroupV4, PwEntryV4> {
|
||||
override val passwordEncoding: String
|
||||
get() = "UTF-8"
|
||||
|
||||
fun getGroupByUUID(groupUUID: UUID): PwGroupV4? {
|
||||
private fun getGroupByUUID(groupUUID: UUID): GroupKDBX? {
|
||||
if (groupUUID == UUID_ZERO)
|
||||
return null
|
||||
return getGroupById(PwNodeIdUUID(groupUUID))
|
||||
return getGroupById(NodeIdUUID(groupUUID))
|
||||
}
|
||||
|
||||
// Retrieve recycle bin in index
|
||||
val recycleBin: PwGroupV4?
|
||||
get() = getGroupByUUID(recycleBinUUID)
|
||||
val recycleBin: GroupKDBX?
|
||||
get() = if (recycleBinUUID == UUID_ZERO) null else getGroupByUUID(recycleBinUUID)
|
||||
|
||||
val lastSelectedGroup: PwGroupV4?
|
||||
val lastSelectedGroup: GroupKDBX?
|
||||
get() = getGroupByUUID(lastSelectedGroupUUID)
|
||||
|
||||
val lastTopVisibleGroup: PwGroupV4?
|
||||
val lastTopVisibleGroup: GroupKDBX?
|
||||
get() = getGroupByUUID(lastTopVisibleGroupUUID)
|
||||
|
||||
fun setDataEngine(dataEngine: CipherEngine) {
|
||||
this.dataEngine = dataEngine
|
||||
}
|
||||
|
||||
fun getCustomIcons(): List<PwIconCustom> {
|
||||
fun getCustomIcons(): List<IconImageCustom> {
|
||||
return customIcons
|
||||
}
|
||||
|
||||
fun addCustomIcon(customIcon: PwIconCustom) {
|
||||
fun addCustomIcon(customIcon: IconImageCustom) {
|
||||
this.customIcons.add(customIcon)
|
||||
}
|
||||
|
||||
@@ -264,7 +322,7 @@ class PwDatabaseV4 : PwDatabase<UUID, UUID, PwGroupV4, PwEntryV4> {
|
||||
fun makeFinalKey(masterSeed: ByteArray) {
|
||||
|
||||
kdfParameters?.let { keyDerivationFunctionParameters ->
|
||||
val kdfEngine = getEngineV4(keyDerivationFunctionParameters)
|
||||
val kdfEngine = getEngineKDBX4(keyDerivationFunctionParameters)
|
||||
|
||||
var transformedMasterKey = kdfEngine.transform(masterKey, keyDerivationFunctionParameters)
|
||||
if (transformedMasterKey.size != 32) {
|
||||
@@ -326,7 +384,7 @@ class PwDatabaseV4 : PwDatabase<UUID, UUID, PwGroupV4, PwEntryV4> {
|
||||
val text = children2.item(k)
|
||||
if (text.nodeType == Node.TEXT_NODE) {
|
||||
val txt = text as Text
|
||||
return Base64Coder.decode(txt.nodeValue)
|
||||
return Base64.decode(txt.nodeValue, BASE_64_FLAG)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -340,42 +398,42 @@ class PwDatabaseV4 : PwDatabase<UUID, UUID, PwGroupV4, PwEntryV4> {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun newGroupId(): PwNodeIdUUID {
|
||||
var newId: PwNodeIdUUID
|
||||
override fun newGroupId(): NodeIdUUID {
|
||||
var newId: NodeIdUUID
|
||||
do {
|
||||
newId = PwNodeIdUUID()
|
||||
newId = NodeIdUUID()
|
||||
} while (isGroupIdUsed(newId))
|
||||
|
||||
return newId
|
||||
}
|
||||
|
||||
override fun newEntryId(): PwNodeIdUUID {
|
||||
var newId: PwNodeIdUUID
|
||||
override fun newEntryId(): NodeIdUUID {
|
||||
var newId: NodeIdUUID
|
||||
do {
|
||||
newId = PwNodeIdUUID()
|
||||
newId = NodeIdUUID()
|
||||
} while (isEntryIdUsed(newId))
|
||||
|
||||
return newId
|
||||
}
|
||||
|
||||
override fun createGroup(): PwGroupV4 {
|
||||
return PwGroupV4()
|
||||
override fun createGroup(): GroupKDBX {
|
||||
return GroupKDBX()
|
||||
}
|
||||
|
||||
override fun createEntry(): PwEntryV4 {
|
||||
return PwEntryV4()
|
||||
override fun createEntry(): EntryKDBX {
|
||||
return EntryKDBX()
|
||||
}
|
||||
|
||||
override fun rootCanContainsEntry(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun isBackup(group: PwGroupV4): Boolean {
|
||||
override fun isInRecycleBin(group: GroupKDBX): Boolean {
|
||||
// To keep compatibility with old V1 databases
|
||||
var currentGroup: PwGroupV4? = group
|
||||
var currentGroup: GroupKDBX? = group
|
||||
while (currentGroup != null) {
|
||||
if (currentGroup.parent == rootGroup
|
||||
&& currentGroup.title.equals("Backup", ignoreCase = true)) {
|
||||
&& currentGroup.title.equals(BACKUP_FOLDER_TITLE, ignoreCase = true)) {
|
||||
return true
|
||||
}
|
||||
currentGroup = currentGroup.parent
|
||||
@@ -393,7 +451,7 @@ class PwDatabaseV4 : PwDatabase<UUID, UUID, PwGroupV4, PwEntryV4> {
|
||||
* Ensure that the recycle bin tree exists, if enabled and create it
|
||||
* if it doesn't exist
|
||||
*/
|
||||
private fun ensureRecycleBin(resources: Resources) {
|
||||
fun ensureRecycleBinExists(resources: Resources) {
|
||||
if (recycleBin == null) {
|
||||
// Create recycle bin
|
||||
val recycleBinGroup = createGroup().apply {
|
||||
@@ -409,61 +467,68 @@ class PwDatabaseV4 : PwDatabase<UUID, UUID, PwGroupV4, PwEntryV4> {
|
||||
}
|
||||
}
|
||||
|
||||
fun removeRecycleBin() {
|
||||
if (recycleBin != null) {
|
||||
recycleBinUUID = UUID_ZERO
|
||||
recycleBinChanged = DateInstant().date
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Define if a Node must be delete or recycle when remove action is called
|
||||
* @param node Node to remove
|
||||
* @return true if node can be recycle, false elsewhere
|
||||
*/
|
||||
fun canRecycle(node: PwNode<*, PwGroupV4, PwEntryV4>): Boolean {
|
||||
fun canRecycle(node: NodeVersioned<*, GroupKDBX, EntryKDBX>): Boolean {
|
||||
if (!isRecycleBinEnabled)
|
||||
return false
|
||||
if (recycleBin == null)
|
||||
return true
|
||||
return false
|
||||
if (!node.isContainedIn(recycleBin!!))
|
||||
return true
|
||||
return false
|
||||
}
|
||||
|
||||
fun recycle(group: PwGroupV4, resources: Resources) {
|
||||
ensureRecycleBin(resources)
|
||||
fun recycle(group: GroupKDBX, resources: Resources) {
|
||||
ensureRecycleBinExists(resources)
|
||||
removeGroupFrom(group, group.parent)
|
||||
addGroupTo(group, recycleBin)
|
||||
group.afterAssignNewParent()
|
||||
}
|
||||
|
||||
fun recycle(entry: PwEntryV4, resources: Resources) {
|
||||
ensureRecycleBin(resources)
|
||||
fun recycle(entry: EntryKDBX, resources: Resources) {
|
||||
ensureRecycleBinExists(resources)
|
||||
removeEntryFrom(entry, entry.parent)
|
||||
addEntryTo(entry, recycleBin)
|
||||
entry.afterAssignNewParent()
|
||||
}
|
||||
|
||||
fun undoRecycle(group: PwGroupV4, origParent: PwGroupV4) {
|
||||
fun undoRecycle(group: GroupKDBX, origParent: GroupKDBX) {
|
||||
removeGroupFrom(group, recycleBin)
|
||||
addGroupTo(group, origParent)
|
||||
}
|
||||
|
||||
fun undoRecycle(entry: PwEntryV4, origParent: PwGroupV4) {
|
||||
fun undoRecycle(entry: EntryKDBX, origParent: GroupKDBX) {
|
||||
removeEntryFrom(entry, recycleBin)
|
||||
addEntryTo(entry, origParent)
|
||||
}
|
||||
|
||||
fun getDeletedObjects(): List<PwDeletedObject> {
|
||||
fun getDeletedObjects(): List<DeletedObject> {
|
||||
return deletedObjects
|
||||
}
|
||||
|
||||
fun addDeletedObject(deletedObject: PwDeletedObject) {
|
||||
fun addDeletedObject(deletedObject: DeletedObject) {
|
||||
this.deletedObjects.add(deletedObject)
|
||||
}
|
||||
|
||||
override fun removeEntryFrom(entryToRemove: PwEntryV4, parent: PwGroupV4?) {
|
||||
override fun removeEntryFrom(entryToRemove: EntryKDBX, parent: GroupKDBX?) {
|
||||
super.removeEntryFrom(entryToRemove, parent)
|
||||
deletedObjects.add(PwDeletedObject(entryToRemove.id))
|
||||
deletedObjects.add(DeletedObject(entryToRemove.id))
|
||||
}
|
||||
|
||||
override fun undoDeleteEntryFrom(entry: PwEntryV4, origParent: PwGroupV4?) {
|
||||
override fun undoDeleteEntryFrom(entry: EntryKDBX, origParent: GroupKDBX?) {
|
||||
super.undoDeleteEntryFrom(entry, origParent)
|
||||
deletedObjects.remove(PwDeletedObject(entry.id))
|
||||
deletedObjects.remove(DeletedObject(entry.id))
|
||||
}
|
||||
|
||||
fun containsPublicCustomData(): Boolean {
|
||||
@@ -477,12 +542,16 @@ class PwDatabaseV4 : PwDatabase<UUID, UUID, PwGroupV4, PwEntryV4> {
|
||||
}
|
||||
|
||||
override fun clearCache() {
|
||||
super.clearCache()
|
||||
binPool.clear()
|
||||
try {
|
||||
super.clearCache()
|
||||
binaryPool.clear()
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Unable to clear cache", e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = PwDatabaseV4::class.java.name
|
||||
private val TAG = DatabaseKDBX::class.java.name
|
||||
|
||||
private const val DEFAULT_HISTORY_MAX_ITEMS = 10 // -1 unlimited
|
||||
private const val DEFAULT_HISTORY_MAX_SIZE = (6 * 1024 * 1024).toLong() // -1 unlimited
|
||||
@@ -492,5 +561,9 @@ class PwDatabaseV4 : PwDatabase<UUID, UUID, PwGroupV4, PwEntryV4> {
|
||||
//private const val VersionElementName = "Version";
|
||||
private const val KeyElementName = "Key"
|
||||
private const val KeyDataElementName = "Data"
|
||||
|
||||
const val BASE_64_FLAG = Base64.DEFAULT
|
||||
|
||||
const val BUFFER_SIZE_BYTES = 3 * 128
|
||||
}
|
||||
}
|
||||
@@ -17,26 +17,32 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.database
|
||||
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.keepass.database.exception.LoadDatabaseDuplicateUuidException
|
||||
import com.kunzisoft.keepass.database.exception.LoadDatabaseKeyFileEmptyException
|
||||
import com.kunzisoft.keepass.utils.MemoryUtil
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryVersioned
|
||||
import com.kunzisoft.keepass.database.element.group.GroupVersioned
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageFactory
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.database.exception.DuplicateUuidDatabaseException
|
||||
import com.kunzisoft.keepass.database.exception.KeyFileEmptyDatabaseException
|
||||
import org.apache.commons.io.IOUtils
|
||||
import java.io.*
|
||||
import java.security.MessageDigest
|
||||
import java.security.NoSuchAlgorithmException
|
||||
import java.util.*
|
||||
|
||||
abstract class PwDatabase<
|
||||
abstract class DatabaseVersioned<
|
||||
GroupId,
|
||||
EntryId,
|
||||
Group : PwGroup<GroupId, EntryId, Group, Entry>,
|
||||
Entry : PwEntry<GroupId, EntryId, Group, Entry>
|
||||
Group : GroupVersioned<GroupId, EntryId, Group, Entry>,
|
||||
Entry : EntryVersioned<GroupId, EntryId, Group, Entry>
|
||||
> {
|
||||
|
||||
// Algorithm used to encrypt the database
|
||||
protected var algorithm: PwEncryptionAlgorithm? = null
|
||||
protected var algorithm: EncryptionAlgorithm? = null
|
||||
|
||||
abstract val kdfEngine: KdfEngine?
|
||||
|
||||
@@ -46,13 +52,13 @@ abstract class PwDatabase<
|
||||
var finalKey: ByteArray? = null
|
||||
protected set
|
||||
|
||||
var iconFactory = PwIconFactory()
|
||||
var iconFactory = IconImageFactory()
|
||||
protected set
|
||||
|
||||
var changeDuplicateId = false
|
||||
|
||||
private var groupIndexes = LinkedHashMap<PwNodeId<GroupId>, Group>()
|
||||
private var entryIndexes = LinkedHashMap<PwNodeId<EntryId>, Entry>()
|
||||
private var groupIndexes = LinkedHashMap<NodeId<GroupId>, Group>()
|
||||
private var entryIndexes = LinkedHashMap<NodeId<EntryId>, Entry>()
|
||||
|
||||
abstract val version: String
|
||||
|
||||
@@ -60,15 +66,15 @@ abstract class PwDatabase<
|
||||
|
||||
abstract var numberKeyEncryptionRounds: Long
|
||||
|
||||
var encryptionAlgorithm: PwEncryptionAlgorithm
|
||||
var encryptionAlgorithm: EncryptionAlgorithm
|
||||
get() {
|
||||
return algorithm ?: PwEncryptionAlgorithm.AESRijndael
|
||||
return algorithm ?: EncryptionAlgorithm.AESRijndael
|
||||
}
|
||||
set(algorithm) {
|
||||
this.algorithm = algorithm
|
||||
}
|
||||
|
||||
abstract val availableEncryptionAlgorithms: List<PwEncryptionAlgorithm>
|
||||
abstract val availableEncryptionAlgorithms: List<EncryptionAlgorithm>
|
||||
|
||||
var rootGroup: Group? = null
|
||||
|
||||
@@ -124,7 +130,7 @@ abstract class PwDatabase<
|
||||
protected fun getFileKey(keyInputStream: InputStream): ByteArray {
|
||||
|
||||
val keyByteArrayOutputStream = ByteArrayOutputStream()
|
||||
MemoryUtil.copyStream(keyInputStream, keyByteArrayOutputStream)
|
||||
IOUtils.copy(keyInputStream, keyByteArrayOutputStream)
|
||||
val keyData = keyByteArrayOutputStream.toByteArray()
|
||||
|
||||
val keyByteArrayInputStream = ByteArrayInputStream(keyData)
|
||||
@@ -134,7 +140,7 @@ abstract class PwDatabase<
|
||||
}
|
||||
|
||||
when (keyData.size.toLong()) {
|
||||
0L -> throw LoadDatabaseKeyFileEmptyException()
|
||||
0L -> throw KeyFileEmptyDatabaseException()
|
||||
32L -> return keyData
|
||||
64L -> try {
|
||||
return hexStringToByteArray(String(keyData))
|
||||
@@ -192,9 +198,9 @@ abstract class PwDatabase<
|
||||
* -------------------------------------
|
||||
*/
|
||||
|
||||
abstract fun newGroupId(): PwNodeId<GroupId>
|
||||
abstract fun newGroupId(): NodeId<GroupId>
|
||||
|
||||
abstract fun newEntryId(): PwNodeId<EntryId>
|
||||
abstract fun newEntryId(): NodeId<EntryId>
|
||||
|
||||
abstract fun createGroup(): Group
|
||||
|
||||
@@ -219,7 +225,7 @@ abstract class PwDatabase<
|
||||
* ID number to check for
|
||||
* @return True if the ID is used, false otherwise
|
||||
*/
|
||||
fun isGroupIdUsed(id: PwNodeId<GroupId>): Boolean {
|
||||
fun isGroupIdUsed(id: NodeId<GroupId>): Boolean {
|
||||
return groupIndexes.containsKey(id)
|
||||
}
|
||||
|
||||
@@ -234,7 +240,7 @@ abstract class PwDatabase<
|
||||
}
|
||||
}
|
||||
|
||||
fun getGroupById(id: PwNodeId<GroupId>): Group? {
|
||||
fun getGroupById(id: NodeId<GroupId>): Group? {
|
||||
return this.groupIndexes[id]
|
||||
}
|
||||
|
||||
@@ -247,7 +253,7 @@ abstract class PwDatabase<
|
||||
group.parent?.addChildGroup(group)
|
||||
this.groupIndexes[newGroupId] = group
|
||||
} else {
|
||||
throw LoadDatabaseDuplicateUuidException(Type.GROUP, groupId)
|
||||
throw DuplicateUuidDatabaseException(Type.GROUP, groupId)
|
||||
}
|
||||
} else {
|
||||
this.groupIndexes[groupId] = group
|
||||
@@ -275,7 +281,7 @@ abstract class PwDatabase<
|
||||
}
|
||||
}
|
||||
|
||||
fun isEntryIdUsed(id: PwNodeId<EntryId>): Boolean {
|
||||
fun isEntryIdUsed(id: NodeId<EntryId>): Boolean {
|
||||
return entryIndexes.containsKey(id)
|
||||
}
|
||||
|
||||
@@ -283,7 +289,7 @@ abstract class PwDatabase<
|
||||
return entryIndexes.values
|
||||
}
|
||||
|
||||
fun getEntryById(id: PwNodeId<EntryId>): Entry? {
|
||||
fun getEntryById(id: NodeId<EntryId>): Entry? {
|
||||
return this.entryIndexes[id]
|
||||
}
|
||||
|
||||
@@ -296,7 +302,7 @@ abstract class PwDatabase<
|
||||
entry.parent?.addChildEntry(entry)
|
||||
this.entryIndexes[newEntryId] = entry
|
||||
} else {
|
||||
throw LoadDatabaseDuplicateUuidException(Type.ENTRY, entryId)
|
||||
throw DuplicateUuidDatabaseException(Type.ENTRY, entryId)
|
||||
}
|
||||
} else {
|
||||
this.entryIndexes[entryId] = entry
|
||||
@@ -376,19 +382,19 @@ abstract class PwDatabase<
|
||||
addEntryTo(entry, origParent)
|
||||
}
|
||||
|
||||
abstract fun isBackup(group: Group): Boolean
|
||||
abstract fun isInRecycleBin(group: Group): Boolean
|
||||
|
||||
fun isGroupSearchable(group: Group?, omitBackup: Boolean): Boolean {
|
||||
if (group == null)
|
||||
return false
|
||||
if (omitBackup && isBackup(group))
|
||||
if (omitBackup && isInRecycleBin(group))
|
||||
return false
|
||||
return true
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private const val TAG = "PwDatabase"
|
||||
private const val TAG = "DatabaseVersioned"
|
||||
|
||||
val UUID_ZERO = UUID(0, 0)
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.entry
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
import com.kunzisoft.keepass.utils.MemoryUtil
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil
|
||||
|
||||
import java.util.HashMap
|
||||
|
||||
@@ -48,7 +48,7 @@ class AutoType : Parcelable {
|
||||
this.enabled = parcel.readByte().toInt() != 0
|
||||
this.obfuscationOptions = parcel.readLong()
|
||||
this.defaultSequence = parcel.readString() ?: defaultSequence
|
||||
this.windowSeqPairs = MemoryUtil.readStringParcelableMap(parcel)
|
||||
this.windowSeqPairs = ParcelableUtil.readStringParcelableMap(parcel)
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
@@ -59,7 +59,7 @@ class AutoType : Parcelable {
|
||||
dest.writeByte((if (enabled) 1 else 0).toByte())
|
||||
dest.writeLong(obfuscationOptions)
|
||||
dest.writeString(defaultSequence)
|
||||
MemoryUtil.writeStringParcelableMap(dest, windowSeqPairs)
|
||||
ParcelableUtil.writeStringParcelableMap(dest, windowSeqPairs)
|
||||
}
|
||||
|
||||
fun put(key: String, value: String) {
|
||||
@@ -17,15 +17,16 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.entry
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
import java.io.UnsupportedEncodingException
|
||||
import java.util.Arrays
|
||||
import java.util.UUID
|
||||
|
||||
import com.kunzisoft.keepass.database.element.group.GroupKDB
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
||||
import com.kunzisoft.keepass.database.element.node.NodeKDBInterface
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Structure containing information about one entry.
|
||||
@@ -48,7 +49,7 @@ import java.util.UUID
|
||||
* @author Dominik Reichl <dominik.reichl></dominik.reichl>@t-online.de>
|
||||
* @author Jeremy Jamet <jeremy.jamet></jeremy.jamet>@kunzisoft.com>
|
||||
*/
|
||||
class PwEntryV3 : PwEntry<Int, UUID, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
class EntryKDB : EntryVersioned<Int, UUID, GroupKDB, EntryKDB>, NodeKDBInterface {
|
||||
|
||||
/** A string describing what is in pBinaryData */
|
||||
var binaryDesc = ""
|
||||
@@ -56,12 +57,11 @@ class PwEntryV3 : PwEntry<Int, UUID, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
* @return the actual binaryData byte array.
|
||||
*/
|
||||
var binaryData: ByteArray = ByteArray(0)
|
||||
private set
|
||||
|
||||
// Determine if this is a MetaStream entry
|
||||
val isMetaStream: Boolean
|
||||
get() {
|
||||
if (Arrays.equals(binaryData, ByteArray(0))) return false
|
||||
if (binaryData.contentEquals(ByteArray(0))) return false
|
||||
if (notes.isEmpty()) return false
|
||||
if (binaryDesc != PMS_ID_BINDESC) return false
|
||||
if (title.isEmpty()) return false
|
||||
@@ -72,12 +72,12 @@ class PwEntryV3 : PwEntry<Int, UUID, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
return if (url != PMS_ID_URL) false else icon.isMetaStreamIcon
|
||||
}
|
||||
|
||||
override fun initNodeId(): PwNodeId<UUID> {
|
||||
return PwNodeIdUUID()
|
||||
override fun initNodeId(): NodeId<UUID> {
|
||||
return NodeIdUUID()
|
||||
}
|
||||
|
||||
override fun copyNodeId(nodeId: PwNodeId<UUID>): PwNodeId<UUID> {
|
||||
return PwNodeIdUUID(nodeId.id)
|
||||
override fun copyNodeId(nodeId: NodeId<UUID>): NodeId<UUID> {
|
||||
return NodeIdUUID(nodeId.id)
|
||||
}
|
||||
|
||||
constructor() : super()
|
||||
@@ -85,18 +85,19 @@ class PwEntryV3 : PwEntry<Int, UUID, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
constructor(parcel: Parcel) : super(parcel) {
|
||||
title = parcel.readString() ?: title
|
||||
username = parcel.readString() ?: username
|
||||
parcel.readByteArray(passwordBytes)
|
||||
password = parcel.readString() ?: password
|
||||
url = parcel.readString() ?: url
|
||||
notes = parcel.readString() ?: notes
|
||||
binaryDesc = parcel.readString() ?: binaryDesc
|
||||
binaryData = ByteArray(parcel.readInt())
|
||||
parcel.readByteArray(binaryData)
|
||||
}
|
||||
|
||||
override fun readParentParcelable(parcel: Parcel): PwGroupV3? {
|
||||
return parcel.readParcelable(PwGroupV3::class.java.classLoader)
|
||||
override fun readParentParcelable(parcel: Parcel): GroupKDB? {
|
||||
return parcel.readParcelable(GroupKDB::class.java.classLoader)
|
||||
}
|
||||
|
||||
override fun writeParentParcelable(parent: PwGroupV3?, parcel: Parcel, flags: Int) {
|
||||
override fun writeParentParcelable(parent: GroupKDB?, parcel: Parcel, flags: Int) {
|
||||
parcel.writeParcelable(parent, flags)
|
||||
}
|
||||
|
||||
@@ -104,22 +105,19 @@ class PwEntryV3 : PwEntry<Int, UUID, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
super.writeToParcel(dest, flags)
|
||||
dest.writeString(title)
|
||||
dest.writeString(username)
|
||||
dest.writeByteArray(passwordBytes)
|
||||
dest.writeString(password)
|
||||
dest.writeString(url)
|
||||
dest.writeString(notes)
|
||||
dest.writeString(binaryDesc)
|
||||
dest.writeInt(binaryData.size)
|
||||
dest.writeByteArray(binaryData)
|
||||
}
|
||||
|
||||
fun updateWith(source: PwEntryV3) {
|
||||
fun updateWith(source: EntryKDB) {
|
||||
super.updateWith(source)
|
||||
title = source.title
|
||||
username = source.username
|
||||
|
||||
val passLen = source.passwordBytes.size
|
||||
passwordBytes = ByteArray(passLen)
|
||||
System.arraycopy(source.passwordBytes, 0, passwordBytes, 0, passLen)
|
||||
|
||||
password = source.password
|
||||
url = source.url
|
||||
notes = source.notes
|
||||
binaryDesc = source.binaryDesc
|
||||
@@ -131,32 +129,10 @@ class PwEntryV3 : PwEntry<Int, UUID, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
|
||||
override var username = ""
|
||||
|
||||
var passwordBytes: ByteArray = ByteArray(0)
|
||||
private set
|
||||
|
||||
/** Securely erase old password before copying new. */
|
||||
fun setPassword(buf: ByteArray, offset: Int, len: Int) {
|
||||
fill(passwordBytes, 0.toByte())
|
||||
passwordBytes = ByteArray(len)
|
||||
System.arraycopy(buf, offset, passwordBytes, 0, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the actual password byte array.
|
||||
*/
|
||||
override var password: String
|
||||
get() = String(passwordBytes)
|
||||
set(pass) {
|
||||
var password: ByteArray
|
||||
try {
|
||||
password = pass.toByteArray(charset("UTF-8"))
|
||||
setPassword(password, 0, password.size)
|
||||
} catch (e: UnsupportedEncodingException) {
|
||||
password = pass.toByteArray()
|
||||
setPassword(password, 0, password.size)
|
||||
}
|
||||
|
||||
}
|
||||
override var password = ""
|
||||
|
||||
override var url = ""
|
||||
|
||||
@@ -167,13 +143,6 @@ class PwEntryV3 : PwEntry<Int, UUID, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
override val type: Type
|
||||
get() = Type.ENTRY
|
||||
|
||||
fun setBinaryData(buf: ByteArray, offset: Int, len: Int) {
|
||||
/** Securely erase old data before copying new. */
|
||||
fill(binaryData, 0.toByte())
|
||||
binaryData = ByteArray(len)
|
||||
System.arraycopy(buf, offset, binaryData, 0, len)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
/** Size of byte buffer needed to hold this struct. */
|
||||
@@ -183,22 +152,14 @@ class PwEntryV3 : PwEntry<Int, UUID, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
private const val PMS_ID_URL = "$"
|
||||
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<PwEntryV3> = object : Parcelable.Creator<PwEntryV3> {
|
||||
override fun createFromParcel(`in`: Parcel): PwEntryV3 {
|
||||
return PwEntryV3(`in`)
|
||||
val CREATOR: Parcelable.Creator<EntryKDB> = object : Parcelable.Creator<EntryKDB> {
|
||||
override fun createFromParcel(parcel: Parcel): EntryKDB {
|
||||
return EntryKDB(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<PwEntryV3?> {
|
||||
override fun newArray(size: Int): Array<EntryKDB?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* fill byte array
|
||||
*/
|
||||
private fun fill(array: ByteArray, value: Byte) {
|
||||
for (i in array.indices)
|
||||
array[i] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,24 +17,34 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.entry
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedBinary
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseKDBX
|
||||
import com.kunzisoft.keepass.database.element.group.GroupKDBX
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageCustom
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
||||
import com.kunzisoft.keepass.database.element.node.NodeKDBXInterface
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.database.element.security.BinaryAttachment
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
import com.kunzisoft.keepass.utils.MemoryUtil
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil
|
||||
import java.util.*
|
||||
|
||||
class PwEntryV4 : PwEntry<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
class EntryKDBX : EntryVersioned<UUID, UUID, GroupKDBX, EntryKDBX>, NodeKDBXInterface {
|
||||
|
||||
// To decode each field not parcelable
|
||||
@Transient
|
||||
private var mDatabase: PwDatabaseV4? = null
|
||||
private var mDatabase: DatabaseKDBX? = null
|
||||
@Transient
|
||||
private var mDecodeRef = false
|
||||
|
||||
override var icon: PwIcon
|
||||
override var icon: IconImage
|
||||
get() {
|
||||
return when {
|
||||
iconCustom.isUnknown -> super.icon
|
||||
@@ -42,19 +52,19 @@ class PwEntryV4 : PwEntry<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
}
|
||||
}
|
||||
set(value) {
|
||||
if (value is PwIconStandard)
|
||||
iconCustom = PwIconCustom.UNKNOWN_ICON
|
||||
if (value is IconImageStandard)
|
||||
iconCustom = IconImageCustom.UNKNOWN_ICON
|
||||
super.icon = value
|
||||
}
|
||||
var iconCustom = PwIconCustom.UNKNOWN_ICON
|
||||
var iconCustom = IconImageCustom.UNKNOWN_ICON
|
||||
private var customData = HashMap<String, String>()
|
||||
var fields = HashMap<String, ProtectedString>()
|
||||
val binaries = HashMap<String, ProtectedBinary>()
|
||||
var binaries = HashMap<String, BinaryAttachment>()
|
||||
var foregroundColor = ""
|
||||
var backgroundColor = ""
|
||||
var overrideURL = ""
|
||||
var autoType = AutoType()
|
||||
var history = ArrayList<PwEntryV4>()
|
||||
var history = ArrayList<EntryKDBX>()
|
||||
var additional = ""
|
||||
var tags = ""
|
||||
|
||||
@@ -93,12 +103,12 @@ class PwEntryV4 : PwEntry<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
constructor() : super()
|
||||
|
||||
constructor(parcel: Parcel) : super(parcel) {
|
||||
iconCustom = parcel.readParcelable(PwIconCustom::class.java.classLoader) ?: iconCustom
|
||||
iconCustom = parcel.readParcelable(IconImageCustom::class.java.classLoader) ?: iconCustom
|
||||
usageCount = parcel.readLong()
|
||||
locationChanged = parcel.readParcelable(PwDate::class.java.classLoader) ?: locationChanged
|
||||
customData = MemoryUtil.readStringParcelableMap(parcel)
|
||||
fields = MemoryUtil.readStringParcelableMap(parcel, ProtectedString::class.java)
|
||||
// TODO binaries = MemoryUtil.readStringParcelableMap(parcel, ProtectedBinary.class);
|
||||
locationChanged = parcel.readParcelable(DateInstant::class.java.classLoader) ?: locationChanged
|
||||
customData = ParcelableUtil.readStringParcelableMap(parcel)
|
||||
fields = ParcelableUtil.readStringParcelableMap(parcel, ProtectedString::class.java)
|
||||
binaries = ParcelableUtil.readStringParcelableMap(parcel, BinaryAttachment::class.java)
|
||||
foregroundColor = parcel.readString() ?: foregroundColor
|
||||
backgroundColor = parcel.readString() ?: backgroundColor
|
||||
overrideURL = parcel.readString() ?: overrideURL
|
||||
@@ -114,9 +124,9 @@ class PwEntryV4 : PwEntry<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
dest.writeParcelable(iconCustom, flags)
|
||||
dest.writeLong(usageCount)
|
||||
dest.writeParcelable(locationChanged, flags)
|
||||
MemoryUtil.writeStringParcelableMap(dest, customData)
|
||||
MemoryUtil.writeStringParcelableMap(dest, flags, fields)
|
||||
// TODO MemoryUtil.writeStringParcelableMap(dest, flags, binaries);
|
||||
ParcelableUtil.writeStringParcelableMap(dest, customData)
|
||||
ParcelableUtil.writeStringParcelableMap(dest, flags, fields)
|
||||
ParcelableUtil.writeStringParcelableMap(dest, flags, binaries)
|
||||
dest.writeString(foregroundColor)
|
||||
dest.writeString(backgroundColor)
|
||||
dest.writeString(overrideURL)
|
||||
@@ -131,11 +141,11 @@ class PwEntryV4 : PwEntry<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
* Update with deep copy of each entry element
|
||||
* @param source
|
||||
*/
|
||||
fun updateWith(source: PwEntryV4, copyHistory: Boolean = true) {
|
||||
fun updateWith(source: EntryKDBX, copyHistory: Boolean = true) {
|
||||
super.updateWith(source)
|
||||
iconCustom = PwIconCustom(source.iconCustom)
|
||||
iconCustom = IconImageCustom(source.iconCustom)
|
||||
usageCount = source.usageCount
|
||||
locationChanged = PwDate(source.locationChanged)
|
||||
locationChanged = DateInstant(source.locationChanged)
|
||||
// Add all custom elements in map
|
||||
customData.clear()
|
||||
customData.putAll(source.customData)
|
||||
@@ -155,7 +165,7 @@ class PwEntryV4 : PwEntry<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
tags = source.tags
|
||||
}
|
||||
|
||||
fun startToManageFieldReferences(db: PwDatabaseV4) {
|
||||
fun startToManageFieldReferences(db: DatabaseKDBX) {
|
||||
this.mDatabase = db
|
||||
this.mDecodeRef = true
|
||||
}
|
||||
@@ -165,24 +175,24 @@ class PwEntryV4 : PwEntry<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
this.mDecodeRef = false
|
||||
}
|
||||
|
||||
override fun initNodeId(): PwNodeId<UUID> {
|
||||
return PwNodeIdUUID()
|
||||
override fun initNodeId(): NodeId<UUID> {
|
||||
return NodeIdUUID()
|
||||
}
|
||||
|
||||
override fun copyNodeId(nodeId: PwNodeId<UUID>): PwNodeId<UUID> {
|
||||
return PwNodeIdUUID(nodeId.id)
|
||||
override fun copyNodeId(nodeId: NodeId<UUID>): NodeId<UUID> {
|
||||
return NodeIdUUID(nodeId.id)
|
||||
}
|
||||
|
||||
override fun readParentParcelable(parcel: Parcel): PwGroupV4? {
|
||||
return parcel.readParcelable(PwGroupV4::class.java.classLoader)
|
||||
override fun readParentParcelable(parcel: Parcel): GroupKDBX? {
|
||||
return parcel.readParcelable(GroupKDBX::class.java.classLoader)
|
||||
}
|
||||
|
||||
override fun writeParentParcelable(parent: PwGroupV4?, parcel: Parcel, flags: Int) {
|
||||
override fun writeParentParcelable(parent: GroupKDBX?, parcel: Parcel, flags: Int) {
|
||||
parcel.writeParcelable(parent, flags)
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a reference key with the SprEngineV4
|
||||
* Decode a reference key with the FieldReferencesEngine
|
||||
* @param decodeRef
|
||||
* @param key
|
||||
* @return
|
||||
@@ -190,7 +200,7 @@ class PwEntryV4 : PwEntry<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
private fun decodeRefKey(decodeRef: Boolean, key: String): String {
|
||||
return fields[key]?.toString()?.let { text ->
|
||||
return if (decodeRef) {
|
||||
if (mDatabase == null) text else SprEngineV4().compile(text, this, mDatabase!!)
|
||||
if (mDatabase == null) text else FieldReferencesEngine().compile(text, this, mDatabase!!)
|
||||
} else text
|
||||
} ?: ""
|
||||
}
|
||||
@@ -235,10 +245,10 @@ class PwEntryV4 : PwEntry<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
|
||||
override var usageCount: Long = 0
|
||||
|
||||
override var locationChanged = PwDate()
|
||||
override var locationChanged = DateInstant()
|
||||
|
||||
fun afterChangeParent() {
|
||||
locationChanged = PwDate()
|
||||
locationChanged = DateInstant()
|
||||
}
|
||||
|
||||
private fun isStandardField(key: String): Boolean {
|
||||
@@ -274,7 +284,7 @@ class PwEntryV4 : PwEntry<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
fields[label] = value
|
||||
}
|
||||
|
||||
fun putProtectedBinary(key: String, value: ProtectedBinary) {
|
||||
fun putProtectedBinary(key: String, value: BinaryAttachment) {
|
||||
binaries[key] = value
|
||||
}
|
||||
|
||||
@@ -290,7 +300,7 @@ class PwEntryV4 : PwEntry<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
return customData.isNotEmpty()
|
||||
}
|
||||
|
||||
fun addEntryToHistory(entry: PwEntryV4) {
|
||||
fun addEntryToHistory(entry: EntryKDBX) {
|
||||
history.add(entry)
|
||||
}
|
||||
|
||||
@@ -330,12 +340,12 @@ class PwEntryV4 : PwEntry<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
const val STR_NOTES = "Notes"
|
||||
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<PwEntryV4> = object : Parcelable.Creator<PwEntryV4> {
|
||||
override fun createFromParcel(parcel: Parcel): PwEntryV4 {
|
||||
return PwEntryV4(parcel)
|
||||
val CREATOR: Parcelable.Creator<EntryKDBX> = object : Parcelable.Creator<EntryKDBX> {
|
||||
override fun createFromParcel(parcel: Parcel): EntryKDBX {
|
||||
return EntryKDBX(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<PwEntryV4?> {
|
||||
override fun newArray(size: Int): Array<EntryKDBX?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.kunzisoft.keepass.database.element.entry
|
||||
|
||||
import android.os.Parcel
|
||||
import com.kunzisoft.keepass.database.element.group.GroupVersioned
|
||||
import com.kunzisoft.keepass.database.element.node.NodeVersioned
|
||||
|
||||
abstract class EntryVersioned
|
||||
<
|
||||
GroupId,
|
||||
EntryId,
|
||||
ParentGroup: GroupVersioned<GroupId, EntryId, ParentGroup, Entry>,
|
||||
Entry: EntryVersioned<GroupId, EntryId, ParentGroup, Entry>
|
||||
>
|
||||
: NodeVersioned<EntryId, ParentGroup, Entry>, EntryVersionedInterface<ParentGroup> {
|
||||
|
||||
constructor() : super()
|
||||
|
||||
constructor(parcel: Parcel) : super(parcel)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.kunzisoft.keepass.database.element.entry
|
||||
|
||||
import com.kunzisoft.keepass.database.element.node.NodeVersionedInterface
|
||||
|
||||
interface EntryVersionedInterface<ParentGroup> : NodeVersionedInterface<ParentGroup> {
|
||||
|
||||
var username: String
|
||||
|
||||
var password: String
|
||||
|
||||
var url: String
|
||||
|
||||
var notes: String
|
||||
}
|
||||
@@ -17,24 +17,26 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.entry
|
||||
|
||||
import com.kunzisoft.keepass.database.search.EntrySearchHandlerV4
|
||||
import com.kunzisoft.keepass.database.search.SearchParametersV4
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseKDBX
|
||||
import com.kunzisoft.keepass.database.element.group.GroupKDBX
|
||||
import com.kunzisoft.keepass.database.search.EntryKDBXSearchHandler
|
||||
import com.kunzisoft.keepass.database.search.SearchParametersKDBX
|
||||
import com.kunzisoft.keepass.utils.StringUtil
|
||||
import java.util.*
|
||||
|
||||
class SprEngineV4 {
|
||||
class FieldReferencesEngine {
|
||||
|
||||
inner class TargetResult(var entry: PwEntryV4?, var wanted: Char)
|
||||
inner class TargetResult(var entry: EntryKDBX?, var wanted: Char)
|
||||
|
||||
private inner class SprContextV4 {
|
||||
|
||||
var databaseV4: PwDatabaseV4? = null
|
||||
var entry: PwEntryV4
|
||||
var databaseV4: DatabaseKDBX? = null
|
||||
var entry: EntryKDBX
|
||||
var refsCache: MutableMap<String, String> = HashMap()
|
||||
|
||||
internal constructor(db: PwDatabaseV4, entry: PwEntryV4) {
|
||||
internal constructor(db: DatabaseKDBX, entry: EntryKDBX) {
|
||||
this.databaseV4 = db
|
||||
this.entry = entry
|
||||
}
|
||||
@@ -46,7 +48,7 @@ class SprEngineV4 {
|
||||
}
|
||||
}
|
||||
|
||||
fun compile(text: String, entry: PwEntryV4, database: PwDatabaseV4): String {
|
||||
fun compile(text: String, entry: EntryKDBX, database: DatabaseKDBX): String {
|
||||
return compileInternal(text, SprContextV4(database, entry), 0)
|
||||
}
|
||||
|
||||
@@ -139,7 +141,7 @@ class SprEngineV4 {
|
||||
val scan = Character.toUpperCase(ref[2])
|
||||
val wanted = Character.toUpperCase(ref[0])
|
||||
|
||||
val searchParametersV4 = SearchParametersV4()
|
||||
val searchParametersV4 = SearchParametersKDBX()
|
||||
searchParametersV4.setupNone()
|
||||
|
||||
searchParametersV4.searchString = ref.substring(4)
|
||||
@@ -161,7 +163,7 @@ class SprEngineV4 {
|
||||
return null
|
||||
}
|
||||
|
||||
val list = ArrayList<PwEntryV4>()
|
||||
val list = ArrayList<EntryKDBX>()
|
||||
// TODO type parameter
|
||||
searchEntries(contextV4.databaseV4!!.rootGroup, searchParametersV4, list)
|
||||
|
||||
@@ -195,7 +197,7 @@ class SprEngineV4 {
|
||||
return newText
|
||||
}
|
||||
|
||||
private fun searchEntries(root: PwGroupV4?, searchParametersV4: SearchParametersV4?, listStorage: MutableList<PwEntryV4>?) {
|
||||
private fun searchEntries(root: GroupKDBX?, searchParametersV4: SearchParametersKDBX?, listStorage: MutableList<EntryKDBX>?) {
|
||||
if (searchParametersV4 == null) {
|
||||
return
|
||||
}
|
||||
@@ -205,7 +207,7 @@ class SprEngineV4 {
|
||||
|
||||
val terms = StringUtil.splitStringTerms(searchParametersV4.searchString)
|
||||
if (terms.size <= 1 || searchParametersV4.regularExpression) {
|
||||
root!!.doForEachChild(EntrySearchHandlerV4(searchParametersV4, listStorage), null)
|
||||
root!!.doForEachChild(EntryKDBXSearchHandler(searchParametersV4, listStorage), null)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -214,9 +216,9 @@ class SprEngineV4 {
|
||||
Collections.sort(terms, stringLengthComparator)
|
||||
|
||||
val fullSearch = searchParametersV4.searchString
|
||||
var childEntries: List<PwEntryV4>? = root!!.getChildEntries()
|
||||
var childEntries: List<EntryKDBX>? = root!!.getChildEntries()
|
||||
for (i in terms.indices) {
|
||||
val pgNew = ArrayList<PwEntryV4>()
|
||||
val pgNew = ArrayList<EntryKDBX>()
|
||||
|
||||
searchParametersV4.searchString = terms[i]
|
||||
|
||||
@@ -226,12 +228,12 @@ class SprEngineV4 {
|
||||
negate = searchParametersV4.searchString.isNotEmpty()
|
||||
}
|
||||
|
||||
if (!root.doForEachChild(EntrySearchHandlerV4(searchParametersV4, pgNew), null)) {
|
||||
if (!root.doForEachChild(EntryKDBXSearchHandler(searchParametersV4, pgNew), null)) {
|
||||
childEntries = null
|
||||
break
|
||||
}
|
||||
|
||||
val complement = ArrayList<PwEntryV4>()
|
||||
val complement = ArrayList<EntryKDBX>()
|
||||
if (negate) {
|
||||
for (entry in childEntries!!) {
|
||||
if (!pgNew.contains(entry)) {
|
||||
@@ -18,13 +18,18 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.group
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryKDB
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdInt
|
||||
import com.kunzisoft.keepass.database.element.node.NodeKDBInterface
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import java.util.*
|
||||
|
||||
class PwGroupV3 : PwGroup<Int, UUID, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
class GroupKDB : GroupVersioned<Int, UUID, GroupKDB, EntryKDB>, NodeKDBInterface {
|
||||
|
||||
var level = 0 // short
|
||||
/** Used by KeePass internally, don't use */
|
||||
@@ -37,11 +42,11 @@ class PwGroupV3 : PwGroup<Int, UUID, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
flags = parcel.readInt()
|
||||
}
|
||||
|
||||
override fun readParentParcelable(parcel: Parcel): PwGroupV3? {
|
||||
return parcel.readParcelable(PwGroupV3::class.java.classLoader)
|
||||
override fun readParentParcelable(parcel: Parcel): GroupKDB? {
|
||||
return parcel.readParcelable(GroupKDB::class.java.classLoader)
|
||||
}
|
||||
|
||||
override fun writeParentParcelable(parent: PwGroupV3?, parcel: Parcel, flags: Int) {
|
||||
override fun writeParentParcelable(parent: GroupKDB?, parcel: Parcel, flags: Int) {
|
||||
parcel.writeParcelable(parent, flags)
|
||||
}
|
||||
|
||||
@@ -51,7 +56,7 @@ class PwGroupV3 : PwGroup<Int, UUID, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
dest.writeInt(flags)
|
||||
}
|
||||
|
||||
fun updateWith(source: PwGroupV3) {
|
||||
fun updateWith(source: GroupKDB) {
|
||||
super.updateWith(source)
|
||||
level = source.level
|
||||
flags = source.flags
|
||||
@@ -60,12 +65,12 @@ class PwGroupV3 : PwGroup<Int, UUID, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
override val type: Type
|
||||
get() = Type.GROUP
|
||||
|
||||
override fun initNodeId(): PwNodeId<Int> {
|
||||
return PwNodeIdInt()
|
||||
override fun initNodeId(): NodeId<Int> {
|
||||
return NodeIdInt()
|
||||
}
|
||||
|
||||
override fun copyNodeId(nodeId: PwNodeId<Int>): PwNodeId<Int> {
|
||||
return PwNodeIdInt(nodeId.id)
|
||||
override fun copyNodeId(nodeId: NodeId<Int>): NodeId<Int> {
|
||||
return NodeIdInt(nodeId.id)
|
||||
}
|
||||
|
||||
override fun afterAssignNewParent() {
|
||||
@@ -74,7 +79,7 @@ class PwGroupV3 : PwGroup<Int, UUID, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
}
|
||||
|
||||
fun setGroupId(groupId: Int) {
|
||||
this.nodeId = PwNodeIdInt(groupId)
|
||||
this.nodeId = NodeIdInt(groupId)
|
||||
}
|
||||
|
||||
override fun allowAddEntryIfIsRoot(): Boolean {
|
||||
@@ -84,12 +89,12 @@ class PwGroupV3 : PwGroup<Int, UUID, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
companion object {
|
||||
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<PwGroupV3> = object : Parcelable.Creator<PwGroupV3> {
|
||||
override fun createFromParcel(parcel: Parcel): PwGroupV3 {
|
||||
return PwGroupV3(parcel)
|
||||
val CREATOR: Parcelable.Creator<GroupKDB> = object : Parcelable.Creator<GroupKDB> {
|
||||
override fun createFromParcel(parcel: Parcel): GroupKDB {
|
||||
return GroupKDB(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<PwGroupV3?> {
|
||||
override fun newArray(size: Int): Array<GroupKDB?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
@@ -17,18 +17,28 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.group
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseVersioned
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryKDBX
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageCustom
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
||||
import com.kunzisoft.keepass.database.element.node.NodeKDBXInterface
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
|
||||
import java.util.HashMap
|
||||
import java.util.UUID
|
||||
|
||||
class PwGroupV4 : PwGroup<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
class GroupKDBX : GroupVersioned<UUID, UUID, GroupKDBX, EntryKDBX>, NodeKDBXInterface {
|
||||
|
||||
// TODO Encapsulate
|
||||
override var icon: PwIcon
|
||||
override var icon: IconImage
|
||||
get() {
|
||||
return if (iconCustom.isUnknown)
|
||||
super.icon
|
||||
@@ -36,11 +46,11 @@ class PwGroupV4 : PwGroup<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
iconCustom
|
||||
}
|
||||
set(value) {
|
||||
if (value is PwIconStandard)
|
||||
iconCustom = PwIconCustom.UNKNOWN_ICON
|
||||
if (value is IconImageStandard)
|
||||
iconCustom = IconImageCustom.UNKNOWN_ICON
|
||||
super.icon = value
|
||||
}
|
||||
var iconCustom = PwIconCustom.UNKNOWN_ICON
|
||||
var iconCustom = IconImageCustom.UNKNOWN_ICON
|
||||
private val customData = HashMap<String, String>()
|
||||
var notes = ""
|
||||
|
||||
@@ -48,28 +58,28 @@ class PwGroupV4 : PwGroup<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
var defaultAutoTypeSequence = ""
|
||||
var enableAutoType: Boolean? = null
|
||||
var enableSearching: Boolean? = null
|
||||
var lastTopVisibleEntry: UUID = PwDatabase.UUID_ZERO
|
||||
var lastTopVisibleEntry: UUID = DatabaseVersioned.UUID_ZERO
|
||||
|
||||
override var expires: Boolean = false
|
||||
|
||||
override val type: Type
|
||||
get() = Type.GROUP
|
||||
|
||||
override fun initNodeId(): PwNodeId<UUID> {
|
||||
return PwNodeIdUUID()
|
||||
override fun initNodeId(): NodeId<UUID> {
|
||||
return NodeIdUUID()
|
||||
}
|
||||
|
||||
override fun copyNodeId(nodeId: PwNodeId<UUID>): PwNodeId<UUID> {
|
||||
return PwNodeIdUUID(nodeId.id)
|
||||
override fun copyNodeId(nodeId: NodeId<UUID>): NodeId<UUID> {
|
||||
return NodeIdUUID(nodeId.id)
|
||||
}
|
||||
|
||||
constructor() : super()
|
||||
|
||||
constructor(parcel: Parcel) : super(parcel) {
|
||||
iconCustom = parcel.readParcelable(PwIconCustom::class.java.classLoader) ?: iconCustom
|
||||
iconCustom = parcel.readParcelable(IconImageCustom::class.java.classLoader) ?: iconCustom
|
||||
usageCount = parcel.readLong()
|
||||
locationChanged = parcel.readParcelable(PwDate::class.java.classLoader) ?: locationChanged
|
||||
// TODO customData = MemoryUtil.readStringParcelableMap(in);
|
||||
locationChanged = parcel.readParcelable(DateInstant::class.java.classLoader) ?: locationChanged
|
||||
// TODO customData = ParcelableUtil.readStringParcelableMap(in);
|
||||
notes = parcel.readString() ?: notes
|
||||
isExpanded = parcel.readByte().toInt() != 0
|
||||
defaultAutoTypeSequence = parcel.readString() ?: defaultAutoTypeSequence
|
||||
@@ -80,11 +90,11 @@ class PwGroupV4 : PwGroup<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
lastTopVisibleEntry = parcel.readSerializable() as UUID
|
||||
}
|
||||
|
||||
override fun readParentParcelable(parcel: Parcel): PwGroupV4? {
|
||||
return parcel.readParcelable(PwGroupV4::class.java.classLoader)
|
||||
override fun readParentParcelable(parcel: Parcel): GroupKDBX? {
|
||||
return parcel.readParcelable(GroupKDBX::class.java.classLoader)
|
||||
}
|
||||
|
||||
override fun writeParentParcelable(parent: PwGroupV4?, parcel: Parcel, flags: Int) {
|
||||
override fun writeParentParcelable(parent: GroupKDBX?, parcel: Parcel, flags: Int) {
|
||||
parcel.writeParcelable(parent, flags)
|
||||
}
|
||||
|
||||
@@ -93,7 +103,7 @@ class PwGroupV4 : PwGroup<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
dest.writeParcelable(iconCustom, flags)
|
||||
dest.writeLong(usageCount)
|
||||
dest.writeParcelable(locationChanged, flags)
|
||||
// TODO MemoryUtil.writeStringParcelableMap(dest, customData);
|
||||
// TODO ParcelableUtil.writeStringParcelableMap(dest, customData);
|
||||
dest.writeString(notes)
|
||||
dest.writeByte((if (isExpanded) 1 else 0).toByte())
|
||||
dest.writeString(defaultAutoTypeSequence)
|
||||
@@ -102,11 +112,11 @@ class PwGroupV4 : PwGroup<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
dest.writeSerializable(lastTopVisibleEntry)
|
||||
}
|
||||
|
||||
fun updateWith(source: PwGroupV4) {
|
||||
fun updateWith(source: GroupKDBX) {
|
||||
super.updateWith(source)
|
||||
iconCustom = PwIconCustom(source.iconCustom)
|
||||
iconCustom = IconImageCustom(source.iconCustom)
|
||||
usageCount = source.usageCount
|
||||
locationChanged = PwDate(source.locationChanged)
|
||||
locationChanged = DateInstant(source.locationChanged)
|
||||
// Add all custom elements in map
|
||||
customData.clear()
|
||||
for ((key, value) in source.customData) {
|
||||
@@ -122,10 +132,10 @@ class PwGroupV4 : PwGroup<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
|
||||
override var usageCount: Long = 0
|
||||
|
||||
override var locationChanged = PwDate()
|
||||
override var locationChanged = DateInstant()
|
||||
|
||||
override fun afterAssignNewParent() {
|
||||
locationChanged = PwDate()
|
||||
locationChanged = DateInstant()
|
||||
}
|
||||
|
||||
override fun putCustomData(key: String, value: String) {
|
||||
@@ -143,12 +153,12 @@ class PwGroupV4 : PwGroup<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
companion object {
|
||||
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<PwGroupV4> = object : Parcelable.Creator<PwGroupV4> {
|
||||
override fun createFromParcel(parcel: Parcel): PwGroupV4 {
|
||||
return PwGroupV4(parcel)
|
||||
val CREATOR: Parcelable.Creator<GroupKDBX> = object : Parcelable.Creator<GroupKDBX> {
|
||||
override fun createFromParcel(parcel: Parcel): GroupKDBX {
|
||||
return GroupKDBX(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<PwGroupV4?> {
|
||||
override fun newArray(size: Int): Array<GroupKDBX?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,17 @@
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.group
|
||||
|
||||
import android.os.Parcel
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryVersioned
|
||||
import com.kunzisoft.keepass.database.element.node.NodeVersioned
|
||||
|
||||
abstract class PwGroup
|
||||
abstract class GroupVersioned
|
||||
<
|
||||
GroupId,
|
||||
EntryId,
|
||||
Group: PwGroup<GroupId, EntryId, Group, Entry>,
|
||||
Entry: PwEntry<GroupId, EntryId, Group, Entry>
|
||||
Group: GroupVersioned<GroupId, EntryId, Group, Entry>,
|
||||
Entry: EntryVersioned<GroupId, EntryId, Group, Entry>
|
||||
>
|
||||
: PwNode<GroupId, Group, Entry>, PwGroupInterface<Group, Entry> {
|
||||
: NodeVersioned<GroupId, Group, Entry>, GroupVersionedInterface<Group, Entry> {
|
||||
|
||||
private var titleGroup = ""
|
||||
@Transient
|
||||
@@ -28,7 +30,7 @@ abstract class PwGroup
|
||||
dest.writeString(titleGroup)
|
||||
}
|
||||
|
||||
protected fun updateWith(source: PwGroup<GroupId, EntryId, Group, Entry>) {
|
||||
protected fun updateWith(source: GroupVersioned<GroupId, EntryId, Group, Entry>) {
|
||||
super.updateWith(source)
|
||||
titleGroup = source.titleGroup
|
||||
childGroups.clear()
|
||||
@@ -69,6 +71,11 @@ abstract class PwGroup
|
||||
this.childEntries.remove(entry)
|
||||
}
|
||||
|
||||
override fun removeChildren() {
|
||||
this.childGroups.clear()
|
||||
this.childEntries.clear()
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return titleGroup
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.group
|
||||
|
||||
import com.kunzisoft.keepass.database.NodeHandler
|
||||
import com.kunzisoft.keepass.database.action.node.NodeHandler
|
||||
import com.kunzisoft.keepass.database.element.node.NodeVersionedInterface
|
||||
|
||||
interface PwGroupInterface<Group: PwGroupInterface<Group, Entry>, Entry> : PwNodeInterface<Group> {
|
||||
interface GroupVersionedInterface<Group: GroupVersionedInterface<Group, Entry>, Entry> : NodeVersionedInterface<Group> {
|
||||
|
||||
fun getChildGroups(): MutableList<Group>
|
||||
|
||||
@@ -16,6 +17,8 @@ interface PwGroupInterface<Group: PwGroupInterface<Group, Entry>, Entry> : PwNod
|
||||
|
||||
fun removeChildEntry(entry: Entry)
|
||||
|
||||
fun removeChildren()
|
||||
|
||||
fun allowAddEntryIfIsRoot(): Boolean
|
||||
|
||||
fun doForEachChildAndForIt(entryHandler: NodeHandler<Entry>,
|
||||
@@ -17,11 +17,11 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.icon
|
||||
|
||||
import android.os.Parcelable
|
||||
|
||||
abstract class PwIcon protected constructor() : Parcelable {
|
||||
abstract class IconImage protected constructor() : Parcelable {
|
||||
|
||||
abstract val iconId: Int
|
||||
abstract val isUnknown: Boolean
|
||||
@@ -17,14 +17,15 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.icon
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseVersioned
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
class PwIconCustom : PwIcon {
|
||||
class IconImageCustom : IconImage {
|
||||
|
||||
val uuid: UUID
|
||||
@Transient
|
||||
@@ -40,7 +41,7 @@ class PwIconCustom : PwIcon {
|
||||
this.imageData = ByteArray(0)
|
||||
}
|
||||
|
||||
constructor(icon: PwIconCustom) : super() {
|
||||
constructor(icon: IconImageCustom) : super() {
|
||||
uuid = icon.uuid
|
||||
imageData = icon.imageData
|
||||
}
|
||||
@@ -68,7 +69,7 @@ class PwIconCustom : PwIcon {
|
||||
return true
|
||||
if (other == null)
|
||||
return false
|
||||
if (other !is PwIconCustom)
|
||||
if (other !is IconImageCustom)
|
||||
return false
|
||||
return uuid == other.uuid
|
||||
}
|
||||
@@ -83,15 +84,15 @@ class PwIconCustom : PwIcon {
|
||||
get() = false
|
||||
|
||||
companion object {
|
||||
val UNKNOWN_ICON = PwIconCustom(PwDatabase.UUID_ZERO, ByteArray(0))
|
||||
val UNKNOWN_ICON = IconImageCustom(DatabaseVersioned.UUID_ZERO, ByteArray(0))
|
||||
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<PwIconCustom> = object : Parcelable.Creator<PwIconCustom> {
|
||||
override fun createFromParcel(parcel: Parcel): PwIconCustom {
|
||||
return PwIconCustom(parcel)
|
||||
val CREATOR: Parcelable.Creator<IconImageCustom> = object : Parcelable.Creator<IconImageCustom> {
|
||||
override fun createFromParcel(parcel: Parcel): IconImageCustom {
|
||||
return IconImageCustom(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<PwIconCustom?> {
|
||||
override fun newArray(size: Int): Array<IconImageCustom?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
@@ -17,61 +17,61 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.icon
|
||||
|
||||
import org.apache.commons.collections.map.AbstractReferenceMap
|
||||
import org.apache.commons.collections.map.ReferenceMap
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
class PwIconFactory {
|
||||
class IconImageFactory {
|
||||
/** customIconMap
|
||||
* Cache for icon drawable.
|
||||
* Keys: Integer, Values: PwIconStandard
|
||||
* Keys: Integer, Values: IconImageStandard
|
||||
*/
|
||||
private val cache = ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK)
|
||||
|
||||
/** standardIconMap
|
||||
* Cache for icon drawable.
|
||||
* Keys: UUID, Values: PwIconCustom
|
||||
* Keys: UUID, Values: IconImageCustom
|
||||
*/
|
||||
private val customCache = ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK)
|
||||
|
||||
val unknownIcon: PwIconStandard
|
||||
get() = getIcon(PwIcon.UNKNOWN_ID)
|
||||
val unknownIcon: IconImageStandard
|
||||
get() = getIcon(IconImage.UNKNOWN_ID)
|
||||
|
||||
val keyIcon: PwIconStandard
|
||||
get() = getIcon(PwIconStandard.KEY)
|
||||
val keyIcon: IconImageStandard
|
||||
get() = getIcon(IconImageStandard.KEY)
|
||||
|
||||
val trashIcon: PwIconStandard
|
||||
get() = getIcon(PwIconStandard.TRASH)
|
||||
val trashIcon: IconImageStandard
|
||||
get() = getIcon(IconImageStandard.TRASH)
|
||||
|
||||
val folderIcon: PwIconStandard
|
||||
get() = getIcon(PwIconStandard.FOLDER)
|
||||
val folderIcon: IconImageStandard
|
||||
get() = getIcon(IconImageStandard.FOLDER)
|
||||
|
||||
fun getIcon(iconId: Int): PwIconStandard {
|
||||
var icon: PwIconStandard? = cache[iconId] as PwIconStandard?
|
||||
fun getIcon(iconId: Int): IconImageStandard {
|
||||
var icon: IconImageStandard? = cache[iconId] as IconImageStandard?
|
||||
|
||||
if (icon == null) {
|
||||
icon = PwIconStandard(iconId)
|
||||
icon = IconImageStandard(iconId)
|
||||
cache[iconId] = icon
|
||||
}
|
||||
|
||||
return icon
|
||||
}
|
||||
|
||||
fun getIcon(iconUuid: UUID): PwIconCustom {
|
||||
var icon: PwIconCustom? = customCache[iconUuid] as PwIconCustom?
|
||||
fun getIcon(iconUuid: UUID): IconImageCustom {
|
||||
var icon: IconImageCustom? = customCache[iconUuid] as IconImageCustom?
|
||||
|
||||
if (icon == null) {
|
||||
icon = PwIconCustom(iconUuid)
|
||||
icon = IconImageCustom(iconUuid)
|
||||
customCache[iconUuid] = icon
|
||||
}
|
||||
|
||||
return icon
|
||||
}
|
||||
|
||||
fun put(icon: PwIconCustom) {
|
||||
fun put(icon: IconImageCustom) {
|
||||
customCache[icon.uuid] = icon
|
||||
}
|
||||
}
|
||||
@@ -17,12 +17,12 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.icon
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
class PwIconStandard : PwIcon {
|
||||
class IconImageStandard : IconImage {
|
||||
|
||||
constructor() {
|
||||
this.iconId = KEY
|
||||
@@ -32,7 +32,7 @@ class PwIconStandard : PwIcon {
|
||||
this.iconId = iconId
|
||||
}
|
||||
|
||||
constructor(icon: PwIconStandard) {
|
||||
constructor(icon: IconImageStandard) {
|
||||
this.iconId = icon.iconId
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class PwIconStandard : PwIcon {
|
||||
return true
|
||||
if (other == null)
|
||||
return false
|
||||
if (other !is PwIconStandard) {
|
||||
if (other !is IconImageStandard) {
|
||||
return false
|
||||
}
|
||||
return iconId == other.iconId
|
||||
@@ -77,12 +77,12 @@ class PwIconStandard : PwIcon {
|
||||
const val FOLDER = 48
|
||||
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<PwIconStandard> = object : Parcelable.Creator<PwIconStandard> {
|
||||
override fun createFromParcel(parcel: Parcel): PwIconStandard {
|
||||
return PwIconStandard(parcel)
|
||||
val CREATOR: Parcelable.Creator<IconImageStandard> = object : Parcelable.Creator<IconImageStandard> {
|
||||
override fun createFromParcel(parcel: Parcel): IconImageStandard {
|
||||
return IconImageStandard(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<PwIconStandard?> {
|
||||
override fun newArray(size: Int): Array<IconImageStandard?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.node
|
||||
|
||||
interface NodeVersioned: PwNodeInterface<GroupVersioned> {
|
||||
import com.kunzisoft.keepass.database.element.Group
|
||||
|
||||
val nodeId: PwNodeId<*>?
|
||||
interface Node: NodeVersionedInterface<Group> {
|
||||
|
||||
val nodeId: NodeId<*>?
|
||||
|
||||
val nodePositionInParent: Int
|
||||
get() {
|
||||
@@ -15,7 +17,7 @@ interface NodeVersioned: PwNodeInterface<GroupVersioned> {
|
||||
return -1
|
||||
}
|
||||
|
||||
fun addParentFrom(node: NodeVersioned) {
|
||||
fun addParentFrom(node: Node) {
|
||||
parent = node.parent
|
||||
}
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.node
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
abstract class PwNodeId<Id> : Parcelable {
|
||||
abstract class NodeId<Id> : Parcelable {
|
||||
|
||||
abstract val id: Id
|
||||
|
||||
@@ -34,7 +34,7 @@ abstract class PwNodeId<Id> : Parcelable {
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other !is PwNodeId<*>) return false
|
||||
if (other !is NodeId<*>) return false
|
||||
|
||||
if (id != other.id) return false
|
||||
|
||||
@@ -17,19 +17,19 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.node
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
import java.util.Random
|
||||
|
||||
class PwNodeIdInt : PwNodeId<Int> {
|
||||
class NodeIdInt : NodeId<Int> {
|
||||
|
||||
override var id: Int = -1
|
||||
private set
|
||||
|
||||
constructor(source: PwNodeIdInt) : this(source.id)
|
||||
constructor(source: NodeIdInt) : this(source.id)
|
||||
|
||||
@JvmOverloads
|
||||
constructor(groupId: Int = Random().nextInt()) : super() {
|
||||
@@ -50,7 +50,7 @@ class PwNodeIdInt : PwNodeId<Int> {
|
||||
return true
|
||||
if (other == null)
|
||||
return false
|
||||
if (other !is PwNodeIdInt) {
|
||||
if (other !is NodeIdInt) {
|
||||
return false
|
||||
}
|
||||
return id == other.id
|
||||
@@ -66,12 +66,12 @@ class PwNodeIdInt : PwNodeId<Int> {
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<PwNodeIdInt> = object : Parcelable.Creator<PwNodeIdInt> {
|
||||
override fun createFromParcel(parcel: Parcel): PwNodeIdInt {
|
||||
return PwNodeIdInt(parcel)
|
||||
val CREATOR: Parcelable.Creator<NodeIdInt> = object : Parcelable.Creator<NodeIdInt> {
|
||||
override fun createFromParcel(parcel: Parcel): NodeIdInt {
|
||||
return NodeIdInt(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<PwNodeIdInt?> {
|
||||
override fun newArray(size: Int): Array<NodeIdInt?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
@@ -17,19 +17,19 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.node
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
class PwNodeIdUUID : PwNodeId<UUID> {
|
||||
class NodeIdUUID : NodeId<UUID> {
|
||||
|
||||
override var id: UUID = UUID.randomUUID()
|
||||
private set
|
||||
|
||||
constructor(source: PwNodeIdUUID) : this(source.id)
|
||||
constructor(source: NodeIdUUID) : this(source.id)
|
||||
|
||||
@JvmOverloads
|
||||
constructor(uuid: UUID = UUID.randomUUID()) : super() {
|
||||
@@ -50,7 +50,7 @@ class PwNodeIdUUID : PwNodeId<UUID> {
|
||||
return true
|
||||
if (other == null)
|
||||
return false
|
||||
if (other !is PwNodeIdUUID) {
|
||||
if (other !is NodeIdUUID) {
|
||||
return false
|
||||
}
|
||||
return this.id == other.id
|
||||
@@ -66,12 +66,12 @@ class PwNodeIdUUID : PwNodeId<UUID> {
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<PwNodeIdUUID> = object : Parcelable.Creator<PwNodeIdUUID> {
|
||||
override fun createFromParcel(parcel: Parcel): PwNodeIdUUID {
|
||||
return PwNodeIdUUID(parcel)
|
||||
val CREATOR: Parcelable.Creator<NodeIdUUID> = object : Parcelable.Creator<NodeIdUUID> {
|
||||
override fun createFromParcel(parcel: Parcel): NodeIdUUID {
|
||||
return NodeIdUUID(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<PwNodeIdUUID?> {
|
||||
override fun newArray(size: Int): Array<NodeIdUUID?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,19 @@
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.node
|
||||
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
import org.joda.time.LocalDateTime
|
||||
|
||||
interface PwNodeV3Interface : NodeTimeInterface {
|
||||
interface NodeKDBInterface : NodeTimeInterface {
|
||||
|
||||
override var expires: Boolean
|
||||
// If expireDate is before NEVER_EXPIRE date less 1 month (to be sure)
|
||||
// it is not expires
|
||||
get() = LocalDateTime(expiryTime.date)
|
||||
.isBefore(LocalDateTime.fromDateFields(PwDate.NEVER_EXPIRE.date)
|
||||
.isBefore(LocalDateTime.fromDateFields(DateInstant.NEVER_EXPIRE.date)
|
||||
.minusMonths(1))
|
||||
set(value) {
|
||||
if (!value)
|
||||
expiryTime = PwDate.NEVER_EXPIRE
|
||||
expiryTime = DateInstant.NEVER_EXPIRE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,15 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.node
|
||||
|
||||
interface PwNodeV4Interface : NodeTimeInterface {
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
|
||||
interface NodeKDBXInterface : NodeTimeInterface {
|
||||
|
||||
var usageCount: Long
|
||||
|
||||
var locationChanged: PwDate
|
||||
var locationChanged: DateInstant
|
||||
|
||||
fun putCustomData(key: String, value: String)
|
||||
|
||||
@@ -17,17 +17,19 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.node
|
||||
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
|
||||
interface NodeTimeInterface {
|
||||
|
||||
var creationTime: PwDate
|
||||
var creationTime: DateInstant
|
||||
|
||||
var lastModificationTime: PwDate
|
||||
var lastModificationTime: DateInstant
|
||||
|
||||
var lastAccessTime: PwDate
|
||||
var lastAccessTime: DateInstant
|
||||
|
||||
var expiryTime: PwDate
|
||||
var expiryTime: DateInstant
|
||||
|
||||
var expires: Boolean
|
||||
|
||||
@@ -18,18 +18,24 @@
|
||||
*
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.node
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryVersionedInterface
|
||||
import com.kunzisoft.keepass.database.element.group.GroupVersionedInterface
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
|
||||
import org.joda.time.LocalDateTime
|
||||
|
||||
/**
|
||||
* Abstract class who manage Groups and Entries
|
||||
*/
|
||||
abstract class PwNode<IdType, Parent : PwGroupInterface<Parent, Entry>, Entry : PwEntryInterface<Parent>> : PwNodeInterface<Parent>, Parcelable {
|
||||
abstract class NodeVersioned<IdType, Parent : GroupVersionedInterface<Parent, Entry>, Entry : EntryVersionedInterface<Parent>>
|
||||
: NodeVersionedInterface<Parent>, NodeTimeInterface, Parcelable {
|
||||
|
||||
var nodeId: PwNodeId<IdType> = this.initNodeId()
|
||||
var nodeId: NodeId<IdType> = this.initNodeId()
|
||||
|
||||
val id: IdType
|
||||
get() = nodeId.id
|
||||
@@ -37,13 +43,13 @@ abstract class PwNode<IdType, Parent : PwGroupInterface<Parent, Entry>, Entry :
|
||||
protected constructor()
|
||||
|
||||
protected constructor(parcel: Parcel) {
|
||||
this.nodeId = parcel.readParcelable(PwNodeId::class.java.classLoader) ?: nodeId
|
||||
this.nodeId = parcel.readParcelable(NodeId::class.java.classLoader) ?: nodeId
|
||||
this.parent = this.readParentParcelable(parcel)
|
||||
this.icon = parcel.readParcelable(PwIcon::class.java.classLoader) ?: icon
|
||||
this.creationTime = parcel.readParcelable(PwDate::class.java.classLoader) ?: creationTime
|
||||
this.lastModificationTime = parcel.readParcelable(PwDate::class.java.classLoader) ?: lastModificationTime
|
||||
this.lastAccessTime = parcel.readParcelable(PwDate::class.java.classLoader) ?: lastAccessTime
|
||||
this.expiryTime = parcel.readParcelable(PwDate::class.java.classLoader) ?: expiryTime
|
||||
this.icon = parcel.readParcelable(IconImage::class.java.classLoader) ?: icon
|
||||
this.creationTime = parcel.readParcelable(DateInstant::class.java.classLoader) ?: creationTime
|
||||
this.lastModificationTime = parcel.readParcelable(DateInstant::class.java.classLoader) ?: lastModificationTime
|
||||
this.lastAccessTime = parcel.readParcelable(DateInstant::class.java.classLoader) ?: lastAccessTime
|
||||
this.expiryTime = parcel.readParcelable(DateInstant::class.java.classLoader) ?: expiryTime
|
||||
this.expires = parcel.readByte().toInt() != 0
|
||||
}
|
||||
|
||||
@@ -62,33 +68,33 @@ abstract class PwNode<IdType, Parent : PwGroupInterface<Parent, Entry>, Entry :
|
||||
return 0
|
||||
}
|
||||
|
||||
protected fun updateWith(source: PwNode<IdType, Parent, Entry>) {
|
||||
protected fun updateWith(source: NodeVersioned<IdType, Parent, Entry>) {
|
||||
this.nodeId = copyNodeId(source.nodeId)
|
||||
this.parent = source.parent
|
||||
this.icon = source.icon
|
||||
this.creationTime = PwDate(source.creationTime)
|
||||
this.lastModificationTime = PwDate(source.lastModificationTime)
|
||||
this.lastAccessTime = PwDate(source.lastAccessTime)
|
||||
this.expiryTime = PwDate(source.expiryTime)
|
||||
this.creationTime = DateInstant(source.creationTime)
|
||||
this.lastModificationTime = DateInstant(source.lastModificationTime)
|
||||
this.lastAccessTime = DateInstant(source.lastAccessTime)
|
||||
this.expiryTime = DateInstant(source.expiryTime)
|
||||
this.expires = source.expires
|
||||
}
|
||||
|
||||
protected abstract fun initNodeId(): PwNodeId<IdType>
|
||||
protected abstract fun copyNodeId(nodeId: PwNodeId<IdType>): PwNodeId<IdType>
|
||||
protected abstract fun initNodeId(): NodeId<IdType>
|
||||
protected abstract fun copyNodeId(nodeId: NodeId<IdType>): NodeId<IdType>
|
||||
protected abstract fun readParentParcelable(parcel: Parcel): Parent?
|
||||
protected abstract fun writeParentParcelable(parent: Parent?, parcel: Parcel, flags: Int)
|
||||
|
||||
final override var parent: Parent? = null
|
||||
|
||||
override var icon: PwIcon = PwIconStandard()
|
||||
override var icon: IconImage = IconImageStandard()
|
||||
|
||||
final override var creationTime: PwDate = PwDate()
|
||||
final override var creationTime: DateInstant = DateInstant()
|
||||
|
||||
final override var lastModificationTime: PwDate = PwDate()
|
||||
final override var lastModificationTime: DateInstant = DateInstant()
|
||||
|
||||
final override var lastAccessTime: PwDate = PwDate()
|
||||
final override var lastAccessTime: DateInstant = DateInstant()
|
||||
|
||||
final override var expiryTime: PwDate = PwDate()
|
||||
final override var expiryTime: DateInstant = DateInstant.NEVER_EXPIRE
|
||||
|
||||
final override val isCurrentlyExpires: Boolean
|
||||
get() = expires
|
||||
@@ -117,7 +123,7 @@ abstract class PwNode<IdType, Parent : PwGroupInterface<Parent, Entry>, Entry :
|
||||
}
|
||||
|
||||
override fun touch(modified: Boolean, touchParents: Boolean) {
|
||||
val now = PwDate()
|
||||
val now = DateInstant()
|
||||
lastAccessTime = now
|
||||
|
||||
if (modified) {
|
||||
@@ -134,7 +140,7 @@ abstract class PwNode<IdType, Parent : PwGroupInterface<Parent, Entry>, Entry :
|
||||
return true
|
||||
if (other == null)
|
||||
return false
|
||||
if (other !is PwNode<*, *, *>) {
|
||||
if (other !is NodeVersioned<*, *, *>) {
|
||||
return false
|
||||
}
|
||||
return type == other.type && nodeId == other.nodeId
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.node
|
||||
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
|
||||
interface PwNodeInterface<ParentGroup> : NodeTimeInterface, Parcelable {
|
||||
interface NodeVersionedInterface<ParentGroup> : NodeTimeInterface, Parcelable {
|
||||
|
||||
var title: String
|
||||
|
||||
/**
|
||||
* @return Visual icon
|
||||
*/
|
||||
var icon: PwIcon
|
||||
var icon: IconImage
|
||||
|
||||
/**
|
||||
* @return Type of Node
|
||||
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright 2018 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element.security
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseKDBX.Companion.BUFFER_SIZE_BYTES
|
||||
import com.kunzisoft.keepass.stream.ReadBytes
|
||||
import com.kunzisoft.keepass.stream.readFromStream
|
||||
import java.io.*
|
||||
import java.util.zip.GZIPInputStream
|
||||
import java.util.zip.GZIPOutputStream
|
||||
|
||||
class BinaryAttachment : Parcelable {
|
||||
|
||||
var isCompressed: Boolean? = null
|
||||
private set
|
||||
var isProtected: Boolean = false
|
||||
private set
|
||||
private var dataFile: File? = null
|
||||
|
||||
fun length(): Long {
|
||||
if (dataFile != null)
|
||||
return dataFile!!.length()
|
||||
return 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty protected binary
|
||||
*/
|
||||
constructor() {
|
||||
this.isCompressed = null
|
||||
this.isProtected = false
|
||||
this.dataFile = null
|
||||
}
|
||||
|
||||
constructor(dataFile: File, enableProtection: Boolean = false, compressed: Boolean? = null) {
|
||||
this.isCompressed = compressed
|
||||
this.isProtected = enableProtection
|
||||
this.dataFile = dataFile
|
||||
}
|
||||
|
||||
private constructor(parcel: Parcel) {
|
||||
val compressedByte = parcel.readByte().toInt()
|
||||
isCompressed = if (compressedByte == 2) null else compressedByte != 0
|
||||
isProtected = parcel.readByte().toInt() != 0
|
||||
dataFile = File(parcel.readString())
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun getInputDataStream(): InputStream {
|
||||
return when {
|
||||
dataFile != null -> FileInputStream(dataFile!!)
|
||||
else -> ByteArrayInputStream(ByteArray(0))
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun compress() {
|
||||
if (dataFile != null) {
|
||||
// To compress, create a new binary with file
|
||||
if (isCompressed != true) {
|
||||
val fileBinaryCompress = File(dataFile!!.parent, dataFile!!.name + "_temp")
|
||||
val outputStream = GZIPOutputStream(FileOutputStream(fileBinaryCompress))
|
||||
readFromStream(getInputDataStream(), BUFFER_SIZE_BYTES,
|
||||
object : ReadBytes {
|
||||
override fun read(buffer: ByteArray) {
|
||||
outputStream.write(buffer)
|
||||
}
|
||||
})
|
||||
outputStream.close()
|
||||
|
||||
// Remove unGzip file
|
||||
if (dataFile!!.delete()) {
|
||||
if (fileBinaryCompress.renameTo(dataFile)) {
|
||||
// Harmonize with database compression
|
||||
isCompressed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun decompress() {
|
||||
if (dataFile != null) {
|
||||
if (isCompressed != false) {
|
||||
val fileBinaryDecompress = File(dataFile!!.parent, dataFile!!.name + "_temp")
|
||||
val outputStream = FileOutputStream(fileBinaryDecompress)
|
||||
readFromStream(GZIPInputStream(getInputDataStream()), BUFFER_SIZE_BYTES,
|
||||
object : ReadBytes {
|
||||
override fun read(buffer: ByteArray) {
|
||||
outputStream.write(buffer)
|
||||
}
|
||||
})
|
||||
outputStream.close()
|
||||
|
||||
// Remove gzip file
|
||||
if (dataFile!!.delete()) {
|
||||
if (fileBinaryDecompress.renameTo(dataFile)) {
|
||||
// Harmonize with database compression
|
||||
isCompressed = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun clear() {
|
||||
if (dataFile != null && !dataFile!!.delete())
|
||||
throw IOException("Unable to delete temp file " + dataFile!!.absolutePath)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other)
|
||||
return true
|
||||
if (other == null || javaClass != other.javaClass)
|
||||
return false
|
||||
if (other !is BinaryAttachment)
|
||||
return false
|
||||
|
||||
var sameData = false
|
||||
if (dataFile != null && dataFile == other.dataFile)
|
||||
sameData = true
|
||||
|
||||
return isCompressed == other.isCompressed
|
||||
&& isProtected == other.isProtected
|
||||
&& sameData
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
|
||||
var result = 0
|
||||
result = 31 * result + if (isCompressed == null) 2 else if (isCompressed!!) 1 else 0
|
||||
result = 31 * result + if (isProtected) 1 else 0
|
||||
result = 31 * result + dataFile!!.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||
dest.writeByte((if (isCompressed == null) 2 else if (isCompressed!!) 1 else 0).toByte())
|
||||
dest.writeByte((if (isProtected) 1 else 0).toByte())
|
||||
dest.writeString(dataFile?.absolutePath)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private val TAG = BinaryAttachment::class.java.name
|
||||
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<BinaryAttachment> = object : Parcelable.Creator<BinaryAttachment> {
|
||||
override fun createFromParcel(parcel: Parcel): BinaryAttachment {
|
||||
return BinaryAttachment(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<BinaryAttachment?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.security
|
||||
|
||||
import android.content.res.Resources
|
||||
|
||||
@@ -30,7 +30,7 @@ import com.kunzisoft.keepass.utils.ObjectNameResource
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
enum class PwEncryptionAlgorithm : ObjectNameResource {
|
||||
enum class EncryptionAlgorithm : ObjectNameResource {
|
||||
|
||||
AESRijndael,
|
||||
Twofish,
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element
|
||||
package com.kunzisoft.keepass.database.element.security
|
||||
|
||||
class MemoryProtectionConfig {
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element.security
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import android.util.Log
|
||||
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.util.Arrays
|
||||
|
||||
class ProtectedBinary : Parcelable {
|
||||
|
||||
var isProtected: Boolean = false
|
||||
private set
|
||||
private var data: ByteArray? = null
|
||||
private var dataFile: File? = null
|
||||
private var size: Int = 0
|
||||
|
||||
fun length(): Long {
|
||||
if (data != null)
|
||||
return data!!.size.toLong()
|
||||
return if (dataFile != null) size.toLong() else 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty protected binary
|
||||
*/
|
||||
constructor() {
|
||||
this.isProtected = false
|
||||
this.data = null
|
||||
this.dataFile = null
|
||||
this.size = 0
|
||||
}
|
||||
|
||||
constructor(protectedBinary: ProtectedBinary) {
|
||||
this.isProtected = protectedBinary.isProtected
|
||||
this.data = protectedBinary.data
|
||||
this.dataFile = protectedBinary.dataFile
|
||||
this.size = protectedBinary.size
|
||||
}
|
||||
|
||||
constructor(enableProtection: Boolean, data: ByteArray?) {
|
||||
this.isProtected = enableProtection
|
||||
this.data = data
|
||||
this.dataFile = null
|
||||
if (data != null)
|
||||
this.size = data.size
|
||||
else
|
||||
this.size = 0
|
||||
}
|
||||
|
||||
constructor(enableProtection: Boolean, dataFile: File, size: Int) {
|
||||
this.isProtected = enableProtection
|
||||
this.data = null
|
||||
this.dataFile = dataFile
|
||||
this.size = size
|
||||
}
|
||||
|
||||
private constructor(parcel: Parcel) {
|
||||
isProtected = parcel.readByte().toInt() != 0
|
||||
parcel.readByteArray(data)
|
||||
dataFile = File(parcel.readString())
|
||||
size = parcel.readInt()
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun getData(): InputStream? {
|
||||
return when {
|
||||
data != null -> ByteArrayInputStream(data)
|
||||
dataFile != null -> FileInputStream(dataFile!!)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
data = null
|
||||
if (dataFile != null && !dataFile!!.delete())
|
||||
Log.e(TAG, "Unable to delete temp file " + dataFile!!.absolutePath)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other)
|
||||
return true
|
||||
if (other == null || javaClass != other.javaClass)
|
||||
return false
|
||||
if (other !is ProtectedBinary)
|
||||
return false
|
||||
return isProtected == other.isProtected &&
|
||||
size == other.size &&
|
||||
Arrays.equals(data, other.data) &&
|
||||
dataFile != null &&
|
||||
dataFile == other.dataFile
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
|
||||
var result = 0
|
||||
result = 31 * result + if (isProtected) 1 else 0
|
||||
result = 31 * result + dataFile!!.hashCode()
|
||||
result = 31 * result + Integer.valueOf(size).hashCode()
|
||||
result = 31 * result + Arrays.hashCode(data)
|
||||
return result
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||
dest.writeByte((if (isProtected) 1 else 0).toByte())
|
||||
dest.writeByteArray(data)
|
||||
dest.writeString(dataFile!!.absolutePath)
|
||||
dest.writeInt(size)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private val TAG = ProtectedBinary::class.java.name
|
||||
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<ProtectedBinary> = object : Parcelable.Creator<ProtectedBinary> {
|
||||
override fun createFromParcel(parcel: Parcel): ProtectedBinary {
|
||||
return ProtectedBinary(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<ProtectedBinary?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,4 +19,4 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.exception
|
||||
|
||||
class SamsungClipboardException(e: Exception) : Exception(e)
|
||||
class ClipboardException(e: Exception) : Exception(e)
|
||||
@@ -3,8 +3,8 @@ package com.kunzisoft.keepass.database.exception
|
||||
import android.content.res.Resources
|
||||
import androidx.annotation.StringRes
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.element.PwNodeId
|
||||
import com.kunzisoft.keepass.database.element.Type
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
|
||||
abstract class DatabaseException : Exception {
|
||||
|
||||
@@ -12,7 +12,8 @@ abstract class DatabaseException : Exception {
|
||||
var parameters: (Array<out String>)? = null
|
||||
|
||||
constructor() : super()
|
||||
|
||||
constructor(message: String) : super(message)
|
||||
constructor(message: String, throwable: Throwable) : super(message, throwable)
|
||||
constructor(throwable: Throwable) : super(throwable)
|
||||
|
||||
fun getLocalizedMessage(resources: Resources): String {
|
||||
@@ -26,33 +27,25 @@ open class LoadDatabaseException : DatabaseException {
|
||||
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.error_load_database
|
||||
|
||||
constructor() : super()
|
||||
|
||||
constructor(vararg params: String) : super() {
|
||||
parameters = params
|
||||
}
|
||||
|
||||
constructor(throwable: Throwable) : super(throwable)
|
||||
}
|
||||
|
||||
class LoadDatabaseArcFourException : LoadDatabaseException {
|
||||
class ArcFourDatabaseException : LoadDatabaseException {
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.error_arc4
|
||||
|
||||
constructor() : super()
|
||||
constructor(exception: Throwable) : super(exception)
|
||||
}
|
||||
|
||||
class LoadDatabaseFileNotFoundException : LoadDatabaseException {
|
||||
class FileNotFoundDatabaseException : LoadDatabaseException {
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.file_not_found_content
|
||||
|
||||
constructor() : super()
|
||||
constructor(exception: Throwable) : super(exception)
|
||||
}
|
||||
|
||||
class LoadDatabaseInvalidAlgorithmException : LoadDatabaseException {
|
||||
class InvalidAlgorithmDatabaseException : LoadDatabaseException {
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.invalid_algorithm
|
||||
|
||||
@@ -60,102 +53,97 @@ class LoadDatabaseInvalidAlgorithmException : LoadDatabaseException {
|
||||
constructor(exception: Throwable) : super(exception)
|
||||
}
|
||||
|
||||
class LoadDatabaseDuplicateUuidException: LoadDatabaseException {
|
||||
class DuplicateUuidDatabaseException: LoadDatabaseException {
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.invalid_db_same_uuid
|
||||
|
||||
constructor(type: Type, uuid: PwNodeId<*>) : super() {
|
||||
constructor(type: Type, uuid: NodeId<*>) : super() {
|
||||
parameters = arrayOf(type.name, uuid.toString())
|
||||
}
|
||||
constructor(exception: Throwable) : super(exception)
|
||||
}
|
||||
|
||||
class LoadDatabaseIOException : LoadDatabaseException {
|
||||
class IODatabaseException : LoadDatabaseException {
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.error_load_database
|
||||
|
||||
constructor() : super()
|
||||
constructor(exception: Throwable) : super(exception)
|
||||
}
|
||||
|
||||
class LoadDatabaseKDFMemoryException : LoadDatabaseException {
|
||||
class KDFMemoryDatabaseException : LoadDatabaseException {
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.error_load_database_KDF_memory
|
||||
|
||||
constructor() : super()
|
||||
constructor(exception: Throwable) : super(exception)
|
||||
}
|
||||
|
||||
class LoadDatabaseSignatureException : LoadDatabaseException {
|
||||
class SignatureDatabaseException : LoadDatabaseException {
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.invalid_db_sig
|
||||
|
||||
constructor() : super()
|
||||
constructor(exception: Throwable) : super(exception)
|
||||
}
|
||||
|
||||
class LoadDatabaseVersionException : LoadDatabaseException {
|
||||
class VersionDatabaseException : LoadDatabaseException {
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.unsupported_db_version
|
||||
|
||||
constructor() : super()
|
||||
constructor(exception: Throwable) : super(exception)
|
||||
}
|
||||
|
||||
class LoadDatabaseInvalidCredentialsException : LoadDatabaseException {
|
||||
class InvalidCredentialsDatabaseException : LoadDatabaseException {
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.invalid_credentials
|
||||
|
||||
constructor() : super()
|
||||
constructor(exception: Throwable) : super(exception)
|
||||
}
|
||||
|
||||
class LoadDatabaseKeyFileEmptyException : LoadDatabaseException {
|
||||
class KeyFileEmptyDatabaseException : LoadDatabaseException {
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.keyfile_is_empty
|
||||
constructor() : super()
|
||||
constructor(exception: Throwable) : super(exception)
|
||||
}
|
||||
|
||||
class LoadDatabaseNoMemoryException: LoadDatabaseException {
|
||||
class NoMemoryDatabaseException: LoadDatabaseException {
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.error_out_of_memory
|
||||
constructor() : super()
|
||||
constructor(exception: Throwable) : super(exception)
|
||||
}
|
||||
|
||||
class MoveDatabaseEntryException: LoadDatabaseException {
|
||||
class EntryDatabaseException: LoadDatabaseException {
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.error_move_entry_here
|
||||
constructor() : super()
|
||||
constructor(exception: Throwable) : super(exception)
|
||||
}
|
||||
|
||||
class MoveDatabaseGroupException: LoadDatabaseException {
|
||||
class MoveGroupDatabaseException: LoadDatabaseException {
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.error_move_folder_in_itself
|
||||
constructor() : super()
|
||||
constructor(exception: Throwable) : super(exception)
|
||||
}
|
||||
|
||||
class CopyDatabaseEntryException: LoadDatabaseException {
|
||||
class CopyEntryDatabaseException: LoadDatabaseException {
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.error_copy_entry_here
|
||||
constructor() : super()
|
||||
constructor(exception: Throwable) : super(exception)
|
||||
}
|
||||
|
||||
class CopyDatabaseGroupException: LoadDatabaseException {
|
||||
class CopyGroupDatabaseException: LoadDatabaseException {
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.error_copy_group_here
|
||||
constructor() : super()
|
||||
constructor(exception: Throwable) : super(exception)
|
||||
}
|
||||
|
||||
class DatabaseOutputException : Exception {
|
||||
// TODO Output Exception
|
||||
open class DatabaseOutputException : DatabaseException {
|
||||
@StringRes
|
||||
override var errorId: Int = R.string.error_save_database
|
||||
constructor(string: String) : super(string)
|
||||
|
||||
constructor(string: String, e: Exception) : super(string, e)
|
||||
|
||||
constructor(e: Exception) : super(e)
|
||||
}
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.file
|
||||
|
||||
abstract class PwDbHeader {
|
||||
abstract class DatabaseHeader {
|
||||
|
||||
/**
|
||||
* Seed that gets hashed with the userkey to form the final key
|
||||
@@ -25,7 +25,7 @@ import com.kunzisoft.keepass.stream.LEDataInputStream
|
||||
|
||||
import java.io.IOException
|
||||
|
||||
class PwDbHeaderV3 : PwDbHeader() {
|
||||
class DatabaseHeaderKDB : DatabaseHeader() {
|
||||
|
||||
/**
|
||||
* Used for the dwKeyEncRounds AES transformations
|
||||
@@ -23,13 +23,17 @@ import com.kunzisoft.keepass.crypto.CrsAlgorithm
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.AesKdf
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfParameters
|
||||
import com.kunzisoft.keepass.database.NodeHandler
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.database.exception.LoadDatabaseVersionException
|
||||
import com.kunzisoft.keepass.database.action.node.NodeHandler
|
||||
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseKDBX
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryKDBX
|
||||
import com.kunzisoft.keepass.database.element.group.GroupKDBX
|
||||
import com.kunzisoft.keepass.database.element.node.NodeKDBXInterface
|
||||
import com.kunzisoft.keepass.database.exception.VersionDatabaseException
|
||||
import com.kunzisoft.keepass.stream.CopyInputStream
|
||||
import com.kunzisoft.keepass.stream.HmacBlockStream
|
||||
import com.kunzisoft.keepass.stream.LEDataInputStream
|
||||
import com.kunzisoft.keepass.utils.Types
|
||||
import com.kunzisoft.keepass.utils.DatabaseInputOutputUtils
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
@@ -40,7 +44,7 @@ import java.security.NoSuchAlgorithmException
|
||||
import javax.crypto.Mac
|
||||
import javax.crypto.spec.SecretKeySpec
|
||||
|
||||
class PwDbHeaderV4(private val databaseV4: PwDatabaseV4) : PwDbHeader() {
|
||||
class DatabaseHeaderKDBX(private val databaseV4: DatabaseKDBX) : DatabaseHeader() {
|
||||
var innerRandomStreamKey: ByteArray = ByteArray(32)
|
||||
var streamStartBytes: ByteArray = ByteArray(32)
|
||||
var innerRandomStream: CrsAlgorithm? = null
|
||||
@@ -89,7 +93,7 @@ class PwDbHeaderV4(private val databaseV4: PwDatabaseV4) : PwDbHeader() {
|
||||
this.masterSeed = ByteArray(32)
|
||||
}
|
||||
|
||||
private inner class NodeHasCustomData<T:PwNodeV4Interface> : NodeHandler<T>() {
|
||||
private inner class NodeHasCustomData<T: NodeKDBXInterface> : NodeHandler<T>() {
|
||||
|
||||
internal var containsCustomData = false
|
||||
|
||||
@@ -102,7 +106,7 @@ class PwDbHeaderV4(private val databaseV4: PwDatabaseV4) : PwDbHeader() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getMinKdbxVersion(databaseV4: PwDatabaseV4): Long {
|
||||
private fun getMinKdbxVersion(databaseV4: DatabaseKDBX): Long {
|
||||
// https://keepass.info/help/kb/kdbx_4.html
|
||||
|
||||
// Return v4 if AES is not use
|
||||
@@ -115,8 +119,8 @@ class PwDbHeaderV4(private val databaseV4: PwDatabaseV4) : PwDbHeader() {
|
||||
return FILE_VERSION_32_3
|
||||
}
|
||||
|
||||
val entryHandler = NodeHasCustomData<PwEntryV4>()
|
||||
val groupHandler = NodeHasCustomData<PwGroupV4>()
|
||||
val entryHandler = NodeHasCustomData<EntryKDBX>()
|
||||
val groupHandler = NodeHasCustomData<GroupKDBX>()
|
||||
databaseV4.rootGroup?.doForEachChildAndForIt(entryHandler, groupHandler)
|
||||
return if (databaseV4.containsCustomData()
|
||||
|| entryHandler.containsCustomData
|
||||
@@ -130,9 +134,9 @@ class PwDbHeaderV4(private val databaseV4: PwDatabaseV4) : PwDbHeader() {
|
||||
/** Assumes the input stream is at the beginning of the .kdbx file
|
||||
* @param inputStream
|
||||
* @throws IOException
|
||||
* @throws LoadDatabaseVersionException
|
||||
* @throws VersionDatabaseException
|
||||
*/
|
||||
@Throws(IOException::class, LoadDatabaseVersionException::class)
|
||||
@Throws(IOException::class, VersionDatabaseException::class)
|
||||
fun loadFromFile(inputStream: InputStream): HeaderAndHash {
|
||||
val messageDigest: MessageDigest
|
||||
try {
|
||||
@@ -150,12 +154,12 @@ class PwDbHeaderV4(private val databaseV4: PwDatabaseV4) : PwDbHeader() {
|
||||
val sig2 = littleEndianDataInputStream.readInt()
|
||||
|
||||
if (!matchesHeader(sig1, sig2)) {
|
||||
throw LoadDatabaseVersionException()
|
||||
throw VersionDatabaseException()
|
||||
}
|
||||
|
||||
version = littleEndianDataInputStream.readUInt() // Erase previous value
|
||||
if (!validVersion(version)) {
|
||||
throw LoadDatabaseVersionException()
|
||||
throw VersionDatabaseException()
|
||||
}
|
||||
|
||||
var done = false
|
||||
@@ -216,7 +220,7 @@ class PwDbHeaderV4(private val databaseV4: PwDatabaseV4) : PwDbHeader() {
|
||||
PwDbHeaderV4Fields.KdfParameters -> databaseV4.kdfParameters = KdfParameters.deserialize(fieldData)
|
||||
|
||||
PwDbHeaderV4Fields.PublicCustomData -> {
|
||||
databaseV4.publicCustomData = KdfParameters.deserialize(fieldData) // TODO verify
|
||||
databaseV4.publicCustomData = KdfParameters.deserialize(fieldData)!! // TODO verify
|
||||
throw IOException("Invalid header type: $fieldID")
|
||||
}
|
||||
else -> throw IOException("Invalid header type: $fieldID")
|
||||
@@ -239,7 +243,7 @@ class PwDbHeaderV4(private val databaseV4: PwDatabaseV4) : PwDbHeader() {
|
||||
throw IOException("Invalid cipher ID.")
|
||||
}
|
||||
|
||||
databaseV4.dataCipher = Types.bytestoUUID(pbId)
|
||||
databaseV4.dataCipher = DatabaseInputOutputUtils.bytesToUuid(pbId)
|
||||
}
|
||||
|
||||
private fun setTransformRound(roundsByte: ByteArray?) {
|
||||
@@ -256,7 +260,7 @@ class PwDbHeaderV4(private val databaseV4: PwDatabaseV4) : PwDbHeader() {
|
||||
}
|
||||
|
||||
val flag = LEDataInputStream.readInt(pbFlags, 0)
|
||||
if (flag < 0 || flag >= PwCompressionAlgorithm.values().size) {
|
||||
if (flag < 0 || flag >= CompressionAlgorithm.values().size) {
|
||||
throw IOException("Unrecognized compression flag.")
|
||||
}
|
||||
|
||||
@@ -298,17 +302,17 @@ class PwDbHeaderV4(private val databaseV4: PwDatabaseV4) : PwDbHeader() {
|
||||
const val FILE_VERSION_32_3: Long = 0x00030001
|
||||
const val FILE_VERSION_32_4: Long = 0x00040000
|
||||
|
||||
fun getCompressionFromFlag(flag: Int): PwCompressionAlgorithm? {
|
||||
fun getCompressionFromFlag(flag: Int): CompressionAlgorithm? {
|
||||
return when (flag) {
|
||||
0 -> PwCompressionAlgorithm.None
|
||||
1 -> PwCompressionAlgorithm.GZip
|
||||
0 -> CompressionAlgorithm.None
|
||||
1 -> CompressionAlgorithm.GZip
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
fun getFlagFromCompression(compression: PwCompressionAlgorithm): Int {
|
||||
fun getFlagFromCompression(compression: CompressionAlgorithm): Int {
|
||||
return when (compression) {
|
||||
PwCompressionAlgorithm.GZip -> 1
|
||||
CompressionAlgorithm.GZip -> 1
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
@@ -319,7 +323,7 @@ class PwDbHeaderV4(private val databaseV4: PwDatabaseV4) : PwDbHeader() {
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun computeHeaderHmac(header: ByteArray, key: ByteArray): ByteArray {
|
||||
val blockKey = HmacBlockStream.GetHmacKey64(key, Types.ULONG_MAX_VALUE)
|
||||
val blockKey = HmacBlockStream.GetHmacKey64(key, DatabaseInputOutputUtils.ULONG_MAX_VALUE)
|
||||
|
||||
val hmac: Mac
|
||||
try {
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user