Exemple #1
0
        // Token: 0x0600056A RID: 1386 RVA: 0x000200D0 File Offset: 0x0001E2D0
        private void BlockDevice(AutoblockThresholdType autoblockThresholdType)
        {
            AirSyncDiagnostics.TraceInfo <AutoblockThresholdType>(ExTraceGlobals.RequestsTracer, this, "BlockDevice {0}", autoblockThresholdType);
            EnhancedTimeSpan deviceBlockDuration = ADNotificationManager.GetAutoBlockThreshold(autoblockThresholdType).DeviceBlockDuration;
            ExDateTime       utcNow = ExDateTime.UtcNow;

            lock (this.instanceLock)
            {
                if (this.blockTime > utcNow || this.nextUnblockTime < utcNow)
                {
                    this.blockTime       = utcNow;
                    this.nextUnblockTime = utcNow + deviceBlockDuration;
                    this.autoBlockReason = DeviceAccessStateReason.UserAgentsChanges + (int)autoblockThresholdType;
                    this.timeToUpdateAD  = utcNow;
                    this.SaveDeviceBehavior(true);
                    if (deviceBlockDuration != EnhancedTimeSpan.Zero)
                    {
                        AirSyncCounters.AutoBlockedDevices.Increment();
                    }
                    if (this.ProtocolLogger != null)
                    {
                        this.ProtocolLogger.SetValue(ProtocolLoggerData.AutoBlockEvent, autoblockThresholdType.ToString());
                    }
                }
            }
        }
Exemple #2
0
        // Token: 0x06000562 RID: 1378 RVA: 0x0001F9A8 File Offset: 0x0001DBA8
        private BackOffValue GetAutoBlockBackOffTimeForSyncCommands()
        {
            int behaviorTypeIncidenceLimit = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.SyncCommands).BehaviorTypeIncidenceLimit;
            EnhancedTimeSpan behaviorTypeIncidenceDuration = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.SyncCommands).BehaviorTypeIncidenceDuration;

            if (behaviorTypeIncidenceDuration.TotalSeconds == 0.0)
            {
                return(BackOffValue.NoBackOffValue);
            }
            if (this.syncTimes == null || this.syncTimes.Count == 0 || this.syncTimes.Count <= behaviorTypeIncidenceLimit / 2)
            {
                AirSyncDiagnostics.TraceInfo(ExTraceGlobals.RequestsTracer, this, "GetAutoblockBackOffTime: Skip calculating backOff time.");
                return(new BackOffValue
                {
                    BackOffDuration = -1.0 * behaviorTypeIncidenceDuration.TotalSeconds,
                    BackOffType = BackOffType.Low,
                    BackOffReason = AutoblockThresholdType.SyncCommands.ToString()
                });
            }
            TimeSpan     currentDuration = ExDateTime.UtcNow.Subtract(this.syncTimes[0]);
            BackOffValue backOffValue    = this.CalculateAutoBlockBackOffTime(behaviorTypeIncidenceLimit, behaviorTypeIncidenceDuration, this.syncTimes.Count, currentDuration, AutoblockThresholdType.SyncCommands.ToString());

            AirSyncDiagnostics.TraceInfo <int, double>(ExTraceGlobals.RequestsTracer, this, "GetAutoblockBackOffTime: SyncCommandLimit:{0}, backOffDuration:{1}", behaviorTypeIncidenceLimit, backOffValue.BackOffDuration);
            return(backOffValue);
        }
Exemple #3
0
        // Token: 0x06000558 RID: 1368 RVA: 0x0001F11C File Offset: 0x0001D31C
        public void RecordNewUserAgent(string newUserAgent)
        {
            EnhancedTimeSpan behaviorTypeIncidenceDuration = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.UserAgentsChanges).BehaviorTypeIncidenceDuration;

            lock (this.instanceLock)
            {
                if (newUserAgent != null && !this.userAgentStrings.Contains(newUserAgent))
                {
                    ExDateTime utcNow          = ExDateTime.UtcNow;
                    ExDateTime windowStartTime = utcNow - behaviorTypeIncidenceDuration;
                    DeviceBehavior.ClearOldRecords(windowStartTime, this.userAgentTimes, this.userAgentStrings);
                    this.userAgentTimes.Add(utcNow);
                    this.userAgentStrings.Add(newUserAgent);
                    this.SaveDeviceBehavior(false);
                    int behaviorTypeIncidenceLimit = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.UserAgentsChanges).BehaviorTypeIncidenceLimit;
                    if (behaviorTypeIncidenceLimit > 0 && this.userAgentTimes.Count > behaviorTypeIncidenceLimit)
                    {
                        this.BlockDevice(AutoblockThresholdType.UserAgentsChanges);
                    }
                    else if (utcNow > this.blockTime && utcNow < this.nextUnblockTime)
                    {
                        this.UnblockDevice();
                    }
                }
            }
        }
