Initial implementation of using YubiKey for decryption (#533)
This commit is contained in:
parent
13804b79e6
commit
955e50c3d3
23 changed files with 606 additions and 118 deletions
63
passKit/Helpers/YubiKeyConnection.swift
Normal file
63
passKit/Helpers/YubiKeyConnection.swift
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
//
|
||||
// YubiKeyConnection.swift
|
||||
// passKit
|
||||
//
|
||||
// Copyright © 2022 Bob Sun. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import YubiKit
|
||||
|
||||
public class YubiKeyConnection: NSObject {
|
||||
public static let shared = YubiKeyConnection()
|
||||
|
||||
var accessoryConnection: YKFAccessoryConnection?
|
||||
var nfcConnection: YKFNFCConnection?
|
||||
var connectionCallback: ((_ connection: YKFConnectionProtocol) -> Void)?
|
||||
var cancellationCallback: ((_ error: Error) -> Void)?
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
YubiKitManager.shared.delegate = self
|
||||
YubiKitManager.shared.startAccessoryConnection()
|
||||
}
|
||||
|
||||
public func connection(cancellation: @escaping (_ error: Error) -> Void, completion: @escaping (_ connection: YKFConnectionProtocol) -> Void) {
|
||||
if let connection = accessoryConnection {
|
||||
completion(connection)
|
||||
} else {
|
||||
connectionCallback = completion
|
||||
if #available(iOSApplicationExtension 13.0, *) {
|
||||
YubiKitManager.shared.startNFCConnection()
|
||||
}
|
||||
}
|
||||
cancellationCallback = cancellation
|
||||
}
|
||||
}
|
||||
|
||||
extension YubiKeyConnection: YKFManagerDelegate {
|
||||
public func didConnectNFC(_ connection: YKFNFCConnection) {
|
||||
nfcConnection = connection
|
||||
if let callback = connectionCallback {
|
||||
callback(connection)
|
||||
}
|
||||
}
|
||||
|
||||
public func didDisconnectNFC(_: YKFNFCConnection, error _: Error?) {
|
||||
nfcConnection = nil
|
||||
}
|
||||
|
||||
public func didConnectAccessory(_ connection: YKFAccessoryConnection) {
|
||||
accessoryConnection = connection
|
||||
}
|
||||
|
||||
public func didDisconnectAccessory(_: YKFAccessoryConnection, error _: Error?) {
|
||||
accessoryConnection = nil
|
||||
}
|
||||
|
||||
public func didFailConnectingNFC(_ error: Error) {
|
||||
if let callback = cancellationCallback {
|
||||
callback(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue