[Mono.Security] Clear Certificates after Import or Remove [part of PR #1004]
authorSebastien Pouliot <sebastien@xamarin.com>
Fri, 26 Sep 2014 18:23:33 +0000 (14:23 -0400)
committerSebastien Pouliot <sebastien@xamarin.com>
Fri, 26 Sep 2014 18:35:20 +0000 (14:35 -0400)
PR: https://github.com/mono/mono/pull/1004

commit: https://github.com/rahvee/mono/commit/9fa2a1928a50114eb144202b939269f3f8d823f2

Modified to match Mono guidelines.

mcs/class/Mono.Security/Mono.Security.X509/X509Store.cs

index b22f1b5ae25e12fc20f9250a0e5e4a415b3a49a0..d3671c0bf9fa234bfa28f40eea84dfbffe3f4c6f 100644 (file)
@@ -97,10 +97,26 @@ namespace Mono.Security.X509 {
                // methods
 
                public void Clear () 
+               {
+                       /* 
+                        * Both _certificates and _crls extend CollectionBase, whose Clear() method calls OnClear() and 
+                        * OnClearComplete(), which should be overridden in derivative classes. So we should not worry about
+                        * other threads that might be holding references to _certificates or _crls. They should be smart enough
+                        * to handle this gracefully.  And if not, it's their own fault.
+                        */
+                       ClearCertificates ();
+                       ClearCrls ();
+               }
+
+               void ClearCertificates()
                {
                        if (_certificates != null)
                                _certificates.Clear ();
                        _certificates = null;
+               }
+
+               void ClearCrls ()
+               {
                        if (_crls != null)
                                _crls.Clear ();
                        _crls = null;
@@ -117,6 +133,7 @@ namespace Mono.Security.X509 {
                                        fs.Write (data, 0, data.Length);
                                        fs.Close ();
                                }
+                               ClearCertificates ();   // We have modified the store on disk.  So forget the old state.
                        }
 #if !NET_2_1
                        // Try to save privateKey if available..
@@ -141,6 +158,7 @@ namespace Mono.Security.X509 {
                                        byte[] data = crl.RawData;
                                        fs.Write (data, 0, data.Length);
                                }
+                               ClearCrls ();   // We have modified the store on disk.  So forget the old state.
                        }
                }
 
@@ -149,6 +167,7 @@ namespace Mono.Security.X509 {
                        string filename = Path.Combine (_storePath, GetUniqueName (certificate));
                        if (File.Exists (filename)) {
                                File.Delete (filename);
+                               ClearCertificates ();   // We have modified the store on disk.  So forget the old state.
                        }
                }
 
@@ -157,6 +176,7 @@ namespace Mono.Security.X509 {
                        string filename = Path.Combine (_storePath, GetUniqueName (crl));
                        if (File.Exists (filename)) {
                                File.Delete (filename);
+                               ClearCrls ();   // We have modified the store on disk.  So forget the old state.
                        }
                }