Esempio n. 1
0
        private static void PushCertificate(ITopologyConfigurationSession session, Server sourceServer, Task.TaskProgressLoggingDelegate writeProgress, Task.TaskWarningLoggingDelegate writeWarning, string thumbprint)
        {
            SecureString securePassword = FederationCertificate.GeneratePassword();

            FederationCertificate.EnableCertificateForNetworkService(sourceServer.Name, thumbprint);
            string base64cert = null;

            try
            {
                base64cert = FederationCertificate.ExportCertificate(sourceServer.Name, securePassword, thumbprint);
            }
            catch (InvalidOperationException)
            {
                writeWarning(Strings.WarningPushFailed(thumbprint));
                return;
            }
            catch (LocalizedException)
            {
                writeWarning(Strings.WarningPushFailed(thumbprint));
                return;
            }
            Dictionary <TopologySite, List <TopologyServer> > dictionary = null;
            TopologySite topologySite = null;

            FederationCertificate.DiscoverServers(session, true, out dictionary, out topologySite);
            if (topologySite != null)
            {
                List <TopologyServer> list;
                if (dictionary.TryGetValue(topologySite, out list))
                {
                    int count = list.Count;
                    int num   = 0;
                    foreach (TopologyServer topologyServer in list)
                    {
                        int percent = (int)((double)(++num) / (double)count * 100.0);
                        writeProgress(Strings.ProgressActivityPushFederationCertificate(thumbprint), Strings.ProgressActivityPushFederationServer(topologyServer.Name), percent);
                        if (!topologyServer.Id.Equals(sourceServer.Id))
                        {
                            try
                            {
                                FederationTrustCertificateState federationTrustCertificateState = FederationCertificate.TestForCertificate(topologyServer.Name, thumbprint);
                                if (federationTrustCertificateState == FederationTrustCertificateState.NotInstalled)
                                {
                                    FederationCertificate.ImportCertificate(topologyServer.Name, securePassword, base64cert);
                                }
                                if (federationTrustCertificateState != FederationTrustCertificateState.ServerUnreachable)
                                {
                                    FederationCertificate.EnableCertificateForNetworkService(topologyServer.Name, thumbprint);
                                }
                            }
                            catch (InvalidOperationException)
                            {
                                writeWarning(Strings.WarningPushCertificate(thumbprint, topologyServer.Name));
                            }
                            catch (LocalizedException)
                            {
                                writeWarning(Strings.WarningPushCertificate(thumbprint, topologyServer.Name));
                            }
                        }
                    }
                }
                return;
            }
            writeWarning(Strings.WarningCannotGetLocalSite(thumbprint));
        }
Esempio n. 2
0
        internal static FederationTrustCertificateState TestForCertificate(string serverName, string thumbprint)
        {
            ExchangeCertificate exchangeCertificate;

            return(FederationCertificate.TestForCertificate(serverName, thumbprint, out exchangeCertificate));
        }