didactek / deft-simple-usb

Usermode support of custom USB device drivers in Swift on macOS and Linux, using either the libusb system library or the IOUSBHost framework.
Apache License 2.0
18 stars 1 forks source link

Using in a sandboxed app #1

Open txbrown opened 2 years ago

txbrown commented 2 years ago

When using inside a sandboxed app I get

Error:Unable to open io_service_t object and create user client. with reason: IOServiceOpen failed.

I am fairly confident this is more of an Apple usb security level but I thought I'd ask just in case. There isn't much info about this and the only forum question is still unanswered

kit-transue commented 2 years ago

I have not found great sources of documentation for using USB in the post-kext era. I've managed to get a few hack-with-hardware devices working, but I'm definitely not an expert and don't have broad experience in the domain. That said:

I'd look at what device you are trying to get a connection to. Again: my notes are slim, but I recall "can't get exclusive access" happens when the OS thinks it should be providing the driver for the device. I think I get that with the MCP2221 which offers an HID interface: macOS sees that and--quite properly, IMO--binds to it. User mode applications should still be able to communicate with the device; they just have to go through the HID API.

My suggestions:

While the documentation can be slim, the fundamental security architecture seems sound and also reasonable. You should not need special DriverKit certification from Apple, nor should you need to be root. My mental model is that the documentation is very old and while much of it describes a kext model that has (thankfully!) disappeared, parts of that technology came over to the usermode side and the documentation is yet to be modernized.

mickeyl commented 1 year ago

I have the same problem, but I'm using an SPM-based command line program which should not use the sandbox in the first place. The error is

Error Domain=IOUSBHostErrorDomain Code=-536870203 "Failed to create IOUSBHostObject." UserInfo={NSLocalizedRecoverySuggestion=Another client likely has exclusive access., NSLocalizedDescription=Failed to create IOUSBHostObject., NSLocalizedFailureReason=Exclusive open of usb object failed.}

It's not even working when launching as root.