Skip to content
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

android.runtime.JavaProxyThrowable: [System.Security.Cryptography.CryptographicException]: Cryptography_ConcurrentUseNotSupported #9752

Open
aritchie opened this issue Feb 4, 2025 · 2 comments
Assignees
Labels
Area: App Runtime Issues in `libmonodroid.so`. need-attention A xamarin-android contributor needs to review

Comments

@aritchie
Copy link

aritchie commented Feb 4, 2025

Android framework version

net9.0-android

Affected platform version

.NET 9.0.100, 9.0.102

Description

Trying to perform SHA1 hash with android assembly compression disabled ComputeHash to throw an exception: [System.Security.Cryptography.CryptographicException]: Cryptography_ConcurrentUseNotSupported

Steps to Reproduce

  1. Create a blank .net9.0 android application
  2. Add msbuild property:
<AndroidEnableAssemblyCompression>false</AndroidEnableAssemblyCompression>
  1. Add the following code:
  var hash = sha.ComputeHash(bytes); // will die here
  var hi = Convert.ToHexString(hash);
  Console.WriteLine("SAMPLE HASH: " + hi);
  1. Run in release mode
  2. Observe logcat for exception (shown in log output field)

Repro Sample: https://github.com/aritchie/android_net9_crypto_crash

Did you find any workaround?

No

Tried the following and causes an crypto loop internal mono crash

#if NET9_0 && ANDROID
this will cause an internal crash with mono
var hash = SHA1.HashData(bytes);
var hi = Convert.ToHexString(hash);
#endif

Relevant log output

ndroid.runtime.JavaProxyThrowable: [System.Security.Cryptography.CryptographicException]: Cryptography_ConcurrentUseNotSupported
02-04 15:00:51.928 I/MonoDroid(30757): 	at System.Security.Cryptography.ConcurrencyBlock.Enter + 0x1a(Unknown Source)
02-04 15:00:51.928 I/MonoDroid(30757): 	at System.Security.Cryptography.HashProviderDispenser+EvpHashProvider.FinalizeHashAndReset + 0x0(Unknown Source)
02-04 15:00:51.928 I/MonoDroid(30757): 	at System.Security.Cryptography.HashProvider.FinalizeHashAndReset + 0x13(Unknown Source)
02-04 15:00:51.928 I/MonoDroid(30757): 	at System.Security.Cryptography.SHA1+Implementation.HashFinal + 0x0(Unknown Source)
02-04 15:00:51.928 I/MonoDroid(30757): 	at System.Security.Cryptography.HashAlgorithm.CaptureHashCodeAndReinitialize + 0x0(Unknown Source)
02-04 15:00:51.928 I/MonoDroid(30757): 	at System.Security.Cryptography.HashAlgorithm.ComputeHash + 0x22(Unknown Source)
02-04 15:00:51.928 I/MonoDroid(30757): 	at Sentry.Internal.Extensions.HashExtensions.GetHashString + 0x11(Unknown Source)
@grendello
Copy link
Contributor

Please record output of logcat using the following steps:

$ adb shell setprop debug.mono.log default,assembly,mono_log_level=debug,mono_log_mask=all
$ adb logcat -G 64M
$ adb logcat -c
# Start the application, wait for it to crash, then wait 5s and:
$ adb logcat -d > log.txt

Please attach the resulting file, thanks!

@grendello grendello added need-info Issues that need more information from the author. and removed needs-triage Issues that need to be assigned. labels Feb 4, 2025
@aritchie
Copy link
Author

aritchie commented Feb 4, 2025

@dotnet-policy-service dotnet-policy-service bot added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: App Runtime Issues in `libmonodroid.so`. need-attention A xamarin-android contributor needs to review
Projects
None yet
Development

No branches or pull requests

2 participants