Beispiel #1
0
        internal static X509Certificate2 LoadCertificateWithPrivateKey(string thumbprint, WriteVerboseDelegate writeVerbose)
        {
            X509Certificate2 exchangeFederationCertByThumbprint = FederationCertificate.GetExchangeFederationCertByThumbprint(thumbprint, writeVerbose);

            if (!exchangeFederationCertByThumbprint.HasPrivateKey)
            {
                writeVerbose(Strings.ErrorCertificateHasNoPrivateKey(thumbprint));
                return(null);
            }
            try
            {
                if (!(exchangeFederationCertByThumbprint.PrivateKey is RSACryptoServiceProvider))
                {
                    writeVerbose(Strings.ErrorCertificateHasNoPrivateKey(thumbprint));
                    return(null);
                }
            }
            catch (CryptographicException)
            {
                writeVerbose(Strings.ErrorCertificateHasNoPrivateKey(thumbprint));
                return(null);
            }
            catch (NotSupportedException)
            {
                writeVerbose(Strings.ErrorCertificateHasNoPrivateKey(thumbprint));
                return(null);
            }
            return(exchangeFederationCertByThumbprint);
        }
Beispiel #2
0
        internal static void PushCertificate(Task.TaskProgressLoggingDelegate writeProgress, Task.TaskWarningLoggingDelegate writeWarning, string thumbprint)
        {
            ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 324, "PushCertificate", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\FederationProvisioning\\FederationCertificate.cs");
            Server sourceServer = null;

            try
            {
                sourceServer = topologyConfigurationSession.FindLocalServer();
            }
            catch (LocalServerNotFoundException)
            {
                writeWarning(Strings.WarningPushFailed(thumbprint));
                return;
            }
            FederationCertificate.PushCertificate(topologyConfigurationSession, sourceServer, writeProgress, writeWarning, thumbprint);
        }
Beispiel #3
0
        internal static void DiscoverServers(ITopologyConfigurationSession session, bool limitedSearch, out Dictionary <TopologySite, List <TopologyServer> > siteDictionary, out TopologySite localSite)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            ExchangeTopology exchangeTopology = ExchangeTopology.Discover(session, ExchangeTopologyScope.ServerAndSiteTopology);

            localSite      = exchangeTopology.LocalSite;
            siteDictionary = new Dictionary <TopologySite, List <TopologyServer> >();
            if (localSite == null)
            {
                return;
            }
            List <ITopologySite> list = new List <ITopologySite>();

            if (limitedSearch)
            {
                foreach (ITopologySiteLink topologySiteLink in localSite.TopologySiteLinks)
                {
                    foreach (ITopologySite item in topologySiteLink.TopologySites)
                    {
                        if (!list.Contains(item))
                        {
                            list.Add(item);
                        }
                    }
                }
            }
            foreach (TopologyServer topologyServer in exchangeTopology.AllTopologyServers)
            {
                if (topologyServer.TopologySite != null && FederationCertificate.IsServerQualifiedForFederationTrust(topologyServer) && (!limitedSearch || list.Contains(topologyServer.TopologySite)))
                {
                    List <TopologyServer> list2;
                    if (!siteDictionary.TryGetValue(topologyServer.TopologySite, out list2))
                    {
                        list2 = new List <TopologyServer>();
                        siteDictionary.Add(topologyServer.TopologySite, list2);
                    }
                    list2.Add(topologyServer);
                }
            }
        }
Beispiel #4
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));
        }
Beispiel #5
0
        internal static void PushCertificate(Server sourceServer, Task.TaskProgressLoggingDelegate writeProgress, Task.TaskWarningLoggingDelegate writeWarning, string thumbprint)
        {
            ITopologyConfigurationSession session = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 354, "PushCertificate", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\FederationProvisioning\\FederationCertificate.cs");

            FederationCertificate.PushCertificate(session, sourceServer, writeProgress, writeWarning, thumbprint);
        }
Beispiel #6
0
        internal static FederationTrustCertificateState TestForCertificate(string serverName, string thumbprint)
        {
            ExchangeCertificate exchangeCertificate;

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