Add driver name when on macOS 12.0 (#223)

This commit is contained in:
Max Goedjen 2021-11-07 12:27:18 -08:00 committed by GitHub
parent 4ab3783a15
commit faed5514e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 6 deletions

View File

@ -9,7 +9,6 @@ extension SmartCard {
public class Store: SecretStore { public class Store: SecretStore {
// TODO: Read actual smart card name, eg "YubiKey 5c"
@Published public var isAvailable: Bool = false @Published public var isAvailable: Bool = false
public let id = UUID() public let id = UUID()
public private(set) var name = NSLocalizedString("Smart Card", comment: "Smart Card") public private(set) var name = NSLocalizedString("Smart Card", comment: "Smart Card")
@ -103,12 +102,22 @@ extension SmartCard.Store {
private func loadSecrets() { private func loadSecrets() {
guard let tokenID = tokenID else { return } guard let tokenID = tokenID else { return }
// Hack to read name if there's only one smart card
let slotNames = TKSmartCardSlotManager().slotNames let fallbackName = NSLocalizedString("Smart Card", comment: "Smart Card")
if watcher.nonSecureEnclaveTokens.count == 1 && slotNames.count == 1 { if #available(macOS 12.0, *) {
name = slotNames.first! if let driverName = watcher.tokenInfo(forTokenID: tokenID)?.driverName {
name = driverName
} else {
name = fallbackName
}
} else { } else {
name = NSLocalizedString("Smart Card", comment: "Smart Card") // Hack to read name if there's only one smart card
let slotNames = TKSmartCardSlotManager().slotNames
if watcher.nonSecureEnclaveTokens.count == 1 && slotNames.count == 1 {
name = slotNames.first!
} else {
name = fallbackName
}
} }
let attributes = [ let attributes = [