mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-26 20:06:37 -08:00
fix: Refactoring Credential Provider
This commit is contained in:
59 files changed
+2495
-1896
No files matched your search
@@ -55,6 +55,7 @@ import com.kunzisoft.keepass.database.merge.DatabaseKDBXMerger
|
||||
import com.kunzisoft.keepass.database.search.SearchHelper
|
||||
import com.kunzisoft.keepass.database.search.SearchParameters
|
||||
import com.kunzisoft.keepass.hardware.HardwareKey
|
||||
import com.kunzisoft.keepass.model.SearchInfo
|
||||
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater
|
||||
import com.kunzisoft.keepass.utils.SingletonHolder
|
||||
import com.kunzisoft.keepass.utils.StringUtil.toFormattedColorInt
|
||||
@@ -885,28 +886,15 @@ open class Database {
|
||||
}
|
||||
|
||||
fun createVirtualGroupFromSearchInfo(
|
||||
searchInfoString: String,
|
||||
searchInfoByDomain: Boolean,
|
||||
searchInfo: SearchInfo,
|
||||
max: Int = Integer.MAX_VALUE
|
||||
): Group? {
|
||||
return mSearchHelper.createVirtualGroupWithSearchResult(this,
|
||||
SearchParameters().apply {
|
||||
searchQuery = searchInfoString
|
||||
searchInTitles = true
|
||||
searchInUsernames = false
|
||||
searchInPasswords = false
|
||||
searchInUrls = true
|
||||
searchByDomain = searchInfoByDomain
|
||||
searchInNotes = true
|
||||
searchInOTP = false
|
||||
searchInOther = true
|
||||
searchInUUIDs = false
|
||||
searchInTags = false
|
||||
searchInCurrentGroup = false
|
||||
searchInSearchableGroup = true
|
||||
searchInRecycleBin = false
|
||||
searchInTemplates = false
|
||||
}, null, max)
|
||||
return mSearchHelper.createVirtualGroupWithSearchResult(
|
||||
database = this,
|
||||
searchParameters = searchInfo.buildSearchParameters(),
|
||||
fromGroup = null,
|
||||
max = max
|
||||
)
|
||||
}
|
||||
|
||||
val tagPool: Tags
|
||||
|
||||
@@ -49,6 +49,10 @@ class Tags: Parcelable {
|
||||
}
|
||||
}
|
||||
|
||||
fun contains(tag: String): Boolean {
|
||||
return mTags.contains(tag)
|
||||
}
|
||||
|
||||
fun isEmpty(): Boolean {
|
||||
return mTags.isEmpty()
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.kunzisoft.keepass.database.element.Entry
|
||||
import com.kunzisoft.keepass.database.element.Group
|
||||
import com.kunzisoft.keepass.database.element.node.NodeHandler
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.model.EntryInfoPasskey.FIELD_RELYING_PARTY
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_FIELD
|
||||
import com.kunzisoft.keepass.utils.UuidUtil
|
||||
import com.kunzisoft.keepass.utils.inTheSameDomainAs
|
||||
@@ -171,8 +172,10 @@ class SearchHelper {
|
||||
}
|
||||
if (searchParameters.searchInOther) {
|
||||
entry.getExtraFields().forEach { field ->
|
||||
if (field.name != OTP_FIELD
|
||||
|| (field.name == OTP_FIELD && searchParameters.searchInOTP)) {
|
||||
if ( (field.name != OTP_FIELD && field.name != FIELD_RELYING_PARTY)
|
||||
|| (searchParameters.searchInOTP && field.name == OTP_FIELD)
|
||||
|| (searchParameters.searchInRelyingParty && field.name == FIELD_RELYING_PARTY)
|
||||
) {
|
||||
if (checkSearchQuery(field.protectedValue.toString(), searchParameters))
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ class SearchParameters() : Parcelable{
|
||||
var searchInExpired = false
|
||||
var searchInNotes = true
|
||||
var searchInOTP = false
|
||||
var searchInRelyingParty = false
|
||||
var searchInOther = true
|
||||
var searchInUUIDs = false
|
||||
var searchInTags = false
|
||||
|
||||
@@ -22,10 +22,15 @@ package com.kunzisoft.keepass.model
|
||||
import android.os.Parcel
|
||||
import android.os.ParcelUuid
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.database.element.Attachment
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
import com.kunzisoft.keepass.database.element.Field
|
||||
import com.kunzisoft.keepass.database.element.Tags
|
||||
import com.kunzisoft.keepass.database.element.entry.AutoType
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
import com.kunzisoft.keepass.database.element.template.TemplateField
|
||||
import com.kunzisoft.keepass.model.EntryInfoPasskey.setPasskey
|
||||
import com.kunzisoft.keepass.otp.OtpElement
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_TOKEN_FIELD
|
||||
@@ -33,7 +38,8 @@ import com.kunzisoft.keepass.utils.readBooleanCompat
|
||||
import com.kunzisoft.keepass.utils.readListCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.writeBooleanCompat
|
||||
import java.util.*
|
||||
import java.util.Locale
|
||||
import java.util.UUID
|
||||
|
||||
class EntryInfo : NodeInfo {
|
||||
|
||||
@@ -113,6 +119,14 @@ class EntryInfo : NodeInfo {
|
||||
return customFields.lastOrNull { it.name == label }?.protectedValue?.toString() ?: ""
|
||||
}
|
||||
|
||||
fun addOrReplaceField(field: Field) {
|
||||
customFields.lastOrNull { it.name == field.name }?.let {
|
||||
it.apply {
|
||||
protectedValue = field.protectedValue
|
||||
}
|
||||
} ?: customFields.add(field)
|
||||
}
|
||||
|
||||
// Return true if modified
|
||||
private fun addUniqueField(field: Field, number: Int = 0) {
|
||||
var sameName = false
|
||||
@@ -226,6 +240,7 @@ class EntryInfo : NodeInfo {
|
||||
}
|
||||
|
||||
if (database?.allowEntryCustomFields() == true) {
|
||||
// TODO Move in a dedicated creditcard class
|
||||
val creditCard: CreditCard? = registerInfo.creditCard
|
||||
creditCard?.cardholder?.let {
|
||||
addUniqueField(Field(TemplateField.LABEL_HOLDER, ProtectedString(false, it)))
|
||||
@@ -240,6 +255,9 @@ class EntryInfo : NodeInfo {
|
||||
creditCard?.cvv?.let {
|
||||
addUniqueField(Field(TemplateField.LABEL_CVV, ProtectedString(true, it)))
|
||||
}
|
||||
registerInfo.passkey?.let {
|
||||
setPasskey(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.kunzisoft.keepass.model
|
||||
|
||||
import com.kunzisoft.keepass.database.element.Field
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
|
||||
object EntryInfoPasskey {
|
||||
|
||||
// field names from KeypassXC are used
|
||||
private const val FIELD_USERNAME = "KPEX_PASSKEY_USERNAME"
|
||||
private const val FIELD_PRIVATE_KEY = "KPEX_PASSKEY_PRIVATE_KEY_PEM"
|
||||
private const val FIELD_CREDENTIAL_ID = "KPEX_PASSKEY_CREDENTIAL_ID"
|
||||
private const val FIELD_USER_HANDLE = "KPEX_PASSKEY_USER_HANDLE"
|
||||
const val FIELD_RELYING_PARTY = "KPEX_PASSKEY_RELYING_PARTY"
|
||||
|
||||
private const val PASSKEY_TAG = "Passkey"
|
||||
|
||||
fun EntryInfo.getPasskey(): Passkey? {
|
||||
if (this.tags.toList().contains(PASSKEY_TAG).not()) {
|
||||
return null
|
||||
}
|
||||
var username = ""
|
||||
var privateKeyPem = ""
|
||||
var credId = ""
|
||||
var userHandle = ""
|
||||
var relyingParty = ""
|
||||
for (field in this.customFields) {
|
||||
when (field.name) {
|
||||
FIELD_USERNAME -> {
|
||||
username = field.protectedValue.stringValue
|
||||
}
|
||||
FIELD_PRIVATE_KEY -> {
|
||||
privateKeyPem = field.protectedValue.stringValue
|
||||
}
|
||||
FIELD_CREDENTIAL_ID -> {
|
||||
credId = field.protectedValue.stringValue
|
||||
}
|
||||
FIELD_USER_HANDLE -> {
|
||||
userHandle = field.protectedValue.stringValue
|
||||
}
|
||||
FIELD_RELYING_PARTY -> {
|
||||
relyingParty = field.protectedValue.stringValue
|
||||
}
|
||||
}
|
||||
}
|
||||
return Passkey(
|
||||
username = username,
|
||||
displayName = this.getVisualTitle(),
|
||||
privateKeyPem = privateKeyPem,
|
||||
credentialId = credId,
|
||||
userHandle = userHandle,
|
||||
relyingParty = relyingParty
|
||||
)
|
||||
}
|
||||
|
||||
fun EntryInfo.setPasskey(passkey: Passkey) {
|
||||
tags.put(PASSKEY_TAG)
|
||||
title = passkey.displayName
|
||||
username = passkey.username
|
||||
url = passkey.relyingParty
|
||||
addOrReplaceField(
|
||||
Field(
|
||||
FIELD_USERNAME,
|
||||
ProtectedString(enableProtection = false, passkey.username)
|
||||
)
|
||||
)
|
||||
addOrReplaceField(
|
||||
Field(
|
||||
FIELD_PRIVATE_KEY,
|
||||
ProtectedString(enableProtection = true, passkey.privateKeyPem)
|
||||
)
|
||||
)
|
||||
addOrReplaceField(
|
||||
Field(
|
||||
FIELD_CREDENTIAL_ID,
|
||||
ProtectedString(enableProtection = true, passkey.credentialId)
|
||||
)
|
||||
)
|
||||
addOrReplaceField(
|
||||
Field(
|
||||
FIELD_USER_HANDLE,
|
||||
ProtectedString(enableProtection = true, passkey.userHandle)
|
||||
)
|
||||
)
|
||||
addOrReplaceField(
|
||||
Field(
|
||||
FIELD_RELYING_PARTY,
|
||||
ProtectedString(enableProtection = false, passkey.relyingParty)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.kunzisoft.keepass.model
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class Passkey(
|
||||
val username: String,
|
||||
val displayName: String,
|
||||
val privateKeyPem: String,
|
||||
val credentialId: String,
|
||||
val userHandle: String,
|
||||
val relyingParty: String,
|
||||
): Parcelable
|
||||
@@ -4,15 +4,19 @@ import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
|
||||
data class RegisterInfo(val searchInfo: SearchInfo,
|
||||
val username: String?,
|
||||
val password: String?,
|
||||
val creditCard: CreditCard?): Parcelable {
|
||||
data class RegisterInfo(
|
||||
val searchInfo: SearchInfo,
|
||||
val username: String?,
|
||||
val password: String? = null,
|
||||
val creditCard: CreditCard? = null,
|
||||
val passkey: Passkey? = null
|
||||
): Parcelable {
|
||||
|
||||
constructor(parcel: Parcel) : this(
|
||||
parcel.readParcelableCompat() ?: SearchInfo(),
|
||||
parcel.readString() ?: "",
|
||||
parcel.readString() ?: "",
|
||||
parcel.readParcelableCompat(),
|
||||
parcel.readParcelableCompat()) {
|
||||
}
|
||||
|
||||
@@ -21,6 +25,7 @@ data class RegisterInfo(val searchInfo: SearchInfo,
|
||||
parcel.writeString(username)
|
||||
parcel.writeString(password)
|
||||
parcel.writeParcelable(creditCard, flags)
|
||||
parcel.writeParcelable(passkey, flags)
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.res.Resources
|
||||
import android.net.Uri
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.search.SearchParameters
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields
|
||||
import com.kunzisoft.keepass.utils.ObjectNameResource
|
||||
import com.kunzisoft.keepass.utils.readBooleanCompat
|
||||
@@ -33,6 +34,7 @@ class SearchInfo : ObjectNameResource, Parcelable {
|
||||
get() {
|
||||
return if (webDomain == null) null else field
|
||||
}
|
||||
var relyingParty: String? = null
|
||||
var otpString: String? = null
|
||||
|
||||
constructor()
|
||||
@@ -42,6 +44,7 @@ class SearchInfo : ObjectNameResource, Parcelable {
|
||||
applicationId = toCopy?.applicationId
|
||||
webDomain = toCopy?.webDomain
|
||||
webScheme = toCopy?.webScheme
|
||||
relyingParty = toCopy?.relyingParty
|
||||
otpString = toCopy?.otpString
|
||||
}
|
||||
|
||||
@@ -53,6 +56,8 @@ class SearchInfo : ObjectNameResource, Parcelable {
|
||||
webDomain = if (readDomain.isNullOrEmpty()) null else readDomain
|
||||
val readScheme = parcel.readString()
|
||||
webScheme = if (readScheme.isNullOrEmpty()) null else readScheme
|
||||
val readRelyingParty = parcel.readString()
|
||||
relyingParty = if (readRelyingParty.isNullOrEmpty()) null else readRelyingParty
|
||||
val readOtp = parcel.readString()
|
||||
otpString = if (readOtp.isNullOrEmpty()) null else readOtp
|
||||
}
|
||||
@@ -66,6 +71,7 @@ class SearchInfo : ObjectNameResource, Parcelable {
|
||||
parcel.writeString(applicationId ?: "")
|
||||
parcel.writeString(webDomain ?: "")
|
||||
parcel.writeString(webScheme ?: "")
|
||||
parcel.writeString(relyingParty ?: "")
|
||||
parcel.writeString(otpString ?: "")
|
||||
}
|
||||
|
||||
@@ -82,12 +88,55 @@ class SearchInfo : ObjectNameResource, Parcelable {
|
||||
return applicationId == null
|
||||
&& webDomain == null
|
||||
&& webScheme == null
|
||||
&& relyingParty == null
|
||||
&& otpString == null
|
||||
}
|
||||
|
||||
fun isASearchByDomain(): Boolean {
|
||||
private fun isASearchByDomain(): Boolean {
|
||||
return toString() == webDomain && webDomain != null
|
||||
}
|
||||
}
|
||||
|
||||
private fun isAPasskeySearch(): Boolean {
|
||||
return toString() == relyingParty && relyingParty != null
|
||||
}
|
||||
|
||||
fun buildSearchParameters(): SearchParameters {
|
||||
return SearchParameters().apply {
|
||||
if (isAPasskeySearch()) {
|
||||
searchQuery = toString()
|
||||
searchInTitles = false
|
||||
searchInUsernames = false
|
||||
searchInPasswords = false
|
||||
searchInUrls = false
|
||||
searchInNotes = false
|
||||
searchInOTP = false
|
||||
searchInOther = false
|
||||
searchInUUIDs = false
|
||||
searchInTags = false
|
||||
searchInRelyingParty = true
|
||||
searchInCurrentGroup = false
|
||||
searchInSearchableGroup = false
|
||||
searchInRecycleBin = false
|
||||
searchInTemplates = false
|
||||
} else {
|
||||
searchQuery = toString()
|
||||
searchInTitles = true
|
||||
searchInUsernames = false
|
||||
searchInPasswords = false
|
||||
searchInUrls = true
|
||||
searchByDomain = isASearchByDomain()
|
||||
searchInNotes = true
|
||||
searchInOTP = false
|
||||
searchInOther = true
|
||||
searchInUUIDs = false
|
||||
searchInTags = false
|
||||
searchInCurrentGroup = false
|
||||
searchInSearchableGroup = true
|
||||
searchInRecycleBin = false
|
||||
searchInTemplates = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
@@ -97,6 +146,7 @@ class SearchInfo : ObjectNameResource, Parcelable {
|
||||
if (applicationId != other.applicationId) return false
|
||||
if (webDomain != other.webDomain) return false
|
||||
if (webScheme != other.webScheme) return false
|
||||
if (relyingParty != other.relyingParty) return false
|
||||
if (otpString != other.otpString) return false
|
||||
|
||||
return true
|
||||
@@ -107,12 +157,13 @@ class SearchInfo : ObjectNameResource, Parcelable {
|
||||
result = 31 * result + (applicationId?.hashCode() ?: 0)
|
||||
result = 31 * result + (webDomain?.hashCode() ?: 0)
|
||||
result = 31 * result + (webScheme?.hashCode() ?: 0)
|
||||
result = 31 * result + (relyingParty?.hashCode() ?: 0)
|
||||
result = 31 * result + (otpString?.hashCode() ?: 0)
|
||||
return result
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return otpString ?: webDomain ?: applicationId ?: ""
|
||||
return otpString ?: webDomain ?: applicationId ?: relyingParty ?: ""
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
Reference in new issue
Block a user