2 // FileCertificateStore.cs: Handles a file-based certificate store.
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.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.
34 using Mono.Security.Authenticode;
35 using Mono.Security.X509;
36 using Mono.Security.X509.Stores;
38 namespace Mono.Security.X509.Stores {
40 public class FileCertificateStore : ICertificateStore {
43 private string _location;
44 private bool _readOnly;
45 private bool _createIfRequired;
46 private bool _includeArchives;
47 private bool _saveOnClose;
48 private SoftwarePublisherCertificate _spc;
50 public FileCertificateStore ()
53 _includeArchives = false;
54 _createIfRequired = true;
59 public X509CertificateCollection Certificates {
62 return _spc.Certificates;
67 public IntPtr Handle {
68 get { return (IntPtr) 0; }
73 public void Open (string name, string location, bool readOnly, bool createIfNonExisting, bool includeArchives)
76 _location = _location;
78 _createIfRequired = createIfNonExisting;
79 _includeArchives = includeArchives;
82 if (File.Exists (_name)) {
83 _spc = SoftwarePublisherCertificate.CreateFromFile (_name);
85 else if (_createIfRequired) {
86 _spc = new SoftwarePublisherCertificate ();
94 byte[] store = _spc.GetBytes ();
95 using (FileStream fs = File.OpenWrite (_name)) {
96 fs.Write (store, 0, store.Length);
102 public void Add (X509Certificate certificate)
104 if ((!_readOnly) && (_spc != null)) {
105 _spc.Certificates.Add (certificate);
110 public void Remove (X509Certificate certificate)
112 if ((!_readOnly) && (_spc != null)) {
113 _spc.Certificates.Remove (certificate);