From 101135b4980addd6ca2e453a2a1ffceee2252b43 Mon Sep 17 00:00:00 2001 From: Ben Toews Date: Tue, 1 Aug 2017 11:57:46 -0600 Subject: [PATCH 1/2] don't allow multiple user clients --- SoftU2FDriver/SoftU2FDriver.cpp | 12 ++++++++++++ SoftU2FDriver/SoftU2FDriver.hpp | 2 ++ 2 files changed, 14 insertions(+) diff --git a/SoftU2FDriver/SoftU2FDriver.cpp b/SoftU2FDriver/SoftU2FDriver.cpp index 01761c8..dcc4b15 100644 --- a/SoftU2FDriver/SoftU2FDriver.cpp +++ b/SoftU2FDriver/SoftU2FDriver.cpp @@ -35,3 +35,15 @@ void SoftU2FDriver::free() { IOWorkLoop* SoftU2FDriver::getWorkLoop() const { return _workLoop; } + +IOReturn SoftU2FDriver::newUserClient(task_t owningTask, void *securityID, UInt32 type, OSDictionary *properties, IOUserClient **handler) { + IOLog("%s[%p]::%s()\n", getName(), this, __FUNCTION__); + + // Check that another client isn't already connected. + if (getClient()) { + IOLog("%s[%p]::%s() -> kIOReturnExclusiveAccess\n", getName(), this, __FUNCTION__); + return kIOReturnExclusiveAccess; + } + + return super::newUserClient(owningTask, securityID, type, properties, handler); +} diff --git a/SoftU2FDriver/SoftU2FDriver.hpp b/SoftU2FDriver/SoftU2FDriver.hpp index 641e577..5f360cc 100644 --- a/SoftU2FDriver/SoftU2FDriver.hpp +++ b/SoftU2FDriver/SoftU2FDriver.hpp @@ -20,6 +20,8 @@ public : virtual bool start(IOService *provider) override; void free() override; IOWorkLoop* getWorkLoop() const override; + + virtual IOReturn newUserClient(task_t owningTask, void *securityID, UInt32 type, OSDictionary *properties, IOUserClient **handler) override; }; #endif /* SoftU2F_hpp */ From 4519b2b7d4c9112eed7f12bf73af6cac7441cfc2 Mon Sep 17 00:00:00 2001 From: Ben Toews Date: Tue, 1 Aug 2017 12:05:55 -0600 Subject: [PATCH 2/2] kill app when we can't connect to driver --- SoftU2FTool/AppDelegate.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SoftU2FTool/AppDelegate.swift b/SoftU2FTool/AppDelegate.swift index 84672f9..6c3a13b 100644 --- a/SoftU2FTool/AppDelegate.swift +++ b/SoftU2FTool/AppDelegate.swift @@ -12,12 +12,13 @@ class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ aNotification: Notification) { if !U2FAuthenticator.start() { print("Error starting authenticator") + NSApplication.shared().terminate(self) } } func applicationWillTerminate(_ aNotification: Notification) { - if !U2FAuthenticator.stop() { + if U2FAuthenticator.shared != nil && !U2FAuthenticator.stop() { print("Error stopping authenticator") } }