In corlib/System.Runtime.InteropServices:
[mono.git] / mcs / class / corlib / Test / System.Security.Cryptography / RSACryptoServiceProviderTest.cs
index cf82863de961a659070f08796189e9b0d1c34672..8767c8156c3980ffff04c57111e864fb1a7e9fb4 100644 (file)
@@ -5,7 +5,7 @@
 //     Sebastien Pouliot <sebastien@ximian.com>
 //
 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004,2006 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -166,28 +166,28 @@ public class RSACryptoServiceProviderTest : Assertion {
        [ExpectedException (typeof (CryptographicException))]
        public void TooSmallKeyPair () 
        {
-               rsa = new RSACryptoServiceProvider (256);\r
-#if NET_2_0\r
-               // in 2.0 MS delay the creation of the key pair until it is required\r
-               // (same trick that Mono almost always used ;-) but they also delay\r
-               // the parameter validation (what Mono didn't). So here we must "get"\r
-               // the key (export) to trigger the exception\r
-               rsa.ToXmlString (true);\r
-#endif\r
+               rsa = new RSACryptoServiceProvider (256);
+#if NET_2_0
+               // in 2.0 MS delay the creation of the key pair until it is required
+               // (same trick that Mono almost always used ;-) but they also delay
+               // the parameter validation (what Mono didn't). So here we must "get"
+               // the key (export) to trigger the exception
+               rsa.ToXmlString (true);
+#endif
        }
 
        [Test]
        [ExpectedException (typeof (CryptographicException))]
        public void TooBigKeyPair () 
        {
-               rsa = new RSACryptoServiceProvider (32768);\r
-#if NET_2_0\r
-               // in 2.0 MS delay the creation of the key pair until it is required\r
-               // (same trick that Mono almost always used ;-) but they also delay\r
-               // the parameter validation (what Mono didn't). So here we must "get"\r
-               // the key (export) to trigger the exception\r
-               rsa.ToXmlString (true);\r
-#endif\r
+               rsa = new RSACryptoServiceProvider (32768);
+#if NET_2_0
+               // in 2.0 MS delay the creation of the key pair until it is required
+               // (same trick that Mono almost always used ;-) but they also delay
+               // the parameter validation (what Mono didn't). So here we must "get"
+               // the key (export) to trigger the exception
+               rsa.ToXmlString (true);
+#endif
        }
 
        [Test]
@@ -309,8 +309,8 @@ public class RSACryptoServiceProviderTest : Assertion {
                rsa = new RSACryptoServiceProvider (minKeySize);
                rsa.VerifyHash (hash, null, sign);
        }
-#endif\r
-\r
+#endif
+
        [Test]
        [ExpectedException (typeof (ObjectDisposedException))]
        public void SignHashDisposed () 
@@ -395,9 +395,9 @@ public class RSACryptoServiceProviderTest : Assertion {
                byte[] hash = new byte [20];
                rsa = new RSACryptoServiceProvider (minKeySize);
                rsa.VerifyHash (hash, "1.3.14.3.2.26", null);
-       }\r
-\r
-#if NET_2_0\r
+       }
+
+#if NET_2_0
        [Test]
        [Category ("NotWorking")]
        public void ImportDisposed ()
@@ -1062,6 +1062,8 @@ public class RSACryptoServiceProviderTest : Assertion {
                        if (!(ce.InnerException is UnauthorizedAccessException))
                                throw;
                }
+               catch (UnauthorizedAccessException) {
+               }
        }
 #endif
 
@@ -1090,6 +1092,42 @@ public class RSACryptoServiceProviderTest : Assertion {
                }
        }
 
