Skip to content

[System.Security]Android DllNotFoundException: libSystem.Security.Cryptography.Native.OpenSsl #115450

Closed as duplicate of#111019
@MakesYT

Description

@MakesYT

Description

System.TypeInitializationException: The type initializer for 'Crypto' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'CryptoInitializer' threw an exception.
 ---> System.DllNotFoundException: libSystem.Security.Cryptography.Native.OpenSsl
   at Interop.CryptoInitializer..cctor()
   --- End of inner exception stack trace ---
   at Interop.Crypto..cctor()
   --- End of inner exception stack trace ---
   at System.Net.Security.CertificateValidation.BuildChainAndVerifyProperties(X509Chain chain, X509Certificate2 remoteCertificate, Boolean checkCertName, Boolean _, String hostName)
   at System.Net.Security.CertificateValidation.BuildChainAndVerifyProperties(X509Chain chain, X509Certificate2 remoteCertificate, Boolean checkCertName, Boolean isServer, String hostName, Span`1 certificateBuffer)
   at System.Net.Quic.QuicConnection.SslConnectionOptions.ValidateCertificate(X509Certificate2 certificate, Span`1 certData, Span`1 chainData)
   at System.Net.Quic.QuicConnection.SslConnectionOptions.StartAsyncCertificateValidation(IntPtr certificatePtr, IntPtr chainPtr)
   at System.Net.Quic.ValueTaskSource.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Quic.QuicConnection.FinishConnectAsync(QuicClientConnectionOptions options, CancellationToken cancellationToken)
   at System.Net.Quic.QuicConnection.<ConnectAsync>g__StartConnectAsync|2_0(QuicClientConnectionOptions options, CancellationToken cancellationToken)
   at System.Net.Quic.QuicConnection.<ConnectAsync>g__StartConnectAsync|2_0(QuicClientConnectionOptions options, CancellationToken cancellationToken)
   at QuicTest.ViewModels.MainViewModel.<.ctor>b__1_0() in D:\CSs\QuicTest\QuicTest\QuicTest\ViewModels\MainViewModel.cs:line 25

I noticed that there is a special Native implementation of Crypto on Android, but System.Net.Security.CertificateValidation.BuildChainAndVerifyProperties seems to ignore this implementation, still calling libSystem.Security.Cryptography.Native.OpenSsl instead of libSystem.Security.Cryptography.Native.Android.

Moreover, in one version, the Android implementation of libSystem.Security.Cryptography.Native.OpenSsl was renamed to libSystem.Security.Cryptography.Native.Android, and I am not sure if this is what caused the error.

Reproduction Steps

Git clone https://github.com/MakesYT/Android_Quic/tree/master

  1. unpack QuicTest/QuicTest.Android/android/.lib/arm64-v8a.7z
  2. run QuicServer
  3. run QuicTest/QuicTest.Android/QuicTest.Android.csproj

Expected behavior

A normal connection receives data

Actual behavior

If both the server and the client are in WIndows, it will work fine

System.TypeInitializationException: The type initializer for 'Crypto' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'CryptoInitializer' threw an exception.
 ---> System.DllNotFoundException: libSystem.Security.Cryptography.Native.OpenSsl
   at Interop.CryptoInitializer..cctor()
   --- End of inner exception stack trace ---
   at Interop.Crypto..cctor()
   --- End of inner exception stack trace ---
   at System.Net.Security.CertificateValidation.BuildChainAndVerifyProperties(X509Chain chain, X509Certificate2 remoteCertificate, Boolean checkCertName, Boolean _, String hostName)
   at System.Net.Security.CertificateValidation.BuildChainAndVerifyProperties(X509Chain chain, X509Certificate2 remoteCertificate, Boolean checkCertName, Boolean isServer, String hostName, Span`1 certificateBuffer)
   at System.Net.Quic.QuicConnection.SslConnectionOptions.ValidateCertificate(X509Certificate2 certificate, Span`1 certData, Span`1 chainData)
   at System.Net.Quic.QuicConnection.SslConnectionOptions.StartAsyncCertificateValidation(IntPtr certificatePtr, IntPtr chainPtr)
   at System.Net.Quic.ValueTaskSource.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Quic.QuicConnection.FinishConnectAsync(QuicClientConnectionOptions options, CancellationToken cancellationToken)
   at System.Net.Quic.QuicConnection.<ConnectAsync>g__StartConnectAsync|2_0(QuicClientConnectionOptions options, CancellationToken cancellationToken)
   at System.Net.Quic.QuicConnection.<ConnectAsync>g__StartConnectAsync|2_0(QuicClientConnectionOptions options, CancellationToken cancellationToken)
   at QuicTest.ViewModels.MainViewModel.<.ctor>b__1_0() in D:\CSs\QuicTest\QuicTest\QuicTest\ViewModels\MainViewModel.cs:line 25

Regression?

No response

Known Workarounds

No response

Configuration

.NET10 Pr3

  1. QuicServer On Windows11 24h2 x64 normal work
  2. QuicTest/QuicTest.Android/QuicTest.Android.csproj Android 15 arm64v8

Other information

Moreover, in one version, the Android implementation of libSystem.Security.Cryptography.Native.OpenSsl was renamed to libSystem.Security.Cryptography.Native.Android, and I am not sure if this is what caused the error.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions