using System; using System.Globalization; namespace System.Security.Cryptography.X509Certificates { /// Represents a collection of objects. This class cannot be inherited. // Token: 0x02000289 RID: 649 public class X509Certificate2Collection : X509CertificateCollection { /// Initializes a new instance of the class without any information. // Token: 0x060017D0 RID: 6096 RVA: 0x000502E4 File Offset: 0x0004E4E4 public X509Certificate2Collection() { } /// Initializes a new instance of the class using the specified certificate collection. /// An object. // Token: 0x060017D1 RID: 6097 RVA: 0x000502EC File Offset: 0x0004E4EC public X509Certificate2Collection(X509Certificate2Collection certificates) { this.AddRange(certificates); } /// Initializes a new instance of the class using an object. /// An object to start the collection from. // Token: 0x060017D2 RID: 6098 RVA: 0x000502FC File Offset: 0x0004E4FC public X509Certificate2Collection(X509Certificate2 certificate) { this.Add(certificate); } /// Initializes a new instance of the class using an array of objects. /// An array of objects. // Token: 0x060017D3 RID: 6099 RVA: 0x0005030C File Offset: 0x0004E50C public X509Certificate2Collection(X509Certificate2[] certificates) { this.AddRange(certificates); } /// Gets or sets the element at the specified index. /// The element at the specified index. /// The zero-based index of the element to get or set. /// /// is less than zero.-or- is equal to or greater than the property. /// /// is null. // Token: 0x17000787 RID: 1927 public X509Certificate2 this[int index] { get { if (index < 0) { throw new ArgumentOutOfRangeException("negative index"); } if (index >= base.InnerList.Count) { throw new ArgumentOutOfRangeException("index >= Count"); } return (X509Certificate2)base.InnerList[index]; } set { base.InnerList[index] = value; } } /// Adds an object to the end of the . /// The index at which the has been added. /// An X.509 certificate represented as an object. /// /// is null. // Token: 0x060017D6 RID: 6102 RVA: 0x00050378 File Offset: 0x0004E578 public int Add(X509Certificate2 certificate) { if (certificate == null) { throw new ArgumentNullException("certificate"); } return base.InnerList.Add(certificate); } /// Adds multiple objects in an array to the object. /// An array of objects. /// /// is null. // Token: 0x060017D7 RID: 6103 RVA: 0x00050398 File Offset: 0x0004E598 [global::System.MonoTODO("Method isn't transactional (like documented)")] public void AddRange(X509Certificate2[] certificates) { if (certificates == null) { throw new ArgumentNullException("certificates"); } for (int i = 0; i < certificates.Length; i++) { base.InnerList.Add(certificates[i]); } } /// Adds multiple objects in an object to another object. /// An object. /// /// is null. // Token: 0x060017D8 RID: 6104 RVA: 0x000503DC File Offset: 0x0004E5DC [global::System.MonoTODO("Method isn't transactional (like documented)")] public void AddRange(X509Certificate2Collection certificates) { if (certificates == null) { throw new ArgumentNullException("certificates"); } base.InnerList.AddRange(certificates); } /// Determines whether the object contains a specific certificate. /// true if the contains the specified ; otherwise, false. /// The object to locate in the collection. /// /// is null. // Token: 0x060017D9 RID: 6105 RVA: 0x000503FC File Offset: 0x0004E5FC public bool Contains(X509Certificate2 certificate) { if (certificate == null) { throw new ArgumentNullException("certificate"); } foreach (object obj in base.InnerList) { X509Certificate2 x509Certificate = (X509Certificate2)obj; if (x509Certificate.Equals(certificate)) { return true; } } return false; } /// Exports X.509 certificate information into a byte array. /// X.509 certificate information in a byte array. /// A supported object. // Token: 0x060017DA RID: 6106 RVA: 0x0005048C File Offset: 0x0004E68C [global::System.MonoTODO("only support X509ContentType.Cert")] public byte[] Export(X509ContentType contentType) { return this.Export(contentType, null); } /// Exports X.509 certificate information into a byte array using a password. /// X.509 certificate information in a byte array. /// A supported object. /// A string used to protect the byte array. /// The certificate is unreadable, the content is invalid or, in the case of a certificate requiring a password, the private key could not be exported because the password provided was incorrect. // Token: 0x060017DB RID: 6107 RVA: 0x00050498 File Offset: 0x0004E698 [global::System.MonoTODO("only support X509ContentType.Cert")] public byte[] Export(X509ContentType contentType, string password) { switch (contentType) { case X509ContentType.Cert: case X509ContentType.SerializedCert: case X509ContentType.Pfx: if (this.Count > 0) { return this[this.Count - 1].Export(contentType, password); } break; case X509ContentType.SerializedStore: break; case X509ContentType.Pkcs7: break; default: { string text = global::Locale.GetText("Cannot export certificate(s) to the '{0}' format", new object[] { contentType }); throw new CryptographicException(text); } } return null; } /// Searches an object using the search criteria specified by the enumeration and the object. /// An object. /// One of the values. /// The search criteria as an object. /// true to allow only valid certificates to be returned from the search; otherwise, false. /// /// is invalid. // Token: 0x060017DC RID: 6108 RVA: 0x0005051C File Offset: 0x0004E71C [global::System.MonoTODO("Does not support X509FindType.FindByTemplateName, FindByApplicationPolicy and FindByCertificatePolicy")] public X509Certificate2Collection Find(X509FindType findType, object findValue, bool validOnly) { if (findValue == null) { throw new ArgumentNullException("findValue"); } string text = string.Empty; string text2 = string.Empty; X509KeyUsageFlags x509KeyUsageFlags = X509KeyUsageFlags.None; DateTime dateTime = DateTime.MinValue; switch (findType) { case X509FindType.FindByThumbprint: case X509FindType.FindBySubjectName: case X509FindType.FindBySubjectDistinguishedName: case X509FindType.FindByIssuerName: case X509FindType.FindByIssuerDistinguishedName: case X509FindType.FindBySerialNumber: case X509FindType.FindByTemplateName: case X509FindType.FindBySubjectKeyIdentifier: try { text = (string)findValue; } catch (Exception ex) { string text3 = global::Locale.GetText("Invalid find value type '{0}', expected '{1}'.", new object[] { findValue.GetType(), "string" }); throw new CryptographicException(text3, ex); } break; case X509FindType.FindByTimeValid: case X509FindType.FindByTimeNotYetValid: case X509FindType.FindByTimeExpired: try { dateTime = (DateTime)findValue; } catch (Exception ex2) { string text4 = global::Locale.GetText("Invalid find value type '{0}', expected '{1}'.", new object[] { findValue.GetType(), "X509DateTime" }); throw new CryptographicException(text4, ex2); } break; case X509FindType.FindByApplicationPolicy: case X509FindType.FindByCertificatePolicy: case X509FindType.FindByExtension: try { text2 = (string)findValue; } catch (Exception ex3) { string text5 = global::Locale.GetText("Invalid find value type '{0}', expected '{1}'.", new object[] { findValue.GetType(), "X509KeyUsageFlags" }); throw new CryptographicException(text5, ex3); } try { CryptoConfig.EncodeOID(text2); } catch (CryptographicUnexpectedOperationException) { string text6 = global::Locale.GetText("Invalid OID value '{0}'.", new object[] { text2 }); throw new ArgumentException("findValue", text6); } break; case X509FindType.FindByKeyUsage: try { x509KeyUsageFlags = (X509KeyUsageFlags)((int)findValue); } catch (Exception ex4) { string text7 = global::Locale.GetText("Invalid find value type '{0}', expected '{1}'.", new object[] { findValue.GetType(), "X509KeyUsageFlags" }); throw new CryptographicException(text7, ex4); } break; default: { string text8 = global::Locale.GetText("Invalid find type '{0}'.", new object[] { findType }); throw new CryptographicException(text8); } } CultureInfo invariantCulture = CultureInfo.InvariantCulture; X509Certificate2Collection x509Certificate2Collection = new X509Certificate2Collection(); foreach (object obj in base.InnerList) { X509Certificate2 x509Certificate = (X509Certificate2)obj; bool flag = false; switch (findType) { case X509FindType.FindByThumbprint: flag = string.Compare(text, x509Certificate.Thumbprint, true, invariantCulture) == 0 || string.Compare(text, x509Certificate.GetCertHashString(), true, invariantCulture) == 0; break; case X509FindType.FindBySubjectName: { string nameInfo = x509Certificate.GetNameInfo(X509NameType.SimpleName, false); flag = nameInfo.IndexOf(text, StringComparison.InvariantCultureIgnoreCase) >= 0; break; } case X509FindType.FindBySubjectDistinguishedName: flag = string.Compare(text, x509Certificate.Subject, true, invariantCulture) == 0; break; case X509FindType.FindByIssuerName: { string nameInfo2 = x509Certificate.GetNameInfo(X509NameType.SimpleName, true); flag = nameInfo2.IndexOf(text, StringComparison.InvariantCultureIgnoreCase) >= 0; break; } case X509FindType.FindByIssuerDistinguishedName: flag = string.Compare(text, x509Certificate.Issuer, true, invariantCulture) == 0; break; case X509FindType.FindBySerialNumber: flag = string.Compare(text, x509Certificate.SerialNumber, true, invariantCulture) == 0; break; case X509FindType.FindByTimeValid: flag = dateTime >= x509Certificate.NotBefore && dateTime <= x509Certificate.NotAfter; break; case X509FindType.FindByTimeNotYetValid: flag = dateTime < x509Certificate.NotBefore; break; case X509FindType.FindByTimeExpired: flag = dateTime > x509Certificate.NotAfter; break; case X509FindType.FindByApplicationPolicy: flag = x509Certificate.Extensions.Count == 0; break; case X509FindType.FindByExtension: flag = x509Certificate.Extensions[text2] != null; break; case X509FindType.FindByKeyUsage: { X509KeyUsageExtension x509KeyUsageExtension = x509Certificate.Extensions["2.5.29.15"] as X509KeyUsageExtension; flag = x509KeyUsageExtension == null || (x509KeyUsageExtension.KeyUsages & x509KeyUsageFlags) == x509KeyUsageFlags; break; } case X509FindType.FindBySubjectKeyIdentifier: { X509SubjectKeyIdentifierExtension x509SubjectKeyIdentifierExtension = x509Certificate.Extensions["2.5.29.14"] as X509SubjectKeyIdentifierExtension; if (x509SubjectKeyIdentifierExtension != null) { flag = string.Compare(text, x509SubjectKeyIdentifierExtension.SubjectKeyIdentifier, true, invariantCulture) == 0; } break; } } if (flag) { if (validOnly) { try { if (x509Certificate.Verify()) { x509Certificate2Collection.Add(x509Certificate); } } catch { } } else { x509Certificate2Collection.Add(x509Certificate); } } } return x509Certificate2Collection; } /// Returns an enumerator that can iterate through a object. /// An object that can iterate through the object. // Token: 0x060017DD RID: 6109 RVA: 0x00050A58 File Offset: 0x0004EC58 public new X509Certificate2Enumerator GetEnumerator() { return new X509Certificate2Enumerator(this); } /// Imports a certificate in the form of a byte array into a object. /// A byte array containing data from an X.509 certificate. // Token: 0x060017DE RID: 6110 RVA: 0x00050A60 File Offset: 0x0004EC60 [global::System.MonoTODO("same limitations as X509Certificate2.Import")] public void Import(byte[] rawData) { X509Certificate2 x509Certificate = new X509Certificate2(); x509Certificate.Import(rawData); this.Add(x509Certificate); } /// Imports a certificate, in the form of a byte array that requires a password to access the certificate, into a object. /// A byte array containing data from an object. /// The password required to access the certificate information. /// One of the values that controls how and where the private key is imported. // Token: 0x060017DF RID: 6111 RVA: 0x00050A84 File Offset: 0x0004EC84 [global::System.MonoTODO("same limitations as X509Certificate2.Import")] public void Import(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags) { X509Certificate2 x509Certificate = new X509Certificate2(); x509Certificate.Import(rawData, password, keyStorageFlags); this.Add(x509Certificate); } /// Imports a certificate file into a object. /// The name of the file containing the certificate information. // Token: 0x060017E0 RID: 6112 RVA: 0x00050AA8 File Offset: 0x0004ECA8 [global::System.MonoTODO("same limitations as X509Certificate2.Import")] public void Import(string fileName) { X509Certificate2 x509Certificate = new X509Certificate2(); x509Certificate.Import(fileName); this.Add(x509Certificate); } /// Imports a certificate file that requires a password into a object. /// The name of the file containing the certificate information. /// The password required to access the certificate information. /// One of the values that controls how and where the private key is imported. // Token: 0x060017E1 RID: 6113 RVA: 0x00050ACC File Offset: 0x0004ECCC [global::System.MonoTODO("same limitations as X509Certificate2.Import")] public void Import(string fileName, string password, X509KeyStorageFlags keyStorageFlags) { X509Certificate2 x509Certificate = new X509Certificate2(); x509Certificate.Import(fileName, password, keyStorageFlags); this.Add(x509Certificate); } /// Inserts an object into the object at the specified index. /// The zero-based index at which to insert . /// The object to insert. /// /// is less than zero.-or- is greater than the property. /// The collection is read-only.-or- The collection has a fixed size. /// /// is null. // Token: 0x060017E2 RID: 6114 RVA: 0x00050AF0 File Offset: 0x0004ECF0 public void Insert(int index, X509Certificate2 certificate) { if (certificate == null) { throw new ArgumentNullException("certificate"); } if (index < 0) { throw new ArgumentOutOfRangeException("negative index"); } if (index >= base.InnerList.Count) { throw new ArgumentOutOfRangeException("index >= Count"); } base.InnerList.Insert(index, certificate); } /// Removes the first occurrence of a certificate from the object. /// The object to be removed from the object. /// /// is null. // Token: 0x060017E3 RID: 6115 RVA: 0x00050B4C File Offset: 0x0004ED4C public void Remove(X509Certificate2 certificate) { if (certificate == null) { throw new ArgumentNullException("certificate"); } for (int i = 0; i < base.InnerList.Count; i++) { X509Certificate x509Certificate = (X509Certificate)base.InnerList[i]; if (x509Certificate.Equals(certificate)) { base.InnerList.RemoveAt(i); return; } } } /// Removes multiple objects in an array from an object. /// An array of objects. /// /// is null. // Token: 0x060017E4 RID: 6116 RVA: 0x00050BB4 File Offset: 0x0004EDB4 [global::System.MonoTODO("Method isn't transactional (like documented)")] public void RemoveRange(X509Certificate2[] certificates) { if (certificates == null) { throw new ArgumentNullException("certificate"); } foreach (X509Certificate2 x509Certificate in certificates) { this.Remove(x509Certificate); } } /// Removes multiple objects in an object from another object. /// An object. /// /// is null. // Token: 0x060017E5 RID: 6117 RVA: 0x00050BF4 File Offset: 0x0004EDF4 [global::System.MonoTODO("Method isn't transactional (like documented)")] public void RemoveRange(X509Certificate2Collection certificates) { if (certificates == null) { throw new ArgumentNullException("certificate"); } foreach (X509Certificate2 x509Certificate in certificates) { this.Remove(x509Certificate); } } } }