+       [Test]
+       [ExpectedException (typeof (CryptographicException))]
+       public void Bug79269 ()
+       {
+               rsa = new RSACryptoServiceProvider ();
+               rsa.FromXmlString ("<RSAKeyValue><Modulus>iSObDmmhDgrl4NiLaviFcpv4NdysBWJcqiVz3AQbPdajtXaQQ8VJdfRkixah132yKOFGCWZhHS3EuPMh8dcNwGwta2nh+m2IV6ktzI4+mZ7CSNAsmlDY0JI+H8At1vKvNArlC5jkVGuliYroJeSU/NLPLNYgspi7TtXGy9Rfug8=</Modulus><Exponent>EQ==</Exponent></RSAKeyValue>");
+#if NET_2_0
+               Assert ("PublicOnly", rsa.PublicOnly);
+#endif
+               string b64 = @"YgyAhscnTTIcDeLJTZcOYYyHVxNhV6d03jeZYjq0sPMEsfCCbE/NcFyYHD9BTuiduqPplCLbGpfZIZYJ6vAP9m5z4Q9eEw79kmEFCsm8wSKEo/gKiptVpwQ78VOPrWd/wEkTTeeg2nVim3JIsTKGFlV7rKxIWQhGN9aAqgP8nZI=";
+               byte [] bytes = Convert.FromBase64String (b64);
+               rsa.Decrypt (bytes, true);
+       }
+
+       [Test]
+       [ExpectedException (typeof (CryptographicException))]
+       public void Bug79320_OAEP ()
+       {
+               string s = "hdphq/mn8goBi43YGPkmOfPj5vXjHrKPJkT4mLT3l+XzLttHMLC4/yBYkuzlXtbrl2jtAJRb6oA8UcQFalUMnCa09LDZrgNU2yySn7YbiG8raSq7u2nfDCbPu+c8T9fyHxrCHrX0zeqqImX33csIn6rIrQZ8HKcMsoQso4qtS2A=";
+               byte [] bytes = Convert.FromBase64String (s);
+               RSACryptoServiceProvider r = new RSACryptoServiceProvider ();
+               r.FromXmlString ("<RSAKeyValue><Modulus>iSObDmmhDgrl4NiLaviFcpv4NdysBWJcqiVz3AQbPdajtXaQQ8VJdfRkixah132yKOFGCWZhHS3EuPMh8dcNwGwta2nh+m2IV6ktzI4+mZ7CSNAsmlDY0JI+H8At1vKvNArlC5jkVGuliYroJeSU/NLPLNYgspi7TtXGy9Rfug8=</Modulus><Exponent>EQ==</Exponent><P>pd4svtxrnTWXVSb151/JFgT9szI6dxQ5pAFPd4A4yuxLLEay2W2z7d9LVk5siMFhZ10uTJGWzNP5pSgLT8wdww==</P><Q>06j6m4cGRc3uoKVuFFGA19JG3Bi4tDBEQHebEc/Y3+eThrOasYIRrQmGUfqWnd9eFitO9GOaVJ0muNDV7NOxxQ==</Q><DP>OoqmYXr4zhLqHg3AM4s36adomZlBz6zJDLUrGx4yKYCTAJFsTL1OkDCxLYUXP1NPjeSm7dkIDA6UWGh8doRGvQ==</DP><DQ>PkDCLb5NI5br1OVcnJBxMGsFyEOBnmiMi2545x8DjSX+Nq1LnZ6555ljvcIsTIz9jgy83nel3KaxCS5dCWtwhQ==</DQ><InverseQ>OrFYaG7wTqim/bub4qY0CvIfhsjG4/4MEabg0UFTf/+tekKas7DDKg2TD5BS2q0O3XEt7xIfp0S6dpOAnrlyGQ==</InverseQ><D>IESc9FUW1iCuj0ICr8IBSCSy3383iMvZkXI5YPHoSskXdf3Hl3m27pPbbAVTQcM4+o9bxfn4u5JMZ8C8sV/G/8Cfl4ss1NVMbZOecvVObRqRpqXaveq5fN2X0EklH1wzm5w3O8cMXdbC/hc0gKUqaMjFVn1zpf3zVjpOkY0eGRE=</D></RSAKeyValue>");
+               AssertNotNull (r.Decrypt (bytes, true));
+       }
+
+       [Test]
+       [ExpectedException (typeof (CryptographicException))]
+       public void Bug79320_PKCS1 ()
+       {
+               string s = "hdphq/mn8goBi43YGPkmOfPj5vXjHrKPJkT4mLT3l+XzLttHMLC4/yBYkuzlXtbrl2jtAJRb6oA8UcQFalUMnCa09LDZrgNU2yySn7YbiG8raSq7u2nfDCbPu+c8T9fyHxrCHrX0zeqqImX33csIn6rIrQZ8HKcMsoQso4qtS2A=";
+               byte [] bytes = Convert.FromBase64String (s);
+               RSACryptoServiceProvider r = new RSACryptoServiceProvider ();
+               r.FromXmlString ("<RSAKeyValue><Modulus>iSObDmmhDgrl4NiLaviFcpv4NdysBWJcqiVz3AQbPdajtXaQQ8VJdfRkixah132yKOFGCWZhHS3EuPMh8dcNwGwta2nh+m2IV6ktzI4+mZ7CSNAsmlDY0JI+H8At1vKvNArlC5jkVGuliYroJeSU/NLPLNYgspi7TtXGy9Rfug8=</Modulus><Exponent>EQ==</Exponent><P>pd4svtxrnTWXVSb151/JFgT9szI6dxQ5pAFPd4A4yuxLLEay2W2z7d9LVk5siMFhZ10uTJGWzNP5pSgLT8wdww==</P><Q>06j6m4cGRc3uoKVuFFGA19JG3Bi4tDBEQHebEc/Y3+eThrOasYIRrQmGUfqWnd9eFitO9GOaVJ0muNDV7NOxxQ==</Q><DP>OoqmYXr4zhLqHg3AM4s36adomZlBz6zJDLUrGx4yKYCTAJFsTL1OkDCxLYUXP1NPjeSm7dkIDA6UWGh8doRGvQ==</DP><DQ>PkDCLb5NI5br1OVcnJBxMGsFyEOBnmiMi2545x8DjSX+Nq1LnZ6555ljvcIsTIz9jgy83nel3KaxCS5dCWtwhQ==</DQ><InverseQ>OrFYaG7wTqim/bub4qY0CvIfhsjG4/4MEabg0UFTf/+tekKas7DDKg2TD5BS2q0O3XEt7xIfp0S6dpOAnrlyGQ==</InverseQ><D>IESc9FUW1iCuj0ICr8IBSCSy3383iMvZkXI5YPHoSskXdf3Hl3m27pPbbAVTQcM4+o9bxfn4u5JMZ8C8sV/G/8Cfl4ss1NVMbZOecvVObRqRpqXaveq5fN2X0EklH1wzm5w3O8cMXdbC/hc0gKUqaMjFVn1zpf3zVjpOkY0eGRE=</D></RSAKeyValue>");
+               AssertNotNull (r.Decrypt (bytes, true));
+       }
+
 #if NET_2_0
        [Test]
        [Category ("NotWorking")]
