Skip to content

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

Open
@matouskozak

Description

@matouskozak

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

if (!Interop.AndroidCrypto.DsaSign(key, hash, destination, out int actualLength))
{
throw new CryptographicException();
}

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 #106951
fyi: @bartonjs @vcsjones

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions