From 479075490df3a8d63da184f2997cb37142fd7fda Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Tue, 17 Nov 2026 21:19:16 -0800 Subject: [PATCH] Switch to authenticationrequirement instead of flag (#872) --- .../Packages/Resources/Localizable.xcstrings | 748 +++++++++--------- .../SecretKit/Types/CreationOptions.swift | 15 +- .../CryptoKitMigrator.swift | 2 +- .../SecureEnclaveStore.swift | 10 +- .../SmartCardSecretKit/SmartCardStore.swift | 2 +- .../OpenSSHPublicKeyWriterTests.swift | 4 +- .../OpenSSHSignatureWriterTests.swift | 2 +- .../AuthenticationHandlerTests.swift | 6 +- .../Tests/SecretAgentKitTests/StubStore.swift | 2 +- .../Tests/SecretKitTests/AnySecretTests.swift | 2 +- .../Preview Content/PreviewStore.swift | 1 - .../Views/Secrets/CreateSecretView.swift | 27 +- 12 files changed, 411 insertions(+), 410 deletions(-) diff --git a/Sources/Packages/Resources/Localizable.xcstrings b/Sources/Packages/Resources/Localizable.xcstrings index e266347..92206af 100644 --- a/Sources/Packages/Resources/Localizable.xcstrings +++ b/Sources/Packages/Resources/Localizable.xcstrings @@ -6720,24 +6720,24 @@ } } }, - "create_secret_allow_while_locked_description" : { + "create_secret_after_first_unlock_notify_description" : { "extractionState" : "manual", "localizations" : { "en" : { "stringUnit" : { "state" : "translated", - "value" : "Consider enabling this if you run scripts while your Mac is locked." + "value" : "No authentication is required, and you will be notified when a secret is used. Use is allowed even when your Mac is locked." } } } }, - "create_secret_allow_while_locked_label" : { + "create_secret_after_first_unlock_notify_title" : { "extractionState" : "manual", "localizations" : { "en" : { "stringUnit" : { "state" : "translated", - "value" : "Allow While Locked" + "value" : "Allow While Locked and Notify" } } } @@ -8592,376 +8592,6 @@ } } }, - "create_secret_notify_description" : { - "extractionState" : "manual", - "localizations" : { - "af" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "ar" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "ca" : { - "stringUnit" : { - "state" : "translated", - "value" : "No es requerirà cap autenticació mentre el Mac estiga desbloquejat, però seràs notificat quan s'utilitze ùn secret." - } - }, - "cs" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "da" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "de" : { - "stringUnit" : { - "state" : "translated", - "value" : "Es ist keine Authentifizierung erforderlich solange dein Mac entsperrt ist, aber du wirst benachrichtigt, wenn ein Secret verwendet wird." - } - }, - "el" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "en" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "es" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "fi" : { - "stringUnit" : { - "state" : "translated", - "value" : "Todennusta ei vaadita Macisi ollessa lukitsematta, mutta saat ilmoituksen kun salaisuutta käytetään." - } - }, - "fr" : { - "stringUnit" : { - "state" : "translated", - "value" : "Aucune authentification n'est requise lorsque votre Mac est déverrouillé, mais vous serez averti lorsqu'un secret sera utilisé." - } - }, - "he" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "hu" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "it" : { - "stringUnit" : { - "state" : "translated", - "value" : "Non è richiesta alcuna autenticazione finché il tuo Mac è sbloccato, ma verrete notificati quando un Segreto viene usato." - } - }, - "ja" : { - "stringUnit" : { - "state" : "translated", - "value" : "お使いのMacでロックが解除されている間は認証が必要になりません。シークレットが利用されると通知されます。" - } - }, - "ko" : { - "stringUnit" : { - "state" : "translated", - "value" : "Mac이 잠금 해제되어 있는 동안에는 인증이 필요하지 않지만 비밀이 사용되면 알림을 받게 됩니다." - } - }, - "nb" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "nl" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "pl" : { - "stringUnit" : { - "state" : "translated", - "value" : "Uwierzytelnianie nie jest wymagane gdy twój Mac jest odblokowany. Otrzymasz powiadomienie kiedy sekret zostanie użyty." - } - }, - "pt" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "pt-BR" : { - "stringUnit" : { - "state" : "translated", - "value" : "Nenhuma autenticação é solicitada enquanto seu Mac estiver desbloqueado, mas você será notificado quando um segredo for usado." - } - }, - "ro" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "ru" : { - "stringUnit" : { - "state" : "translated", - "value" : "Аутентификация не потребуется пока Ваш Mac разблокирован, но Вы получите уведомление, если секрет будет использован." - } - }, - "sr" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "sv" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "tr" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "uk" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "vi" : { - "stringUnit" : { - "state" : "new", - "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." - } - }, - "zh-Hans" : { - "stringUnit" : { - "state" : "translated", - "value" : "当Mac已解锁时无需验证,但密钥串被使用时会通知您。" - } - }, - "zh-Hant" : { - "stringUnit" : { - "state" : "translated", - "value" : "當Mac已解鎖時無需驗證,但Secret被使用时會通知您。" - } - } - } - }, - "create_secret_notify_title" : { - "extractionState" : "manual", - "localizations" : { - "af" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "ar" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "ca" : { - "stringUnit" : { - "state" : "translated", - "value" : "Notifica" - } - }, - "cs" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "da" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "de" : { - "stringUnit" : { - "state" : "translated", - "value" : "Benachrichtigen" - } - }, - "el" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "en" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "es" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "fi" : { - "stringUnit" : { - "state" : "translated", - "value" : "Ilmoita" - } - }, - "fr" : { - "stringUnit" : { - "state" : "translated", - "value" : "Notifier" - } - }, - "he" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "hu" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "it" : { - "stringUnit" : { - "state" : "translated", - "value" : "Notifica" - } - }, - "ja" : { - "stringUnit" : { - "state" : "translated", - "value" : "通知のみ" - } - }, - "ko" : { - "stringUnit" : { - "state" : "translated", - "value" : "알림" - } - }, - "nb" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "nl" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "pl" : { - "stringUnit" : { - "state" : "translated", - "value" : "Powiadom" - } - }, - "pt" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "pt-BR" : { - "stringUnit" : { - "state" : "translated", - "value" : "Notificar" - } - }, - "ro" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "ru" : { - "stringUnit" : { - "state" : "translated", - "value" : "Уведомить" - } - }, - "sr" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "sv" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "tr" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "uk" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "vi" : { - "stringUnit" : { - "state" : "new", - "value" : "Notify" - } - }, - "zh-Hans" : { - "stringUnit" : { - "state" : "translated", - "value" : "通知" - } - }, - "zh-Hant" : { - "stringUnit" : { - "state" : "translated", - "value" : "通知" - } - } - } - }, "create_secret_protection_level_title" : { "extractionState" : "manual", "localizations" : { @@ -10072,6 +9702,376 @@ } } }, + "create_secret_while_unlocked_notify_description" : { + "extractionState" : "manual", + "localizations" : { + "af" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "ar" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "ca" : { + "stringUnit" : { + "state" : "translated", + "value" : "No es requerirà cap autenticació mentre el Mac estiga desbloquejat, però seràs notificat quan s'utilitze ùn secret." + } + }, + "cs" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "da" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "Es ist keine Authentifizierung erforderlich solange dein Mac entsperrt ist, aber du wirst benachrichtigt, wenn ein Secret verwendet wird." + } + }, + "el" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "es" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "fi" : { + "stringUnit" : { + "state" : "translated", + "value" : "Todennusta ei vaadita Macisi ollessa lukitsematta, mutta saat ilmoituksen kun salaisuutta käytetään." + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "Aucune authentification n'est requise lorsque votre Mac est déverrouillé, mais vous serez averti lorsqu'un secret sera utilisé." + } + }, + "he" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "hu" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "it" : { + "stringUnit" : { + "state" : "translated", + "value" : "Non è richiesta alcuna autenticazione finché il tuo Mac è sbloccato, ma verrete notificati quando un Segreto viene usato." + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "お使いのMacでロックが解除されている間は認証が必要になりません。シークレットが利用されると通知されます。" + } + }, + "ko" : { + "stringUnit" : { + "state" : "translated", + "value" : "Mac이 잠금 해제되어 있는 동안에는 인증이 필요하지 않지만 비밀이 사용되면 알림을 받게 됩니다." + } + }, + "nb" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "nl" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "pl" : { + "stringUnit" : { + "state" : "translated", + "value" : "Uwierzytelnianie nie jest wymagane gdy twój Mac jest odblokowany. Otrzymasz powiadomienie kiedy sekret zostanie użyty." + } + }, + "pt" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "pt-BR" : { + "stringUnit" : { + "state" : "translated", + "value" : "Nenhuma autenticação é solicitada enquanto seu Mac estiver desbloqueado, mas você será notificado quando um segredo for usado." + } + }, + "ro" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Аутентификация не потребуется пока Ваш Mac разблокирован, но Вы получите уведомление, если секрет будет использован." + } + }, + "sr" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "sv" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "tr" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "uk" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "vi" : { + "stringUnit" : { + "state" : "new", + "value" : "No authentication is required while your Mac is unlocked, but you will be notified when a secret is used." + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "当Mac已解锁时无需验证,但密钥串被使用时会通知您。" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "當Mac已解鎖時無需驗證,但Secret被使用时會通知您。" + } + } + } + }, + "create_secret_while_unlocked_notify_title" : { + "extractionState" : "manual", + "localizations" : { + "af" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "ar" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "ca" : { + "stringUnit" : { + "state" : "translated", + "value" : "Notifica" + } + }, + "cs" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "da" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "Benachrichtigen" + } + }, + "el" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "es" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "fi" : { + "stringUnit" : { + "state" : "translated", + "value" : "Ilmoita" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "Notifier" + } + }, + "he" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "hu" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "it" : { + "stringUnit" : { + "state" : "translated", + "value" : "Notifica" + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "通知のみ" + } + }, + "ko" : { + "stringUnit" : { + "state" : "translated", + "value" : "알림" + } + }, + "nb" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "nl" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "pl" : { + "stringUnit" : { + "state" : "translated", + "value" : "Powiadom" + } + }, + "pt" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "pt-BR" : { + "stringUnit" : { + "state" : "translated", + "value" : "Notificar" + } + }, + "ro" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Уведомить" + } + }, + "sr" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "sv" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "tr" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "uk" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "vi" : { + "stringUnit" : { + "state" : "new", + "value" : "Notify" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "通知" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "通知" + } + } + } + }, "delete_confirmation_cancel_button" : { "extractionState" : "manual", "localizations" : { diff --git a/Sources/Packages/Sources/SecretKit/Types/CreationOptions.swift b/Sources/Packages/Sources/SecretKit/Types/CreationOptions.swift index b74231c..73dae83 100644 --- a/Sources/Packages/Sources/SecretKit/Types/CreationOptions.swift +++ b/Sources/Packages/Sources/SecretKit/Types/CreationOptions.swift @@ -7,9 +7,6 @@ public struct Attributes: Sendable, Codable, Hashable { /// The authentication requirements for the key. This is simply a description of the option recorded at creation – modifying it doers not modify the key's authentication requirements. public let authentication: AuthenticationRequirement - - /// Whether the key can be used while unlocked. This is only applicable to keys with `notRequired` authentication requirements. - public let allowWhileLocked: Bool /// The string appended to the end of the SSH Public Key. /// If nil, a default value will be used. @@ -18,12 +15,10 @@ public struct Attributes: Sendable, Codable, Hashable { public init( keyType: KeyType, authentication: AuthenticationRequirement, - allowWhileLocked: Bool, publicKeyAttribution: String? = nil ) { self.keyType = keyType self.authentication = authentication - self.allowWhileLocked = allowWhileLocked self.publicKeyAttribution = publicKeyAttribution } @@ -36,9 +31,13 @@ public struct Attributes: Sendable, Codable, Hashable { /// The option specified public enum AuthenticationRequirement: String, Hashable, Sendable, Codable, Identifiable { - /// Authentication is not required for usage. - case notRequired - + /// Authentication is not required for usage. Authentication is not permitted while the device is locked. + /// - Note: This option was previously known as `notRequired` and its value is pinned accordingly. + case notRequiredWhileUnlocked = "notRequired" + + /// Authentication is not required for usage, and authentication is permitted while the device is locked. + case notRequiredAfterFirstUnlock + /// The user needs to authenticate, using either a biometric option, a connected authorized watch, or password entry.. case presenceRequired diff --git a/Sources/Packages/Sources/SecureEnclaveSecretKit/CryptoKitMigrator.swift b/Sources/Packages/Sources/SecureEnclaveSecretKit/CryptoKitMigrator.swift index 3f2470f..3828a27 100644 --- a/Sources/Packages/Sources/SecureEnclaveSecretKit/CryptoKitMigrator.swift +++ b/Sources/Packages/Sources/SecureEnclaveSecretKit/CryptoKitMigrator.swift @@ -47,7 +47,7 @@ extension SecureEnclave { .contains("DeviceOwnerAuthentication") ? .presenceRequired : .unknown do { let parsed = try CryptoKit.SecureEnclave.P256.Signing.PrivateKey(dataRepresentation: tokenObjectID) - let secret = Secret(id: UUID().uuidString, name: name, publicKey: parsed.publicKey.x963Representation, attributes: Attributes(keyType: .init(algorithm: .ecdsa, size: 256), authentication: auth, allowWhileLocked: false)) + 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.") markMigrated(secret: secret, oldID: id) diff --git a/Sources/Packages/Sources/SecureEnclaveSecretKit/SecureEnclaveStore.swift b/Sources/Packages/Sources/SecureEnclaveSecretKit/SecureEnclaveStore.swift index 5735da2..c9dc46d 100644 --- a/Sources/Packages/Sources/SecureEnclaveSecretKit/SecureEnclaveStore.swift +++ b/Sources/Packages/Sources/SecureEnclaveSecretKit/SecureEnclaveStore.swift @@ -92,7 +92,7 @@ extension SecureEnclave { public func create(name: String, attributes: Attributes) async throws -> Secret { var accessError: SecurityError? let flags: SecAccessControlCreateFlags = switch attributes.authentication { - case .notRequired: + case .notRequiredWhileUnlocked, .notRequiredAfterFirstUnlock: [.privateKeyUsage] case .presenceRequired: [.userPresence, .privateKeyUsage] @@ -246,11 +246,17 @@ extension SecureEnclave.Store { func saveKey(_ key: Data, name: String, attributes: Attributes) throws -> String { let encodedAttributes = try JSONEncoder().encode(attributes) let id = UUID().uuidString + let accessibility = switch attributes.authentication { + case .biometryCurrent, .presenceRequired, .notRequiredWhileUnlocked, .unknown: + kSecAttrAccessibleWhenUnlockedThisDeviceOnly + case .notRequiredAfterFirstUnlock: + kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly + } let keychainAttributes = KeychainDictionary([ kSecClass: Constants.keyClass, kSecAttrService: Constants.keyTag, kSecUseDataProtectionKeychain: true, - kSecAttrAccessible: attributes.allowWhileLocked ? kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly : kSecAttrAccessibleWhenUnlockedThisDeviceOnly, + kSecAttrAccessible: accessibility, kSecAttrAccount: id, kSecValueData: key, kSecAttrLabel: name, diff --git a/Sources/Packages/Sources/SmartCardSecretKit/SmartCardStore.swift b/Sources/Packages/Sources/SmartCardSecretKit/SmartCardStore.swift index 66d6cd2..fd8d63d 100644 --- a/Sources/Packages/Sources/SmartCardSecretKit/SmartCardStore.swift +++ b/Sources/Packages/Sources/SmartCardSecretKit/SmartCardStore.swift @@ -156,7 +156,7 @@ extension SmartCard.Store { let publicKeySecRef = SecKeyCopyPublicKey(publicKeyRef)! let publicKeyAttributes = SecKeyCopyAttributes(publicKeySecRef) as! [CFString: Any] let publicKey = publicKeyAttributes[kSecValueData] as! Data - let attributes = Attributes(keyType: KeyType(secAttr: algorithmSecAttr, size: keySize)!, authentication: .presenceRequired, allowWhileLocked: false) + let attributes = Attributes(keyType: KeyType(secAttr: algorithmSecAttr, size: keySize)!, authentication: .presenceRequired) let secret = SmartCard.Secret(id: tokenID, name: name, publicKey: publicKey, attributes: attributes) guard signatureAlgorithm(for: secret) != nil else { return nil } return secret diff --git a/Sources/Packages/Tests/SSHProtocolKitTests/OpenSSHPublicKeyWriterTests.swift b/Sources/Packages/Tests/SSHProtocolKitTests/OpenSSHPublicKeyWriterTests.swift index b1ff535..7832d17 100644 --- a/Sources/Packages/Tests/SSHProtocolKitTests/OpenSSHPublicKeyWriterTests.swift +++ b/Sources/Packages/Tests/SSHProtocolKitTests/OpenSSHPublicKeyWriterTests.swift @@ -46,8 +46,8 @@ import SSHProtocolKit extension OpenSSHPublicKeyWriterTests { enum Constants { - static let ecdsa256Secret = TestSecret(id: Data(), name: "Test Key (ECDSA 256)", publicKey: Data(base64Encoded: "BOVEjgAA5PHqRgwykjN5qM21uWCHFSY/Sqo5gkHAkn+e1MMQKHOLga7ucB9b3mif33MBid59GRK9GEPVlMiSQwo=")!, attributes: Attributes(keyType: KeyType(algorithm: .ecdsa, size: 256), authentication: .notRequired, allowWhileLocked: true, publicKeyAttribution: "test@example.com")) - static let ecdsa384Secret = TestSecret(id: Data(), name: "Test Key (ECDSA 384)", publicKey: Data(base64Encoded: "BG2MNc/C5OTHFE2tBvbZCVcpOGa8vBMquiTLkH4lwkeqOPxhi+PyYUfQZMTRJNPiTyWPoMBqNiCIFRVv60yPN/AHufHaOgbdTP42EgMlMMImkAjYUEv9DESHTVIs2PW1yQ==")!, attributes: Attributes(keyType: KeyType(algorithm: .ecdsa, size: 384), authentication: .notRequired, allowWhileLocked: true, publicKeyAttribution: "test@example.com")) + static let ecdsa256Secret = TestSecret(id: Data(), name: "Test Key (ECDSA 256)", publicKey: Data(base64Encoded: "BOVEjgAA5PHqRgwykjN5qM21uWCHFSY/Sqo5gkHAkn+e1MMQKHOLga7ucB9b3mif33MBid59GRK9GEPVlMiSQwo=")!, attributes: Attributes(keyType: KeyType(algorithm: .ecdsa, size: 256), authentication: .notRequiredWhileUnlocked, publicKeyAttribution: "test@example.com")) + static let ecdsa384Secret = TestSecret(id: Data(), name: "Test Key (ECDSA 384)", publicKey: Data(base64Encoded: "BG2MNc/C5OTHFE2tBvbZCVcpOGa8vBMquiTLkH4lwkeqOPxhi+PyYUfQZMTRJNPiTyWPoMBqNiCIFRVv60yPN/AHufHaOgbdTP42EgMlMMImkAjYUEv9DESHTVIs2PW1yQ==")!, attributes: Attributes(keyType: KeyType(algorithm: .ecdsa, size: 384), authentication: .notRequiredWhileUnlocked, publicKeyAttribution: "test@example.com")) } diff --git a/Sources/Packages/Tests/SSHProtocolKitTests/OpenSSHSignatureWriterTests.swift b/Sources/Packages/Tests/SSHProtocolKitTests/OpenSSHSignatureWriterTests.swift index 0fd0404..e987334 100644 --- a/Sources/Packages/Tests/SSHProtocolKitTests/OpenSSHSignatureWriterTests.swift +++ b/Sources/Packages/Tests/SSHProtocolKitTests/OpenSSHSignatureWriterTests.swift @@ -51,7 +51,7 @@ private extension OpenSSHSignatureWriterTests { publicKey: Data(repeating: 0x01, count: 65), attributes: Attributes( keyType: KeyType(algorithm: .ecdsa, size: 256), - authentication: .notRequired, allowWhileLocked: true, + authentication: .notRequiredWhileUnlocked, publicKeyAttribution: "test@example.com" ) ) diff --git a/Sources/Packages/Tests/SecretAgentKitTests/AuthenticationHandlerTests.swift b/Sources/Packages/Tests/SecretAgentKitTests/AuthenticationHandlerTests.swift index e5ea5fa..e91082c 100644 --- a/Sources/Packages/Tests/SecretAgentKitTests/AuthenticationHandlerTests.swift +++ b/Sources/Packages/Tests/SecretAgentKitTests/AuthenticationHandlerTests.swift @@ -34,7 +34,7 @@ public struct TestSecret: Secret { init(authenticationRequirement: AuthenticationRequirement, testEvaluationResult: Bool, approval: ApprovalMode = .manual) { self.canceled = false self.testEvaluationResult = testEvaluationResult - self.secret = AnySecret(TestSecret(attributes: .init(keyType: .ecdsa256, authentication: authenticationRequirement, allowWhileLocked: false))) + self.secret = AnySecret(TestSecret(attributes: .init(keyType: .ecdsa256, authentication: authenticationRequirement))) self.approval = approval } @@ -121,7 +121,7 @@ public struct TestSecret: Secret { calledPresentPending = true } let contextA = TestContext(authenticationRequirement: .presenceRequired, testEvaluationResult: true, approval: .manual) - let contextB = TestContext(authenticationRequirement: .notRequired, testEvaluationResult: true) + let contextB = TestContext(authenticationRequirement: .notRequiredWhileUnlocked, testEvaluationResult: true) var unauthenticatedResult = false Task { Task { @@ -145,7 +145,7 @@ public struct TestSecret: Secret { } let contextA = TestContext(authenticationRequirement: .presenceRequired, testEvaluationResult: true) let contextB = TestContext(authenticationRequirement: .presenceRequired, testEvaluationResult: true) - let contextC = TestContext(authenticationRequirement: .notRequired, testEvaluationResult: true) + let contextC = TestContext(authenticationRequirement: .notRequiredWhileUnlocked, testEvaluationResult: true) Task { _ = try? await handler.authenticatedContext(for: .init(secret: .init(contextA.secret), provenance: .test, target: nil), context: contextA) } diff --git a/Sources/Packages/Tests/SecretAgentKitTests/StubStore.swift b/Sources/Packages/Tests/SecretAgentKitTests/StubStore.swift index 66f8c0b..2aa65ff 100644 --- a/Sources/Packages/Tests/SecretAgentKitTests/StubStore.swift +++ b/Sources/Packages/Tests/SecretAgentKitTests/StubStore.swift @@ -77,7 +77,7 @@ extension Stub { let privateKey: Data init(keySize: Int, publicKey: Data, privateKey: Data) { - self.attributes = Attributes(keyType: .init(algorithm: .ecdsa, size: keySize), authentication: .notRequired, allowWhileLocked: false, publicKeyAttribution: "ecdsa-\(keySize)@example.com") + self.attributes = Attributes(keyType: .init(algorithm: .ecdsa, size: keySize), authentication: .notRequiredWhileUnlocked, publicKeyAttribution: "ecdsa-\(keySize)@example.com") self.publicKey = publicKey self.privateKey = privateKey } diff --git a/Sources/Packages/Tests/SecretKitTests/AnySecretTests.swift b/Sources/Packages/Tests/SecretKitTests/AnySecretTests.swift index ac13975..1b2df81 100644 --- a/Sources/Packages/Tests/SecretKitTests/AnySecretTests.swift +++ b/Sources/Packages/Tests/SecretKitTests/AnySecretTests.swift @@ -9,7 +9,7 @@ import Testing @Test func eraser() { let data = Data(UUID().uuidString.utf8) - let secret = SmartCard.Secret(id: data, name: "Name", publicKey: data, attributes: Attributes(keyType: KeyType(algorithm: .ecdsa, size: 256), authentication: .notRequired, allowWhileLocked: true)) + let secret = SmartCard.Secret(id: data, name: "Name", publicKey: data, attributes: Attributes(keyType: KeyType(algorithm: .ecdsa, size: 256), authentication: .notRequiredWhileUnlocked)) let erased = AnySecret(secret) #expect(erased.id == secret.id as AnyHashable) #expect(erased.name == secret.name) diff --git a/Sources/Secretive/Preview Content/PreviewStore.swift b/Sources/Secretive/Preview Content/PreviewStore.swift index efdcdea..5a14b7c 100644 --- a/Sources/Secretive/Preview Content/PreviewStore.swift +++ b/Sources/Secretive/Preview Content/PreviewStore.swift @@ -15,7 +15,6 @@ extension Preview { Attributes( keyType: .init(algorithm: .ecdsa, size: 256), authentication: .presenceRequired, - allowWhileLocked: true, ) } } diff --git a/Sources/Secretive/Views/Secrets/CreateSecretView.swift b/Sources/Secretive/Views/Secrets/CreateSecretView.swift index d99bbac..5d8de93 100644 --- a/Sources/Secretive/Views/Secrets/CreateSecretView.swift +++ b/Sources/Secretive/Views/Secrets/CreateSecretView.swift @@ -10,16 +10,15 @@ struct CreateSecretView: View { @State private var name = "" @State private var keyAttribution = "" @State private var authenticationRequirement: AuthenticationRequirement = .presenceRequired - @State private var allowWhileLocked = false @State private var keyType: KeyType? @State var advanced = false @State var errorText: String? private var authenticationOptions: [AuthenticationRequirement] { if advanced || authenticationRequirement == .biometryCurrent { - [.presenceRequired, .notRequired, .biometryCurrent] + [.presenceRequired, .notRequiredWhileUnlocked, .notRequiredAfterFirstUnlock, .biometryCurrent] } else { - [.presenceRequired, .notRequired] + [.presenceRequired, .notRequiredWhileUnlocked] } } @@ -33,9 +32,12 @@ struct CreateSecretView: View { ForEach(authenticationOptions) { option in HStack { switch option { - case .notRequired: + case .notRequiredWhileUnlocked: Image(systemName: "bell") - Text(.createSecretNotifyTitle) + Text(.createSecretWhileUnlockedNotifyTitle) + case .notRequiredAfterFirstUnlock: + Image(systemName: "lock.display") + Text(.createSecretAfterFirstUnlockNotifyTitle) case .presenceRequired: Image(systemName: "lock") Text(.createSecretRequireAuthenticationTitle) @@ -50,9 +52,11 @@ struct CreateSecretView: View { } } Group { - switch authenticationRequirement { - case .notRequired: - Text(.createSecretNotifyDescription) + switch authenticationRequirement { + case .notRequiredAfterFirstUnlock: + Text(.createSecretAfterFirstUnlockNotifyDescription) + case .notRequiredWhileUnlocked: + Text(.createSecretWhileUnlockedNotifyDescription) case .presenceRequired: Text(.createSecretRequireAuthenticationDescription) case .biometryCurrent: @@ -74,12 +78,6 @@ struct CreateSecretView: View { } if advanced { Section { - Toggle(isOn: $allowWhileLocked) { - Text(.createSecretAllowWhileLockedLabel) - Text(.createSecretAllowWhileLockedDescription) - .font(.subheadline) - .foregroundStyle(.secondary) - } VStack { Picker(.createSecretKeyTypeLabel, selection: $keyType) { ForEach(store.supportedKeyTypes.available, id: \.self) { option in @@ -153,7 +151,6 @@ struct CreateSecretView: View { attributes: .init( keyType: keyType!, authentication: authenticationRequirement, - allowWhileLocked: allowWhileLocked, publicKeyAttribution: attribution ) )