Exemplo n.º 1
0
        private void Connect(ReplicationTopology topology)
        {
            EdgeSyncLog        edgeSyncLog = new EdgeSyncLog(string.Empty, new Version(), string.Empty, string.Empty, string.Empty);
            EdgeSyncLogSession logSession  = edgeSyncLog.OpenSession(string.Empty, string.Empty, 0, string.Empty, EdgeSyncLoggingLevel.None);

            try
            {
                DirectTrust.Load();
                NetworkCredential networkCredential = Util.ExtractNetworkCredential(topology.LocalHub, this.edgeServer.Fqdn, logSession);
                if (networkCredential == null)
                {
                    this.failureDetail = Strings.NoCredentialsFound(this.EdgeServer.Fqdn).ToString();
                }
                else
                {
                    this.edgeConnection = (LdapTargetConnection)TestEdgeConnectionFactory.Create(topology.LocalHub, new TargetServerConfig(this.EdgeServer.Name, this.EdgeServer.Fqdn, this.EdgeServer.EdgeSyncAdamSslPort), networkCredential, SyncTreeType.General, logSession);
                    this.failureDetail  = string.Empty;
                    if (this.edgeConnection != null)
                    {
                        this.ExtractLeaseInfo();
                        this.ExtractCookieRecords();
                    }
                }
            }
            catch (ExDirectoryException ex)
            {
                this.failureDetail  = ex.Message;
                this.edgeConnection = null;
            }
            finally
            {
                DirectTrust.Unload();
            }
        }
 public MserveTargetConnection(int localServerVersion, MserveTargetServerConfig config, EnhancedTimeSpan syncInterval, TestShutdownAndLeaseDelegate testShutdownAndLease, EdgeSyncLogSession logSession) : base(localServerVersion, config, syncInterval, logSession, ExTraceGlobals.TargetConnectionTracer)
 {
     this.testShutdownAndLease = testShutdownAndLease;
     this.config = config;
     this.InitializeTenantMEUSyncControlCache();
     this.InitializeClientToken();
     this.configSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(false, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 313, ".ctor", "f:\\15.00.1497\\sources\\dev\\EdgeSync\\src\\Mserve\\MserveTargetConnection.cs");
     if (EdgeSyncSvc.EdgeSync != null && EdgeSyncSvc.EdgeSync.AppConfig != null)
     {
         this.duplicatedAddEntriesCacheSize = EdgeSyncSvc.EdgeSync.AppConfig.DuplicatedAddEntriesCacheSize;
         this.podSiteStartRange             = EdgeSyncSvc.EdgeSync.AppConfig.PodSiteStartRange;
         this.podSiteEndRange           = EdgeSyncSvc.EdgeSync.AppConfig.PodSiteEndRange;
         this.trackDuplicatedAddEntries = EdgeSyncSvc.EdgeSync.AppConfig.TrackDuplicatedAddEntries;
         if (!this.trackDuplicatedAddEntries)
         {
             this.duplicatedAddEntriesCacheSize = 0;
         }
     }
 }
Exemplo n.º 3
0
 public EhfRecipientTargetConnection(int localServerVersion, EhfTargetServerConfig config, EdgeSyncLogSession logSession, EhfPerfCounterHandler perfCounterHandler, IAdminSyncService adminSyncservice, EhfADAdapter adapter, EnhancedTimeSpan syncInterval, EhfSynchronizationProvider provider) : base(localServerVersion, config, logSession, perfCounterHandler, null, null, adminSyncservice, adapter, syncInterval)
 {
     this.provider = provider;
 }
Exemplo n.º 4
0
 public EhfRecipientTargetConnection(int localServerVersion, EhfTargetServerConfig config, EhfSynchronizationProvider provider, EdgeSyncLogSession logSession) : base(localServerVersion, config, provider.RecipientSyncInterval, logSession)
 {
     this.provider = provider;
 }
Exemplo n.º 5
0
        public static NetworkCredential DecryptEdgeSyncCredential(Server localServer, EdgeSyncCredential cred, EdgeSyncLogSession logSession)
        {
            X509Certificate2 x509Certificate = null;
            X509Store        x509Store       = null;

            try
            {
                if (localServer.InternalTransportCertificate == null)
                {
                    logSession.LogCredential(cred.EdgeServerFQDN, "Failed to retrieve the default certificate.  Unable to decrypt credentials.");
                    EdgeSyncEvents.Log.LogEvent(EdgeSyncEventLogConstants.Tuple_NoCredentialsFound, null, new object[]
                    {
                        cred.EdgeServerFQDN
                    });
                    return(null);
                }
                X509Certificate2 x509Certificate2 = new X509Certificate2(localServer.InternalTransportCertificate);
                x509Store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
                x509Store.Open(OpenFlags.OpenExistingOnly);
                X509Certificate2Collection x509Certificate2Collection = x509Store.Certificates.Find(X509FindType.FindByThumbprint, x509Certificate2.Thumbprint, false);
                if (x509Certificate2Collection.Count <= 0)
                {
                    logSession.LogCredential(cred.EdgeServerFQDN, "Failed to retrieve the certificate from the local store.");
                    EdgeSyncEvents.Log.LogEvent(EdgeSyncEventLogConstants.Tuple_NoCredentialsFound, null, new object[]
                    {
                        cred.EdgeServerFQDN
                    });
                    return(null);
                }
                x509Certificate = x509Certificate2Collection[0];
            }
            catch (ArgumentException)
            {
                logSession.LogCredential(cred.EdgeServerFQDN, "Failed to retrieve certificate.");
                EdgeSyncEvents.Log.LogEvent(EdgeSyncEventLogConstants.Tuple_NoCredentialsFound, null, new object[]
                {
                    cred.EdgeServerFQDN
                });
                return(null);
            }
            catch (CryptographicException)
            {
                logSession.LogCredential(cred.EdgeServerFQDN, "Failed to retrieve certificate because of Corrupt or mismatched keys.");
                EdgeSyncEvents.Log.LogEvent(EdgeSyncEventLogConstants.Tuple_NoCredentialsFound, null, new object[]
                {
                    cred.EdgeServerFQDN
                });
                return(null);
            }
            catch (SecurityException)
            {
                logSession.LogCredential(cred.EdgeServerFQDN, "Failed to retrieve certificate because we don't have permission.");
                EdgeSyncEvents.Log.LogEvent(EdgeSyncEventLogConstants.Tuple_NoCredentialsFound, null, new object[]
                {
                    cred.EdgeServerFQDN
                });
                return(null);
            }
            finally
            {
                if (x509Store != null)
                {
                    x509Store.Close();
                }
            }
            byte[] bytes;
            try
            {
                AsymmetricAlgorithm privateKey = x509Certificate.PrivateKey;
                if (privateKey == null)
                {
                    logSession.LogCredential(cred.EdgeServerFQDN, "Failed to retrieve certificate because it doesn't have private key.");
                    logSession.LogCertificate(EdgeSyncLoggingLevel.Low, EdgeSyncEvent.TargetConnection, x509Certificate);
                    EdgeSyncEvents.Log.LogEvent(EdgeSyncEventLogConstants.Tuple_CredentialDecryptionException, null, new object[]
                    {
                        cred.EdgeServerFQDN,
                        SystemStrings.NoPrivateKey,
                        x509Certificate.Thumbprint,
                        x509Certificate.Subject
                    });
                    return(null);
                }
                RSACryptoServiceProvider rsacryptoServiceProvider = (RSACryptoServiceProvider)privateKey;
                bytes = rsacryptoServiceProvider.Decrypt(cred.EncryptedESRAPassword, false);
            }
            catch (CryptographicException ex)
            {
                logSession.LogException(EdgeSyncLoggingLevel.Low, EdgeSyncEvent.TargetConnection, ex, "Failed to decrypt the credential.");
                logSession.LogCertificate(EdgeSyncLoggingLevel.Low, EdgeSyncEvent.TargetConnection, x509Certificate);
                EdgeSyncEvents.Log.LogEvent(EdgeSyncEventLogConstants.Tuple_CredentialDecryptionException, null, new object[]
                {
                    cred.EdgeServerFQDN,
                    ex.Message,
                    x509Certificate.Thumbprint,
                    x509Certificate.Subject
                });
                return(null);
            }
            logSession.LogCredentialDetail(cred.ESRAUsername, new DateTime(cred.EffectiveDate));
            return(new NetworkCredential(cred.ESRAUsername, Encoding.ASCII.GetString(bytes)));
        }
Exemplo n.º 6
0
 public override TargetConnection CreateTargetConnection(TargetServerConfig targetServerConfig, SyncTreeType type, TestShutdownAndLeaseDelegate testShutdownAndLease, EdgeSyncLogSession logSession)
 {
     if (type == SyncTreeType.Configuration)
     {
         return(new EhfConfigTargetConnection(EdgeSyncSvc.EdgeSync.Topology.LocalServer.VersionNumber, (EhfTargetServerConfig)targetServerConfig, this.ConfigurationSyncInterval, logSession));
     }
     if (type == SyncTreeType.Recipients)
     {
         return(new EhfRecipientTargetConnection(EdgeSyncSvc.EdgeSync.Topology.LocalServer.VersionNumber, (EhfTargetServerConfig)targetServerConfig, this, logSession));
     }
     throw new NotSupportedException("Only config and recipient synchronization is supported by EHF sync provider");
 }
 public EhfConfigTargetConnection(int localServerVersion, EhfTargetServerConfig config, EnhancedTimeSpan syncInterval, EdgeSyncLogSession logSession) : base(localServerVersion, config, syncInterval, logSession)
 {
 }
Exemplo n.º 8
0
 public LdapTargetConnection(int localServerVersion, TargetServerConfig config, EdgeSyncLogSession logSession) : base(localServerVersion, config)
 {
     this.logSession = logSession;
 }
Exemplo n.º 9
0
 public EdgeSyncDiag(EdgeSyncLogSession logSession, Trace tracer)
 {
     this.logSession = logSession;
     this.tracer     = tracer;
 }
Exemplo n.º 10
0
 public FileLeaseManager(string leaseFileName, string primaryLeaseLocation, string backupLeaseLocation, EnhancedTimeSpan syncInterval, EdgeSyncLogSession logSession, Trace tracer)
 {
     this.logSession = logSession;
     this.tracer     = tracer;
     this.interSiteLeaseExpiryInterval = 2L * syncInterval;
     this.primaryLeaseFilePath         = Path.Combine(primaryLeaseLocation, leaseFileName);
     this.backupLeaseFilePath          = Path.Combine(backupLeaseLocation, leaseFileName);
 }
        public static TargetConnection Create(Server localHub, TargetServerConfig targetServerConfig, NetworkCredential credential, SyncTreeType type, EdgeSyncLogSession logSession)
        {
            TargetConnection result;

            try
            {
                result = new LdapTargetConnection(localHub.VersionNumber, targetServerConfig, credential, type, logSession);
            }
            catch (ExDirectoryException ex)
            {
                if (ex.InnerException is LdapException)
                {
                    LdapException ex2 = ex.InnerException as LdapException;
                    if (ex2.ErrorCode == 49)
                    {
                        string userName = credential.UserName;
                        string host     = targetServerConfig.Host;
                    }
                }
                throw;
            }
            return(result);
        }
Exemplo n.º 12
0
 public EhfTargetConnection(int localServerVersion, EhfTargetServerConfig config, EdgeSyncLogSession logSession, EhfPerfCounterHandler perfCounterHandler, IProvisioningService provisioningService, IManagementService managementService, IAdminSyncService adminSyncService, EhfADAdapter adapter, EnhancedTimeSpan syncInterval) : this(localServerVersion, config, syncInterval, logSession)
 {
     this.provisioningService = new EhfProvisioningService(provisioningService, managementService, adminSyncService);
     this.adapter             = adapter;
     this.perfCounterHandler  = perfCounterHandler;
 }
