Switch to authenticationrequirement instead of flag (#872)

This commit is contained in:
Max Goedjen authored and GitHub committed 2026-11-18 05:19:16 +00:00
1 parent c0562ba50a
commit 479075490d
12 files changed
+410 -409

No files matched your search

+374 -374
View File
@@ -6720,24 +6720,24 @@
} }
} }
}, },
"create_secret_allow_while_locked_description" : { "create_secret_after_first_unlock_notify_description" : {
"extractionState" : "manual", "extractionState" : "manual",
"localizations" : { "localizations" : {
"en" : { "en" : {
"stringUnit" : { "stringUnit" : {
"state" : "translated", "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", "extractionState" : "manual",
"localizations" : { "localizations" : {
"en" : { "en" : {
"stringUnit" : { "stringUnit" : {
"state" : "translated", "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" : { "create_secret_protection_level_title" : {
"extractionState" : "manual", "extractionState" : "manual",
"localizations" : { "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" : { "delete_confirmation_cancel_button" : {
"extractionState" : "manual", "extractionState" : "manual",
"localizations" : { "localizations" : {
@@ -8,9 +8,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. /// 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 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. /// The string appended to the end of the SSH Public Key.
/// If nil, a default value will be used. /// If nil, a default value will be used.
public var publicKeyAttribution: String? public var publicKeyAttribution: String?
@@ -18,12 +15,10 @@ public struct Attributes: Sendable, Codable, Hashable {
public init( public init(
keyType: KeyType, keyType: KeyType,
authentication: AuthenticationRequirement, authentication: AuthenticationRequirement,
allowWhileLocked: Bool,
publicKeyAttribution: String? = nil publicKeyAttribution: String? = nil
) { ) {
self.keyType = keyType self.keyType = keyType
self.authentication = authentication self.authentication = authentication
self.allowWhileLocked = allowWhileLocked
self.publicKeyAttribution = publicKeyAttribution self.publicKeyAttribution = publicKeyAttribution
} }
@@ -36,8 +31,12 @@ public struct Attributes: Sendable, Codable, Hashable {
/// The option specified /// The option specified
public enum AuthenticationRequirement: String, Hashable, Sendable, Codable, Identifiable { public enum AuthenticationRequirement: String, Hashable, Sendable, Codable, Identifiable {
/// Authentication is not required for usage. /// Authentication is not required for usage. Authentication is not permitted while the device is locked.
case notRequired /// - 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.. /// The user needs to authenticate, using either a biometric option, a connected authorized watch, or password entry..
case presenceRequired case presenceRequired
@@ -47,7 +47,7 @@ extension SecureEnclave {
.contains("DeviceOwnerAuthentication") ? .presenceRequired : .unknown .contains("DeviceOwnerAuthentication") ? .presenceRequired : .unknown
do { do {
let parsed = try CryptoKit.SecureEnclave.P256.Signing.PrivateKey(dataRepresentation: tokenObjectID) 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 { guard !migratedPublicKeys.contains(parsed.publicKey.x963Representation) else {
logger.log("Skipping \(name), public key already present. Marking as migrated.") logger.log("Skipping \(name), public key already present. Marking as migrated.")
markMigrated(secret: secret, oldID: id) markMigrated(secret: secret, oldID: id)
@@ -92,7 +92,7 @@ extension SecureEnclave {
public func create(name: String, attributes: Attributes) async throws -> Secret { public func create(name: String, attributes: Attributes) async throws -> Secret {
var accessError: SecurityError? var accessError: SecurityError?
let flags: SecAccessControlCreateFlags = switch attributes.authentication { let flags: SecAccessControlCreateFlags = switch attributes.authentication {
case .notRequired: case .notRequiredWhileUnlocked, .notRequiredAfterFirstUnlock:
[.privateKeyUsage] [.privateKeyUsage]
case .presenceRequired: case .presenceRequired:
[.userPresence, .privateKeyUsage] [.userPresence, .privateKeyUsage]
@@ -246,11 +246,17 @@ extension SecureEnclave.Store {
func saveKey(_ key: Data, name: String, attributes: Attributes) throws -> String { func saveKey(_ key: Data, name: String, attributes: Attributes) throws -> String {
let encodedAttributes = try JSONEncoder().encode(attributes) let encodedAttributes = try JSONEncoder().encode(attributes)
let id = UUID().uuidString let id = UUID().uuidString
let accessibility = switch attributes.authentication {
case .biometryCurrent, .presenceRequired, .notRequiredWhileUnlocked, .unknown:
kSecAttrAccessibleWhenUnlockedThisDeviceOnly
case .notRequiredAfterFirstUnlock:
kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
}
let keychainAttributes = KeychainDictionary([ let keychainAttributes = KeychainDictionary([
kSecClass: Constants.keyClass, kSecClass: Constants.keyClass,
kSecAttrService: Constants.keyTag, kSecAttrService: Constants.keyTag,
kSecUseDataProtectionKeychain: true, kSecUseDataProtectionKeychain: true,
kSecAttrAccessible: attributes.allowWhileLocked ? kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly : kSecAttrAccessibleWhenUnlockedThisDeviceOnly, kSecAttrAccessible: accessibility,
kSecAttrAccount: id, kSecAttrAccount: id,
kSecValueData: key, kSecValueData: key,
kSecAttrLabel: name, kSecAttrLabel: name,
@@ -156,7 +156,7 @@ extension SmartCard.Store {
let publicKeySecRef = SecKeyCopyPublicKey(publicKeyRef)! let publicKeySecRef = SecKeyCopyPublicKey(publicKeyRef)!
let publicKeyAttributes = SecKeyCopyAttributes(publicKeySecRef) as! [CFString: Any] let publicKeyAttributes = SecKeyCopyAttributes(publicKeySecRef) as! [CFString: Any]
let publicKey = publicKeyAttributes[kSecValueData] as! Data 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) let secret = SmartCard.Secret(id: tokenID, name: name, publicKey: publicKey, attributes: attributes)
guard signatureAlgorithm(for: secret) != nil else { return nil } guard signatureAlgorithm(for: secret) != nil else { return nil }
return secret return secret
@@ -46,8 +46,8 @@ import SSHProtocolKit
extension OpenSSHPublicKeyWriterTests { extension OpenSSHPublicKeyWriterTests {
enum Constants { 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 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: .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: .notRequiredWhileUnlocked, publicKeyAttribution: "test@example.com"))
} }
@@ -51,7 +51,7 @@ private extension OpenSSHSignatureWriterTests {
publicKey: Data(repeating: 0x01, count: 65), publicKey: Data(repeating: 0x01, count: 65),
attributes: Attributes( attributes: Attributes(
keyType: KeyType(algorithm: .ecdsa, size: 256), keyType: KeyType(algorithm: .ecdsa, size: 256),
authentication: .notRequired, allowWhileLocked: true, authentication: .notRequiredWhileUnlocked,
publicKeyAttribution: "test@example.com" publicKeyAttribution: "test@example.com"
) )
) )
@@ -34,7 +34,7 @@ public struct TestSecret: Secret {
init(authenticationRequirement: AuthenticationRequirement, testEvaluationResult: Bool, approval: ApprovalMode = .manual) { init(authenticationRequirement: AuthenticationRequirement, testEvaluationResult: Bool, approval: ApprovalMode = .manual) {
self.canceled = false self.canceled = false
self.testEvaluationResult = testEvaluationResult 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 self.approval = approval
} }
@@ -121,7 +121,7 @@ public struct TestSecret: Secret {
calledPresentPending = true calledPresentPending = true
} }
let contextA = TestContext(authenticationRequirement: .presenceRequired, testEvaluationResult: true, approval: .manual) 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 var unauthenticatedResult = false
Task { Task {
Task { Task {
@@ -145,7 +145,7 @@ public struct TestSecret: Secret {
} }
let contextA = TestContext(authenticationRequirement: .presenceRequired, testEvaluationResult: true) let contextA = TestContext(authenticationRequirement: .presenceRequired, testEvaluationResult: true)
let contextB = 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 { Task {
_ = try? await handler.authenticatedContext(for: .init(secret: .init(contextA.secret), provenance: .test, target: nil), context: contextA) _ = try? await handler.authenticatedContext(for: .init(secret: .init(contextA.secret), provenance: .test, target: nil), context: contextA)
} }
@@ -77,7 +77,7 @@ extension Stub {
let privateKey: Data let privateKey: Data
init(keySize: Int, publicKey: Data, 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.publicKey = publicKey
self.privateKey = privateKey self.privateKey = privateKey
} }
@@ -9,7 +9,7 @@ import Testing
@Test func eraser() { @Test func eraser() {
let data = Data(UUID().uuidString.utf8) 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) let erased = AnySecret(secret)
#expect(erased.id == secret.id as AnyHashable) #expect(erased.id == secret.id as AnyHashable)
#expect(erased.name == secret.name) #expect(erased.name == secret.name)
@@ -15,7 +15,6 @@ extension Preview {
Attributes( Attributes(
keyType: .init(algorithm: .ecdsa, size: 256), keyType: .init(algorithm: .ecdsa, size: 256),
authentication: .presenceRequired, authentication: .presenceRequired,
allowWhileLocked: true,
) )
} }
} }
@@ -10,16 +10,15 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
@State private var name = "" @State private var name = ""
@State private var keyAttribution = "" @State private var keyAttribution = ""
@State private var authenticationRequirement: AuthenticationRequirement = .presenceRequired @State private var authenticationRequirement: AuthenticationRequirement = .presenceRequired
@State private var allowWhileLocked = false
@State private var keyType: KeyType? @State private var keyType: KeyType?
@State var advanced = false @State var advanced = false
@State var errorText: String? @State var errorText: String?
private var authenticationOptions: [AuthenticationRequirement] { private var authenticationOptions: [AuthenticationRequirement] {
if advanced || authenticationRequirement == .biometryCurrent { if advanced || authenticationRequirement == .biometryCurrent {
[.presenceRequired, .notRequired, .biometryCurrent] [.presenceRequired, .notRequiredWhileUnlocked, .notRequiredAfterFirstUnlock, .biometryCurrent]
} else { } else {
[.presenceRequired, .notRequired] [.presenceRequired, .notRequiredWhileUnlocked]
} }
} }
@@ -33,9 +32,12 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
ForEach(authenticationOptions) { option in ForEach(authenticationOptions) { option in
HStack { HStack {
switch option { switch option {
case .notRequired: case .notRequiredWhileUnlocked:
Image(systemName: "bell") Image(systemName: "bell")
Text(.createSecretNotifyTitle) Text(.createSecretWhileUnlockedNotifyTitle)
case .notRequiredAfterFirstUnlock:
Image(systemName: "lock.display")
Text(.createSecretAfterFirstUnlockNotifyTitle)
case .presenceRequired: case .presenceRequired:
Image(systemName: "lock") Image(systemName: "lock")
Text(.createSecretRequireAuthenticationTitle) Text(.createSecretRequireAuthenticationTitle)
@@ -50,9 +52,11 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
} }
} }
Group { Group {
switch authenticationRequirement { switch authenticationRequirement {
case .notRequired: case .notRequiredAfterFirstUnlock:
Text(.createSecretNotifyDescription) Text(.createSecretAfterFirstUnlockNotifyDescription)
case .notRequiredWhileUnlocked:
Text(.createSecretWhileUnlockedNotifyDescription)
case .presenceRequired: case .presenceRequired:
Text(.createSecretRequireAuthenticationDescription) Text(.createSecretRequireAuthenticationDescription)
case .biometryCurrent: case .biometryCurrent:
@@ -74,12 +78,6 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
} }
if advanced { if advanced {
Section { Section {
Toggle(isOn: $allowWhileLocked) {
Text(.createSecretAllowWhileLockedLabel)
Text(.createSecretAllowWhileLockedDescription)
.font(.subheadline)
.foregroundStyle(.secondary)
}
VStack { VStack {
Picker(.createSecretKeyTypeLabel, selection: $keyType) { Picker(.createSecretKeyTypeLabel, selection: $keyType) {
ForEach(store.supportedKeyTypes.available, id: \.self) { option in ForEach(store.supportedKeyTypes.available, id: \.self) { option in
@@ -153,7 +151,6 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
attributes: .init( attributes: .init(
keyType: keyType!, keyType: keyType!,
authentication: authenticationRequirement, authentication: authenticationRequirement,
allowWhileLocked: allowWhileLocked,
publicKeyAttribution: attribution publicKeyAttribution: attribution
) )
) )