Skip to content

System.Security.Cryptography.Native.Openssl should not load OpenSSL eagerly on macOS #46771

Closed

Description

@VSadov

OpenSSL is optional on macOS - it's needed only for AES-GCM/CCM encryption.

However we have __attribute__((constructor)) static void InitializeOpenSSLShim() which aborts if OpenSSL is not found.
As a result, when System.Security.Cryptography.Native.Openssl is statically linked in a single-file scenario, every app will probe for OpenSSL and fail if not found.

We need to either delay-load on first use or invoke initialization explicitly from managed code.

Activity

  1. self-assigned this
    on Jan 8, 2021
  2. added
    untriaged
    on Jan 8, 2021
  3. am11 commented on Jan 8, 2021

    @am11
    Member

    Related #46076.

    delay-load on first use

    like libgdiplus


    would be great!

  4. EgorBo commented on Jan 9, 2021

    @EgorBo
    Member

    BTW, can we use https://developer.apple.com/documentation/cryptokit on mac? it should support AES-GCM/CCM so we can drop this OpenSSL requirement completely on macOS.
    We only need to link System.Native.Security.Apple against Cryptokit framework and write a small wrapper in ObjC. Example: https://github.com/dotnet/runtime/blob/master/src/libraries/Native/Unix/System.Native/pal_log.m
    cc @bartonjs

  5. bartonjs commented on Jan 11, 2021

    @bartonjs
    Member

    BTW, can we use https://developer.apple.com/documentation/cryptokit on mac? ... ObjC

    My understanding is that CryptoKit only has Swift bindings, no Objective C bindings. I found references to being able to call into "Swift-only" things from Objective C using some sort of Xcode-generated header, but nothing talking about how to do it outside of Xcode or what the calling conventions would look like for instance functions.

    If someone can figure out how to call it from the Apple crypto shim, then sure!

  6. bartonjs commented on Jan 11, 2021

    @bartonjs
    Member

    InitializeAppleCryptoSslShim

    That function is in System.Security.Cryptography.Native.Apple, which doesn't link to OpenSSL.

    On macOS both shims can be used. System.Security.Cryptography.Native.Apple is the only one used in the majority of programs that need any crypto. System.Security.Cryptography.Native.OpenSsl gets loaded when the AesGcm or AesCcm types are used, or any of the types whose name explicitly ends in "OpenSsl", (e.g. RSAOpenSsl). I don't really expect that anyone is using the *OpenSsl types from macOS, we might be able to drop support for them (from macOS) in 6 if we have reasons.

  7. VSadov commented on Jan 11, 2021

    @VSadov
    MemberAuthor

    Right - the problem is not InitializeAppleCryptoSslShim, it is the InitializeOpenSSLShim

    Both have __attribute__((constructor)), so I got confused. Initially I thought both functions cause the trouble.
    Only InitializeOpenSSLShim aborts if the library is not found.

  8. VSadov commented on Jan 13, 2021

    @VSadov
    MemberAuthor

    This was fixed in #46640

  9. ghost locked as resolved and limited conversation to collaborators on Feb 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

untriaged

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions