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