mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-26 03:46:46 -08:00
fix: CreditCard Autofill recognition #1793
This commit is contained in:
12 files changed
+96
-54
No files matched your search
@@ -35,6 +35,8 @@ import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.model.AppOrigin
|
||||
import com.kunzisoft.keepass.model.AppOriginEntryField
|
||||
import com.kunzisoft.keepass.model.CreditCard
|
||||
import com.kunzisoft.keepass.model.CreditCardEntryFields
|
||||
import com.kunzisoft.keepass.model.EntryInfo
|
||||
import com.kunzisoft.keepass.model.Passkey
|
||||
import com.kunzisoft.keepass.model.PasskeyEntryFields
|
||||
@@ -358,6 +360,15 @@ class Entry : Node, EntryVersionedInterface<Group> {
|
||||
return null
|
||||
}
|
||||
|
||||
fun getCreditCard(): CreditCard? {
|
||||
entryKDBX?.let {
|
||||
return CreditCardEntryFields.parseFields { key ->
|
||||
it.getFieldValue(key)?.toString()
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun getPasskey(): Passkey? {
|
||||
entryKDBX?.let {
|
||||
return PasskeyEntryFields.parseFields { key ->
|
||||
@@ -492,6 +503,8 @@ class Entry : Node, EntryVersionedInterface<Group> {
|
||||
entryInfo.customFields = getExtraFields().toMutableList()
|
||||
// Add otpElement to generate token
|
||||
entryInfo.otpModel = getOtpElement()?.otpModel
|
||||
// Add Credit Card
|
||||
entryInfo.creditCard = getCreditCard()
|
||||
// Add Passkey
|
||||
entryInfo.passkey = getPasskey()
|
||||
entryInfo.appOrigin = getAppOrigin()
|
||||
@@ -533,6 +546,8 @@ class Entry : Node, EntryVersionedInterface<Group> {
|
||||
customData = newEntryInfo.customData
|
||||
autoType = newEntryInfo.autoType
|
||||
addExtraFields(newEntryInfo.customFields)
|
||||
// WARNING : Custom objects like creditCard, passkey and appOrigin are not directly saved
|
||||
// Priority to custom fields
|
||||
database?.attachmentPool?.let { binaryPool ->
|
||||
newEntryInfo.attachments.forEach { attachment ->
|
||||
putAttachment(attachment, binaryPool)
|
||||
|
||||
@@ -2,25 +2,22 @@ package com.kunzisoft.keepass.model
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.utils.readSerializableCompat
|
||||
import org.joda.time.DateTime
|
||||
|
||||
data class CreditCard(val cardholder: String?,
|
||||
val number: String?,
|
||||
val expiration: DateTime?,
|
||||
val cvv: String?) : Parcelable {
|
||||
data class CreditCard(
|
||||
val cardholder: String?,
|
||||
val number: String?,
|
||||
val cvv: String?
|
||||
) : Parcelable {
|
||||
|
||||
constructor(parcel: Parcel) : this(
|
||||
parcel.readString(),
|
||||
parcel.readString(),
|
||||
parcel.readSerializableCompat<DateTime>(),
|
||||
parcel.readString()) {
|
||||
}
|
||||
|
||||
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||
parcel.writeString(cardholder)
|
||||
parcel.writeString(number)
|
||||
parcel.writeSerializable(expiration)
|
||||
parcel.writeString(cvv)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,13 +19,11 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.model
|
||||
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
import com.kunzisoft.keepass.database.element.Field
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_CVV
|
||||
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_HOLDER
|
||||
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_NUMBER
|
||||
import org.joda.time.DateTime
|
||||
|
||||
object CreditCardEntryFields {
|
||||
|
||||
@@ -37,7 +35,6 @@ object CreditCardEntryFields {
|
||||
fun parseFields(getField: (id: String) -> String?): CreditCard? {
|
||||
val cardHolderField = getField(LABEL_HOLDER)
|
||||
val cardNumberField = getField(LABEL_NUMBER)
|
||||
val cardExpiration = DateTime() // TODO Expiration
|
||||
val cardCVVField = getField(LABEL_CVV)
|
||||
if (cardHolderField == null
|
||||
|| cardNumberField == null)
|
||||
@@ -45,7 +42,6 @@ object CreditCardEntryFields {
|
||||
return CreditCard(
|
||||
cardholder = cardHolderField,
|
||||
number = cardNumberField,
|
||||
expiration = cardExpiration,
|
||||
cvv = cardCVVField
|
||||
)
|
||||
}
|
||||
@@ -69,10 +65,6 @@ object CreditCardEntryFields {
|
||||
)
|
||||
)
|
||||
}
|
||||
creditCard.expiration?.let {
|
||||
expires = true
|
||||
expiryTime = DateInstant(creditCard.expiration.toInstant())
|
||||
}
|
||||
creditCard.cvv?.let {
|
||||
addOrReplaceField(
|
||||
Field(
|
||||
@@ -83,4 +75,17 @@ object CreditCardEntryFields {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect if the current field is a Credit Card field
|
||||
*/
|
||||
fun Field.isCreditCard(): Boolean {
|
||||
return when(name) {
|
||||
CREDIT_CARD_TAG -> true
|
||||
LABEL_HOLDER -> true
|
||||
LABEL_NUMBER -> true
|
||||
LABEL_CVV -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,7 @@ class EntryInfo : NodeInfo {
|
||||
var attachments: MutableList<Attachment> = mutableListOf()
|
||||
var autoType: AutoType = AutoType()
|
||||
var otpModel: OtpModel? = null
|
||||
var creditCard: CreditCard? = null
|
||||
var passkey: Passkey? = null
|
||||
var appOrigin: AppOrigin? = null
|
||||
var isTemplate: Boolean = false
|
||||
@@ -80,6 +81,7 @@ class EntryInfo : NodeInfo {
|
||||
parcel.readListCompat(attachments)
|
||||
autoType = parcel.readParcelableCompat() ?: autoType
|
||||
otpModel = parcel.readParcelableCompat() ?: otpModel
|
||||
creditCard = parcel.readParcelableCompat() ?: creditCard
|
||||
passkey = parcel.readParcelableCompat() ?: passkey
|
||||
appOrigin = parcel.readParcelableCompat() ?: appOrigin
|
||||
isTemplate = parcel.readBooleanCompat()
|
||||
@@ -103,6 +105,7 @@ class EntryInfo : NodeInfo {
|
||||
parcel.writeList(attachments)
|
||||
parcel.writeParcelable(autoType, flags)
|
||||
parcel.writeParcelable(otpModel, flags)
|
||||
parcel.writeParcelable(creditCard, flags)
|
||||
parcel.writeParcelable(passkey, flags)
|
||||
parcel.writeParcelable(appOrigin, flags)
|
||||
parcel.writeBooleanCompat(isTemplate)
|
||||
@@ -224,6 +227,10 @@ class EntryInfo : NodeInfo {
|
||||
saveSearchInfo(database, registerInfo.searchInfo)
|
||||
registerInfo.username?.let { username = it }
|
||||
registerInfo.password?.let { password = it }
|
||||
registerInfo.expiration?.let {
|
||||
expires = true
|
||||
expiryTime = it
|
||||
}
|
||||
setCreditCard(registerInfo.creditCard)
|
||||
val dataOverwrite: Boolean = setPasskey(registerInfo.passkey)
|
||||
saveAppOrigin(database, registerInfo.appOrigin)
|
||||
@@ -265,6 +272,7 @@ class EntryInfo : NodeInfo {
|
||||
if (attachments != other.attachments) return false
|
||||
if (autoType != other.autoType) return false
|
||||
if (otpModel != other.otpModel) return false
|
||||
if (creditCard != other.creditCard) return false
|
||||
if (passkey != other.passkey) return false
|
||||
if (appOrigin != other.appOrigin) return false
|
||||
if (isTemplate != other.isTemplate) return false
|
||||
@@ -286,6 +294,7 @@ class EntryInfo : NodeInfo {
|
||||
result = 31 * result + attachments.hashCode()
|
||||
result = 31 * result + autoType.hashCode()
|
||||
result = 31 * result + (otpModel?.hashCode() ?: 0)
|
||||
result = 31 * result + (creditCard?.hashCode() ?: 0)
|
||||
result = 31 * result + (passkey?.hashCode() ?: 0)
|
||||
result = 31 * result + (appOrigin?.hashCode() ?: 0)
|
||||
result = 31 * result + isTemplate.hashCode()
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.kunzisoft.keepass.model
|
||||
import android.content.res.Resources
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
import com.kunzisoft.keepass.utils.ObjectNameResource
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
|
||||
@@ -10,6 +11,7 @@ data class RegisterInfo(
|
||||
val searchInfo: SearchInfo,
|
||||
val username: String? = null,
|
||||
val password: String? = null,
|
||||
val expiration: DateInstant? = null,
|
||||
val creditCard: CreditCard? = null,
|
||||
val passkey: Passkey? = null,
|
||||
val appOrigin: AppOrigin? = null
|
||||
@@ -19,6 +21,7 @@ data class RegisterInfo(
|
||||
searchInfo = parcel.readParcelableCompat() ?: SearchInfo(),
|
||||
username = parcel.readString(),
|
||||
password = parcel.readString(),
|
||||
expiration = parcel.readParcelableCompat(),
|
||||
creditCard = parcel.readParcelableCompat(),
|
||||
passkey = parcel.readParcelableCompat(),
|
||||
appOrigin = parcel.readParcelableCompat()
|
||||
@@ -28,6 +31,7 @@ data class RegisterInfo(
|
||||
parcel.writeParcelable(searchInfo, flags)
|
||||
parcel.writeString(username)
|
||||
parcel.writeString(password)
|
||||
parcel.writeParcelable(expiration, flags)
|
||||
parcel.writeParcelable(creditCard, flags)
|
||||
parcel.writeParcelable(passkey, flags)
|
||||
parcel.writeParcelable(appOrigin, flags)
|
||||
|
||||
Reference in new issue
Block a user