@@ -1097,19 +1135,19 @@ public class RSACryptoServiceProviderTest : Assertion {
        {
                rsa = new RSACryptoServiceProvider (minKeySize);
                CspKeyContainerInfo info = rsa.CspKeyContainerInfo;
-               Assert ("Accessible", info.Accessible);\r
-// FIXME       AssertNotNull ("CryptoKeySecurity", info.CryptoKeySecurity);\r
-               Assert ("Exportable", info.Exportable);\r
+               Assert ("Accessible", info.Accessible);
+// FIXME       AssertNotNull ("CryptoKeySecurity", info.CryptoKeySecurity);
+               Assert ("Exportable", info.Exportable);
                Assert ("HardwareDevice", !info.HardwareDevice);
                AssertNotNull ("KeyContainerName", info.KeyContainerName);
                AssertEquals ("KeyNumber", KeyNumber.Exchange, info.KeyNumber);
-               Assert ("MachineKeyStore", !info.MachineKeyStore);\r
-               Assert ("Protected", !info.Protected);\r
+               Assert ("MachineKeyStore", !info.MachineKeyStore);
+               Assert ("Protected", !info.Protected);
                AssertNotNull ("ProviderName", info.ProviderName);
                AssertEquals ("ProviderType", 1, info.ProviderType);
                Assert ("RandomlyGenerated", info.RandomlyGenerated);
-               Assert ("Removable", !info.Removable);\r
-               AssertNotNull ("UniqueKeyContainerName", info.UniqueKeyContainerName);\r
+               Assert ("Removable", !info.Removable);
+               AssertNotNull ("UniqueKeyContainerName", info.UniqueKeyContainerName);
        }
 
        [Test]
@@ -1120,8 +1158,8 @@ public class RSACryptoServiceProviderTest : Assertion {
                RSAParameters rsap = AllTests.GetRsaKey (true);
                rsa.ImportParameters (rsap);
                CspKeyContainerInfo info = rsa.CspKeyContainerInfo;
-               Assert ("Accessible", info.Accessible);\r
-// FIXME       AssertNotNull ("CryptoKeySecurity", info.CryptoKeySecurity);\r
+               Assert ("Accessible", info.Accessible);
+// FIXME       AssertNotNull ("CryptoKeySecurity", info.CryptoKeySecurity);
                Assert ("Exportable", info.Exportable);
                Assert ("HardwareDevice", !info.HardwareDevice);
                AssertNotNull ("KeyContainerName", info.KeyContainerName);
@@ -1144,8 +1182,8 @@ public class RSACryptoServiceProviderTest : Assertion {
                RSAParameters rsap = AllTests.GetRsaKey (false);
                rsa.ImportParameters (rsap);
                CspKeyContainerInfo info = rsa.CspKeyContainerInfo;
-               Assert ("Accessible", !info.Accessible);\r
-               // info.CryptoKeySecurity throws a CryptographicException at this stage\r
+               Assert ("Accessible", !info.Accessible);
+               // info.CryptoKeySecurity throws a CryptographicException at this stage
                // info.Exportable throws a CryptographicException at this stage
                Assert ("HardwareDevice", !info.HardwareDevice);
                AssertNotNull ("KeyContainerName", info.KeyContainerName);