2004-05-01 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Sat, 1 May 2004 17:09:57 +0000 (17:09 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Sat, 1 May 2004 17:09:57 +0000 (17:09 -0000)
* CryptoConvert.cs: Synched with Mono.Security.dll. Fix bug #57941
(truncated key pair).
* RSAManaged.cs: Synched with Mono.Security.dll. Fix bug #57941
(truncated key pair).

svn path=/trunk/mcs/; revision=26514

mcs/class/corlib/Mono.Security.Cryptography/ChangeLog
mcs/class/corlib/Mono.Security.Cryptography/CryptoConvert.cs
mcs/class/corlib/Mono.Security.Cryptography/RSAManaged.cs

index 9cc605eb292e23bdd22f36480b07f670289a348a..cee90cbe0cdf48d395fee3c5e54cb60f4f0650fd 100644 (file)
@@ -1,3 +1,10 @@
+2004-05-01  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * CryptoConvert.cs: Synched with Mono.Security.dll. Fix bug #57941 
+       (truncated key pair).
+       * RSAManaged.cs: Synched with Mono.Security.dll. Fix bug #57941 
+       (truncated key pair).
+
 2004-04-28  Sebastien Pouliot  <sebastien@ximian.com>
 
        * CryptoConvert.cs: In sync with Mono.Security.dll version.
index 70fb9fe4a810d1ae501c58c71d0c6a7d9364ce8a..058fe0917304ca04d17f8e20d35e8c2add3270a4 100755 (executable)
@@ -133,10 +133,15 @@ namespace Mono.Security.Cryptography {
                                Array.Reverse (rsap.InverseQ);
                                pos += byteHalfLen;
 
-                               // BYTE privateExponent[rsapubkey.bitlen/8];
-                               rsap.D = new byte [byteLen];
-                               Buffer.BlockCopy (blob, pos, rsap.D, 0, byteLen);
-                               Array.Reverse (rsap.D);
+                               // ok, this is hackish but CryptoAPI support it so...
+                               // note: only works because CRT is used by default
+                               // http://bugzilla.ximian.com/show_bug.cgi?id=57941
+                               rsap.D = new byte [byteLen]; // must be allocated
+                               if (pos + byteLen + offset <= blob.Length) {
+                                       // BYTE privateExponent[rsapubkey.bitlen/8];
+                                       Buffer.BlockCopy (blob, pos, rsap.D, 0, byteLen);
+                                       Array.Reverse (rsap.D);
+                               }
 
                                RSA rsa = (RSA)RSA.Create ();
                                rsa.ImportParameters (rsap);
index 79d2ae4a1865dcfb0ba799de0ade9bb096599bc4..6c811101d4e94cdac258f48d2455fa9c7637af3e 100644 (file)
@@ -221,6 +221,12 @@ namespace Mono.Security.Cryptography {
                                if ((d == null) || (p == null) || (q == null))
                                        throw new CryptographicException ("Missing private key");
                                param.D = d.GetBytes ();
+                               // hack for bugzilla #57941 where D wasn't provided
+                               if (param.D.Length != param.Modulus.Length) {
+                                       byte[] normalizedD = new byte [param.Modulus.Length];
+                                       Buffer.BlockCopy (param.D, 0, normalizedD, (normalizedD.Length - param.D.Length), param.D.Length);
+                                       param.D = normalizedD;
+                               }
                                param.P = p.GetBytes ();
                                param.Q = q.GetBytes ();
                                // but CRT parameters are optionals