Add licensing info
[mono.git] / mcs / class / Mono.Security / Mono.Security.X509 / X509StoreManager.cs
1 //
2 // X509StoreManager.cs: X.509 store manager.
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // (C) 2004 Novell (http://www.novell.com)
8 //
9
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 using System;
32 using System.Collections;
33 using System.IO;
34
35 using Mono.Security.X509.Extensions;
36
37 namespace Mono.Security.X509 {
38
39 #if INSIDE_CORLIB
40         internal
41 #else
42         public 
43 #endif
44         sealed class X509StoreManager {
45
46                 static private X509Stores _userStore;
47                 static private X509Stores _machineStore;
48
49                 private X509StoreManager ()
50                 {
51                 }
52
53                 static public X509Stores CurrentUser {
54                         get { 
55                                 if (_userStore == null) {
56                                         string _userPath = Path.Combine (
57                                                 Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
58                                                 ".mono");
59                                         _userPath = Path.Combine (_userPath, "certs");
60
61                                         _userStore = new X509Stores (_userPath);
62                                 }
63                                 return _userStore;
64                         }
65                 }
66
67                 static public X509Stores LocalMachine {
68                         get {
69                                 if (_machineStore == null) {
70                                         string _machinePath = Path.Combine (
71                                                 Environment.GetFolderPath (Environment.SpecialFolder.CommonApplicationData),
72                                                 ".mono");
73                                         _machinePath = Path.Combine (_machinePath, "certs");
74
75                                         _machineStore = new X509Stores (_machinePath);
76                                 }
77                                 return _machineStore;
78                         }
79                 }
80
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
84
85                 static public X509CertificateCollection IntermediateCACertificates {
86                         get { 
87                                 X509CertificateCollection intermediateCerts = new X509CertificateCollection ();
88                                 intermediateCerts.AddRange (CurrentUser.IntermediateCA.Certificates);
89                                 intermediateCerts.AddRange (LocalMachine.IntermediateCA.Certificates);
90                                 return intermediateCerts; 
91                         }
92                 }
93
94                 static public ArrayList IntermediateCACrls {
95                         get { 
96                                 ArrayList intermediateCRLs = new ArrayList ();
97                                 intermediateCRLs.AddRange (CurrentUser.IntermediateCA.Crls);
98                                 intermediateCRLs.AddRange (LocalMachine.IntermediateCA.Crls);
99                                 return intermediateCRLs; 
100                         }
101                 }
102
103                 static public X509CertificateCollection TrustedRootCertificates {
104                         get { 
105                                 X509CertificateCollection trustedCerts = new X509CertificateCollection ();
106                                 trustedCerts.AddRange (CurrentUser.TrustedRoot.Certificates);
107                                 trustedCerts.AddRange (LocalMachine.TrustedRoot.Certificates);
108                                 return trustedCerts; 
109                         }
110                 }
111
112                 static public ArrayList TrustedRootCACrls {
113                         get { 
114                                 ArrayList trustedCRLs = new ArrayList ();
115                                 trustedCRLs.AddRange (CurrentUser.TrustedRoot.Crls);
116                                 trustedCRLs.AddRange (LocalMachine.TrustedRoot.Crls);
117                                 return trustedCRLs; 
118                         }
119                 }
120
121                 static public X509CertificateCollection UntrustedCertificates {
122                         get { 
123                                 X509CertificateCollection untrustedCerts = new X509CertificateCollection ();
124                                 untrustedCerts.AddRange (CurrentUser.Untrusted.Certificates);
125                                 untrustedCerts.AddRange (LocalMachine.Untrusted.Certificates);
126                                 return untrustedCerts; 
127                         }
128                 }
129         }
130 }