Exemplo n.º 1
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();
                    }
                }
            }
        }
Exemplo n.º 2
0
 // Token: 0x06000579 RID: 1401 RVA: 0x000209C4 File Offset: 0x0001EBC4
 public static void AddOrReplace(string token, DeviceBehavior data)
 {
     lock (DeviceBehaviorCache.synchronizationObject)
     {
         if (DeviceBehaviorCache.deviceBehaviorCache != null)
         {
             DeviceBehaviorCache.deviceBehaviorCache[token] = data;
         }
     }
 }
Exemplo n.º 3
0
        // Token: 0x06000575 RID: 1397 RVA: 0x000208E0 File Offset: 0x0001EAE0
        public static bool TryGetValue(string token, out DeviceBehavior data)
        {
            bool result;

            lock (DeviceBehaviorCache.synchronizationObject)
            {
                if (DeviceBehaviorCache.deviceBehaviorCache != null)
                {
                    result = DeviceBehaviorCache.deviceBehaviorCache.TryGetValue(token, out data);
                }
                else
                {
                    data   = null;
                    result = false;
                }
            }
            return(result);
        }
Exemplo n.º 4
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);
                }
            }
        }
Exemplo n.º 5
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);
                    }
                }
            }
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
 // Token: 0x06000565 RID: 1381 RVA: 0x0001FCF7 File Offset: 0x0001DEF7
 private static void ClearOldRecords(ExDateTime windowStartTime, List <ExDateTime> times)
 {
     DeviceBehavior.ClearOldRecords(windowStartTime, times, null);
 }
Exemplo n.º 9
0
        // Token: 0x06000574 RID: 1396 RVA: 0x000208C4 File Offset: 0x0001EAC4
        public static bool TryGetValue(Guid userGuid, DeviceIdentity deviceIdentity, out DeviceBehavior data)
        {
            string token = DeviceBehaviorCache.GetToken(userGuid, deviceIdentity);

            return(DeviceBehaviorCache.TryGetValue(token, out data));
        }
Exemplo n.º 10
0
        // Token: 0x06000578 RID: 1400 RVA: 0x000209A8 File Offset: 0x0001EBA8
        public static void AddOrReplace(Guid userGuid, DeviceIdentity deviceIdentity, DeviceBehavior data)
        {
            string token = DeviceBehaviorCache.GetToken(userGuid, deviceIdentity);

            DeviceBehaviorCache.AddOrReplace(token, data);
        }