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); }
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; } } }
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()); }
/// <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> /// 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); }
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()); }
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); }
/// <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; }
/// <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; }
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()); }