Exemple #4
0
        // Token: 0x0600055D RID: 1373 RVA: 0x0001F608 File Offset: 0x0001D808
        public void AddSyncKey(ExDateTime syncAttemptTime, string collectionId, uint syncKey)
        {
            AirSyncDiagnostics.TraceInfo <string, uint>(ExTraceGlobals.RequestsTracer, this, "AddSyncKey collectionId:{0} syncKey:{1}", collectionId, syncKey);
            DeviceAutoBlockThreshold autoBlockThreshold = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.SyncCommands);

            lock (this.instanceLock)
            {
                int num = this.syncTimes.Count - 1;
                while (num > -1 && !(this.syncTimes[num] == syncAttemptTime))
                {
                    num--;
                }
                if (num == -1)
                {
                    this.RecordSyncCommand(syncAttemptTime);
                    num = this.syncTimes.Count - 1;
                    if (this.syncTimes[num] != syncAttemptTime)
                    {
                        throw new InvalidOperationException("Recently added sync record is not the last one!");
                    }
                    if (this.BlockOnFrequency())
                    {
                        return;
                    }
                }
                int num2 = this.syncKeys[num] ^ ((collectionId != null) ? collectionId.GetHashCode() : 0) ^ syncKey.GetHashCode();
                this.syncKeys[num] = num2;
                AirSyncDiagnostics.TraceInfo <int>(ExTraceGlobals.RequestsTracer, this, "AddSyncKey new hashcode {0}", num2);
                if (this.ProtocolLogger != null)
                {
                    this.ProtocolLogger.SetValue(ProtocolLoggerData.SyncHashCode, num2);
                }
                int        num3 = 0;
                ExDateTime t    = syncAttemptTime - autoBlockThreshold.BehaviorTypeIncidenceDuration;
                for (int i = 0; i < this.syncTimes.Count; i++)
                {
                    if (!(this.syncTimes[i] < t) && this.syncKeys[i] == num2)
                    {
                        num3++;
                    }
                }
                int behaviorTypeIncidenceLimit = autoBlockThreshold.BehaviorTypeIncidenceLimit;
                if (behaviorTypeIncidenceLimit > 0 && num3 >= behaviorTypeIncidenceLimit)
                {
                    this.BlockDevice(AutoblockThresholdType.SyncCommands);
                }
                else if (this.AutoBlockReason != DeviceAccessStateReason.Unknown)
                {
                    this.UnblockDevice();
                }
            }
        }
Exemple #5
0
        // Token: 0x0600056B RID: 1387 RVA: 0x000201B4 File Offset: 0x0001E3B4
        private void UnblockDevice()
        {
            AirSyncDiagnostics.TraceInfo(ExTraceGlobals.RequestsTracer, this, "UnblockDevice");
            TimeSpan timeSpan = ADNotificationManager.Started ? (ADNotificationManager.GetAutoBlockThreshold(this.AutoBlockReason).BehaviorTypeIncidenceDuration *(long)GlobalSettings.AutoBlockADWriteDelay) : TimeSpan.Zero;

            lock (this.instanceLock)
            {
                switch (this.autoBlockReason)
                {
                case DeviceAccessStateReason.UserAgentsChanges:
                    this.userAgentTimes.Clear();
                    this.userAgentStrings.Clear();
                    break;

                case DeviceAccessStateReason.RecentCommands:
                    this.recentCommandTimes.Clear();
                    this.recentCommandHashCodes.Clear();
                    break;

                case DeviceAccessStateReason.Watsons:
                    this.watsons.Clear();
                    break;

                case DeviceAccessStateReason.OutOfBudgets:
                    this.outOfBudgets.Clear();
                    break;

                case DeviceAccessStateReason.SyncCommands:
                    this.syncTimes.Clear();
                    this.syncKeys.Clear();
                    break;

                case DeviceAccessStateReason.CommandFrequency:
                    this.recentCommandTimes.Clear();
                    this.recentCommandHashCodes.Clear();
                    this.syncTimes.Clear();
                    this.syncKeys.Clear();
                    break;
                }
                if (timeSpan > DeviceBehavior.MaxADUpdateDelay)
                {
                    timeSpan = DeviceBehavior.MaxADUpdateDelay;
                }
                this.timeToUpdateAD  = ExDateTime.UtcNow + timeSpan;
                this.nextUnblockTime = ExDateTime.MinValue;
                this.autoBlockReason = DeviceAccessStateReason.Unknown;
                this.SaveDeviceBehavior(true);
            }
        }
