2 // X509StoreManager.cs: X.509 store manager.
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2004 Novell (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
35 using Mono.Security.X509.Extensions;
37 namespace Mono.Security.X509 {
44 sealed class X509StoreManager {
46 static private X509Stores _userStore;
47 static private X509Stores _machineStore;
49 private X509StoreManager ()
53 static public X509Stores CurrentUser {
55 if (_userStore == null) {
56 string _userPath = Path.Combine (
57 Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
59 _userPath = Path.Combine (_userPath, "certs");
61 _userStore = new X509Stores (_userPath);
67 static public X509Stores LocalMachine {
69 if (_machineStore == null) {
70 string _machinePath = Path.Combine (
71 Environment.GetFolderPath (Environment.SpecialFolder.CommonApplicationData),
73 _machinePath = Path.Combine (_machinePath, "certs");
75 _machineStore = new X509Stores (_machinePath);
81 // Merged stores collections
82 // we need to look at both the user and the machine (entreprise)
83 // certificates/CRLs when building/validating a chain
85 static public X509CertificateCollection IntermediateCACertificates {
87 X509CertificateCollection intermediateCerts = new X509CertificateCollection ();
88 intermediateCerts.AddRange (CurrentUser.IntermediateCA.Certificates);
89 intermediateCerts.AddRange (LocalMachine.IntermediateCA.Certificates);
90 return intermediateCerts;
94 static public ArrayList IntermediateCACrls {
96 ArrayList intermediateCRLs = new ArrayList ();
97 intermediateCRLs.AddRange (CurrentUser.IntermediateCA.Crls);
98 intermediateCRLs.AddRange (LocalMachine.IntermediateCA.Crls);
99 return intermediateCRLs;
103 static public X509CertificateCollection TrustedRootCertificates {
105 X509CertificateCollection trustedCerts = new X509CertificateCollection ();
106 trustedCerts.AddRange (CurrentUser.TrustedRoot.Certificates);
107 trustedCerts.AddRange (LocalMachine.TrustedRoot.Certificates);
112 static public ArrayList TrustedRootCACrls {
114 ArrayList trustedCRLs = new ArrayList ();
115 trustedCRLs.AddRange (CurrentUser.TrustedRoot.Crls);
116 trustedCRLs.AddRange (LocalMachine.TrustedRoot.Crls);
121 static public X509CertificateCollection UntrustedCertificates {
123 X509CertificateCollection untrustedCerts = new X509CertificateCollection ();
124 untrustedCerts.AddRange (CurrentUser.Untrusted.Certificates);
125 untrustedCerts.AddRange (LocalMachine.Untrusted.Certificates);
126 return untrustedCerts;