private TimeSpan DefaultTimeout { get; } = new TimeSpan(0, 0, 0, 0, 500); // FUTURE use configuration value

        public LoginAttemptController(
            LoginAttemptClient loginAttemptClient,
            UserAccountClient userAccountClient,
            MemoryUsageLimiter memoryUsageLimiter,
            BlockingAlgorithmOptions blockingOptions,
            IStableStore stableStore)
        {
            _options = blockingOptions;//optionsAccessor.Options;
            _stableStore = stableStore;
            _passwordPopularityTracker = new PasswordPopularityTracker("FIXME-uniquekeyfromconfig"
                //FIXME -- use configuration to get options here"FIXME-uniquekeyfromconfig", thresholdRequiredToTrackPreciseOccurrences: 10);
                );
            
            _loginAttemptCache = new FixedSizeLruCache<string, LoginAttempt>(80000);  // FIXME -- use configuration file for size
            _loginAttemptsInProgress = new Dictionary<string, Task<LoginAttempt>>();
            _ipHistoryCache = new SelfLoadingCache<IPAddress, IpHistory>(
                (id, cancellationToken) =>
                {
                    return Task.Run(() => new IpHistory(id), cancellationToken);
                    // FUTURE -- option to load from stable store
                });
            _loginAttemptClient = loginAttemptClient;
            _loginAttemptClient.SetLocalLoginAttemptController(this);     
            SetUserAccountClient(userAccountClient);
            memoryUsageLimiter.OnReduceMemoryUsageEventHandler += ReduceMemoryUsage;
        }
예제 #2
0
        public Simulator(DebugLogger logger, string path, ExperimentalConfiguration myExperimentalConfiguration, SimulatedPasswords simPasswords)
        {
            _simPasswords = simPasswords;
            _logger       = logger;
            _AttackAttemptsWithValidPasswords =     //System.IO.TextWriter.Synchronized
                                                (new StreamWriter(new FileStream(path + "AttackAttemptsWithValidPasswords.txt", FileMode.CreateNew, FileAccess.Write)));
            _LegitiamteAttemptsWithValidPasswords = //System.IO.TextWriter.Synchronized
                                                    (new StreamWriter(new FileStream(path + "LegitiamteAttemptsWithValidPasswords.txt", FileMode.CreateNew, FileAccess.Write)));
            _OtherAttempts =                        //System.IO.TextWriter.Synchronized
                             (new StreamWriter(new FileStream(path + path + "OtherAttempts.txt", FileMode.CreateNew, FileAccess.Write)));
            _logger.WriteStatus("Entered Simulator constructor");
            _experimentalConfiguration = myExperimentalConfiguration;
            BlockingAlgorithmOptions options = _experimentalConfiguration.BlockingOptions;

            _logger.WriteStatus("Creating binomial ladder");
            _binomialLadderFilter =
                new BinomialLadderFilter(options.NumberOfBitsInBinomialLadderFilter_N, options.HeightOfBinomialLadder_H);
            _ipHistoryCache        = new SelfLoadingCache <IPAddress, SimIpHistory>(address => new SimIpHistory(options.NumberOfFailuresToTrackForGoingBackInTimeToIdentifyTypos));
            _userAccountController = new MemoryUserAccountController();

            _memoryUsageLimiter = new MemoryUsageLimiter();
            _memoryUsageLimiter.OnReduceMemoryUsageEventHandler += ReduceMemoryUsage;

            _recentIncorrectPasswords = new AgingMembershipSketch(16, 128 * 1024);

            _logger.WriteStatus("Exiting Simulator constructor");
        }
예제 #3
0
        public void CacheSelfLoadingAsync()
        {
            // Not to be confused with a self-loathing cache.

            Cache<int, string> c = new SelfLoadingCache<int, string>(
                // Map key to value
                (key, cancelToken) => { return Task.Run(() => key.ToString(), cancelToken); }
                );
            Assert.Equal(0, c.Count);
            for (int i = 1; i <= 1000; i++)
            {
                Assert.Equal(i.ToString(), c[i]);
            }
            Assert.Equal(1000, c.Count);
            Assert.Equal("1000", c.MostRecentlyAccessed.Value);
            Assert.Equal("1", c.LeastRecentlyAccessed.Value);
        }
