-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot load unsigned dylibs on macOS with dart:ffi or native extensions #38314
Comments
We're running into this issue with the game engine we're developing. 👾 After upgrading to 2.5, we can no longer run the tests for our engine because they need to load dylibs. We've tried signing the dylibs, but we can't figure out a way to sign them such that |
@aab29 are you using ffi? Which operating system? If on macOS, did you try signing the library? |
If macOS, can you try the following workaround:
You might want to take a backup copy of the |
Hi @mit-mit ! Thanks for your speedy, helpful response! I'm sorry my reply is so delayed. We've been busy over here. 🤓 ⌨️ No--we are not using ffi. The error message we were getting was similar to the one I found here, but I'm afraid I missed that detail before I commented. We're still using the old native extensions system to interface with our dylibs. 💾 Let me know if you'd like me to create a separate issue or anything. We're currently running Dart 2.5.2, and we're hitting the same error messages we hit under Dart 2.5.0. 🎯 We are indeed running MacOS. For now we're running Mojave (10.14.6), but we're hoping to upgrade to Catalina soon. 🔜 🆙 The workaround you suggested (removing the signature on the main We don't have much experience dealing with code signing, so apologies if we're not doing something obvious. 🤔 From what we can tell, it seems like we should now be codesigning our own dynamic libraries, but if we sign them with our own credentials, it's not possible to interface with the Please let me know if there's any other information we can provide that might be helpful! ℹ️ |
@mit-mit , folks are going to run into this with doing the ffi tutorial. Has there been any progress? Ran into this with -dev.8.2 installed using brew. |
Conceptually speaking it makes sense that a signed Dart binary can only load signed (third party) shared libraries. For now, unsigned binaries can load unsigned (and probably signed) third party libraries. However, future MacOS versions will likely disallow that. I think the path forward would be to include in our tutorial how to sign your own custom made library on MacOS Catalina. cc @mkustermann |
I am still getting same error while using flutter in macos and to call my c++ library My Flutter and Dart version : rmazumder$ flutter --version |
Generally speaking there are two options: Use an unsigned Dart SDK during development or sign the shared libraries. If you are using the standalone We do have unsigned Dart SDKs available which you could use
Those are downloadable via the http://storage.googleapis.com/dart-archive/... URL prefix. |
Just find out something today when I am trying the
Here |
@mkustermann Signing the shared libraries just causes
(and a similar error if you sign without a Team ID). Given that FFI is now a stable feature of Dart, I think the fact that there are unsigned SDKs available (and why they're needed) should be as front-and-center as possible. |
Using a signed shared library isn't an option unless you provide the key that the Dart SDK was signed with. Using an adhoc signature causes:
Signing with your own cert causes the error @filleduchaos mentioned It looks like there is something we have to do on the Dart side to validate the signatures: https://forums.developer.apple.com/thread/27799 |
@gaaclarke if you harden a macOS app's runtime then you can specify in its entitlements that it should be able to load unsigned dylibs at runtime (see the Apple docs. However I'm far from certain if using the hardened runtime is feasible for the Dart SDK. In the meantime maybe the Dart homebrew tap could add an |
We discussed this a couple of days ago:
Conceptually any application that has a plugin architecture with shared objects would run into this.
That seems like a solution for plugin architectures. We could investigate if a jitting VM would qualify for that. @mit-mit. |
@dcharkes allowing the execution of JIT-compiled code is another specifiable entitlement - I don't know that much about Dart SDK internals, but I think if it's signed with the hardened runtime enabled then it would need I have a bit of free time this weekend so I'll try to sign an unsigned SDK with |
I ran a whole bunch of experiments and I have found the issue, I think. The distributed Dart SDKs are already signed with the hardened runtime, which is required for notarization (see: flutter/flutter#36714 (comment)) but don't have all the entitlements necessary to let them operate as freely as the unsigned SDKs. To elaborate, this is the signing information for a signed $ codesign -dv --verbose=1 /tmp/dart-sdk/bin/dart
Executable=/tmp/dart-sdk/bin/dart
Identifier=dart
Format=Mach-O thin (x86_64)
CodeDirectory v=20500 size=250480 flags=0x10000(runtime) hashes=7819+5 location=embedded
Signature size=9043
Timestamp=20 Nov 2019 at 4:07:54 PM
Info.plist=not bound
TeamIdentifier=EQHXZ8M8AV
Runtime Version=10.13.0
Sealed Resources=none
Internal requirements count=1 size=164 And these are the entitlements it was signed with: $ codesign -d --entitlements :- /tmp/dart-sdk/bin/dart
Executable=/tmp/dart-sdk/bin/dart
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
</dict>
</plist> As previously discussed, since |
Excellent research! cc @athomas can you check with out signing contacts if that is a possible change we can make? |
We're in control of the Entitlements.plist used to sign the Dart SDK executables (assuming potential security implications have been considered). Since we're using internal signing infrastructure, this file is not in the open source repo so I bumped an earlier internal email thread on this topic with the necessary information. |
After changing the dart JIT:
dart2aot snapshot:
dart2aot exe
Note that the shared libraries need to be in the same folder (or subfolder):
|
2.8.0-dev.9.0 (probably going out later today) will be signed with the new entitlements. |
@dcharkes that seems like a reasonable enough compromise for development, though it probably should work with an absolute path? I'll check that out when I pull the new version. |
It doesn't matter whether you're using an absolute or relative path in Dart afaik. MacOS doesn't allow you to open a shared library from a folder that's not the same or a sub folder of the dart executable (or the dartprecompiledruntime executable). |
This has landed a couple of weeks ago, and all new dev and stable released will be signed this way. |
Hi @mit-mit, You asked the OP above if they use FFI - I've been having the same loadError when trying to run Obviously FFI is not your library, so I don't expect you to fully support it, but the fact you mentioned it makes me wonder if you know of an issue between FFI and mac builds? It seems like nobody has the answer! Thanks |
@jcush Are you are running a |
Hi @johnpryan, Thanks for your response - I'm not on a Silicon processor, no, I'm running a 2019 16" MBP. I've actually checked out CocoaPods/CocoaPods#9907 already and that's about Silicon. Thanks |
Carbon copy of dart-lang/site-www#4055 (comment) for reference on the current state on MacOS: ================================================================================ I did some local testing, there's three modes for dylibs with 1. Signed with an identity
Running with the downloaded (by the Dart team signed) SDK works with any file path.
2. Signed ad hocUsing
Running with the downloaded (by the Dart team signed) SDK works with any file path. 3. Completely unsigned
I cannot open this dylib (with an absolute path) with the signed SDK Trying to open with a relative path will lead to A completely unsigned dylib cannot be opened with an ad hoc signed A In conclusionThe Dart SDK (or any executable for that matter) can only open signed or ad hoc signed dylibs. Paths don't matter. Opening unsigned dylibs (or running unsigned code) is completely disallowed on MacOS. |
Now that the Dart SDK is signed (i.e.
dart
is signed), we don't seem to be able to load unsigned dylibs anymore:The text was updated successfully, but these errors were encountered: