Author: atsushi
Date: 2006-09-11 11:03:53 -0400 (Mon, 11 Sep 2006)
New Revision: 65233

Modified:
   
trunk/mcs/class/System/System.Security.Cryptography.X509Certificates/ChangeLog
   
trunk/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2.cs
   
trunk/mcs/class/System/Test/System.Security.Cryptography.X509Certificates/ChangeLog
   
trunk/mcs/class/System/Test/System.Security.Cryptography.X509Certificates/X509Certificate2Test.cs
Log:
2006-09-11  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * X509Certificate2.cs : implemented HasPrivateKey. Return null
          when the corresponding RSA or DSA has no private key.

        * X509Certificate2Test.cs : added test for PrivateKey and
          HasPrivateKey for non-private-inclusive certificate.



Modified: 
trunk/mcs/class/System/System.Security.Cryptography.X509Certificates/ChangeLog
===================================================================
--- 
trunk/mcs/class/System/System.Security.Cryptography.X509Certificates/ChangeLog  
    2006-09-11 14:46:12 UTC (rev 65232)
+++ 
trunk/mcs/class/System/System.Security.Cryptography.X509Certificates/ChangeLog  
    2006-09-11 15:03:53 UTC (rev 65233)
@@ -1,3 +1,8 @@
+2006-09-11  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * X509Certificate2.cs : implemented HasPrivateKey. Return null
+         when the corresponding RSA or DSA has no private key.
+
 2006-09-05  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * X509Certificate2.cs: Call import in ctor to be sure the private key

Modified: 
trunk/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2.cs
===================================================================
--- 
trunk/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2.cs
    2006-09-11 14:46:12 UTC (rev 65232)
+++ 
trunk/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2.cs
    2006-09-11 15:03:53 UTC (rev 65233)
@@ -31,7 +31,7 @@
 
 using System.IO;
 using System.Text;
-
+using Mono.Security.Cryptography;
 using MX = Mono.Security.X509;
 
 namespace System.Security.Cryptography.X509Certificates {
@@ -136,9 +136,9 @@
                        set { _name = value; }
                }
 
-               [MonoTODO]
+               [MonoTODO ("Probably it could be more efficient")]
                public bool HasPrivateKey {
-                       get { return false; }
+                       get { return PrivateKey != null; }
                }
 
                [MonoTODO]
@@ -160,10 +160,31 @@
 
                public AsymmetricAlgorithm PrivateKey {
                        get {
-                               if (_cert.RSA != null)
-                                       return _cert.RSA; 
-                               else if (_cert.DSA != null)
-                                       return _cert.DSA;
+                               if (_cert.RSA != null) {
+                                       RSACryptoServiceProvider rcsp = 
_cert.RSA as RSACryptoServiceProvider;
+                                       if (rcsp != null)
+                                               return rcsp.PublicOnly ? null : 
rcsp;
+                                       RSAManaged rsam = _cert.RSA as 
RSAManaged;
+                                       if (rsam != null)
+                                               return rsam.PublicOnly ? null : 
rsam;
+                                       try {
+                                               _cert.RSA.ExportParameters 
(true);
+                                               return _cert.RSA;
+                                       } catch (CryptographicException) {
+                                               return null;
+                                       }
+                               }
+                               else if (_cert.DSA != null) {
+                                       DSACryptoServiceProvider dcsp = 
_cert.DSA as DSACryptoServiceProvider;
+                                       if (dcsp != null)
+                                               return dcsp.PublicOnly ? null : 
dcsp;
+                                       try {
+                                               _cert.DSA.ExportParameters 
(true);
+                                               return _cert.DSA;
+                                       } catch (CryptographicException) {
+                                               return null;
+                                       }
+                               }
                                return null;
                        }
                        set {

Modified: 
trunk/mcs/class/System/Test/System.Security.Cryptography.X509Certificates/ChangeLog
===================================================================
--- 
trunk/mcs/class/System/Test/System.Security.Cryptography.X509Certificates/ChangeLog
 2006-09-11 14:46:12 UTC (rev 65232)
+++ 
trunk/mcs/class/System/Test/System.Security.Cryptography.X509Certificates/ChangeLog
 2006-09-11 15:03:53 UTC (rev 65233)
@@ -1,3 +1,8 @@
+2006-09-11  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * X509Certificate2Test.cs : added test for PrivateKey and
+         HasPrivateKey for non-private-inclusive certificate.
+
 2006-08-08  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * X509Certificate2Test.cs: Activate test cases blocked by bug #79028.

Modified: 
trunk/mcs/class/System/Test/System.Security.Cryptography.X509Certificates/X509Certificate2Test.cs
===================================================================
--- 
trunk/mcs/class/System/Test/System.Security.Cryptography.X509Certificates/X509Certificate2Test.cs
   2006-09-11 14:46:12 UTC (rev 65232)
+++ 
trunk/mcs/class/System/Test/System.Security.Cryptography.X509Certificates/X509Certificate2Test.cs
   2006-09-11 15:03:53 UTC (rev 65233)
@@ -77,6 +77,8 @@
                                Assert.IsNotNull (cert.GetRawCertData (), 
"#C4");
                                Assert.AreEqual (cert_a.Length, 
cert.GetRawCertData ().Length, "#C5");
                                Assert.AreEqual (cert_a, cert.GetRawCertData 
(), "#C6");
+                               Assert.IsFalse (cert.HasPrivateKey, "#C7");
+                               Assert.IsNull (cert.PrivateKey, "#C8");
                        } finally {
                                File.Delete (tempFile);
                        }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to