2020-03-04 07:14:38 +00:00
|
|
|
import Foundation
|
|
|
|
import Security
|
|
|
|
import CryptoTokenKit
|
|
|
|
|
2020-03-06 06:47:13 +00:00
|
|
|
// TODO: Might need to split this up into "sub-stores?"
|
|
|
|
// ie, each token has its own Store.
|
2020-03-04 07:14:38 +00:00
|
|
|
extension SmartCard {
|
|
|
|
|
|
|
|
public class Store: SecretStore {
|
|
|
|
|
|
|
|
// TODO: Read actual smart card name, eg "YubiKey 5c"
|
|
|
|
public let name = NSLocalizedString("Smart Card", comment: "Smart Card")
|
|
|
|
@Published public fileprivate(set) var secrets: [Secret] = []
|
|
|
|
fileprivate let watcher = TKTokenWatcher()
|
|
|
|
|
|
|
|
public init() {
|
|
|
|
watcher.setInsertionHandler { (string) in
|
2020-03-06 06:47:13 +00:00
|
|
|
guard !string.contains("setoken") else { return }
|
|
|
|
let driver = TKSmartCardTokenDriver()
|
|
|
|
let token = TKToken(tokenDriver: driver, instanceID: string)
|
|
|
|
let session = TKSmartCardTo kenSession(token: token)
|
|
|
|
print(session)
|
|
|
|
|
2020-03-04 07:14:38 +00:00
|
|
|
}
|
|
|
|
print(watcher.tokenIDs)
|
|
|
|
}
|
|
|
|
|
|
|
|
public func sign(data: Data, with secret: SmartCard.Secret) throws -> Data {
|
|
|
|
fatalError()
|
|
|
|
}
|
|
|
|
|
|
|
|
public func delete(secret: SmartCard.Secret) throws {
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|