using System; using System.Collections.Generic; using Mono.Security.X509; namespace System.Security.Cryptography.X509Certificates { /// Represents an X.509 store, which is a physical store where certificates are persisted and managed. This class cannot be inherited. // Token: 0x0200029F RID: 671 public sealed class X509Store { /// Initializes a new instance of the class using the personal certificates of the current user store. // Token: 0x06001881 RID: 6273 RVA: 0x0005394C File Offset: 0x00051B4C public X509Store() : this("MY", StoreLocation.CurrentUser) { } /// Initializes a new instance of the class using the specified store name. /// A string value representing the store name. See for more information. // Token: 0x06001882 RID: 6274 RVA: 0x0005395C File Offset: 0x00051B5C public X509Store(string storeName) : this(storeName, StoreLocation.CurrentUser) { } /// Initializes a new instance of the class using the specified value. /// One of the values. // Token: 0x06001883 RID: 6275 RVA: 0x00053968 File Offset: 0x00051B68 public X509Store(StoreName storeName) : this(storeName, StoreLocation.CurrentUser) { } /// Initializes a new instance of the class using the specified value. /// One of the values. // Token: 0x06001884 RID: 6276 RVA: 0x00053974 File Offset: 0x00051B74 public X509Store(StoreLocation storeLocation) : this("MY", storeLocation) { } /// Initializes a new instance of the class using the specified and values. /// One of the values. /// One of the values. /// /// is not a valid location or is not a valid name. // Token: 0x06001885 RID: 6277 RVA: 0x00053984 File Offset: 0x00051B84 public X509Store(StoreName storeName, StoreLocation storeLocation) { if (storeName < StoreName.AddressBook || storeName > StoreName.TrustedPublisher) { throw new ArgumentException("storeName"); } if (storeLocation < StoreLocation.CurrentUser || storeLocation > StoreLocation.LocalMachine) { throw new ArgumentException("storeLocation"); } if (storeName != StoreName.CertificateAuthority) { this._name = storeName.ToString(); } else { this._name = "CA"; } this._location = storeLocation; } /// Initializes a new instance of the class using an Intptr handle to an HCERTSTORE store. /// An handle to an HCERTSTORE store. /// The parameter is null. /// The parameter points to an invalid context. // Token: 0x06001886 RID: 6278 RVA: 0x00053A04 File Offset: 0x00051C04 [global::System.MonoTODO("Mono's stores are fully managed. All handles are invalid.")] public X509Store(IntPtr storeHandle) { if (storeHandle == IntPtr.Zero) { throw new ArgumentNullException("storeHandle"); } throw new CryptographicException("Invalid handle."); } /// Initializes a new instance of the class using a string representing a value from the enumeration and a value from the enumeration. /// A string representing a value from the enumeration. /// One of the values. /// /// contains invalid values. // Token: 0x06001887 RID: 6279 RVA: 0x00053A34 File Offset: 0x00051C34 public X509Store(string storeName, StoreLocation storeLocation) { if (storeLocation < StoreLocation.CurrentUser || storeLocation > StoreLocation.LocalMachine) { throw new ArgumentException("storeLocation"); } this._name = storeName; this._location = storeLocation; } /// Returns a collection of certificates located in an X.509 certificate store. /// An object. // Token: 0x170007B2 RID: 1970 // (get) Token: 0x06001888 RID: 6280 RVA: 0x00053A64 File Offset: 0x00051C64 public X509Certificate2Collection Certificates { get { if (this.list == null) { this.list = new X509Certificate2Collection(); } else if (this.store == null) { this.list.Clear(); } return this.list; } } /// Gets the location of the X.509 certificate store. /// One of the values. // Token: 0x170007B3 RID: 1971 // (get) Token: 0x06001889 RID: 6281 RVA: 0x00053AA0 File Offset: 0x00051CA0 public StoreLocation Location { get { return this._location; } } /// Gets the name of the X.509 certificate store. /// One of the values. // Token: 0x170007B4 RID: 1972 // (get) Token: 0x0600188A RID: 6282 RVA: 0x00053AA8 File Offset: 0x00051CA8 public string Name { get { return this._name; } } // Token: 0x170007B5 RID: 1973 // (get) Token: 0x0600188B RID: 6283 RVA: 0x00053AB0 File Offset: 0x00051CB0 private X509Stores Factory { get { if (this._location == StoreLocation.CurrentUser) { return X509StoreManager.CurrentUser; } return X509StoreManager.LocalMachine; } } // Token: 0x170007B6 RID: 1974 // (get) Token: 0x0600188C RID: 6284 RVA: 0x00053ACC File Offset: 0x00051CCC private bool IsOpen { get { return this.store != null; } } // Token: 0x170007B7 RID: 1975 // (get) Token: 0x0600188D RID: 6285 RVA: 0x00053ADC File Offset: 0x00051CDC private bool IsReadOnly { get { return Environment.UnityWebSecurityEnabled || (this._flags & OpenFlags.ReadWrite) == OpenFlags.ReadOnly; } } // Token: 0x170007B8 RID: 1976 // (get) Token: 0x0600188E RID: 6286 RVA: 0x00053AF8 File Offset: 0x00051CF8 internal X509Store Store { get { return this.store; } } /// Gets an handle to an HCERTSTORE store. /// An handle to an HCERTSTORE store. // Token: 0x170007B9 RID: 1977 // (get) Token: 0x0600188F RID: 6287 RVA: 0x00053B00 File Offset: 0x00051D00 [global::System.MonoTODO("Mono's stores are fully managed. Always returns IntPtr.Zero.")] public IntPtr StoreHandle { get { return IntPtr.Zero; } } /// Adds a certificate to an X.509 certificate store. /// An object. /// /// is null. /// The certificate could not be added to the store. // Token: 0x06001890 RID: 6288 RVA: 0x00053B08 File Offset: 0x00051D08 public void Add(X509Certificate2 certificate) { if (certificate == null) { throw new ArgumentNullException("certificate"); } if (!this.IsOpen) { throw new CryptographicException(global::Locale.GetText("Store isn't opened.")); } if (this.IsReadOnly) { throw new CryptographicException(global::Locale.GetText("Store is read-only.")); } if (!this.Exists(certificate)) { try { this.store.Import(new X509Certificate(certificate.RawData)); } finally { this.Certificates.Add(certificate); } } } /// Adds a collection of certificates to an X.509 certificate store. /// An object. /// /// is null. /// The caller does not have the required permission. // Token: 0x06001891 RID: 6289 RVA: 0x00053BB0 File Offset: 0x00051DB0 [global::System.MonoTODO("Method isn't transactional (like documented)")] public void AddRange(X509Certificate2Collection certificates) { if (certificates == null) { throw new ArgumentNullException("certificates"); } if (certificates.Count == 0) { return; } if (!this.IsOpen) { throw new CryptographicException(global::Locale.GetText("Store isn't opened.")); } if (this.IsReadOnly) { throw new CryptographicException(global::Locale.GetText("Store is read-only.")); } foreach (X509Certificate2 x509Certificate in certificates) { if (!this.Exists(x509Certificate)) { try { this.store.Import(new X509Certificate(x509Certificate.RawData)); } finally { this.Certificates.Add(x509Certificate); } } } } /// Closes an X.509 certificate store. // Token: 0x06001892 RID: 6290 RVA: 0x00053C80 File Offset: 0x00051E80 public void Close() { this.store = null; if (this.list != null) { this.list.Clear(); } } /// Opens an X.509 certificate store or creates a new store, depending on flag settings. /// One the values. /// The store is unreadable. /// The caller does not have the required permission. /// The store contains invalid values. // Token: 0x06001893 RID: 6291 RVA: 0x00053CA0 File Offset: 0x00051EA0 public void Open(OpenFlags flags) { if (string.IsNullOrEmpty(this._name)) { throw new CryptographicException(global::Locale.GetText("Invalid store name (null or empty).")); } string name = this._name; string text; if (name != null) { if (X509Store.<>f__switch$mapF == null) { X509Store.<>f__switch$mapF = new Dictionary(1) { { "Root", 0 } }; } int num; if (X509Store.<>f__switch$mapF.TryGetValue(name, out num)) { if (num == 0) { text = "Trust"; goto IL_8B; } } } text = this._name; IL_8B: bool flag = (flags & OpenFlags.OpenExistingOnly) != OpenFlags.OpenExistingOnly; this.store = this.Factory.Open(text, flag); if (this.store == null) { throw new CryptographicException(global::Locale.GetText("Store {0} doesn't exists.", new object[] { this._name })); } this._flags = flags; foreach (X509Certificate x509Certificate in this.store.Certificates) { this.Certificates.Add(new X509Certificate2(x509Certificate.RawData)); } } /// Removes a certificate from an X.509 certificate store. /// The certificate to remove. /// /// is null. /// The caller does not have the required permission. // Token: 0x06001894 RID: 6292 RVA: 0x00053DFC File Offset: 0x00051FFC public void Remove(X509Certificate2 certificate) { if (certificate == null) { throw new ArgumentNullException("certificate"); } if (!this.IsOpen) { throw new CryptographicException(global::Locale.GetText("Store isn't opened.")); } if (!this.Exists(certificate)) { return; } if (this.IsReadOnly) { throw new CryptographicException(global::Locale.GetText("Store is read-only.")); } try { this.store.Remove(new X509Certificate(certificate.RawData)); } finally { this.Certificates.Remove(certificate); } } /// Removes a range of certificates from an X.509 certificate store. /// A range of certificates to remove. /// /// is null. /// The caller does not have the required permission. // Token: 0x06001895 RID: 6293 RVA: 0x00053EA4 File Offset: 0x000520A4 [global::System.MonoTODO("Method isn't transactional (like documented)")] public void RemoveRange(X509Certificate2Collection certificates) { if (certificates == null) { throw new ArgumentNullException("certificates"); } if (certificates.Count == 0) { return; } if (!this.IsOpen) { throw new CryptographicException(global::Locale.GetText("Store isn't opened.")); } bool flag = false; foreach (X509Certificate2 x509Certificate in certificates) { if (this.Exists(x509Certificate)) { flag = true; } } if (!flag) { return; } if (this.IsReadOnly) { throw new CryptographicException(global::Locale.GetText("Store is read-only.")); } try { foreach (X509Certificate2 x509Certificate2 in certificates) { this.store.Remove(new X509Certificate(x509Certificate2.RawData)); } } finally { this.Certificates.RemoveRange(certificates); } } // Token: 0x06001896 RID: 6294 RVA: 0x00053FA0 File Offset: 0x000521A0 private bool Exists(X509Certificate2 certificate) { if (this.store == null || this.list == null || certificate == null) { return false; } foreach (X509Certificate2 x509Certificate in this.list) { if (certificate.Equals(x509Certificate)) { return true; } } return false; } // Token: 0x0400137A RID: 4986 private string _name; // Token: 0x0400137B RID: 4987 private StoreLocation _location; // Token: 0x0400137C RID: 4988 private X509Certificate2Collection list; // Token: 0x0400137D RID: 4989 private OpenFlags _flags; // Token: 0x0400137E RID: 4990 private X509Store store; } }