Exemplo n.º 1
0
        ICertificateResolver LocateChild <T>(ICertificateResolver resolver)
        {
            CertificateResolverCollection resolvers = (CertificateResolverCollection)resolver;

            for (int i = 0; i < resolvers.Count; ++i)
            {
                if (resolvers[i] is T)
                {
                    return(resolvers[i]);
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        void SubscribeToResolverEvents(ICertificateResolver resolver)
        {
            CertificateResolverCollection resolvers = resolver as CertificateResolverCollection;

            if (resolvers != null)
            {
                resolvers.Error += m_diagnostics.OnResolverError;

                foreach (var resover in resolvers)
                {
                    resover.Error += m_diagnostics.OnResolverError;
                }
            }
        }
Exemplo n.º 3
0
        public void TestCollectionRetryAlways()
        {
            CertificateResolverCollection resolvers = new CertificateResolverCollection();

            resolvers.TryNextWhen = CertificateResolverCollection.TryNextCriteria.Always;

            resolvers.Add(new ThrowingCertResolver());
            resolvers.Add(m_resolver);

            Assert.DoesNotThrow(() => resolvers.GetCertificates(m_address));
            Assert.True(!resolvers.GetCertificates(m_address).IsNullOrEmpty());

            resolvers.Insert(0, new NullResolver());
            Assert.True(!resolvers.GetCertificates(m_address).IsNullOrEmpty());
        }
Exemplo n.º 4
0
 /// <summary>
 /// Create a resolver as defined in the Resolvers setting
 /// </summary>
 /// <returns>The certificate resolver instance corresponding to the settings.</returns>
 public ICertificateResolver CreateResolver()
 {
     if (this.Resolvers == null)
     {
         throw new NotSupportedException();
     }
     
     CertificateResolverCollection resolvers = new CertificateResolverCollection();
     foreach (CertResolverSettings resolverSettings in this.Resolvers)
     {
         resolvers.Add(resolverSettings.CreateResolver());
     }
     
     return resolvers;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Create a resolver as defined in the Resolvers setting
        /// </summary>
        /// <returns>The certificate resolver instance corresponding to the settings.</returns>
        public ICertificateResolver CreateResolver()
        {
            if (this.Resolvers == null)
            {
                throw new NotSupportedException();
            }

            CertificateResolverCollection resolvers = new CertificateResolverCollection();

            foreach (CertResolverSettings resolverSettings in this.Resolvers)
            {
                resolvers.Add(resolverSettings.CreateResolver());
            }

            return(resolvers);
        }
        /// <summary>
        /// Creates the DNS certificate resolver from the configured settings.
        /// </summary>
        /// <returns>A configured DNS certificate resolver.</returns>
        public override ICertificateResolver CreateResolver()
        {
            this.Validate();

            if (string.IsNullOrEmpty(this.BackupServerIP))
            {
                return(CreateResolver(this.ServerIP));
            }

            CertificateResolverCollection resolvers = new CertificateResolverCollection();

            resolvers.TryNextWhen = CertificateResolverCollection.TryNextCriteria.Exception;
            resolvers.Add(this.CreateResolver(this.ServerIP));
            resolvers.Add(this.CreateResolver(this.BackupServerIP));
            return(resolvers);
        }
Exemplo n.º 7
0
        public void TestCollectionRetryException()
        {
            CertificateResolverCollection resolvers = new CertificateResolverCollection();

            resolvers.TryNextWhen = CertificateResolverCollection.TryNextCriteria.Exception;

            resolvers.Add(new NullResolver());
            resolvers.Add(m_resolver);
            Assert.True(resolvers.GetCertificates(m_address).IsNullOrEmpty());

            resolvers.TryNextWhen = CertificateResolverCollection.TryNextCriteria.NotFound;
            Assert.True(!resolvers.GetCertificates(m_address).IsNullOrEmpty());

            resolvers.Clear();

            resolvers.Add(new ThrowingCertResolver());
            resolvers.Add(m_resolver);
            Assert.Throws <InvalidOperationException>(() => resolvers.GetCertificates(m_address));

            resolvers.TryNextWhen = CertificateResolverCollection.TryNextCriteria.Exception;
            Assert.True(!resolvers.GetCertificates(m_address).IsNullOrEmpty());
        }
Exemplo n.º 8
0
        public void CreateResolverTest()
        {
            DnsCertResolverSettings settings = new DnsCertResolverSettings()
            {
                ServerIP            = "1.2.3.4",
                TimeoutMilliseconds = 7000
            };

            ICertificateResolver resolver = settings.CreateResolver();

            Validate(resolver, settings.ServerIP, settings.TimeoutMilliseconds);
            Assert.True(resolver is DnsCertResolver);

            settings.BackupServerIP = "3.4.5.6";
            resolver = settings.CreateResolver();
            Assert.True(resolver is CertificateResolverCollection);

            CertificateResolverCollection resolvers = resolver as CertificateResolverCollection;

            Assert.True(resolvers.Count == 2);
            Validate(resolvers[0], settings.ServerIP, settings.TimeoutMilliseconds);
            Validate(resolvers[1], settings.BackupServerIP, settings.TimeoutMilliseconds);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates the maachine store based certificate resolver.
        /// </summary>
        /// <returns>An instance of a machine-based certificate store resolver.</returns>
        public override ICertificateResolver CreateResolver()
        {
            Validate();

            if (string.IsNullOrEmpty(ServerIP) && string.IsNullOrEmpty(BackupServerIP))
            {
                return(new LdapCertResolver(null,
                                            TimeSpan.FromMilliseconds(TimeoutMilliseconds)
                                            , m_cache));
            }

            if (string.IsNullOrEmpty(BackupServerIP))
            {
                return(CreateResolver(ServerIP));
            }

            CertificateResolverCollection resolvers = new CertificateResolverCollection();

            resolvers.TryNextWhen = CertificateResolverCollection.TryNextCriteria.Exception;
            resolvers.Add(this.CreateResolver(this.ServerIP));
            resolvers.Add(this.CreateResolver(this.BackupServerIP));
            return(resolvers);
        }
 /// <summary>
 /// Creates the DNS certificate resolver from the configured settings.
 /// </summary>
 /// <returns>A configured DNS certificate resolver.</returns>
 public override ICertificateResolver CreateResolver()
 {
     this.Validate();
     
     if (string.IsNullOrEmpty(this.BackupServerIP))
     {
         return CreateResolver(this.ServerIP);
     }
     
     CertificateResolverCollection resolvers = new CertificateResolverCollection();
     resolvers.TryNextWhen = CertificateResolverCollection.TryNextCriteria.Exception;            
     resolvers.Add(this.CreateResolver(this.ServerIP));
     resolvers.Add(this.CreateResolver(this.BackupServerIP));            
     return resolvers;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Creates the maachine store based certificate resolver.
        /// </summary>
        /// <returns>An instance of a machine-based certificate store resolver.</returns>
        public override ICertificateResolver CreateResolver()
        {
            Validate();

            if (string.IsNullOrEmpty(ServerIP) && string.IsNullOrEmpty(BackupServerIP))
            {
                return new LdapCertResolver(null,
                                        TimeSpan.FromMilliseconds(TimeoutMilliseconds)
                                        , m_cache);
            }

            if (string.IsNullOrEmpty(BackupServerIP))
            {
                return CreateResolver(ServerIP);
            }

            CertificateResolverCollection resolvers = new CertificateResolverCollection();
            resolvers.TryNextWhen = CertificateResolverCollection.TryNextCriteria.Exception;
            resolvers.Add(this.CreateResolver(this.ServerIP));
            resolvers.Add(this.CreateResolver(this.BackupServerIP));
            return resolvers;
            
        }
Exemplo n.º 12
0
        public void TestCollectionRetryAlways()
        {
            CertificateResolverCollection resolvers = new CertificateResolverCollection();
            resolvers.TryNextWhen = CertificateResolverCollection.TryNextCriteria.Always;
            
            resolvers.Add(new ThrowingCertResolver());
            resolvers.Add(m_resolver);

            Assert.DoesNotThrow(() => resolvers.GetCertificates(m_address));
            Assert.True(!resolvers.GetCertificates(m_address).IsNullOrEmpty());
            
            resolvers.Insert(0, new NullResolver());
            Assert.True(!resolvers.GetCertificates(m_address).IsNullOrEmpty());
        }
Exemplo n.º 13
0
        public void TestCollectionRetryException()
        {
            CertificateResolverCollection resolvers = new CertificateResolverCollection();
            resolvers.TryNextWhen = CertificateResolverCollection.TryNextCriteria.Exception;
            
            resolvers.Add(new NullResolver());
            resolvers.Add(m_resolver);
            Assert.True(resolvers.GetCertificates(m_address).IsNullOrEmpty());
            
            resolvers.TryNextWhen = CertificateResolverCollection.TryNextCriteria.NotFound;
            Assert.True(!resolvers.GetCertificates(m_address).IsNullOrEmpty());
            
            resolvers.Clear();

            resolvers.Add(new ThrowingCertResolver());
            resolvers.Add(m_resolver);
            Assert.Throws<InvalidOperationException>(() => resolvers.GetCertificates(m_address));
            
            resolvers.TryNextWhen = CertificateResolverCollection.TryNextCriteria.Exception;
            Assert.True(!resolvers.GetCertificates(m_address).IsNullOrEmpty());
        }