From 528d985f29ca7d14a30210dcbb71f8dcc66a1987 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexander=20K=C3=B6plinger?= Date: Sun, 3 Jan 2016 17:11:46 +0100 Subject: [PATCH 1/1] [corlib] Remove RijndaelManaged test that makes no sense with referencesource impl The CreateEncryptor_KeyNull and CreateDecryptor_KeyNull tests tried to verify the previous Mono behavior of throwing a CryptographicException when a null key is passed to the methods [1]. However, with the move to referencesource this no longer happens since when a null key is passed a random one is generated instead [2]. The existing tests passed out of pure luck because a different CryptographicException is thrown later on: ``` System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed. at System.Security.Cryptography.RijndaelManagedTransform.DecryptData (System.Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, System.Byte[]& outputBuffer, Int32 outputOffset, PaddingMode paddingMode, Boolean fLast) [0x007b5] in /Users/alexander/dev/mono/external/referencesource/mscorlib/system/security/cryptography/rijndaelmanagedtransform.cs:751 at System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock (System.Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) [0x000bb] in /Users/alexander/dev/mono/external/referencesource/mscorlib/system/security/cryptography/rijndaelmanagedtransform.cs:336 at MonoTests.System.Security.Cryptography.RijndaelManagedTest.CreateDecryptor_KeyNull () [0x00066] in /Users/alexander/dev/mono/mcs/class/corlib/Test/System.Security.Cryptography/RijndaelManagedTest.cs:233 ``` Unfortunately, sometimes it happens with the random key that this exception *doesn't* get thrown as the padding is valid, which makes the test randomly fail on Jenkins. Deleting those tests is the simplest fix. [1] https://github.com/mono/mono/blob/mono-4.0.0-branch/mcs/class/corlib/System.Security.Cryptography/RijndaelManagedTransform.cs#L107 [2] https://github.com/mono/referencesource/blob/33edf60ec4d35aba11850872777c8b3a484ca484/mscorlib/system/security/cryptography/rijndaelmanaged.cs#L66 --- .../RijndaelManagedTest.cs | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/mcs/class/corlib/Test/System.Security.Cryptography/RijndaelManagedTest.cs b/mcs/class/corlib/Test/System.Security.Cryptography/RijndaelManagedTest.cs index 2d9795ade10..b7bf46057a0 100644 --- a/mcs/class/corlib/Test/System.Security.Cryptography/RijndaelManagedTest.cs +++ b/mcs/class/corlib/Test/System.Security.Cryptography/RijndaelManagedTest.cs @@ -176,19 +176,6 @@ namespace MonoTests.System.Security.Cryptography { ); } - [Test] - [ExpectedException (typeof (CryptographicException))] - public void CreateEncryptor_KeyNull () - { - ICryptoTransform encryptor = aes.CreateEncryptor (null, aes.IV); - byte[] data = new byte[encryptor.InputBlockSize]; - byte[] encdata = encryptor.TransformFinalBlock (data, 0, data.Length); - - ICryptoTransform decryptor = aes.CreateDecryptor (aes.Key, aes.IV); - byte[] decdata = decryptor.TransformFinalBlock (encdata, 0, encdata.Length); - // null key != SymmetricAlgorithm.Key - } - [Test] public void CreateEncryptor_IvNull () { @@ -220,19 +207,6 @@ namespace MonoTests.System.Security.Cryptography { // SymmetricAlgorithm Key and IV not changed by CreateEncryptor } - [Test] - [ExpectedException (typeof (CryptographicException))] - public void CreateDecryptor_KeyNull () - { - ICryptoTransform encryptor = aes.CreateEncryptor (aes.Key, aes.IV); - byte[] data = new byte[encryptor.InputBlockSize]; - byte[] encdata = encryptor.TransformFinalBlock (data, 0, data.Length); - - ICryptoTransform decryptor = aes.CreateDecryptor (null, aes.IV); - byte[] decdata = decryptor.TransformFinalBlock (encdata, 0, encdata.Length); - // null key != SymmetricAlgorithm.Key - } - [Test] public void CreateDecryptor_IvNull () { -- 2.25.1