2006-02-28 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Tue, 28 Feb 2006 14:19:08 +0000 (14:19 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Tue, 28 Feb 2006 14:19:08 +0000 (14:19 -0000)
* CryptoConvert.cs: Make sure we can import a keypair into our RSA
instance (even if the key store isn't available). See bug #77559.
* PKCS8.cs: Make sure we can import a keypair into our RSA instance
(even if the key store isn't available). See bug #77559.

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

mcs/class/Mono.Security/Mono.Security.Cryptography/ChangeLog
mcs/class/Mono.Security/Mono.Security.Cryptography/CryptoConvert.cs
mcs/class/Mono.Security/Mono.Security.Cryptography/PKCS8.cs

index f4c50707dcc0019cb2f01c8ff47635d98823f09c..3353d513a6ee4c8b7d03997c82527da24245eb83 100644 (file)
@@ -1,3 +1,10 @@
+2006-02-28  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * CryptoConvert.cs: Make sure we can import a keypair into our RSA 
+       instance (even if the key store isn't available). See bug #77559.
+       * PKCS8.cs: Make sure we can import a keypair into our RSA instance
+       (even if the key store isn't available). See bug #77559.
+
 2005-11-23  Sebastien Pouliot  <sebastien@ximian.com>
 
        * SymmetricTransform.cs: Synched with corlib version (IV behaviour for
index 1d876703f0c6ee53ecd15ea08eb13ae5d92311d7..e0e9cbd7ede8c064d2718ec531cc0ff575d68668 100644 (file)
@@ -5,11 +5,7 @@
 //     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.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,8 +162,20 @@ namespace Mono.Security.Cryptography {
                                        Array.Reverse (rsap.D);
                                }
 
-                               RSA rsa = (RSA)RSA.Create ();
-                               rsa.ImportParameters (rsap);
+                               RSA rsa = null;
+                               try {
+                                       rsa = RSA.Create ();
+                                       rsa.ImportParameters (rsap);
+                               }
+                               catch (CryptographicException) {
+                                       // this may cause problem when this code is run under
+                                       // the SYSTEM identity on Windows (e.g. ASP.NET). See
+                                       // http://bugzilla.ximian.com/show_bug.cgi?id=77559
+                                       CspParameters csp = new CspParameters ();
+                                       csp.Flags = CspProviderFlags.UseMachineKeyStore;
+                                       rsa = new RSACryptoServiceProvider (csp);
+                                       rsa.ImportParameters (rsap);
+                               }
                                return rsa;
                        }
                        catch (Exception e) {
@@ -287,8 +295,20 @@ namespace Mono.Security.Cryptography {
                                Buffer.BlockCopy (blob, pos, rsap.Modulus, 0, byteLen);
                                Array.Reverse (rsap.Modulus);
 
-                               RSA rsa = (RSA)RSA.Create ();
-                               rsa.ImportParameters (rsap);
+                               RSA rsa = null;
+                               try {
+                                       rsa = RSA.Create ();
+                                       rsa.ImportParameters (rsap);
+                               }
+                               catch (CryptographicException) {
+                                       // this may cause problem when this code is run under
+                                       // the SYSTEM identity on Windows (e.g. ASP.NET). See
+                                       // http://bugzilla.ximian.com/show_bug.cgi?id=77559
+                                       CspParameters csp = new CspParameters ();
+                                       csp.Flags = CspProviderFlags.UseMachineKeyStore;
+                                       rsa = new RSACryptoServiceProvider (csp);
+                                       rsa.ImportParameters (rsap);
+                               }
                                return rsa;
                        }
                        catch (Exception e) {
index d7cedf758f63a8c6116a45964a33d6efdb15fe7f..cc83e116844ce521f9ce64344da06495bcb31801 100644 (file)
@@ -6,7 +6,7 @@
 //     Sebastien Pouliot <sebastien@ximian.com>
 //
 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004-2005 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
@@ -273,8 +273,20 @@ namespace Mono.Security.Cryptography {
                                param.P = Normalize (privateKey [4].Value, keysize2);
                                param.Q = Normalize (privateKey [5].Value, keysize2);
 
-                               RSA rsa = RSA.Create ();
-                               rsa.ImportParameters (param);
+                               RSA rsa = null;
+                               try {
+                                       rsa = RSA.Create ();
+                                       rsa.ImportParameters (param);
+                               }
+                               catch (CryptographicException) {
+                                       // this may cause problem when this code is run under
+                                       // the SYSTEM identity on Windows (e.g. ASP.NET). See
+                                       // http://bugzilla.ximian.com/show_bug.cgi?id=77559
+                                       CspParameters csp = new CspParameters ();
+                                       csp.Flags = CspProviderFlags.UseMachineKeyStore;
+                                       rsa = new RSACryptoServiceProvider (csp);
+                                       rsa.ImportParameters (param);
+                               }
                                return rsa;
                        }