/// <summary> /// Updates the validator with the current state of the configuration. /// </summary> public virtual async Task Update(SecurityConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException("configuration"); } lock (m_lock) { Update( configuration.TrustedIssuerCertificates, configuration.TrustedPeerCertificates, configuration.RejectedCertificateStore); m_rejectSHA1SignedCertificates = configuration.RejectSHA1SignedCertificates; m_rejectUnknownRevocationStatus = configuration.RejectUnknownRevocationStatus; m_minimumCertificateKeySize = configuration.MinimumCertificateKeySize; } if (configuration.ApplicationCertificate != null) { m_applicationCertificate = await configuration.ApplicationCertificate.Find(false); } }
/// <summary> /// Ensures that the application configuration is valid. /// </summary> /// <param name="applicationType">Type of the application.</param> public virtual async Task Validate(ApplicationType applicationType) { if (String.IsNullOrEmpty(ApplicationName)) { throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "ApplicationName must be specified."); } if (SecurityConfiguration == null) { throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "SecurityConfiguration must be specified."); } SecurityConfiguration.Validate(); // load private key await SecurityConfiguration.ApplicationCertificate.LoadPrivateKeyEx(SecurityConfiguration.CertificatePasswordProvider); Func <string> generateDefaultUri = () => { var sb = new StringBuilder(); sb.Append("urn:"); sb.Append(Utils.GetHostName()); sb.Append(":"); sb.Append(ApplicationName); return(sb.ToString()); }; if (String.IsNullOrEmpty(ApplicationUri)) { m_applicationUri = generateDefaultUri(); } if (applicationType == ApplicationType.Client || applicationType == ApplicationType.ClientAndServer) { if (ClientConfiguration == null) { throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "ClientConfiguration must be specified."); } ClientConfiguration.Validate(); } if (applicationType == ApplicationType.Server || applicationType == ApplicationType.ClientAndServer) { if (ServerConfiguration == null) { throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "ServerConfiguration must be specified."); } ServerConfiguration.Validate(); } if (applicationType == ApplicationType.DiscoveryServer) { if (DiscoveryServerConfiguration == null) { throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "DiscoveryServerConfiguration must be specified."); } DiscoveryServerConfiguration.Validate(); } // toggle the state of the hi-res clock. HiResClock.Disabled = m_disableHiResClock; if (m_disableHiResClock) { if (m_serverConfiguration != null) { if (m_serverConfiguration.PublishingResolution < 50) { m_serverConfiguration.PublishingResolution = 50; } } } await m_certificateValidator.Update(this.SecurityConfiguration); }
/// <summary> /// Updates the validator with the current state of the configuration. /// </summary> public virtual void Update(SecurityConfiguration configuration) { if (configuration == null) throw new ArgumentNullException("configuration"); lock (m_lock) { Update( configuration.TrustedIssuerCertificates, configuration.TrustedPeerCertificates, configuration.RejectedCertificateStore); if (configuration.ApplicationCertificate != null) { m_applicationCertificate = configuration.ApplicationCertificate.Find(false); } } }
/// <summary> /// Ensures that the application configuration is valid. /// </summary> /// <param name="applicationType">Type of the application.</param> public virtual async Task Validate(ApplicationType applicationType) { if (String.IsNullOrEmpty(ApplicationName)) { throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "ApplicationName must be specified."); } if (SecurityConfiguration == null) { throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "SecurityConfiguration must be specified."); } SecurityConfiguration.Validate(); // generate a default uri if null if (String.IsNullOrEmpty(ApplicationUri)) { StringBuilder buffer = new StringBuilder(); buffer.Append("urn:"); buffer.Append(Utils.GetHostName()); buffer.Append(":"); buffer.Append(ApplicationName); m_applicationUri = buffer.ToString(); } // load app cert await SecurityConfiguration.ApplicationCertificate.LoadApplicationCertificate(m_applicationUri, null); if (applicationType == ApplicationType.Client || applicationType == ApplicationType.ClientAndServer) { if (ClientConfiguration == null) { throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "ClientConfiguration must be specified."); } ClientConfiguration.Validate(); } if (applicationType == ApplicationType.Server || applicationType == ApplicationType.ClientAndServer) { if (ServerConfiguration == null) { throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "ServerConfiguration must be specified."); } ServerConfiguration.Validate(); } if (applicationType == ApplicationType.DiscoveryServer) { if (DiscoveryServerConfiguration == null) { throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "DiscoveryServerConfiguration must be specified."); } DiscoveryServerConfiguration.Validate(); } // toggle the state of the hi-res clock. HiResClock.Disabled = m_disableHiResClock; if (m_disableHiResClock) { if (m_serverConfiguration != null) { if (m_serverConfiguration.PublishingResolution < 50) { m_serverConfiguration.PublishingResolution = 50; } } } // create the certificate validator. m_certificateValidator = new CertificateValidator(); await m_certificateValidator.Update(this.SecurityConfiguration); }
/// <summary> /// Ensures that the application configuration is valid. /// </summary> /// <param name="applicationType">Type of the application.</param> public virtual void Validate(ApplicationType applicationType) { if (String.IsNullOrEmpty(ApplicationName)) { throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "ApplicationName must be specified."); } #if !SILVERLIGHT if (SecurityConfiguration == null) { throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "SecurityConfiguration must be specified."); } SecurityConfiguration.Validate(); // ensure application uri matches the certificate. X509Certificate2 certificate = SecurityConfiguration.ApplicationCertificate.LoadPrivateKey(null); if (certificate != null) { ApplicationUri = Utils.GetApplicationUriFromCertficate(certificate); } #endif // generate a default uri. if (String.IsNullOrEmpty(ApplicationUri)) { StringBuilder buffer = new StringBuilder(); buffer.Append("urn:"); buffer.Append(System.Net.Dns.GetHostName()); buffer.Append(":"); buffer.Append(ApplicationName); m_applicationUri = buffer.ToString(); } if (applicationType == ApplicationType.Client || applicationType == ApplicationType.ClientAndServer) { if (ClientConfiguration == null) { throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "ClientConfiguration must be specified."); } ClientConfiguration.Validate(); } if (applicationType == ApplicationType.Server || applicationType == ApplicationType.ClientAndServer) { if (ServerConfiguration == null) { throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "ServerConfiguration must be specified."); } ServerConfiguration.Validate(); } if (applicationType == ApplicationType.DiscoveryServer) { if (DiscoveryServerConfiguration == null) { throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "DiscoveryServerConfiguration must be specified."); } DiscoveryServerConfiguration.Validate(); } // toggle the state of the hi-res clock. HiResClock.Disabled = m_disableHiResClock; if (m_disableHiResClock) { if (m_serverConfiguration != null) { if (m_serverConfiguration.PublishingResolution < 50) { m_serverConfiguration.PublishingResolution = 50; } } } #if !SILVERLIGHT // create the certificate validator. m_certificateValidator = new CertificateValidator(); m_certificateValidator.Update(this.SecurityConfiguration); #endif }