X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;ds=inline;f=mcs%2Fclass%2Fcorlib%2FTest%2FSystem.Security.Cryptography%2FRSACryptoServiceProviderTest.cs;h=8767c8156c3980ffff04c57111e864fb1a7e9fb4;hb=3d693eeb90339833968d66c3dc9fde2fa3ba2cef;hp=cf82863de961a659070f08796189e9b0d1c34672;hpb=10452fd9a95bce87fb15cd90d138888c91768723;p=mono.git diff --git a/mcs/class/corlib/Test/System.Security.Cryptography/RSACryptoServiceProviderTest.cs b/mcs/class/corlib/Test/System.Security.Cryptography/RSACryptoServiceProviderTest.cs index cf82863de96..8767c8156c3 100644 --- a/mcs/class/corlib/Test/System.Security.Cryptography/RSACryptoServiceProviderTest.cs +++ b/mcs/class/corlib/Test/System.Security.Cryptography/RSACryptoServiceProviderTest.cs @@ -5,7 +5,7 @@ // Sebastien Pouliot // // (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); -#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 + 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); -#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 + 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 - +#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); - } - -#if NET_2_0 + } + +#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 ("iSObDmmhDgrl4NiLaviFcpv4NdysBWJcqiVz3AQbPdajtXaQQ8VJdfRkixah132yKOFGCWZhHS3EuPMh8dcNwGwta2nh+m2IV6ktzI4+mZ7CSNAsmlDY0JI+H8At1vKvNArlC5jkVGuliYroJeSU/NLPLNYgspi7TtXGy9Rfug8=EQ=="); +#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 ("iSObDmmhDgrl4NiLaviFcpv4NdysBWJcqiVz3AQbPdajtXaQQ8VJdfRkixah132yKOFGCWZhHS3EuPMh8dcNwGwta2nh+m2IV6ktzI4+mZ7CSNAsmlDY0JI+H8At1vKvNArlC5jkVGuliYroJeSU/NLPLNYgspi7TtXGy9Rfug8=EQ==

pd4svtxrnTWXVSb151/JFgT9szI6dxQ5pAFPd4A4yuxLLEay2W2z7d9LVk5siMFhZ10uTJGWzNP5pSgLT8wdww==

06j6m4cGRc3uoKVuFFGA19JG3Bi4tDBEQHebEc/Y3+eThrOasYIRrQmGUfqWnd9eFitO9GOaVJ0muNDV7NOxxQ==OoqmYXr4zhLqHg3AM4s36adomZlBz6zJDLUrGx4yKYCTAJFsTL1OkDCxLYUXP1NPjeSm7dkIDA6UWGh8doRGvQ==PkDCLb5NI5br1OVcnJBxMGsFyEOBnmiMi2545x8DjSX+Nq1LnZ6555ljvcIsTIz9jgy83nel3KaxCS5dCWtwhQ==OrFYaG7wTqim/bub4qY0CvIfhsjG4/4MEabg0UFTf/+tekKas7DDKg2TD5BS2q0O3XEt7xIfp0S6dpOAnrlyGQ==IESc9FUW1iCuj0ICr8IBSCSy3383iMvZkXI5YPHoSskXdf3Hl3m27pPbbAVTQcM4+o9bxfn4u5JMZ8C8sV/G/8Cfl4ss1NVMbZOecvVObRqRpqXaveq5fN2X0EklH1wzm5w3O8cMXdbC/hc0gKUqaMjFVn1zpf3zVjpOkY0eGRE=
"); + 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 ("iSObDmmhDgrl4NiLaviFcpv4NdysBWJcqiVz3AQbPdajtXaQQ8VJdfRkixah132yKOFGCWZhHS3EuPMh8dcNwGwta2nh+m2IV6ktzI4+mZ7CSNAsmlDY0JI+H8At1vKvNArlC5jkVGuliYroJeSU/NLPLNYgspi7TtXGy9Rfug8=EQ==

pd4svtxrnTWXVSb151/JFgT9szI6dxQ5pAFPd4A4yuxLLEay2W2z7d9LVk5siMFhZ10uTJGWzNP5pSgLT8wdww==

06j6m4cGRc3uoKVuFFGA19JG3Bi4tDBEQHebEc/Y3+eThrOasYIRrQmGUfqWnd9eFitO9GOaVJ0muNDV7NOxxQ==OoqmYXr4zhLqHg3AM4s36adomZlBz6zJDLUrGx4yKYCTAJFsTL1OkDCxLYUXP1NPjeSm7dkIDA6UWGh8doRGvQ==PkDCLb5NI5br1OVcnJBxMGsFyEOBnmiMi2545x8DjSX+Nq1LnZ6555ljvcIsTIz9jgy83nel3KaxCS5dCWtwhQ==OrFYaG7wTqim/bub4qY0CvIfhsjG4/4MEabg0UFTf/+tekKas7DDKg2TD5BS2q0O3XEt7xIfp0S6dpOAnrlyGQ==IESc9FUW1iCuj0ICr8IBSCSy3383iMvZkXI5YPHoSskXdf3Hl3m27pPbbAVTQcM4+o9bxfn4u5JMZ8C8sV/G/8Cfl4ss1NVMbZOecvVObRqRpqXaveq5fN2X0EklH1wzm5w3O8cMXdbC/hc0gKUqaMjFVn1zpf3zVjpOkY0eGRE=
"); + 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); -// FIXME AssertNotNull ("CryptoKeySecurity", info.CryptoKeySecurity); - Assert ("Exportable", info.Exportable); + 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); - Assert ("Protected", !info.Protected); + 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); - AssertNotNull ("UniqueKeyContainerName", info.UniqueKeyContainerName); + 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); -// FIXME AssertNotNull ("CryptoKeySecurity", info.CryptoKeySecurity); + 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); - // info.CryptoKeySecurity throws a CryptographicException at this stage + 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);