dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.01k stars 4.67k forks source link

[Android][crypto] Android 7 crashes in `AsymmetricDSASignature` #107867

Open matouskozak opened 1 week ago

matouskozak commented 1 week ago

When running System.Security.Cryptography.Xml.Tests.SignedXmlTest.AsymmetricDSASignature tests on Android 7 emulators, we get the following crash:

08-27 18:39:54.155  2753  2771 I DOTNET  : 1)   [FAIL] System.Security.Cryptography.Xml.Tests.SignedXmlTest.AsymmetricDSASignature   Test name: System.Security.Cryptography.Xml.Tests.SignedXmlTest.AsymmetricDSASignature
08-27 18:39:54.155  2753  2771 I DOTNET  :    Assembly:  [System.Security.Cryptography.Xml.Tests, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]
08-27 18:39:54.155  2753  2771 I DOTNET  :    Exception messages: System.Security.Cryptography.CryptographicException : Error occurred during a cryptographic operation.   Exception stack traces:    at System.Security.Cryptography.DSAImplementation.DSAAndroid.SignHash(ReadOnlySpan`1 hash, Span`1 destination, Int32 signatureLength, SafeDsaHandle key)
08-27 18:39:54.155  2753  2771 I DOTNET  :    at System.Security.Cryptography.DSAImplementation.DSAAndroid.CreateSignature(Byte[] rgbHash)
08-27 18:39:54.155  2753  2771 I DOTNET  :    at System.Security.Cryptography.DSASignatureFormatter.CreateSignature(Byte[] rgbHash)
08-27 18:39:54.155  2753  2771 I DOTNET  :    at System.Security.Cryptography.AsymmetricSignatureFormatter.CreateSignature(HashAlgorithm hash)
08-27 18:39:54.155  2753  2771 I DOTNET  :    at System.Security.Cryptography.Xml.SignedXml.ComputeSignature() in /_/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/SignedXml.cs:line 435
08-27 18:39:54.155  2753  2771 I DOTNET  :    at System.Security.Cryptography.Xml.Tests.SignedXmlTest.AsymmetricDSASignature() in /_/src/libraries/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs:line 316
08-27 18:39:54.155  2753  2771 I DOTNET  :    at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
08-27 18:39:54.155  2753  2771 I DOTNET  :    at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
08-27 18:39:54.155  2753  2771 I DOTNET  :    Execution time: 2.2244818

The exception is thrown by https://github.com/dotnet/runtime/blob/4101144c8dde177addfb93ac46425fd1a8604f7a/src/libraries/Common/src/System/Security/Cryptography/DSAAndroid.cs#L301-L304

and the probable cause:

2024-08-28 19:49:31.026  5166-5187  System.err              net...curity.Cryptography.Xml.Tests  W  java.security.InvalidKeyException: valueN must be 224 or 256 for valueL = 2048
2024-08-28 19:49:31.026  5166-5187  System.err              net...curity.Cryptography.Xml.Tests  W      at com.android.org.bouncycastle.jcajce.provider.asymmetric.dsa.DSASigner.checkKey(DSASigner.java:203)
2024-08-28 19:49:31.026  5166-5187  System.err              net...curity.Cryptography.Xml.Tests  W      at com.android.org.bouncycastle.jcajce.provider.asymmetric.dsa.DSASigner.engineInitSign(DSASigner.java:116)
2024-08-28 19:49:31.026  5166-5187  System.err              net...curity.Cryptography.Xml.Tests  W      at java.security.Signature$Delegate.init(Signature.java:1208)
2024-08-28 19:49:31.026  5166-5187  System.err              net...curity.Cryptography.Xml.Tests  W      at java.security.Signature$Delegate.chooseProvider(Signature.java:1167)
2024-08-28 19:49:31.026  5166-5187  System.err              net...curity.Cryptography.Xml.Tests  W      at java.security.Signature$Delegate.engineInitSign(Signature.java:1232)
2024-08-28 19:49:31.026  5166-5187  System.err              net...curity.Cryptography.Xml.Tests  W      at java.security.Signature.initSign(Signature.java:607)

Discovered in https://github.com/dotnet/runtime/pull/106951 fyi: @bartonjs @vcsjones

dotnet-policy-service[bot] commented 1 week ago

Tagging subscribers to 'arch-android': @vitek-karas, @simonrozsival, @steveisok, @akoeplinger See info in area-owners.md if you want to be subscribed.

dotnet-policy-service[bot] commented 1 week ago

Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones See info in area-owners.md if you want to be subscribed.