From 15e8ed1ec213fe79bc8a8530069b6be9d7b81783 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Sun, 14 Sep 2025 16:11:54 -0700 Subject: [PATCH] =?UTF-8?q?Fix=20issue=20where=20=E2=80=9Cmark=20as=20migr?= =?UTF-8?q?ated=E2=80=9D=20could=20fail=20(#715)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SecureEnclaveSecretKit/CryptoKitMigrator.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Packages/Sources/SecureEnclaveSecretKit/CryptoKitMigrator.swift b/Sources/Packages/Sources/SecureEnclaveSecretKit/CryptoKitMigrator.swift index cf6b3c0..68c73b2 100644 --- a/Sources/Packages/Sources/SecureEnclaveSecretKit/CryptoKitMigrator.swift +++ b/Sources/Packages/Sources/SecureEnclaveSecretKit/CryptoKitMigrator.swift @@ -50,16 +50,16 @@ extension SecureEnclave { let secret = Secret(id: UUID().uuidString, name: name, publicKey: parsed.publicKey.x963Representation, attributes: Attributes(keyType: .init(algorithm: .ecdsa, size: 256), authentication: auth)) guard !migratedPublicKeys.contains(parsed.publicKey.x963Representation) else { logger.log("Skipping \(name), public key already present. Marking as migrated.") - try markMigrated(secret: secret, oldID: id) + markMigrated(secret: secret, oldID: id) continue } logger.log("Migrating \(name).") try store.saveKey(tokenObjectID, name: name, attributes: secret.attributes) logger.log("Migrated \(name).") - try markMigrated(secret: secret, oldID: id) + markMigrated(secret: secret, oldID: id) migratedAny = true } catch { - logger.error("Failed to migrate \(name): \(error).") + logger.error("Failed to migrate \(name): \(error.localizedDescription).") } } if migratedAny { @@ -69,10 +69,10 @@ extension SecureEnclave { - public func markMigrated(secret: Secret, oldID: Data) throws { + public func markMigrated(secret: Secret, oldID: Data) { let updateQuery = KeychainDictionary([ kSecClass: kSecClassKey, - kSecAttrApplicationLabel: secret.id + kSecAttrApplicationLabel: oldID ]) let newID = oldID + Constants.migrationMagicNumber @@ -82,7 +82,7 @@ extension SecureEnclave { let status = SecItemUpdate(updateQuery, updatedAttributes) if status != errSecSuccess { - throw KeychainError(statusCode: status) + logger.warning("Failed to mark \(secret.name) as migrated: \(status).") } }