XPC scaffolding

This commit is contained in:
Max Goedjen
2022-01-02 22:15:18 -08:00
parent 98bf285ad2
commit d80d2ca656
18 changed files with 191 additions and 58 deletions

View File

@@ -7,8 +7,11 @@ import SmartCardSecretKit
import SecretAgentKit
import Brief
import SecretKit
import SecretAgentKitProtocol
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
class AppDelegate: NSObject, NSApplicationDelegate, AgentProtocol {
private let storeList: SecretStoreList = {
let list = SecretStoreList()
@@ -27,9 +30,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
return SocketController(path: path)
}()
private var updateSink: AnyCancellable?
private let logger = Logger()
var delegate: ServiceDelegate? = nil
let listener = NSXPCListener(machServiceName: Bundle.main.bundleIdentifier!)
func applicationDidFinishLaunching(_ aNotification: Notification) {
Logger().debug("SecretAgent finished launching")
logger.debug("SecretAgent finished launching")
DispatchQueue.main.async {
self.socketController.handler = self.agent.handle(reader:writer:)
}
@@ -39,13 +45,37 @@ class AppDelegate: NSObject, NSApplicationDelegate {
guard let update = update else { return }
self.notifier.notify(update: update, ignore: self.updater.ignore(release:))
}
connect()
}
func reloadKeys() {
// TODO: This
// storeList.reloadAll()
try? publicKeyFileStoreController.generatePublicKeys(for: storeList.stores.flatMap({ $0.secrets }), clear: true)
func connect() {
delegate = ServiceDelegate(exportedObject: self)
listener.delegate = delegate
listener.resume()
}
func updatedStore(withID id: UUID) async throws {
logger.debug("Reloading keys for store with id: \(id)")
guard let store = storeList.modifiableStore, store.id == id else { throw AgentProtocolStoreNotFoundError() }
try store.reload()
try publicKeyFileStoreController.generatePublicKeys(for: storeList.stores.flatMap({ $0.secrets }), clear: true)
}
}
class ServiceDelegate: NSObject, NSXPCListenerDelegate {
let exported: AgentProtocol
init(exportedObject: AgentProtocol) {
self.exported = exportedObject
}
func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool {
newConnection.exportedInterface = NSXPCInterface(with: AgentProtocol.self)
newConnection.exportedObject = exported
newConnection.resume()
return true
}
}

View File

@@ -4,6 +4,10 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.application-groups</key>
<array>
<string>$(TeamIdentifierPrefix)com.maxgoedjen.secretive</string>
</array>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.smartcard</key>