Exemple #6
0
        // Token: 0x0600055C RID: 1372 RVA: 0x0001F55C File Offset: 0x0001D75C
        public void RecordOutOfBudget()
        {
            AirSyncDiagnostics.TraceInfo(ExTraceGlobals.RequestsTracer, this, "RecordOutOfBudget");
            ExDateTime utcNow = ExDateTime.UtcNow;
            DeviceAutoBlockThreshold autoBlockThreshold = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.OutOfBudgets);
            ExDateTime windowStartTime = utcNow - autoBlockThreshold.BehaviorTypeIncidenceDuration;

            lock (this.instanceLock)
            {
                DeviceBehavior.ClearOldRecords(windowStartTime, this.outOfBudgets);
                this.outOfBudgets.Add(utcNow);
                this.SaveDeviceBehavior(false);
                int behaviorTypeIncidenceLimit = autoBlockThreshold.BehaviorTypeIncidenceLimit;
                if (behaviorTypeIncidenceLimit > 0 && this.outOfBudgets.Count > behaviorTypeIncidenceLimit)
                {
                    this.BlockDevice(AutoblockThresholdType.OutOfBudgets);
                }
            }
        }
Exemple #7
0
        // Token: 0x06000569 RID: 1385 RVA: 0x0001FF98 File Offset: 0x0001E198
        private bool BlockOnFrequency()
        {
            AirSyncDiagnostics.TraceInfo(ExTraceGlobals.RequestsTracer, this, "BlockOnFrequency");
            int behaviorTypeIncidenceLimit = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.CommandFrequency).BehaviorTypeIncidenceLimit;

            if (behaviorTypeIncidenceLimit == 0)
            {
                return(false);
            }
            ExDateTime utcNow = ExDateTime.UtcNow;
            ExDateTime t      = utcNow - ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.CommandFrequency).BehaviorTypeIncidenceDuration;
            int        num    = 0;

            lock (this.instanceLock)
            {
                foreach (ExDateTime t2 in this.recentCommandTimes)
                {
                    if (t2 > t)
                    {
                        num++;
                    }
                }
                if (num >= behaviorTypeIncidenceLimit)
                {
                    this.BlockDevice(AutoblockThresholdType.CommandFrequency);
                    return(true);
                }
                foreach (ExDateTime t3 in this.syncTimes)
                {
                    if (t3 > t)
                    {
                        num++;
                    }
                }
                if (num >= behaviorTypeIncidenceLimit)
                {
                    this.BlockDevice(AutoblockThresholdType.CommandFrequency);
                    return(true);
                }
            }
            return(false);
        }
Exemple #8
0
        // Token: 0x06000563 RID: 1379 RVA: 0x0001FAA8 File Offset: 0x0001DCA8
        private BackOffValue GetAutoBlockBackOffTimeForCommandsFrequency()
        {
            EnhancedTimeSpan behaviorTypeIncidenceDuration = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.CommandFrequency).BehaviorTypeIncidenceDuration;

            if (behaviorTypeIncidenceDuration.TotalSeconds == 0.0)
            {
                return(BackOffValue.NoBackOffValue);
            }
            BackOffValue backOffValue;

            if ((this.recentCommandTimes != null && this.recentCommandTimes.Count >= 0) || (this.syncTimes != null && this.syncTimes.Count >= 0))
            {
                int        behaviorTypeIncidenceLimit = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.CommandFrequency).BehaviorTypeIncidenceLimit;
                ExDateTime exDateTime  = ExDateTime.MaxValue;
                ExDateTime exDateTime2 = ExDateTime.MaxValue;
                int        num         = 0;
                if (this.syncTimes != null && this.syncKeys.Count > 0)
                {
                    num       += this.syncTimes.Count;
                    exDateTime = this.syncTimes[0];
                }
                if (this.recentCommandTimes != null && this.recentCommandTimes.Count > 0)
                {
                    num        += this.recentCommandTimes.Count;
                    exDateTime2 = this.recentCommandTimes[0];
                }
                TimeSpan currentDuration = (exDateTime < exDateTime2) ? ExDateTime.UtcNow.Subtract(exDateTime) : ExDateTime.UtcNow.Subtract(exDateTime2);
                backOffValue = this.CalculateAutoBlockBackOffTime(behaviorTypeIncidenceLimit, behaviorTypeIncidenceDuration, num, currentDuration, AutoblockThresholdType.CommandFrequency.ToString());
                AirSyncDiagnostics.TraceInfo <int, double>(ExTraceGlobals.RequestsTracer, this, "GetAutoblockBackOffTime: SyncCommandLimit:{0}, backOffDuration:{1}", behaviorTypeIncidenceLimit, backOffValue.BackOffDuration);
            }
            else
            {
                AirSyncDiagnostics.TraceInfo(ExTraceGlobals.RequestsTracer, this, "GetAutoblockBackOffTime: Skip calculating backOff time.");
                backOffValue = new BackOffValue
                {
                    BackOffType     = BackOffType.Low,
                    BackOffReason   = AutoblockThresholdType.CommandFrequency.ToString(),
                    BackOffDuration = -1.0 * behaviorTypeIncidenceDuration.TotalSeconds
                };
            }
            return(backOffValue);
        }
