private void MatchesExpectedHashedPassword(string password, string expected)
        {
            // Arrange
            var salt = GetSalt(expected);

            var random = new Mock <IRandom>();

            random
            .Setup(x => x.GetBytes(It.IsAny <byte[]>()))
            .Callback <byte[]>(x => Buffer.BlockCopy(salt, 0, x, 0, Math.Min(salt.Length, x.Length)));

            var randomFactory = new Mock <IRandomFactory>();

            randomFactory
            .Setup(x => x.Create())
            .Returns(random.Object);

            var torPasswordHasher = new TorPasswordHasher(randomFactory.Object);

            // Act
            var actual = torPasswordHasher.HashPassword(password);

            // Assert
            Assert.Equal(expected, actual);
        }
示例#2
0
        private async Task InitializeAsync()
        {
            _settings.ZippedToolsDirectory    = GetAbsoluteCreate(_settings.ZippedToolsDirectory);
            _settings.ExtractedToolsDirectory = GetAbsoluteCreate(_settings.ExtractedToolsDirectory);

            _tor     = Extract(TorToolSettings);
            _privoxy = Extract(PrivoxyToolSettings);

            if (_settings.TorControlPassword != null && _settings.HashedTorControlPassword == null)
            {
                _settings.HashedTorControlPassword = _torPasswordHasher.HashPassword(_settings.TorControlPassword);
            }

            await ConfigureAndStartAsync(_tor, new TorConfigurationDictionary(_tor.DirectoryPath)).ConfigureAwait(false);
            await ConfigureAndStartAsync(_privoxy, new PrivoxyConfigurationDictionary()).ConfigureAwait(false);
        }
示例#3
0
        private async Task InitializeAsync()
        {
            _settings.ZippedToolsDirectory    = GetAbsoluteCreate(_settings.ZippedToolsDirectory);
            _settings.ExtractedToolsDirectory = GetAbsoluteCreate(_settings.ExtractedToolsDirectory);

            var torToolSettings     = ToolUtility.GetTorToolSettings(_settings);
            var privoxyToolSettings = ToolUtility.GetPrivoxyToolSettings(_settings);

            _tor = await ExtractAsync(torToolSettings).ConfigureAwait(false);

            _privoxy = await ExtractAsync(privoxyToolSettings).ConfigureAwait(false);

            if (_settings.TorSettings.ControlPassword != null && _settings.TorSettings.HashedControlPassword == null)
            {
                _settings.TorSettings.HashedControlPassword = _torPasswordHasher.HashPassword(_settings.TorSettings.ControlPassword);
            }

            await ConfigureAndStartAsync(_tor, new TorConfigurationDictionary()).ConfigureAwait(false);
            await ConfigureAndStartAsync(_privoxy, new PrivoxyConfigurationDictionary()).ConfigureAwait(false);

            WaitForConnect(TorHostName, _settings.TorSettings.SocksPort);
            WaitForConnect(_settings.PrivoxySettings.ListenAddress, _settings.PrivoxySettings.Port);
        }