public static TestConfiguration InitTest(BlockingAlgorithmOptions options = default(BlockingAlgorithmOptions))
        {
            if (options == null)
            {
                options = new BlockingAlgorithmOptions();
            }

            TestConfiguration configuration = new TestConfiguration();

            configuration.MyBlockingAlgorithmOptions = options ?? new BlockingAlgorithmOptions();

            MemoryUsageLimiter memoryUsageLimiter = new MemoryUsageLimiter();

            BinomialLadderFilter localPasswordBinomialLadderFilter =
                new BinomialLadderFilter(options.NumberOfBitsInBinomialLadderFilter_N, options.HeightOfBinomialLadder_H);

            configuration.MyAccountFactory         = new MemoryOnlyUserAccountFactory();
            configuration.MemUserAccountController = new MemoryUserAccountController();

            LoginAttemptController <MemoryUserAccount> myLoginAttemptController =
                new LoginAttemptController <MemoryUserAccount>(
                    new MemoryUserAccountControllerFactory(),
                    configuration.MyAccountFactory,
                    localPasswordBinomialLadderFilter,
                    memoryUsageLimiter, configuration.MyBlockingAlgorithmOptions);

            configuration.MyLoginAttemptClient = myLoginAttemptController;

            return(configuration);
        }
Exemplo n.º 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");
        }
Exemplo n.º 3
0
        public static TestConfiguration InitTest(BlockingAlgorithmOptions options = default(BlockingAlgorithmOptions))
        {
            if (options == null)
            {
                options = new BlockingAlgorithmOptions();
            }

            TestConfiguration configuration = new TestConfiguration();

            configuration.MyBlockingAlgorithmOptions = options ?? new BlockingAlgorithmOptions();

            //configuration.MyResponsibleHosts = new MaxWeightHashing<RemoteHost>("FIXME-uniquekeyfromconfig");
            //RemoteHost localHost = new RemoteHost { Uri = new Uri("http://localhost:80") };
            //configuration.MyResponsibleHosts.Add("localhost", localHost);
            //IStableStore stableStore = configuration.StableStore = new MemoryOnlyStableStore();

            //configuration.MyLoginAttemptClient = new LoginAttemptClient(configuration.MyResponsibleHosts, localHost);

            MemoryUsageLimiter memoryUsageLimiter = new MemoryUsageLimiter();

            BinomialLadderFilter localPasswordBinomialLadderFilter =
                new BinomialLadderFilter(options.NumberOfBitsInBinomialLadderFilter_N, options.HeightOfBinomialLadder_H);

            //MultiperiodFrequencyTracker<string> localPasswordFrequencyTracker =
            //        new MultiperiodFrequencyTracker<string>(
            //            options.NumberOfPopularityMeasurementPeriods,
            //            options.LengthOfShortestPopularityMeasurementPeriod,
            //            options.FactorOfGrowthBetweenPopularityMeasurementPeriods);

            configuration.MyAccountFactory         = new MemoryOnlyUserAccountFactory();
            configuration.MemUserAccountController = new MemoryUserAccountController();

            LoginAttemptController <MemoryUserAccount> myLoginAttemptController =
                new LoginAttemptController <MemoryUserAccount>(
                    new MemoryUserAccountControllerFactory(),
                    configuration.MyAccountFactory,
                    localPasswordBinomialLadderFilter,
                    memoryUsageLimiter, configuration.MyBlockingAlgorithmOptions);

            configuration.MyLoginAttemptClient = myLoginAttemptController;

            //configuration.MyLoginAttemptClient.SetLocalLoginAttemptController(myLoginAttemptController);
            return(configuration);
        }
Exemplo n.º 4
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;
        }