Exemplo n.º 13
0
 public EhfTargetConnection(int localServerVersion, EhfTargetServerConfig config, EnhancedTimeSpan syncInterval, EdgeSyncLogSession logSession) : base(localServerVersion, config, syncInterval, logSession, ExTraceGlobals.TargetConnectionTracer)
 {
     this.config        = config;
     this.configSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(false, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 104, ".ctor", "f:\\15.00.1497\\sources\\dev\\EdgeSync\\src\\EHF\\EhfTargetConnection.cs");
 }
 public TenantSyncControlCacheLogger(EdgeSyncLogSession logSession)
 {
     this.logSession = logSession;
 }
Exemplo n.º 15
0
		protected DatacenterTargetConnection(int localServerVersion, DatacenterTargetServerConfig config, EnhancedTimeSpan syncInterval, EdgeSyncLogSession logSession, Trace tracer) : base(localServerVersion, config)
		{
			this.diagSession = new EdgeSyncDiag(logSession, tracer);
			this.syncInterval = syncInterval;
			this.leaseManager = new FileLeaseManager(this.LeaseFileName, config.PrimaryLeaseLocation, config.BackupLeaseLocation, this.SyncInterval, logSession, this.Tracer);
		}
Exemplo n.º 16
0
 public MserveEdgeSyncService(string provisionUrl, string settingsUrl, string remoteCertSubject, string clientToken, EdgeSyncLogSession logSession, bool batchMode, bool trackDuplicatedAddEntries) : base(provisionUrl, settingsUrl, remoteCertSubject, clientToken, batchMode)
 {
     base.TrackDuplicatedAddEntries = trackDuplicatedAddEntries;
     this.logSession = logSession;
 }
 public override TargetConnection CreateTargetConnection(TargetServerConfig targetServerConfig, SyncTreeType type, TestShutdownAndLeaseDelegate testShutdownAndLease, EdgeSyncLogSession logSession)
 {
     return(new MserveTargetConnection(EdgeSyncSvc.EdgeSync.Topology.LocalServer.VersionNumber, targetServerConfig as MserveTargetServerConfig, this.RecipientSyncInterval, testShutdownAndLease, logSession));
 }