Exemple #9
0
        // Token: 0x0600055A RID: 1370 RVA: 0x0001F358 File Offset: 0x0001D558
        public void RecordCommand(int commandHashcode)
        {
            AirSyncDiagnostics.TraceInfo <int>(ExTraceGlobals.RequestsTracer, this, "RecordCommand HC:{0}", commandHashcode);
            ExDateTime utcNow = ExDateTime.UtcNow;
            DeviceAutoBlockThreshold autoBlockThreshold            = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.RecentCommands);
            EnhancedTimeSpan         behaviorTypeIncidenceDuration = autoBlockThreshold.BehaviorTypeIncidenceDuration;

            if (behaviorTypeIncidenceDuration < ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.CommandFrequency).BehaviorTypeIncidenceDuration)
            {
                behaviorTypeIncidenceDuration = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.CommandFrequency).BehaviorTypeIncidenceDuration;
            }
            ExDateTime exDateTime = utcNow - behaviorTypeIncidenceDuration;

            lock (this.instanceLock)
            {
                DeviceBehavior.ClearOldRecords(exDateTime, this.recentCommandTimes, this.recentCommandHashCodes);
                this.recentCommandTimes.Add(utcNow);
                this.recentCommandHashCodes.Add(commandHashcode);
                this.SaveDeviceBehavior(false);
                if (this.ProtocolLogger != null)
                {
                    this.ProtocolLogger.SetValue(ProtocolLoggerData.CommandHashCode, commandHashcode);
                }
                if (!this.BlockOnFrequency())
                {
                    exDateTime = utcNow - autoBlockThreshold.BehaviorTypeIncidenceDuration;
                    int num = 0;
                    for (int i = 0; i < this.recentCommandTimes.Count; i++)
                    {
                        if (!(this.recentCommandTimes[i] < exDateTime) && this.recentCommandHashCodes[i] == commandHashcode)
                        {
                            num++;
                        }
                    }
                    int behaviorTypeIncidenceLimit = autoBlockThreshold.BehaviorTypeIncidenceLimit;
                    if (behaviorTypeIncidenceLimit > 0 && num > behaviorTypeIncidenceLimit)
                    {
                        this.BlockDevice(AutoblockThresholdType.RecentCommands);
                    }
                }
            }
        }
Exemple #10
0
        // Token: 0x06000568 RID: 1384 RVA: 0x0001FEDC File Offset: 0x0001E0DC
        private void RecordSyncCommand(ExDateTime syncAttemptTime)
        {
            AirSyncDiagnostics.TraceInfo <ExDateTime>(ExTraceGlobals.RequestsTracer, this, "RecordSyncCommand syncAttemptTime:{0:o}", syncAttemptTime);
            ExDateTime       utcNow = ExDateTime.UtcNow;
            EnhancedTimeSpan behaviorTypeIncidenceDuration = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.SyncCommands).BehaviorTypeIncidenceDuration;

            if (behaviorTypeIncidenceDuration < ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.CommandFrequency).BehaviorTypeIncidenceDuration)
            {
                behaviorTypeIncidenceDuration = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.CommandFrequency).BehaviorTypeIncidenceDuration;
            }
            ExDateTime windowStartTime = utcNow - behaviorTypeIncidenceDuration;

            lock (this.instanceLock)
            {
                DeviceBehavior.ClearOldRecords(windowStartTime, this.syncTimes, this.syncKeys);
                this.syncTimes.Add(syncAttemptTime);
                this.syncKeys.Add(0);
                this.SaveDeviceBehavior(false);
            }
        }
