Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Revisit AES-GCM on macOS #29811

Closed
Closed

Description

@vcsjones

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.

  1. 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.
  2. 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.

Activity

  1. vcsjones commented on Jun 7, 2019

    @vcsjones
    MemberAuthor
  2. bartonjs commented on Jun 8, 2019

    @bartonjs
    Member

    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).

  3. vcsjones commented on Jun 8, 2019

    @vcsjones
    MemberAuthor

    Ok, glad to hear! I will finish up what is on my plate already soon, and explore this next.

  4. vcsjones commented on Jun 30, 2019

    @vcsjones
    MemberAuthor

    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.

    1. We would need to write some stub functions in Swift that call in to CryptoKit
    2. Expose those stub functions to Objective-C via the the @objc swift attribute.
    3. 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?

  5. bartonjs commented on Jul 1, 2019

    @bartonjs
    Member

    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 😏.

  6. vcsjones commented on Jul 1, 2019

    @vcsjones
    MemberAuthor

    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.

  7. transferred this issue fromdotnet/corefxon Feb 1, 2020
  8. added this to the Future milestone on Feb 1, 2020
  9. added
    untriaged
    on Feb 23, 2020
  10. vcsjones commented on May 4, 2020

    @vcsjones
    MemberAuthor

    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).
  11. akoeplinger commented on May 4, 2020

    @akoeplinger
    Member

    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?

  12. chamons commented on May 4, 2020

    @chamons

    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?

  13. stephen-hawley commented on May 4, 2020

    @stephen-hawley
  14. removed
    untriaged
    on Jul 7, 2020
  15. bartonjs commented on Jan 12, 2021

    @bartonjs
    Member

    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?

  16. 8 remaining items

  17. janvorli commented on Jan 12, 2021

    @janvorli
    Member

    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.

  18. bartonjs commented on Jan 12, 2021

    @bartonjs
    Member

    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 😄.

  19. am11 commented on Jan 13, 2021

    @am11
    Member

    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.

  20. vcsjones commented on Jan 13, 2021

    @vcsjones
    MemberAuthor

    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.

  21. bartonjs commented on Jan 13, 2021

    @bartonjs
    Member

    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.

  22. vcsjones commented on Jan 13, 2021

    @vcsjones
    MemberAuthor

    We can dlsym() the required symbols

    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.

  23. am11 commented on Jan 13, 2021

    @am11
    Member

    I was reading this part

    const void* v1_0_sentinel = dlsym(libssl, "SSL_state");

    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.

  24. vcsjones commented on Jan 13, 2021

    @vcsjones
    MemberAuthor

    @am11 Ah, okay. So we could dlsym our own library. I thought you meant trying to dlsym the macOS dependencies.

    We can dlsym() the required symbols from /usr/lib/swift/libswiftCore.dylib

  25. am11 commented on Jan 13, 2021

    @am11
    Member

    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).

  26. filipnavara commented on May 11, 2021

    @filipnavara
    Member
  27. vcsjones commented on Sep 30, 2022

    @vcsjones
    MemberAuthor

    Since #76317 sets the groundwork for using CryptoKit in macOS, AES-GCM is feasible now.

  28. self-assigned this
    on Sep 30, 2022
  29. ghost added
    in-pr
    on Oct 1, 2022
  30. ghost locked as resolved and limited conversation to collaborators on Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.Securityin-pr

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions