Example #1
0
        private async Task <Tool> ExtractAsync(ToolSettings toolSettings)
        {
            var tool = ToolUtility.GetLatestToolOrNull(_settings, toolSettings);

            if (tool == null)
            {
                throw new TorSharpException(
                          $"No version of {toolSettings.Name} was found under {_settings.ZippedToolsDirectory}.");
            }

            await ExtractToolAsync(tool, _settings.ReloadTools).ConfigureAwait(false);

            PermissionsUtility.MakeExecutable(_settings, tool.ExecutablePath);

            return(tool);
        }
Example #2
0
        private async Task <PartialToolUpdates> CheckForUpdatesAsync(bool allowExistingTools)
        {
            var privoxy = await CheckForUpdateAsync(
                ToolUtility.GetPrivoxyToolSettings(_settings),
                _privoxyFetcher,
                allowExistingTools).ConfigureAwait(false);

            var tor = await CheckForUpdateAsync(
                ToolUtility.GetTorToolSettings(_settings),
                _torFetcher,
                allowExistingTools).ConfigureAwait(false);

            return(new PartialToolUpdates
            {
                Privoxy = privoxy,
                Tor = tor,
            });
        }
Example #3
0
        private async Task <ToolUpdate> CheckForUpdateAsync(
            ToolSettings toolSettings,
            IFileFetcher fetcher,
            bool useExistingTools)
        {
            var latestLocal = ToolUtility.GetLatestToolOrNull(_settings, toolSettings);

            if (useExistingTools && latestLocal != null)
            {
                return(null);
            }

            EnableSecurityProtocols();

            var latestDownload = await fetcher.GetLatestAsync().ConfigureAwait(false);

            var fileExtension   = ArchiveUtility.GetFileExtension(latestDownload.Format);
            var fileName        = $"{toolSettings.Prefix}{latestDownload.Version}{fileExtension}";
            var destinationPath = Path.Combine(_settings.ZippedToolsDirectory, fileName);

            ToolUpdateStatus status;

            if (latestLocal == null)
            {
                status = ToolUpdateStatus.NoLocalVersion;
            }
            else if (!File.Exists(destinationPath))
            {
                status = ToolUpdateStatus.NewerVersionAvailable;
            }
            else
            {
                status = ToolUpdateStatus.NoUpdateAvailable;
            }

            return(new ToolUpdate(
                       status,
                       latestLocal?.Version,
                       destinationPath,
                       latestDownload));
        }
Example #4
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);
        }