Exemplo n.º 18
0
        public LdapTargetConnection(int localServerVersion, TargetServerConfig config, NetworkCredential credentials, SyncTreeType type, EdgeSyncLogSession logSession) : base(localServerVersion, config)
        {
            this.type       = type;
            this.logSession = logSession;
            LdapDirectoryIdentifier identifier = new LdapDirectoryIdentifier(string.Format(CultureInfo.InvariantCulture, "{0}:{1}", new object[]
            {
                base.Host,
                base.Port
            }));

            ExTraceGlobals.ConnectionTracer.TraceDebug <string>((long)this.GetHashCode(), "Attempting to connect to {0}", base.Host);
            try
            {
                this.connection = new LdapConnection(identifier);
            }
            catch (LdapException ex)
            {
                ExTraceGlobals.ConnectionTracer.TraceError <string, string>((long)this.GetHashCode(), "Failed to create a LdapConnection to {0} because {1}", base.Host, ex.Message);
                throw new ExDirectoryException(ex);
            }
            this.connection.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback(this.VerifyServerCertificate);
            this.connection.SessionOptions.SecureSocketLayer       = true;
            this.connection.SessionOptions.Signing         = false;
            this.connection.SessionOptions.Sealing         = false;
            this.connection.SessionOptions.ReferralChasing = ReferralChasingOptions.None;
            this.connection.SessionOptions.ProtocolVersion = 3;
            this.connection.AuthType = AuthType.Basic;
            try
            {
                this.connection.Bind(credentials);
            }
            catch (DirectoryException ex2)
            {
                ExTraceGlobals.ConnectionTracer.TraceError <string, string>((long)this.GetHashCode(), "Failed to connect to {0} because {1}", base.Host, ex2.Message);
                throw new ExDirectoryException(ex2);
            }
            SearchResponse searchResponse = (SearchResponse)this.SendRequest(new SearchRequest(string.Empty, Schema.Query.QueryAll, System.DirectoryServices.Protocols.SearchScope.Base, null));

            if (searchResponse.Entries.Count == 1)
            {
                SearchResultAttributeCollection attributes = searchResponse.Entries[0].Attributes;
                this.adamConfigurationNamingContext = (string)attributes["configurationNamingContext"][0];
                this.adamRootOrgContainerDN         = "CN=First Organization,CN=Microsoft Exchange,CN=Services," + this.adamConfigurationNamingContext;
                string        ldapFilter = "(&(objectClass=msExchExchangeServer)(networkAddress=ncacn_ip_tcp:" + base.Host + "))";
                SearchRequest request    = new SearchRequest(this.adamConfigurationNamingContext, ldapFilter, System.DirectoryServices.Protocols.SearchScope.Subtree, new string[]
                {
                    "name"
                });
                searchResponse = (SearchResponse)this.SendRequest(request);
                if (searchResponse.Entries.Count > 0)
                {
                    this.serverDistinguishedName = searchResponse.Entries[0].DistinguishedName;
                    this.serverName = (string)searchResponse.Entries[0].Attributes["name"][0];
                    return;
                }
                throw new ExDirectoryException(ResultCode.NoSuchAttribute, "Could not read Edge server config object");
            }
            else
            {
                if (searchResponse.Entries.Count == 0)
                {
                    throw new ExDirectoryException(ResultCode.NoSuchAttribute, "Could not read ADAM config naming context");
                }
                throw new InvalidOperationException("expected single result");
            }
        }
Exemplo n.º 19
0
        public static NetworkCredential ExtractNetworkCredential(Server hubServer, string edgeServerFqdn, EdgeSyncLogSession logSession)
        {
            EdgeSyncCredential edgeSyncCredential = new EdgeSyncCredential();

            edgeSyncCredential.EffectiveDate         = 0L;
            edgeSyncCredential.ESRAUsername          = string.Empty;
            edgeSyncCredential.EncryptedESRAPassword = null;
            bool flag = false;

            foreach (byte[] data in hubServer.EdgeSyncCredentials)
            {
                EdgeSyncCredential edgeSyncCredential2 = EdgeSyncCredential.DeserializeEdgeSyncCredential(data);
                if (edgeServerFqdn.Equals(edgeSyncCredential2.EdgeServerFQDN, StringComparison.OrdinalIgnoreCase) && edgeSyncCredential2.EffectiveDate < DateTime.UtcNow.Ticks && edgeSyncCredential2.EffectiveDate > edgeSyncCredential.EffectiveDate)
                {
                    edgeSyncCredential = edgeSyncCredential2;
                    flag = true;
                }
            }
            if (!flag)
            {
                EdgeSyncEvents.Log.LogEvent(EdgeSyncEventLogConstants.Tuple_NoCredentialsFound, hubServer.Name, new object[]
                {
                    hubServer.Fqdn,
                    edgeServerFqdn
                });
                return(null);
            }
            return(Util.DecryptEdgeSyncCredential(hubServer, edgeSyncCredential, logSession));
        }
 public EhfConfigTargetConnection(int localServerVersion, EhfTargetServerConfig config, EdgeSyncLogSession logSession, EhfPerfCounterHandler perfCounterHandler, IProvisioningService provisioningService, IManagementService managementService, EhfADAdapter adapter, EnhancedTimeSpan syncInterval) : base(localServerVersion, config, logSession, perfCounterHandler, provisioningService, managementService, null, adapter, syncInterval)
 {
 }
 public abstract TargetConnection CreateTargetConnection(TargetServerConfig targetServerConfig, SyncTreeType type, TestShutdownAndLeaseDelegate testShutdownAndLease, EdgeSyncLogSession logSession);