using System; using System.Collections; using System.Globalization; using System.IO; using System.Text; using Mono.Security.X509.Extensions; namespace Mono.Security.X509 { // Token: 0x020000C3 RID: 195 internal class X509Store { // Token: 0x06000A9A RID: 2714 RVA: 0x0002F1C8 File Offset: 0x0002D3C8 internal X509Store(string path, bool crl) { this._storePath = path; this._crl = crl; } // Token: 0x1700015D RID: 349 // (get) Token: 0x06000A9B RID: 2715 RVA: 0x0002F1E0 File Offset: 0x0002D3E0 public X509CertificateCollection Certificates { get { if (this._certificates == null) { this._certificates = this.BuildCertificatesCollection(this._storePath); } return this._certificates; } } // Token: 0x1700015E RID: 350 // (get) Token: 0x06000A9C RID: 2716 RVA: 0x0002F208 File Offset: 0x0002D408 public ArrayList Crls { get { if (!this._crl) { this._crls = new ArrayList(); } if (this._crls == null) { this._crls = this.BuildCrlsCollection(this._storePath); } return this._crls; } } // Token: 0x1700015F RID: 351 // (get) Token: 0x06000A9D RID: 2717 RVA: 0x0002F244 File Offset: 0x0002D444 public string Name { get { if (this._name == null) { int num = this._storePath.LastIndexOf(Path.DirectorySeparatorChar); this._name = this._storePath.Substring(num + 1); } return this._name; } } // Token: 0x06000A9E RID: 2718 RVA: 0x0002F288 File Offset: 0x0002D488 public void Clear() { if (this._certificates != null) { this._certificates.Clear(); } this._certificates = null; if (this._crls != null) { this._crls.Clear(); } this._crls = null; } // Token: 0x06000A9F RID: 2719 RVA: 0x0002F2D0 File Offset: 0x0002D4D0 public void Import(X509Certificate certificate) { this.CheckStore(this._storePath, true); string text = Path.Combine(this._storePath, this.GetUniqueName(certificate)); if (!File.Exists(text)) { using (FileStream fileStream = File.Create(text)) { byte[] rawData = certificate.RawData; fileStream.Write(rawData, 0, rawData.Length); fileStream.Close(); } } } // Token: 0x06000AA0 RID: 2720 RVA: 0x0002F358 File Offset: 0x0002D558 public void Import(X509Crl crl) { this.CheckStore(this._storePath, true); string text = Path.Combine(this._storePath, this.GetUniqueName(crl)); if (!File.Exists(text)) { using (FileStream fileStream = File.Create(text)) { byte[] rawData = crl.RawData; fileStream.Write(rawData, 0, rawData.Length); } } } // Token: 0x06000AA1 RID: 2721 RVA: 0x0002F3D8 File Offset: 0x0002D5D8 public void Remove(X509Certificate certificate) { string text = Path.Combine(this._storePath, this.GetUniqueName(certificate)); if (File.Exists(text)) { File.Delete(text); } } // Token: 0x06000AA2 RID: 2722 RVA: 0x0002F40C File Offset: 0x0002D60C public void Remove(X509Crl crl) { string text = Path.Combine(this._storePath, this.GetUniqueName(crl)); if (File.Exists(text)) { File.Delete(text); } } // Token: 0x06000AA3 RID: 2723 RVA: 0x0002F440 File Offset: 0x0002D640 private string GetUniqueName(X509Certificate certificate) { byte[] array = this.GetUniqueName(certificate.Extensions); string text; if (array == null) { text = "tbp"; array = certificate.Hash; } else { text = "ski"; } return this.GetUniqueName(text, array, ".cer"); } // Token: 0x06000AA4 RID: 2724 RVA: 0x0002F488 File Offset: 0x0002D688 private string GetUniqueName(X509Crl crl) { byte[] array = this.GetUniqueName(crl.Extensions); string text; if (array == null) { text = "tbp"; array = crl.Hash; } else { text = "ski"; } return this.GetUniqueName(text, array, ".crl"); } // Token: 0x06000AA5 RID: 2725 RVA: 0x0002F4D0 File Offset: 0x0002D6D0 private byte[] GetUniqueName(X509ExtensionCollection extensions) { X509Extension x509Extension = extensions["2.5.29.14"]; if (x509Extension == null) { return null; } SubjectKeyIdentifierExtension subjectKeyIdentifierExtension = new SubjectKeyIdentifierExtension(x509Extension); return subjectKeyIdentifierExtension.Identifier; } // Token: 0x06000AA6 RID: 2726 RVA: 0x0002F500 File Offset: 0x0002D700 private string GetUniqueName(string method, byte[] name, string fileExtension) { StringBuilder stringBuilder = new StringBuilder(method); stringBuilder.Append("-"); foreach (byte b in name) { stringBuilder.Append(b.ToString("X2", CultureInfo.InvariantCulture)); } stringBuilder.Append(fileExtension); return stringBuilder.ToString(); } // Token: 0x06000AA7 RID: 2727 RVA: 0x0002F560 File Offset: 0x0002D760 private byte[] Load(string filename) { byte[] array = null; using (FileStream fileStream = File.OpenRead(filename)) { array = new byte[fileStream.Length]; fileStream.Read(array, 0, array.Length); fileStream.Close(); } return array; } // Token: 0x06000AA8 RID: 2728 RVA: 0x0002F5C4 File Offset: 0x0002D7C4 private X509Certificate LoadCertificate(string filename) { byte[] array = this.Load(filename); return new X509Certificate(array); } // Token: 0x06000AA9 RID: 2729 RVA: 0x0002F5E4 File Offset: 0x0002D7E4 private X509Crl LoadCrl(string filename) { byte[] array = this.Load(filename); return new X509Crl(array); } // Token: 0x06000AAA RID: 2730 RVA: 0x0002F604 File Offset: 0x0002D804 private bool CheckStore(string path, bool throwException) { bool flag; try { if (Directory.Exists(path)) { flag = true; } else { Directory.CreateDirectory(path); flag = Directory.Exists(path); } } catch { if (throwException) { throw; } flag = false; } return flag; } // Token: 0x06000AAB RID: 2731 RVA: 0x0002F670 File Offset: 0x0002D870 private X509CertificateCollection BuildCertificatesCollection(string storeName) { X509CertificateCollection x509CertificateCollection = new X509CertificateCollection(); string text = Path.Combine(this._storePath, storeName); if (!this.CheckStore(text, false)) { return x509CertificateCollection; } string[] files = Directory.GetFiles(text, "*.cer"); if (files != null && files.Length > 0) { foreach (string text2 in files) { try { X509Certificate x509Certificate = this.LoadCertificate(text2); x509CertificateCollection.Add(x509Certificate); } catch { } } } return x509CertificateCollection; } // Token: 0x06000AAC RID: 2732 RVA: 0x0002F718 File Offset: 0x0002D918 private ArrayList BuildCrlsCollection(string storeName) { ArrayList arrayList = new ArrayList(); string text = Path.Combine(this._storePath, storeName); if (!this.CheckStore(text, false)) { return arrayList; } string[] files = Directory.GetFiles(text, "*.crl"); if (files != null && files.Length > 0) { foreach (string text2 in files) { try { X509Crl x509Crl = this.LoadCrl(text2); arrayList.Add(x509Crl); } catch { } } } return arrayList; } // Token: 0x040002BE RID: 702 private string _storePath; // Token: 0x040002BF RID: 703 private X509CertificateCollection _certificates; // Token: 0x040002C0 RID: 704 private ArrayList _crls; // Token: 0x040002C1 RID: 705 private bool _crl; // Token: 0x040002C2 RID: 706 private string _name; } }