mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-28 04:46:51 -08:00
fix: Show dedicated Passkey view #2097
This commit is contained in:
21 files changed
+458
-144
No files matched your search
@@ -34,11 +34,13 @@ 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.model.EntryInfo
|
||||
import com.kunzisoft.keepass.model.Passkey
|
||||
import com.kunzisoft.keepass.model.PasskeyEntryFields
|
||||
import com.kunzisoft.keepass.otp.OtpElement
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.StringUtil.toFormattedColorInt
|
||||
import com.kunzisoft.keepass.utils.StringUtil.toFormattedColorString
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import java.util.UUID
|
||||
|
||||
class Entry : Node, EntryVersionedInterface<Group> {
|
||||
@@ -354,6 +356,15 @@ class Entry : Node, EntryVersionedInterface<Group> {
|
||||
return null
|
||||
}
|
||||
|
||||
fun getPasskey(): Passkey? {
|
||||
entryKDBX?.let {
|
||||
return PasskeyEntryFields.parseFields { key ->
|
||||
it.getFieldValue(key)?.toString()
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun startToManageFieldReferences(database: DatabaseKDBX) {
|
||||
entryKDBX?.startToManageFieldReferences(database)
|
||||
}
|
||||
@@ -470,9 +481,12 @@ class Entry : Node, EntryVersionedInterface<Group> {
|
||||
entryInfo.customFields = getExtraFields().toMutableList()
|
||||
// Add otpElement to generate token
|
||||
entryInfo.otpModel = getOtpElement()?.otpModel
|
||||
// Add Passkey
|
||||
entryInfo.passkey = getPasskey()
|
||||
if (!raw) {
|
||||
// Replace parameter fields by generated OTP fields
|
||||
entryInfo.customFields = OtpEntryFields.generateAutoFields(entryInfo.customFields)
|
||||
entryInfo.customFields = PasskeyEntryFields.generateAutoFields(entryInfo.customFields)
|
||||
}
|
||||
database?.attachmentPool?.let { binaryPool ->
|
||||
entryInfo.attachments = getAttachments(binaryPool).toMutableList()
|
||||
|
||||
@@ -24,7 +24,9 @@ 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.model.PasskeyEntryFields
|
||||
import com.kunzisoft.keepass.model.PasskeyEntryFields.FIELD_RELYING_PARTY
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_FIELD
|
||||
import com.kunzisoft.keepass.utils.UuidUtil
|
||||
import com.kunzisoft.keepass.utils.inTheSameDomainAs
|
||||
@@ -184,8 +186,8 @@ class SearchHelper {
|
||||
}
|
||||
if (searchParameters.searchInOther) {
|
||||
if(entry.getExtraFields().any { field ->
|
||||
field.name != OTP_FIELD
|
||||
&& field.name != FIELD_RELYING_PARTY
|
||||
OtpEntryFields.searchExcluded(field)
|
||||
&& PasskeyEntryFields.searchExcluded(field)
|
||||
&& checkSearchQuery(field.protectedValue.toString(), searchParameters)
|
||||
})
|
||||
return true
|
||||
|
||||
@@ -30,7 +30,7 @@ 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.model.PasskeyEntryFields.setPasskey
|
||||
import com.kunzisoft.keepass.otp.OtpElement
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_TOKEN_FIELD
|
||||
@@ -55,6 +55,7 @@ class EntryInfo : NodeInfo {
|
||||
var attachments: MutableList<Attachment> = mutableListOf()
|
||||
var autoType: AutoType = AutoType()
|
||||
var otpModel: OtpModel? = null
|
||||
var passkey: Passkey? = null
|
||||
var isTemplate: Boolean = false
|
||||
|
||||
constructor() : super()
|
||||
@@ -229,9 +230,7 @@ class EntryInfo : NodeInfo {
|
||||
}
|
||||
|
||||
fun saveRegisterInfo(database: Database?, registerInfo: RegisterInfo) {
|
||||
registerInfo.searchInfo.let {
|
||||
title = searchInfoToTitle(it)
|
||||
}
|
||||
saveSearchInfo(database, registerInfo.searchInfo)
|
||||
registerInfo.username?.let {
|
||||
username = it
|
||||
}
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
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)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,8 @@ 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,
|
||||
val relyingParty: String
|
||||
): Parcelable
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.kunzisoft.keepass.model
|
||||
|
||||
import com.kunzisoft.keepass.database.element.Field
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
|
||||
object PasskeyEntryFields {
|
||||
|
||||
// field names from KeypassXC are used
|
||||
const val FIELD_USERNAME = "KPEX_PASSKEY_USERNAME"
|
||||
|
||||
const val FIELD_PRIVATE_KEY = "KPEX_PASSKEY_PRIVATE_KEY_PEM"
|
||||
const val FIELD_CREDENTIAL_ID = "KPEX_PASSKEY_CREDENTIAL_ID"
|
||||
const val FIELD_USER_HANDLE = "KPEX_PASSKEY_USER_HANDLE"
|
||||
const val FIELD_RELYING_PARTY = "KPEX_PASSKEY_RELYING_PARTY"
|
||||
|
||||
const val PASSKEY_FIELD = "Passkey"
|
||||
const val PASSKEY_TAG = "Passkey"
|
||||
|
||||
/**
|
||||
* Parse fields of an entry to retrieve a Passkey
|
||||
*/
|
||||
fun parseFields(getField: (id: String) -> String?): Passkey? {
|
||||
val usernameField = getField(FIELD_USERNAME)
|
||||
val privateKeyField = getField(FIELD_PRIVATE_KEY)
|
||||
val credentialIdField = getField(FIELD_CREDENTIAL_ID)
|
||||
val userHandleField = getField(FIELD_USER_HANDLE)
|
||||
val relyingPartyField = getField(FIELD_RELYING_PARTY)
|
||||
if (usernameField == null
|
||||
|| privateKeyField == null
|
||||
|| credentialIdField == null
|
||||
|| userHandleField == null
|
||||
|| relyingPartyField == null)
|
||||
return null
|
||||
return Passkey(
|
||||
username = usernameField,
|
||||
privateKeyPem = privateKeyField,
|
||||
credentialId = credentialIdField,
|
||||
userHandle = userHandleField,
|
||||
relyingParty = relyingPartyField
|
||||
)
|
||||
}
|
||||
|
||||
fun EntryInfo.setPasskey(passkey: Passkey) {
|
||||
tags.put(PASSKEY_TAG)
|
||||
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)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Build Passkey field from a Passkey
|
||||
*/
|
||||
fun buildPasskeyField(passkey: Passkey): Field {
|
||||
return Field(
|
||||
name = PASSKEY_FIELD,
|
||||
value = ProtectedString(
|
||||
enableProtection = false,
|
||||
string = passkey.relyingParty
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Build new generated fields in a new list from [fieldsToParse] in parameter,
|
||||
* Remove parameters fields use to generate auto fields
|
||||
*/
|
||||
fun generateAutoFields(fieldsToParse: List<Field>): MutableList<Field> {
|
||||
val newCustomFields: MutableList<Field> = ArrayList(fieldsToParse)
|
||||
// Remove parameter fields
|
||||
val usernameField = Field(FIELD_USERNAME)
|
||||
val privateKeyField = Field(FIELD_PRIVATE_KEY)
|
||||
val credentialIdField = Field(FIELD_CREDENTIAL_ID)
|
||||
val userHandleField = Field(FIELD_USER_HANDLE)
|
||||
val relyingPartyField = Field(FIELD_RELYING_PARTY)
|
||||
newCustomFields.remove(usernameField)
|
||||
newCustomFields.remove(privateKeyField)
|
||||
newCustomFields.remove(credentialIdField)
|
||||
newCustomFields.remove(userHandleField)
|
||||
newCustomFields.remove(relyingPartyField)
|
||||
// Empty auto generated OTP Token field
|
||||
if (fieldsToParse.contains(usernameField)
|
||||
|| fieldsToParse.contains(privateKeyField)
|
||||
|| fieldsToParse.contains(credentialIdField)
|
||||
|| fieldsToParse.contains(userHandleField)
|
||||
|| fieldsToParse.contains(relyingPartyField)
|
||||
)
|
||||
newCustomFields.add(
|
||||
Field(
|
||||
name = PASSKEY_FIELD,
|
||||
value = ProtectedString(enableProtection = false)
|
||||
)
|
||||
)
|
||||
return newCustomFields
|
||||
}
|
||||
|
||||
fun searchExcluded(field: Field): Boolean {
|
||||
return when(field.name) {
|
||||
FIELD_USERNAME -> true
|
||||
FIELD_PRIVATE_KEY -> true
|
||||
FIELD_CREDENTIAL_ID -> true
|
||||
FIELD_USER_HANDLE -> true
|
||||
FIELD_RELYING_PARTY -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,6 @@ class SearchInfo : ObjectNameResource, Parcelable {
|
||||
get() {
|
||||
return if (webDomain == null) null else field
|
||||
}
|
||||
var relyingParty: String? = null
|
||||
var otpString: String? = null
|
||||
|
||||
constructor()
|
||||
@@ -46,7 +45,6 @@ class SearchInfo : ObjectNameResource, Parcelable {
|
||||
applicationId = toCopy?.applicationId
|
||||
webDomain = toCopy?.webDomain
|
||||
webScheme = toCopy?.webScheme
|
||||
relyingParty = toCopy?.relyingParty
|
||||
otpString = toCopy?.otpString
|
||||
}
|
||||
|
||||
@@ -60,8 +58,6 @@ 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
|
||||
}
|
||||
@@ -76,7 +72,6 @@ class SearchInfo : ObjectNameResource, Parcelable {
|
||||
parcel.writeString(applicationId ?: "")
|
||||
parcel.writeString(webDomain ?: "")
|
||||
parcel.writeString(webScheme ?: "")
|
||||
parcel.writeString(relyingParty ?: "")
|
||||
parcel.writeString(otpString ?: "")
|
||||
}
|
||||
|
||||
@@ -94,7 +89,6 @@ class SearchInfo : ObjectNameResource, Parcelable {
|
||||
&& applicationId == null
|
||||
&& webDomain == null
|
||||
&& webScheme == null
|
||||
&& relyingParty == null
|
||||
&& otpString == null
|
||||
}
|
||||
|
||||
@@ -102,25 +96,23 @@ class SearchInfo : ObjectNameResource, Parcelable {
|
||||
return toString() == webDomain && webDomain != null
|
||||
}
|
||||
|
||||
private fun isAPasskeySearch(): Boolean {
|
||||
return toString() == relyingParty && relyingParty != null
|
||||
}
|
||||
var isAPasskeySearch: Boolean = false
|
||||
|
||||
fun buildSearchParameters(): SearchParameters {
|
||||
return SearchParameters().apply {
|
||||
searchQuery = this@SearchInfo.toString()
|
||||
allowEmptyQuery = false
|
||||
searchInTitles = !isAPasskeySearch()
|
||||
searchInTitles = !isAPasskeySearch
|
||||
searchInUsernames = false
|
||||
searchInPasswords = false
|
||||
searchInUrls = !isAPasskeySearch()
|
||||
searchInUrls = !isAPasskeySearch
|
||||
searchByDomain = isADomainSearch()
|
||||
searchInNotes = false
|
||||
searchInOTP = false
|
||||
searchInOther = true
|
||||
searchInUUIDs = false
|
||||
searchInTags = false
|
||||
searchInRelyingParty = isAPasskeySearch()
|
||||
searchInRelyingParty = isAPasskeySearch
|
||||
searchInCurrentGroup = false
|
||||
searchInSearchableGroup = true
|
||||
searchInRecycleBin = false
|
||||
@@ -137,7 +129,6 @@ 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
|
||||
@@ -149,13 +140,12 @@ 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 ?: relyingParty ?: tag ?: ""
|
||||
return otpString ?: webDomain ?: applicationId ?: tag ?: ""
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -486,4 +486,25 @@ object OtpEntryFields {
|
||||
newCustomFields.add(Field(OTP_TOKEN_FIELD))
|
||||
return newCustomFields
|
||||
}
|
||||
|
||||
fun searchExcluded(field: Field): Boolean {
|
||||
return when(field.name) {
|
||||
OTP_FIELD -> true
|
||||
TOTP_SEED_FIELD -> true
|
||||
TOTP_SETTING_FIELD -> true
|
||||
HMACOTP_SECRET_FIELD -> true
|
||||
HMACOTP_SECRET_HEX_FIELD -> true
|
||||
HMACOTP_SECRET_BASE32_FIELD -> true
|
||||
HMACOTP_SECRET_BASE64_FIELD -> true
|
||||
HMACOTP_SECRET_COUNTER_FIELD -> true
|
||||
TIMEOTP_SECRET_FIELD -> true
|
||||
TIMEOTP_SECRET_HEX_FIELD -> true
|
||||
TIMEOTP_SECRET_BASE32_FIELD -> true
|
||||
TIMEOTP_SECRET_BASE64_FIELD -> true
|
||||
TIMEOTP_LENGTH_FIELD -> true
|
||||
TIMEOTP_PERIOD_FIELD -> true
|
||||
TIMEOTP_ALGORITHM_FIELD -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user