Example #1
0
        protected override void InternalProcessRecord()
        {
            base.InternalProcessRecord();
            if (base.HasErrors)
            {
                return;
            }
            Dictionary <TopologySite, List <TopologyServer> > dictionary = null;
            TopologySite topologySite = null;

            FederationCertificate.DiscoverServers(base.RootOrgGlobalConfigSession, false, out dictionary, out topologySite);
            if (topologySite == null)
            {
                base.WriteError(new CannotGetLocalSiteException(), ErrorCategory.ReadError, null);
            }
            foreach (KeyValuePair <TopologySite, List <TopologyServer> > keyValuePair in dictionary)
            {
                foreach (TopologyServer topologyServer in keyValuePair.Value)
                {
                    foreach (CertificateRecord certificateRecord in FederationCertificate.FederationCertificates(base.RootOrgGlobalConfigSession))
                    {
                        FederationTrustCertificateState  state          = FederationCertificate.TestForCertificate(topologyServer.Name, certificateRecord.Thumbprint);
                        FederationTrustCertificateStatus sendToPipeline = new FederationTrustCertificateStatus(keyValuePair.Key, topologyServer, state, certificateRecord.Thumbprint);
                        base.WriteObject(sendToPipeline);
                    }
                }
            }
        }
Example #2
0
        public static void ValidateRemoteCertificate(string server, string thumbprint, DateTime?futurePublishDate, bool skipAutomatedDeploymentChecks, Task.TaskErrorLoggingDelegate writeError)
        {
            if (writeError == null)
            {
                throw new ArgumentNullException("writeError");
            }
            if (string.IsNullOrEmpty(thumbprint))
            {
                return;
            }
            ExchangeCertificate             certificate = null;
            FederationTrustCertificateState federationTrustCertificateState = FederationCertificate.TestForCertificate(server, thumbprint, out certificate);

            if (federationTrustCertificateState == FederationTrustCertificateState.ServerUnreachable)
            {
                writeError(new TaskException(Strings.ErrorCannotContactServerForCert(server, thumbprint)), ErrorCategory.InvalidArgument, null);
            }
            else if (federationTrustCertificateState != FederationTrustCertificateState.Installed)
            {
                writeError(new TaskException(Strings.ErrorThumbprintNotFound(thumbprint)), ErrorCategory.InvalidArgument, null);
            }
            OAuthTaskHelper.ValidateCertificate(certificate, futurePublishDate, skipAutomatedDeploymentChecks, writeError);
        }
        // Token: 0x06000006 RID: 6 RVA: 0x000024D0 File Offset: 0x000006D0
        private void PerformDistribution(List <CertificateRecord> certsRequired)
        {
            Servicelet.Tracer.TraceDebug((long)this.GetHashCode(), "PerformDistribution(): Entering");
            List <CertificateRecord> list = new List <CertificateRecord>();

            foreach (CertificateRecord certificateRecord in certsRequired)
            {
                string thumbprint = certificateRecord.Thumbprint;
                Servicelet.Tracer.TraceDebug <string>((long)this.GetHashCode(), "Certificate Required: {0}", thumbprint);
                ExchangeCertificate             exchangeCertificate;
                FederationTrustCertificateState federationTrustCertificateState = FederationCertificate.TestForCertificate(this.localServer.Name, thumbprint, out exchangeCertificate);
                Servicelet.Tracer.TraceDebug <FederationTrustCertificateState>((long)this.GetHashCode(), "Certificate State: {0}", federationTrustCertificateState);
                if (federationTrustCertificateState == FederationTrustCertificateState.NotInstalled)
                {
                    list.Add(certificateRecord);
                    if (this.IsCurrentOrNextCertificate(certificateRecord))
                    {
                        this.eventLogger.LogEvent(MSExchangeCertificateDeploymentEventLogConstants.Tuple_NeedCertificate, null, new object[]
                        {
                            thumbprint
                        });
                    }
                }
                else if (federationTrustCertificateState == FederationTrustCertificateState.Installed)
                {
                    if (this.IsCurrentOrNextCertificate(certificateRecord))
                    {
                        this.VerifyCertificateExpiration(exchangeCertificate);
                    }
                    if (!ManageExchangeCertificate.IsCertEnabledForNetworkService(exchangeCertificate))
                    {
                        Servicelet.Tracer.TraceDebug <string>((long)this.GetHashCode(), "Enabling for Network Service: {0}", thumbprint);
                        try
                        {
                            FederationCertificate.EnableCertificateForNetworkService(this.localServer.Name, thumbprint);
                        }
                        catch (LocalizedException ex)
                        {
                            Servicelet.Tracer.TraceError <LocalizedException>((long)this.GetHashCode(), "Failed to Enable for Network Service: {0}", ex);
                            this.eventLogger.LogEvent(MSExchangeCertificateDeploymentEventLogConstants.Tuple_EnableNetworkServiceException, null, new object[]
                            {
                                thumbprint,
                                ex
                            });
                        }
                        catch (InvalidOperationException ex2)
                        {
                            Servicelet.Tracer.TraceError <InvalidOperationException>((long)this.GetHashCode(), "Failed to Enable for Network Service: {0}", ex2);
                            this.eventLogger.LogEvent(MSExchangeCertificateDeploymentEventLogConstants.Tuple_EnableNetworkServiceException, null, new object[]
                            {
                                thumbprint,
                                ex2
                            });
                        }
                    }
                }
            }
            if (list.Count != 0)
            {
                Dictionary <TopologySite, List <TopologyServer> > dictionary;
                TopologySite topologySite;
                FederationCertificate.DiscoverServers(this.session, true, out dictionary, out topologySite);
                if (topologySite == null)
                {
                    Servicelet.Tracer.TraceError((long)this.GetHashCode(), "Server is not associated with a site");
                    this.eventLogger.LogEvent(MSExchangeCertificateDeploymentEventLogConstants.Tuple_CannotFindLocalSite, null, null);
                    return;
                }
                List <TopologyServer> sourceServers;
                if (dictionary.TryGetValue(topologySite, out sourceServers))
                {
                    this.PullCertificate(sourceServers, list, this.localServer);
                }
                if (list.Count != 0)
                {
                    foreach (KeyValuePair <TopologySite, List <TopologyServer> > keyValuePair in dictionary)
                    {
                        if (!keyValuePair.Key.Equals(topologySite))
                        {
                            this.PullCertificate(keyValuePair.Value, list, this.localServer);
                            if (list.Count == 0)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            foreach (CertificateRecord certificateRecord2 in list)
            {
                Servicelet.Tracer.TraceDebug <string>((long)this.GetHashCode(), "Certificate not found: {0}", certificateRecord2.Thumbprint);
                if (this.IsCurrentOrNextCertificate(certificateRecord2))
                {
                    this.eventLogger.LogEvent(MSExchangeCertificateDeploymentEventLogConstants.Tuple_CertificateNotFound, null, new object[]
                    {
                        certificateRecord2.Thumbprint
                    });
                }
            }
            Servicelet.Tracer.TraceDebug((long)this.GetHashCode(), "PerformDistribution(): Exiting");
        }