Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add passkeys to credential store for quicktype (#520)

Leendert de Borstf0fdfcdf19f3
diff --git a/apps/mobile-app/ios/Autofill/CredentialIdentityStore.swift b/apps/mobile-app/ios/Autofill/CredentialIdentityStore.swift
index 9a4a8c19a..d9e2eb54c 100644
--- a/apps/mobile-app/ios/Autofill/CredentialIdentityStore.swift
+++ b/apps/mobile-app/ios/Autofill/CredentialIdentityStore.swift
@@ -16,6 +16,8 @@ public class CredentialIdentityStore {
/// Save credentials into the native iOS credential store.
public func saveCredentialIdentities(_ credentials: [Credential]) async throws {
+ // TODO: improve implementation to better separate password and passkey identities.
+ // As if a record has both a password and passkey, it will not only show up as a password identity.
var allIdentities: [ASCredentialIdentity] = []
// Create password identities
@@ -32,6 +34,10 @@ public class CredentialIdentityStore {
return nil // Skip credentials with no identifier
}
+ guard let password = credential.password, !password.value.isEmpty else {
+ return nil // Skip credentials with no password (e.g. applies when this record is a passkey)
+ }
+
let effectiveDomain = Self.effectiveDomain(from: host)
return ASPasswordCredentialIdentity(
@@ -99,7 +105,7 @@ public class CredentialIdentityStore {
identifier: credential.service.name ?? "",
type: .domain
)
-
+
// Use the same logic as the UI for determining the identifier
let identifier = usernameOrEmail(credential: credential)
guard !identifier.isEmpty else {
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
index df0374977..4476cefb4 100644
--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
@@ -255,8 +255,9 @@ extension CredentialProviderViewController {
* Handle passkey authentication request
*/
func handlePasskeyAuthentication(_ request: ASPasskeyCredentialRequest) {
- // Set flag to indicate passkey authentication mode
+ // Set flags to indicate passkey authentication mode (not registration, not password)
self.isPasskeyRegistrationMode = false
+ self.isPasskeyAuthenticationMode = true
do {
let vaultStore = VaultStore()
@@ -273,10 +274,14 @@ extension CredentialProviderViewController {
let credentialIdentity = request.credentialIdentity as? ASPasskeyCredentialIdentity
let rpId = credentialIdentity?.relyingPartyIdentifier ?? ""
+ print("PasskeyAuthentication: rpId=\(rpId)")
+
// Check if we have a specific credential ID provided by the system
if let credentialID = credentialIdentity?.credentialID, !credentialID.isEmpty {
+ print("PasskeyAuthentication: Direct credential lookup with ID")
// Direct credential ID lookup - authenticate immediately
guard let passkey = try vaultStore.getPasskey(byCredentialId: credentialID) else {
+ print("PasskeyAuthentication: Credential not found")
extensionContext.cancelRequest(withError: NSError(
domain: ASExtensionErrorDomain,
code: ASExtensionError.credentialIdentityNotFound.rawValue
@@ -284,8 +289,10 @@ extension CredentialProviderViewController {
return
}
+ print("PasskeyAuthentication: Found passkey, authenticating")
try authenticateWithPasskey(passkey, clientDataHash: clientDataHash, rpId: rpId)
} else {
+ print("PasskeyAuthentication: No specific credential ID, showing picker")
// No specific credential - show picker for user to select
showPasskeyPickerView(rpId: rpId, clientDataHash: clientDataHash, vaultStore: vaultStore)
}
@@ -378,7 +385,8 @@ extension CredentialProviderViewController {
* Load credentials with passkeys for the specified RP ID
*/
private func loadPasskeyCredentials(vaultStore: VaultStore, rpId: String) async throws -> [Credential] {
- let credentials = try vaultStore.getAllCredentialsWithPasskeys()
+ // getAllCredentials now includes passkeys for each credential
+ let credentials = try vaultStore.getAllCredentials()
// Filter by RP ID if specified
if !rpId.isEmpty {
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
index 64c0b139a..13a6e630b 100644
--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
@@ -17,6 +17,7 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle
internal var hostingController: UIHostingController<CredentialProviderView>?
internal var passkeyHostingController: UIViewController?
internal var isPasskeyRegistrationMode = false
+ internal var isPasskeyAuthenticationMode = false
private var viewModel: CredentialProviderViewModel?
private var isChoosingTextToInsert = false
private var initialServiceUrl: String?
@@ -24,9 +25,10 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle
override public func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
- // Don't set up credential view if we're in passkey registration mode
- // TODO: make this more clear by design which action is taken for which mode in the viewWillAppear for autofill vs passkey
- if isPasskeyRegistrationMode {
+ // Don't set up credential view if we're in passkey registration or authentication mode
+ // These modes are handled by prepareInterface(forPasskeyRegistration:) and
+ // prepareInterfaceToProvideCredential(for:) respectively
+ if isPasskeyRegistrationMode || isPasskeyAuthenticationMode {
return
}
@@ -298,9 +300,9 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle
}
}
- /// This registers all known AliasVault credentials into iOS native credential storage, which iOS can then use to
- /// suggest autofill credentials when a user focuses an input field on a login form. These suggestions will then be s
- /// hown above the iOS keyboard, which saves the user one step.
+ /// This registers all known AliasVault credentials (both passwords and passkeys) into iOS native credential storage,
+ /// which iOS can then use to suggest autofill credentials when a user focuses an input field on a login form.
+ /// These suggestions will then be shown above the iOS keyboard, which saves the user one step.
///
/// Note: QuickType bar suggestions are only enabled on iOS 26+ due to biometric authentication limitations
/// in iOS 17 and 18 where background authentication doesn't work reliably.
@@ -310,7 +312,7 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle
if #available(iOS 26.0, *) {
do {
try await CredentialIdentityStore.shared.saveCredentialIdentities(credentials)
- print("Registered credential identities for QuickType on iOS 26+")
+ print("Registered credential identities (passwords + passkeys) for QuickType on iOS 26+")
} catch {
print("Failed to save credential identities: \(error)")
}
@@ -404,10 +406,14 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle
}
/// Load credentials from the vault store and register them as credential identities
- /// and then return them to the caller (view model).
+ /// (including both passwords and passkeys) and then return them to the caller (view model).
private func loadCredentials(vaultStore: VaultStore) async throws -> [Credential] {
+ // getAllCredentials now includes passkeys for each credential
let credentials = try vaultStore.getAllCredentials()
+
+ // Register all credential identities (passwords and passkeys)
await self.registerCredentialIdentities(credentials: credentials)
+
return credentials
}
diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift
index e55ba893a..2e63d4a69 100644
--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift
@@ -180,6 +180,91 @@ extension VaultStore {
return passkeys
}
+ /**
+ * Get all passkeys for a specific relying party identifier (RP ID)
+ */
+ public func getPasskeys(forRpId rpId: String) throws -> [Passkey] {
+ guard let dbConn = dbConnection else {
+ throw VaultStoreError.vaultNotUnlocked
+ }
+
+ let query = """
+ SELECT
+ Id,
+ CredentialId,
+ RpId,
+ UserId,
+ PublicKey,
+ PrivateKey,
+ PrfKey,
+ DisplayName,
+ AdditionalData,
+ CreatedAt,
+ UpdatedAt,
+ IsDeleted
+ FROM Passkeys
+ WHERE RpId = ? AND IsDeleted = 0
+ ORDER BY CreatedAt DESC
+ """
+
+ var passkeys: [Passkey] = []
+ for row in try dbConn.prepare(query, [rpId]) {
+ guard let idString = row[0] as? String,
+ let credentialIdString = row[1] as? String,
+ let rpId = row[2] as? String,
+ let publicKeyString = row[4] as? String,
+ let privateKeyString = row[5] as? String,
+ let displayName = row[7] as? String,
+ let createdAtString = row[9] as? String,
+ let updatedAtString = row[10] as? String,
+ let isDeletedInt64 = row[11] as? Int64,
+ let id = UUID(uuidString: idString),
+ let parentCredentialId = UUID(uuidString: credentialIdString),
+ let publicKeyData = publicKeyString.data(using: .utf8),
+ let privateKeyData = privateKeyString.data(using: .utf8) else {
+ continue
+ }
+
+ guard let createdAt = parseDateString(createdAtString),
+ let updatedAt = parseDateString(updatedAtString) else {
+ continue
+ }
+
+ let userId = (row[3] as? String)?.data(using: .utf8)
+ let prfKey = (row[6] as? SQLite.Blob).map { Data($0.bytes) }
+ let isDeleted = isDeletedInt64 == 1
+
+ // Get the actual WebAuthn credential ID from AdditionalData column
+ let webauthnCredentialId: Data
+ if let additionalDataBlob = row[8] as? SQLite.Blob {
+ webauthnCredentialId = Data(additionalDataBlob.bytes)
+ } else {
+ // Fallback: use the passkey ID as a GUID and convert to bytes
+ webauthnCredentialId = (try? PasskeyHelper.guidToBytes(idString)) ?? Data()
+ }
+
+ let passkey = Passkey(
+ id: id,
+ credentialId: webauthnCredentialId,
+ credentialIdString: parentCredentialId.uuidString,
+ rpId: rpId,
+ userId: userId,
+ userName: nil,
+ publicKey: publicKeyData,
+ privateKey: privateKeyData,
+ prfKey: prfKey,
+ displayName: displayName,
+ createdAt: createdAt,
+ updatedAt: updatedAt,
+ isDeleted: isDeleted
+ )
+
+ passkeys.append(passkey)
+ }
+
+ return passkeys
+ }
+
/**
* Get all credentials that have passkeys attached
*/
diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift
index 6245ed3b3..5794ca503 100644
--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift
@@ -314,6 +314,9 @@ extension VaultStore {
)
}
+ // Load passkeys for this credential
+ let passkeys = try getPasskeys(forCredentialId: UUID(uuidString: idString)!)
+
let credential = Credential(
id: UUID(uuidString: idString)!,
alias: alias,
@@ -321,6 +324,7 @@ extension VaultStore {
username: row[2] as? String,
notes: row[3] as? String,
password: password,
+ passkeys: passkeys,
createdAt: createdAt,
updatedAt: updatedAt,
isDeleted: isDeleted