A list of trusted certificates.
Administrators can create a list of trusted certificates by designating all certificates in a particular certificate store as trusted and/or by explictly specifying a list of individual certificates. A trust list can contain either instance certificates or certification authority certificates. If the list contains instance certificates the application will trust peers that use the instance certificate (provided the ApplicationUri and HostName match the certificate). If the list contains certification authority certificates then the application will trust peers that have certificates issued by one of the authorities. Any certificate could be revoked by the issuer (CAs may issue certificates for other CAs). The RevocationMode specifies whether this check should be done each time a certificate in the list are used.
 /// <summary>
 /// Try remove trust list
 /// </summary>
 /// <param name="trustList"></param>
 /// <param name="certificates"></param>
 /// <returns></returns>
 public static bool TryRemove(this CertificateTrustList trustList,
                              IEnumerable <X509Certificate2> certificates)
 {
     try {
         Remove(trustList, certificates);
         return(true);
     }
     catch {
         return(false);
     }
 }
예제 #2
0
        /// <summary>
        /// Updates the validator with a new set of trust lists.
        /// </summary>
        public virtual void Update(
            CertificateTrustList issuerStore,
            CertificateTrustList trustedStore,
            CertificateStoreIdentifier rejectedCertificateStore)
        {
            lock (m_lock)
            {
                m_validatedCertificates.Clear();

                m_trustedCertificateStore = null;
                m_trustedCertificateList  = null;

                if (trustedStore != null)
                {
                    m_trustedCertificateStore = new CertificateStoreIdentifier();

                    m_trustedCertificateStore.StoreType         = trustedStore.StoreType;
                    m_trustedCertificateStore.StorePath         = trustedStore.StorePath;
                    m_trustedCertificateStore.ValidationOptions = trustedStore.ValidationOptions;

                    if (trustedStore.TrustedCertificates != null)
                    {
                        m_trustedCertificateList = new CertificateIdentifierCollection();
                        m_trustedCertificateList.AddRange(trustedStore.TrustedCertificates);
                    }
                }


                m_issuerCertificateStore = null;
                m_issuerCertificateList  = null;

                if (issuerStore != null)
                {
                    m_issuerCertificateStore = new CertificateStoreIdentifier();

                    m_issuerCertificateStore.StoreType         = issuerStore.StoreType;
                    m_issuerCertificateStore.StorePath         = issuerStore.StorePath;
                    m_issuerCertificateStore.ValidationOptions = issuerStore.ValidationOptions;

                    if (issuerStore.TrustedCertificates != null)
                    {
                        m_issuerCertificateList = new CertificateIdentifierCollection();
                        m_issuerCertificateList.AddRange(issuerStore.TrustedCertificates);
                    }
                }

                m_rejectedCertificateStore = null;

                if (rejectedCertificateStore != null)
                {
                    m_rejectedCertificateStore = (CertificateStoreIdentifier)rejectedCertificateStore.MemberwiseClone();
                }
            }
        }
        /// <summary>
        /// Updates the validator with a new set of trust lists.
        /// </summary>
        public virtual void Update(
            CertificateTrustList issuerStore,
            CertificateTrustList trustedStore,
            CertificateStoreIdentifier rejectedCertificateStore)
        {
            lock (m_lock)
            {
                m_validatedCertificates.Clear();

                m_trustedCertificateStore = null;
                m_trustedCertificateList = null;

                if (trustedStore != null)
                {
                    m_trustedCertificateStore = new CertificateStoreIdentifier();

                    m_trustedCertificateStore.StoreType = trustedStore.StoreType;
                    m_trustedCertificateStore.StorePath = trustedStore.StorePath;
                    m_trustedCertificateStore.ValidationOptions = trustedStore.ValidationOptions;

                    if (trustedStore.TrustedCertificates != null)
                    {
                        m_trustedCertificateList = new CertificateIdentifierCollection();
                        m_trustedCertificateList.AddRange(trustedStore.TrustedCertificates);
                    }
                }

                
                m_issuerCertificateStore = null;
                m_issuerCertificateList = null;

                if (issuerStore != null)
                {
                    m_issuerCertificateStore = new CertificateStoreIdentifier();

                    m_issuerCertificateStore.StoreType = issuerStore.StoreType;
                    m_issuerCertificateStore.StorePath = issuerStore.StorePath;
                    m_issuerCertificateStore.ValidationOptions = issuerStore.ValidationOptions;

                    if (issuerStore.TrustedCertificates != null)
                    {
                        m_issuerCertificateList = new CertificateIdentifierCollection();
                        m_issuerCertificateList.AddRange(issuerStore.TrustedCertificates);
                    }
                }
                
                m_rejectedCertificateStore = null;

                if (rejectedCertificateStore != null)
                {
                    m_rejectedCertificateStore = (CertificateStoreIdentifier)rejectedCertificateStore.Clone();
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Ensure valid trust lists.
        /// </summary>
        private CertificateTrustList CreateDefaultTrustList(CertificateTrustList trustList)
        {
            if (trustList != null)
            {
                if (trustList.StorePath != null)
                {
                    return(trustList);
                }
            }

            return(new CertificateTrustList());
        }
        /// <summary>
        /// Ensure valid trust lists.
        /// </summary>
        private CertificateTrustList CreateDefaultTrustList(CertificateTrustList trustList)
        {
            if (trustList != null)
            {
                if (trustList.StorePath != null)
                {
                    return trustList;
                }
            }

            return new CertificateTrustList();
        }
 /// <summary>
 /// Remove certficates
 /// </summary>
 /// <param name="trustList"></param>
 /// <param name="certificates"></param>
 /// <returns></returns>
 public static void Remove(this CertificateTrustList trustList,
                           IEnumerable <X509Certificate2> certificates)
 {
     if (certificates == null)
     {
         throw new ArgumentNullException(nameof(certificates));
     }
     using (var trustedStore = trustList.OpenStore()) {
         trustedStore.Remove(certificates);
         foreach (var cert in certificates)
         {
             trustList.TrustedCertificates.Remove(new CertificateIdentifier(cert));
         }
     }
 }
 /// <summary>
 /// Add to trust list
 /// </summary>
 /// <param name="trustList"></param>
 /// <param name="certificates"></param>
 /// <param name="noCopy"></param>
 /// <returns></returns>
 public static void Add(this CertificateTrustList trustList,
                        IEnumerable <X509Certificate2> certificates, bool noCopy = false)
 {
     if (certificates == null)
     {
         throw new ArgumentNullException(nameof(certificates));
     }
     using (var trustedStore = trustList.OpenStore()) {
         trustedStore.Add(certificates, noCopy);
         foreach (var cert in certificates)
         {
             trustList.TrustedCertificates.Add(new CertificateIdentifier(
                                                   noCopy ? cert : new X509Certificate2(cert)));
         }
     }
 }