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 string _userPath;
47 static private string _localMachinePath;
48 static private X509Stores _userStore;
49 static private X509Stores _machineStore;
51 private X509StoreManager ()
55 internal static string CurrentUserPath {
57 if (_userPath == null) {
58 _userPath = Path.Combine(
59 Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
61 _userPath = Path.Combine(_userPath, "certs");
67 internal static string LocalMachinePath {
69 if (_localMachinePath == null) {
70 _localMachinePath = Path.Combine (
71 Environment.GetFolderPath (Environment.SpecialFolder.CommonApplicationData),
73 _localMachinePath = Path.Combine (_localMachinePath, "certs");
75 return _localMachinePath;
79 static public X509Stores CurrentUser {
81 if (_userStore == null)
82 _userStore = new X509Stores(CurrentUserPath);
88 static public X509Stores LocalMachine {
90 if (_machineStore == null)
91 _machineStore = new X509Stores (LocalMachinePath);
97 // Merged stores collections
98 // we need to look at both the user and the machine (entreprise)
99 // certificates/CRLs when building/validating a chain
101 static public X509CertificateCollection IntermediateCACertificates {
103 X509CertificateCollection intermediateCerts = new X509CertificateCollection ();
104 intermediateCerts.AddRange (CurrentUser.IntermediateCA.Certificates);
105 intermediateCerts.AddRange (LocalMachine.IntermediateCA.Certificates);
106 return intermediateCerts;
110 static public ArrayList IntermediateCACrls {
112 ArrayList intermediateCRLs = new ArrayList ();
113 intermediateCRLs.AddRange (CurrentUser.IntermediateCA.Crls);
114 intermediateCRLs.AddRange (LocalMachine.IntermediateCA.Crls);
115 return intermediateCRLs;
119 static public X509CertificateCollection TrustedRootCertificates {
121 X509CertificateCollection trustedCerts = new X509CertificateCollection ();
122 trustedCerts.AddRange (CurrentUser.TrustedRoot.Certificates);
123 trustedCerts.AddRange (LocalMachine.TrustedRoot.Certificates);
128 static public ArrayList TrustedRootCACrls {
130 ArrayList trustedCRLs = new ArrayList ();
131 trustedCRLs.AddRange (CurrentUser.TrustedRoot.Crls);
132 trustedCRLs.AddRange (LocalMachine.TrustedRoot.Crls);
137 static public X509CertificateCollection UntrustedCertificates {
139 X509CertificateCollection untrustedCerts = new X509CertificateCollection ();
140 untrustedCerts.AddRange (CurrentUser.Untrusted.Certificates);
141 untrustedCerts.AddRange (LocalMachine.Untrusted.Certificates);
142 return untrustedCerts;