fix: add reserved keys filter and TOTP reverse mapping in KDBXMapper
This commit is contained in:
@@ -28,7 +28,9 @@ enum KDBXMapper {
|
|||||||
|
|
||||||
static func entry(from e: KPKEntry) -> Entry {
|
static func entry(from e: KPKEntry) -> Entry {
|
||||||
// e.customAttributes: only non-default attributes
|
// e.customAttributes: only non-default attributes
|
||||||
let customFields: [CustomField] = e.customAttributes.map { attr in
|
let customFields: [CustomField] = e.customAttributes
|
||||||
|
.filter { !reservedKeys.contains($0.key ?? "") }
|
||||||
|
.map { attr in
|
||||||
CustomField(
|
CustomField(
|
||||||
id: UUID(),
|
id: UUID(),
|
||||||
key: attr.key,
|
key: attr.key,
|
||||||
@@ -105,6 +107,11 @@ enum KDBXMapper {
|
|||||||
)
|
)
|
||||||
kpk.addCustomAttribute(attr)
|
kpk.addCustomAttribute(attr)
|
||||||
}
|
}
|
||||||
|
if let totp = e.totp {
|
||||||
|
let uri = totpURI(from: totp)
|
||||||
|
let attr = KPKAttribute(key: "otp", value: uri, isProtected: false)
|
||||||
|
kpk.addCustomAttribute(attr)
|
||||||
|
}
|
||||||
for att in e.attachments {
|
for att in e.attachments {
|
||||||
let bin = KPKBinary(name: att.name, data: att.data)
|
let bin = KPKBinary(name: att.name, data: att.data)
|
||||||
kpk.addBinary(bin)
|
kpk.addBinary(bin)
|
||||||
@@ -118,4 +125,20 @@ enum KDBXMapper {
|
|||||||
guard let u = nsUUID else { return UUID() }
|
guard let u = nsUUID else { return UUID() }
|
||||||
return UUID(uuidString: u.uuidString) ?? UUID()
|
return UUID(uuidString: u.uuidString) ?? UUID()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static func totpURI(from config: TOTPConfig) -> String {
|
||||||
|
var components = URLComponents()
|
||||||
|
components.scheme = "otpauth"
|
||||||
|
components.host = "totp"
|
||||||
|
components.path = "/MyPass"
|
||||||
|
components.queryItems = [
|
||||||
|
URLQueryItem(name: "secret", value: config.secret),
|
||||||
|
URLQueryItem(name: "period", value: String(config.period)),
|
||||||
|
URLQueryItem(name: "digits", value: String(config.digits)),
|
||||||
|
URLQueryItem(name: "algorithm", value: config.algorithm.rawValue),
|
||||||
|
]
|
||||||
|
return components.url?.absoluteString ?? ""
|
||||||
|
}
|
||||||
|
|
||||||
|
private static let reservedKeys: Set<String> = ["Title", "UserName", "Password", "URL", "Notes"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user