From 1641a095bba2be2bfbcb75524d3289c5fbc7a9b3 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Fri, 26 Sep 2014 14:23:33 -0400 Subject: [PATCH] [Mono.Security] Clear Certificates after Import or Remove [part of PR #1004] PR: https://github.com/mono/mono/pull/1004 commit: https://github.com/rahvee/mono/commit/9fa2a1928a50114eb144202b939269f3f8d823f2 Modified to match Mono guidelines. --- .../Mono.Security.X509/X509Store.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/mcs/class/Mono.Security/Mono.Security.X509/X509Store.cs b/mcs/class/Mono.Security/Mono.Security.X509/X509Store.cs index b22f1b5ae25..d3671c0bf9f 100644 --- a/mcs/class/Mono.Security/Mono.Security.X509/X509Store.cs +++ b/mcs/class/Mono.Security/Mono.Security.X509/X509Store.cs @@ -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. } } -- 2.25.1