You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now Core on macOS has quasi-support for AES-GCM. It's there, but you need a modern version of OpenSsl to use it, which isn't there by default and users need to install via homebrew, or software projects need to package it themselves.
There are two new options on the table.
Apple's upcoming CryptoKit has support for AES-GCM (in fact, as of writing, GCM is the only AES mode it supports). This would get support on 10.15 when it releases.
SymCrypt is now open source. I don't know what plans have been made if any to integrate it in to CoreFx, or what the timeline for that looks like.
@bartonjs, do you have any input or thought on this? I realize nothing is going to happen for 3.0 but I'm trying to figure out long-term plans. I was contemplating building a managed wrapper around CryptoKit and releasing it as a nuget package, however if the work would be welcome in CoreFx then perhaps my effort is better spent there.
Reacted by Claire Novotny, Ryan Hurst and Nicolai Søborg
I'm perfectly fine with the GCM code on macOS to try CryptoKit if it's on 10.15, and continuing with the OpenSSL fallback on 10.13/10.14. (If it's kept tidy it might be a reasonable thing to backport into the release/3.x family, once it can all be written).
Some disappointing news on CryptoKit - it has Swift bindings only. There is a work around but it requires bringing the Swift language and Objective-C toolchain in.
We would need to write some stub functions in Swift that call in to CryptoKit
Expose those stub functions to Objective-C via the the @objc swift attribute.
Write objective-c code to consume the Swift functions and have the Objective-C functions export wrappers using the cdecl calling convention that .NET understands. The Objective-C layer would also handle creating an [UInt8] from uint8_t*.
@bartonjs I suppose bringing in Swift and Objective-C is either an unacceptable or very large task, correct?
I have no idea how Swift or Objective-C builds work, so I also don't know if we're talking two extra files in the shim, or two new dylibs, or what.
One dylib with an objective-c and swift file, I think. It shouldn't require any extra tooling beyond what Xcode already has and work in cmake, but it will require a min version of cmake of 3.6.
I'll forge ahead and get something that works (edit: hopefully). Once I get there we can evaluate it to see if it is worth continuing.
I had a few discussions with some folks and it doesn't seem like they intend to add C bindings to CryptoKit for 10.15.
This is something that I've continued to poke and was hoping the have something useful for 5.0.
I have a proof of concept that works with cryptokit but required me to by-hand compile and deploy shim dylibs in a few places.
Perhaps now that Mono is in the tree, the Mono folks have some ideas on how this can fit in the build infrastructure, some day.
@akoeplinger, have y'all given any thought to being able to call Swift functions from runtime/libraries? The gist of the issue:
CryptoKit is new in macOS 10.15 / iOS 13.
It only has Swift bindings.
We can shim the Swift API with a .swift file that has @objc on it, then have a Objective-C call the swift functions via bridging header, and export those functions unmangled, and also taking primitive pointers that work well with .NET's p/invoke.
I don't know how to do the last bullet point in a way the integrates with the existing build-native parts or with cmake. I think things would be easier with Ninja, but I haven't tried yet (and I'm not sure that matters).
At first blush, the API isn’t huge so if it doesn’t wrap in an ObjC header neatly, it could get encapsulated in @objc wrappers which would be accessible.
I don't know how to do the last bullet point in a way the integrates with the existing build-native parts or with cmake.
Even if we can't get it to work with cmake, is it possible to do something with a script that runs some tools and produces an artifact we can check in and then figure out how to pass it to the final compile with weird manually inserted flags or something?
I actually wonder if we still need to support the older macOS versions. There is a change that I'd like to get in (to support a fallback for FlushProcessWriteBuffers implementation in case the machine has no more available wired memory) that would require us to bump the minimum supported macOS to 10.14.
So maybe we could possibly bump the minimum versions all the way to 10.15. I've just found a site showing macOS version market share here: https://gs.statcounter.com/macos-version-market-share/desktop/worldwide
It shows that 67.87% of macOS installations were on 10.15 already in December.
Deciding minimum OS versions is above my pay grade. Maybe @leecow could share what our min-version thoughts are.
My gut expectation is that since 10.12 last got patched 15 months ago 10.13 will be considered out of support when we release 6... so 10.14 is probably an acceptable minimum (which satisfies @janvorli's needs) but that we probably can't get away with 10.15 (so we'd need a separate CryptoKit shim for 6 but could merge for 7),
Then again, maybe Lee will be kind enough to look ahead and write 10.15 in the matrix 😄.
I'm perfectly fine with the GCM code on macOS to try CryptoKit if it's on 10.15, and continuing with the OpenSSL fallback on 10.13/10.14.
If this could be implemented, then it would be possible to adapt to the suitable tech during the runtime (like the opensslshim)? We can dlsym() the required symbols from /usr/lib/swift/libswiftCore.dylib and friends on runtime.
then it would be possible to adapt to the suitable tech during the runtime
The managed side already has a PAL for switching out the Linux and Windows implementation, just need to adapt it for macOS. I did a bit of that work here: vcsjones/runtime@master...vcsjones:cryptokit.
I don't think we need to do anything quite as complicated as what's done for OpenSSL.
I don't think we need to do anything quite as complicated as what's done for OpenSSL.
We might end up needing to do something that complicated if we support 10.14 for the single-file executable mode where it static links all the shim libraries into the program, since it would force an un-bindable CryptoKit load.
Hm. I don't know how well that is going to work since all of the names are mangled. We can dlopen the necessary libraries and frameworks like CryptoKit, but getting the symbols seems like an interesting issue.
I'll get as much as I can working and we can see how to proceed.
e.g. noticed above with @_silgen_name("SayHelloFromSwift"), SayHelloFromSwift is the verbatim symbol used in C code; so mangling would not effect us if @_silgen_name annotation is used. Doc says:
Rather than hard-code Swift mangling into C code, @_silgen_name is used to provide a stable and known symbol name for linking.
When running the app linked with swift object, I was getting error about missing libswiftCore.dylib (as it was not in my DYLD_LIBRARY_PATH). I had to add rpath to linker command. That led me to think there might be some symbols required from Swift's core library if we go dlsym route. Maybe it depends on how we will end up compiling the our binding object (static or shared).
Activity
vcsjones commentedon Jun 7, 2019
/cc @GrabYourPitchforks too.
bartonjs commentedon Jun 8, 2019
I'm perfectly fine with the GCM code on macOS to try CryptoKit if it's on 10.15, and continuing with the OpenSSL fallback on 10.13/10.14. (If it's kept tidy it might be a reasonable thing to backport into the release/3.x family, once it can all be written).
vcsjones commentedon Jun 8, 2019
Ok, glad to hear! I will finish up what is on my plate already soon, and explore this next.
vcsjones commentedon Jun 30, 2019
Some disappointing news on CryptoKit - it has Swift bindings only. There is a work around but it requires bringing the Swift language and Objective-C toolchain in.
@objcswift attribute.[UInt8]fromuint8_t*.@bartonjs I suppose bringing in Swift and Objective-C is either an unacceptable or very large task, correct?
bartonjs commentedon Jul 1, 2019
If it doesn't require any new tools that wouldn't already be present from XCode, or doesn't play well with CMake then it's probably a no-go.
I have no idea how Swift or Objective-C builds work, so I also don't know if we're talking two extra files in the shim, or two new dylibs, or what.
But I'm definitely less pleased about the idea now that it's becoming complicated 😏.
vcsjones commentedon Jul 1, 2019
One dylib with an objective-c and swift file, I think. It shouldn't require any extra tooling beyond what Xcode already has and work in cmake, but it will require a min version of cmake of 3.6.
I'll forge ahead and get something that works (edit: hopefully). Once I get there we can evaluate it to see if it is worth continuing.
I had a few discussions with some folks and it doesn't seem like they intend to add C bindings to CryptoKit for 10.15.
vcsjones commentedon May 4, 2020
This is something that I've continued to poke and was hoping the have something useful for 5.0.
I have a proof of concept that works with cryptokit but required me to by-hand compile and deploy shim dylibs in a few places.
Perhaps now that Mono is in the tree, the Mono folks have some ideas on how this can fit in the build infrastructure, some day.
@akoeplinger, have y'all given any thought to being able to call Swift functions from runtime/libraries? The gist of the issue:
CryptoKitis new in macOS 10.15 / iOS 13..swiftfile that has@objcon it, then have a Objective-C call the swift functions via bridging header, and export those functions unmangled, and also taking primitive pointers that work well with .NET's p/invoke.akoeplinger commentedon May 4, 2020
We haven't thought about that from the Mono side yet, but your plan sounds reasonable.
@chamons are you aware of any gotchas with having such an objective-c/swift shim library?
chamons commentedon May 4, 2020
Off top of my head no, if you wrap it in an objc header then it should work, though it is a lot of moving parts.
@spouliot @stephen-hawley - Thoughts?
stephen-hawley commentedon May 4, 2020
bartonjs commentedon Jan 12, 2021
Even if we can't get it to work with cmake, is it possible to do something with a script that runs some tools and produces an artifact we can check in and then figure out how to pass it to the final compile with weird manually inserted flags or something?
8 remaining items
janvorli commentedon Jan 12, 2021
I actually wonder if we still need to support the older macOS versions. There is a change that I'd like to get in (to support a fallback for FlushProcessWriteBuffers implementation in case the machine has no more available wired memory) that would require us to bump the minimum supported macOS to 10.14.
So maybe we could possibly bump the minimum versions all the way to 10.15. I've just found a site showing macOS version market share here:
https://gs.statcounter.com/macos-version-market-share/desktop/worldwide
It shows that 67.87% of macOS installations were on 10.15 already in December.
bartonjs commentedon Jan 12, 2021
Deciding minimum OS versions is above my pay grade. Maybe @leecow could share what our min-version thoughts are.
My gut expectation is that since 10.12 last got patched 15 months ago 10.13 will be considered out of support when we release 6... so 10.14 is probably an acceptable minimum (which satisfies @janvorli's needs) but that we probably can't get away with 10.15 (so we'd need a separate CryptoKit shim for 6 but could merge for 7),
Then again, maybe Lee will be kind enough to look ahead and write 10.15 in the matrix 😄.
am11 commentedon Jan 13, 2021
If this could be implemented, then it would be possible to adapt to the suitable tech during the runtime (like the opensslshim)? We can
dlsym()the required symbols from/usr/lib/swift/libswiftCore.dyliband friends on runtime.vcsjones commentedon Jan 13, 2021
The managed side already has a PAL for switching out the Linux and Windows implementation, just need to adapt it for macOS. I did a bit of that work here: vcsjones/runtime@master...vcsjones:cryptokit.
I don't think we need to do anything quite as complicated as what's done for OpenSSL.
bartonjs commentedon Jan 13, 2021
We might end up needing to do something that complicated if we support 10.14 for the single-file executable mode where it static links all the shim libraries into the program, since it would force an un-bindable CryptoKit load.
vcsjones commentedon Jan 13, 2021
Hm. I don't know how well that is going to work since all of the names are mangled. We can
dlopenthe necessary libraries and frameworks like CryptoKit, but getting the symbols seems like an interesting issue.I'll get as much as I can working and we can see how to proceed.
am11 commentedon Jan 13, 2021
I was reading this part
runtime/src/libraries/Native/Unix/System.Security.Cryptography.Native/opensslshim.c
Line 135 in 7b99328
e.g. noticed above with
@_silgen_name("SayHelloFromSwift"),SayHelloFromSwiftis the verbatim symbol used in C code; so mangling would not effect us if@_silgen_nameannotation is used. Doc says:vcsjones commentedon Jan 13, 2021
@am11 Ah, okay. So we could dlsym our own library. I thought you meant trying to dlsym the macOS dependencies.
am11 commentedon Jan 13, 2021
When running the app linked with swift object, I was getting error about missing libswiftCore.dylib (as it was not in my DYLD_LIBRARY_PATH). I had to add
rpathto linker command. That led me to think there might be some symbols required from Swift's core library if we go dlsym route. Maybe it depends on how we will end up compiling the our binding object (static or shared).filipnavara commentedon May 11, 2021
Ref: #52482 (comment)
vcsjones commentedon Sep 30, 2022
Since #76317 sets the groundwork for using CryptoKit in macOS, AES-GCM is feasible now.