/// <summary> /// Returns the list of certificates in this <see cref="CertificateChain"/>. /// </summary> /// <returns>An array of <see cref="Certificate"/> instances.</returns> /// <remarks> /// The certificate with index 0 is the end certificate in the chain, the certificate with the highest index is the root certificate [if it can be found]. /// </remarks> // Thanks go out to Hernan de Lahitte for notifying us about a bug in this method. public virtual Certificate[] GetCertificates() { ArrayList ret = new ArrayList(); IntPtr cert = ((Certificate)this.Certificate.Clone()).Handle; int dwVerificationFlags; IntPtr store; CertificateStoreCollection csc = this.Certificate.Store as CertificateStoreCollection; if (csc != null) { csc = new CertificateStoreCollection(csc); } else { csc = new CertificateStoreCollection(new CertificateStore[0]); csc.AddStore(new CertificateStore(this.Certificate.m_Context.hCertStore, true)); } csc.AddStore(new CertificateStore(CertificateStore.RootStore)); store = csc.Handle; while (cert != IntPtr.Zero) { ret.Add(new Certificate(cert, true)); dwVerificationFlags = 0; cert = SspiProvider.CertGetIssuerCertificateFromStore(store, cert, IntPtr.Zero, ref dwVerificationFlags); } return((Certificate[])ret.ToArray(typeof(Certificate))); }
/// <summary> /// Returns the list of certificates in this <see cref="CertificateChain"/>. /// </summary> /// <returns>An array of <see cref="Certificate"/> instances.</returns> /// <remarks> /// The certificate with index 0 is the end certificate in the chain, the certificate with the highest index is the root certificate [if it can be found]. /// </remarks> // Thanks go out to Hernan de Lahitte and Neil for notifying us about a bug in this method. public virtual Certificate[] GetCertificates() { ArrayList ret = new ArrayList(); int dwVerificationFlags; IntPtr store; CertificateStoreCollection csc, cs = this.Certificate.Store as CertificateStoreCollection; if (cs != null) { csc = new CertificateStoreCollection(cs); } else { csc = new CertificateStoreCollection(new CertificateStore[0]); if (this.Certificate.Store == null) { csc.AddStore(new CertificateStore(this.Certificate.m_Context.hCertStore, true)); } else { csc.AddStore(this.Certificate.Store); } } csc.AddStore(CertificateStore.GetCachedStore(CertificateStore.RootStore)); csc.AddStore(CertificateStore.GetCachedStore(CertificateStore.CAStore)); store = csc.Handle; IntPtr cert = this.Certificate.DuplicateHandle(); while (cert != IntPtr.Zero) { ret.Add(new Certificate(cert, false)); dwVerificationFlags = 0; cert = SspiProvider.CertGetIssuerCertificateFromStore(store, cert, IntPtr.Zero, ref dwVerificationFlags); } csc.Dispose(); // don't use csc anymore after this line!!! return((Certificate[])ret.ToArray(typeof(Certificate))); }
/// <summary> /// Returns the list of certificates in this <see cref="CertificateChain"/>. /// </summary> /// <returns>An array of <see cref="Certificate"/> instances.</returns> /// <remarks> /// The certificate with index 0 is the end certificate in the chain, the certificate with the highest index is the root certificate [if it can be found]. /// </remarks> // Thanks go out to Hernan de Lahitte and Neil for notifying us about a bug in this method. public virtual Certificate[] GetCertificates() { ArrayList ret = new ArrayList(); int dwVerificationFlags; IntPtr store; CertificateStoreCollection csc, cs = this.Certificate.Store as CertificateStoreCollection; if (cs != null) { csc = new CertificateStoreCollection(cs); } else { csc = new CertificateStoreCollection(new CertificateStore[0]); if (this.Certificate.Store == null) csc.AddStore(new CertificateStore(this.Certificate.m_Context.hCertStore, true)); else csc.AddStore(this.Certificate.Store); } csc.AddStore(CertificateStore.GetCachedStore(CertificateStore.RootStore)); csc.AddStore(CertificateStore.GetCachedStore(CertificateStore.CAStore)); store = csc.Handle; IntPtr cert = this.Certificate.DuplicateHandle(); while(cert != IntPtr.Zero) { ret.Add(new Certificate(cert, false)); dwVerificationFlags = 0; cert = SspiProvider.CertGetIssuerCertificateFromStore(store, cert, IntPtr.Zero, ref dwVerificationFlags); } csc.Dispose(); // don't use csc anymore after this line!!! return (Certificate[])ret.ToArray(typeof(Certificate)); }