예제 #4
0
        public void CacheSelfLoadingAsync()
        {
            // Not to be confused with a self-loathing cache.

            Cache <int, string> c = new SelfLoadingCache <int, string>(
                // Map key to value
                (key, cancelToken) => { return(Task.Run(() => key.ToString(), cancelToken)); }
                );

            Assert.Equal(0, c.Count);
            for (int i = 1; i <= 1000; i++)
            {
                Assert.Equal(i.ToString(), c[i]);
            }
            Assert.Equal(1000, c.Count);
            Assert.Equal("1000", c.MostRecentlyAccessed.Value);
            Assert.Equal("1", c.LeastRecentlyAccessed.Value);
        }
        public UserAccountController(
            UserAccountClient userAccountClient,
            LoginAttemptClient loginAttemptClient,
            MemoryUsageLimiter memoryUsageLimiter,
            BlockingAlgorithmOptions options,
            IStableStore stableStore,
            LimitPerTimePeriod[] creditLimits)
        {
//            _options = optionsAccessor.Options;
            _options = options;
            _stableStore = stableStore;
            _userAccountClient = userAccountClient;
            CreditLimits = creditLimits;
            _userAccountCache = new SelfLoadingCache<string, UserAccount>(_stableStore.ReadAccountAsync);
            SetLoginAttemptClient(loginAttemptClient);
            userAccountClient.SetLocalUserAccountController(this);
            memoryUsageLimiter.OnReduceMemoryUsageEventHandler += ReduceMemoryUsage;
        }
예제 #6
0
        public LoginAttemptController(
            IUserAccountControllerFactory <TUserAccount> userAccountControllerFactory,
            IUserAccountRepositoryFactory <TUserAccount> userAccountRepositoryFactory,
            IBinomialLadderFilter binomialLadderFilter,
            MemoryUsageLimiter memoryUsageLimiter,
            BlockingAlgorithmOptions blockingOptions
            )
        {
            _options = blockingOptions;
            _binomialLadderFilter         = binomialLadderFilter;
            _userAccountRepositoryFactory = userAccountRepositoryFactory;
            _userAccountControllerFactory = userAccountControllerFactory;


            _recentIncorrectPasswords = new AgingMembershipSketch(blockingOptions.AgingMembershipSketchTables, blockingOptions.AgingMembershipSketchTableSize);

            _ipHistoryCache = new SelfLoadingCache <IPAddress, IpHistory>(address => new IpHistory(address, _options));

            memoryUsageLimiter.OnReduceMemoryUsageEventHandler += ReduceMemoryUsage;
        }
        /// <summary>
        /// Construct the controller.
        /// </summary>
        /// <param name="userAccountControllerFactory">A factory for creating IUserAccountController interfaces for managing user account records.</param>
        /// <param name="userAccountRepositoryFactory">A factory for creating IAccountRepository interfaces for obtaining user account records.</param>
        /// <param name="binomialLadderFilter">A binomial ladder frequency that the controller should use to track frequently-guessed passwords.</param>
        /// <param name="memoryUsageLimiter">A memory usage limiter that the controller should register into so that when memory is tight,
        /// the controller can do its part to free up cached items it may not need anymore.</param>
        /// <param name="blockingOptions">Configuration options.</param>
        public LoginAttemptController(
            IUserAccountControllerFactory <TUserAccount> userAccountControllerFactory,
            IUserAccountRepositoryFactory <TUserAccount> userAccountRepositoryFactory,
            IBinomialLadderFilter binomialLadderFilter,
            MemoryUsageLimiter memoryUsageLimiter,
            BlockingAlgorithmOptions blockingOptions
            )
        {
            // Copy parameters into the controller.
            _options = blockingOptions;
            _binomialLadderFilter         = binomialLadderFilter;
            _userAccountRepositoryFactory = userAccountRepositoryFactory;
            _userAccountControllerFactory = userAccountControllerFactory;

            // Create a membership sketch to track username/password pairs that have failed.
            _recentIncorrectPasswords = new AgingMembershipSketch(blockingOptions.AgingMembershipSketchTables, blockingOptions.AgingMembershipSketchTableSize);

            // Create a cache of records storing information about the behavior of IPs that have issued login attempts.
            _ipHistoryCache = new SelfLoadingCache <IPAddress, IpHistory>(address => new IpHistory(address, _options));

            // When memory is low, the memeory usage limiter should call the ReduceMemoryUsage method of this controller.
            memoryUsageLimiter.OnReduceMemoryUsageEventHandler += ReduceMemoryUsage;
        }