コード例 #1
0
        /// <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)));
        }
コード例 #2
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CertificateStoreCollection"/> class.
		/// </summary>
		/// <param name="collection">The CertificateStoreCollection whose elements are copied to the new certificate store collection.</param>
		/// <exception cref="ArgumentNullException"><paramref name="collection"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
		/// <exception cref="CertificateException">An error occurs while adding a certificate to the collection.</exception>
		public CertificateStoreCollection(CertificateStoreCollection collection) : base(SspiProvider.CertOpenStore(new IntPtr(SecurityConstants.CERT_STORE_PROV_COLLECTION), 0, 0, 0, null), false) {
			if (collection == null)
				throw new ArgumentNullException();
			m_Stores = new ArrayList( collection.m_Stores); // used to hold references to the certificate stores so they cannot be finalized
			for(int i = 0; i < m_Stores.Count; i++) {
				if (SspiProvider.CertAddStoreToCollection(this.Handle, ((CertificateStore)m_Stores[i]).Handle, 0, 0) == 0)
					throw new CertificateException("Could not add the store to the collection.");
			}
		}
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CertificateStoreCollection"/> class.
 /// </summary>
 /// <param name="collection">The CertificateStoreCollection whose elements are copied to the new certificate store collection.</param>
 /// <exception cref="ArgumentNullException"><paramref name="collection"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
 /// <exception cref="CertificateException">An error occurs while adding a certificate to the collection.</exception>
 public CertificateStoreCollection(CertificateStoreCollection collection) : base(SspiProvider.CertOpenStore(new IntPtr(SecurityConstants.CERT_STORE_PROV_COLLECTION), 0, 0, 0, null), false)
 {
     if (collection == null)
     {
         throw new ArgumentNullException();
     }
     m_Stores = new ArrayList(collection.m_Stores);              // used to hold references to the certificate stores so they cannot be finalized
     for (int i = 0; i < m_Stores.Count; i++)
     {
         if (SspiProvider.CertAddStoreToCollection(this.Handle, ((CertificateStore)m_Stores[i]).Handle, 0, 0) == 0)
         {
             throw new CertificateException("Could not add the store to the collection.");
         }
     }
 }
コード例 #4
0
        /// <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)));
        }
コード例 #5
0
ファイル: CertificateChain.cs プロジェクト: QardenEden/Suru
		/// <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));
		}