Exemple #11
0
        // Token: 0x06000285 RID: 645 RVA: 0x0000E88C File Offset: 0x0000CA8C
        private bool TarpitErrorResponse(int httpStatusCode)
        {
            if (httpStatusCode != 441 && httpStatusCode != 449)
            {
                return(true);
            }
            if (httpStatusCode == 451)
            {
                return(!DeviceCapability.DeviceCanHandleRedirect(this.context));
            }
            if (ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.RecentCommands).BehaviorTypeIncidenceDuration == EnhancedTimeSpan.Zero)
            {
                return(false);
            }
            DeviceBehavior deviceBehavior = this.context.DeviceBehavior;

            if (deviceBehavior == null)
            {
                Guid userGuid = AirSyncResponse.UnknownUserGuid;
                if (httpStatusCode != 441)
                {
                    switch (httpStatusCode)
                    {
                    case 449:
                        if (Command.CurrentCommand != null && Command.CurrentCommand.GlobalInfo != null && Command.CurrentCommand.GlobalInfo.DeviceADObjectId != null)
                        {
                            userGuid = Command.CurrentCommand.GlobalInfo.DeviceADObjectId.ObjectGuid;
                            goto IL_136;
                        }
                        goto IL_136;

                    case 451:
                        if (this.context.User != null && this.context.User.ADUser != null && this.context.User.ADUser.Id != null)
                        {
                            userGuid = this.context.User.ADUser.Id.ObjectGuid;
                            goto IL_136;
                        }
                        goto IL_136;
                    }
                    throw new ApplicationException("Unexpected HTTP status code " + httpStatusCode);
                }
IL_136:
                if (!DeviceBehaviorCache.TryGetValue(userGuid, this.context.DeviceIdentity, out deviceBehavior))
                {
                    deviceBehavior = new DeviceBehavior(true);
                    DeviceBehaviorCache.AddOrReplace(userGuid, this.context.DeviceIdentity, deviceBehavior);
                }
            }
            if (deviceBehavior != null)
            {
                lock (deviceBehavior)
                {
                    if (deviceBehavior.IsDeviceAutoBlocked(null) != DeviceAccessStateReason.Unknown)
                    {
                        return(true);
                    }
                    deviceBehavior.RecordCommand(httpStatusCode);
                    if (deviceBehavior.IsDeviceAutoBlocked(null) != DeviceAccessStateReason.Unknown)
                    {
                        return(true);
                    }
                }
                return(false);
            }
            return(false);
        }
Exemple #12
0
        // Token: 0x06000560 RID: 1376 RVA: 0x0001F884 File Offset: 0x0001DA84
        public DeviceAccessStateReason IsDeviceAutoBlocked(ExDateTime requestTime, out TimeSpan blockTime)
        {
            blockTime = TimeSpan.Zero;
            ExDateTime t = (this.AutoBlockReason != DeviceAccessStateReason.Unknown) ? ADNotificationManager.GetAutoBlockThreshold(this.AutoBlockReason).LastChangeTime : ExDateTime.MinValue;
            DeviceAccessStateReason result;

            lock (this.instanceLock)
            {
                if (this.AutoBlockReason != DeviceAccessStateReason.Unknown)
                {
                    if (this.blockTime < t)
                    {
                        this.UnblockDevice();
                    }
                    else if (ExDateTime.UtcNow >= this.nextUnblockTime)
                    {
                        this.UnblockDevice();
                    }
                    else
                    {
                        blockTime = this.nextUnblockTime - requestTime;
                    }
                }
                result = this.AutoBlockReason;
            }
            return(result);
        }
Exemple #13
0
        // Token: 0x0600055F RID: 1375 RVA: 0x0001F7CC File Offset: 0x0001D9CC
        public DeviceAccessStateReason IsDeviceAutoBlocked(string userAgent, out TimeSpan blockTime)
        {
            blockTime = TimeSpan.Zero;
            DeviceAccessStateReason result;

            lock (this.instanceLock)
            {
                if ((string.IsNullOrEmpty(userAgent) || this.userAgentStrings.Contains(userAgent)) && this.AutoBlockReason >= DeviceAccessStateReason.UserAgentsChanges && this.nextUnblockTime > ExDateTime.UtcNow && this.blockTime > ADNotificationManager.GetAutoBlockThreshold(this.AutoBlockReason).LastChangeTime)
                {
                    blockTime = this.nextUnblockTime - ExDateTime.UtcNow;
                    result    = this.AutoBlockReason;
                }
                else
                {
                    result = DeviceAccessStateReason.Unknown;
                }
            }
            return(result);
        }
        public static DeviceAutoBlockThreshold GetAutoBlockThreshold(DeviceAccessStateReason reason)
        {
            AutoblockThresholdType type = (AutoblockThresholdType)(reason - 6);

            return(ADNotificationManager.GetAutoBlockThreshold(type));
        }