Merge pull request #1063 from esdrubal/bug18482
authorRodrigo Kumpera <kumpera@gmail.com>
Mon, 4 Aug 2014 16:28:50 +0000 (12:28 -0400)
committerRodrigo Kumpera <kumpera@gmail.com>
Mon, 4 Aug 2014 16:28:50 +0000 (12:28 -0400)
Resets all private key values on RSAManaged.ImportParameters. Fixes #18482.

mcs/class/Mono.Security/Mono.Security.Cryptography/RSAManaged.cs
mcs/class/Mono.Security/Test/Mono.Security.Cryptography/RSAManagedTest.cs

index 9c406a200c73b9c557c78bac455378663640b2a3..5d798ac5d22188b21bbd7d9c6aae6bbe7e1cf1ec 100644 (file)
@@ -303,6 +303,10 @@ namespace Mono.Security.Cryptography {
        
                        e = new BigInteger (parameters.Exponent);
                        n = new BigInteger (parameters.Modulus);
+                       
+                       //reset all private key values to null
+                       d = dp = dq = qInv = p = q = null;
+                       
                        // only if the private key is present
                        if (parameters.D != null)
                                d = new BigInteger (parameters.D);
index 10b8a12339d3a4d4508cf8f357f0fb91c069222a..5b30c72f2e4492b9b9503d72017dd0d983ba74dd 100644 (file)
@@ -545,5 +545,25 @@ namespace MonoTests.Mono.Security.Cryptography {
                        byte [] bytes = Convert.FromBase64String (b64);
                        rsa.DecryptValue (bytes);
                }
+               
+               [Test]
+               public void Bug18482 ()
+               {
+                       RSAManaged privateRsa = new RSAManaged ();
+                       privateRsa.FromXmlString (MonoXml384);
+                       
+                       var rsaParameters = privateRsa.ExportParameters (false);
+                       
+                       RSAManaged publicRsa = new RSAManaged ();
+                       
+                       //Generates a key pair with private key values
+                       publicRsa.ExportParameters (false);
+                       
+                       //Sets public key values and should reset private key values
+                       publicRsa.ImportParameters (rsaParameters);
+                       
+                       //Should export valid parameters without throwing an exception.
+                       publicRsa.ExportParameters (false);
+               }
        }
 }