public void StampReadFileTest() { var testFile = Path.Combine("Testfiles", "public-resolvers.md"); var stamps = StampTools.ReadStampFile(testFile); Assert.Equal(85, stamps.Count); }
public void StampReadFileTest() { var testFile = Path.Combine("Testfiles", "public-resolvers.md"); var stamps = StampTools.ReadStampFile(testFile); Assert.Equal(192, stamps.Count); Assert.Equal(64, stamps.Count(s => s.Protocol == Models.StampProtocol.DoH)); Assert.Equal(128, stamps.Count(s => s.Protocol == Models.StampProtocol.DnsCrypt)); }
public void StampDecodeTest3() { const string stamp = "sdns://AgUAAAAAAAAAACDyXGrcc5eNecJ8nomJCJ-q6eCLTEn6bHic0hWGUwYQaA5kbnMuZ29vZ2xlLmNvbQ0vZXhwZXJpbWVudGFs"; var result = StampTools.Decode(stamp); Assert.Equal(StampProtocol.DoH, result.Protocol); Assert.Equal("dns.google.com", result.Hostname); }
public void StampDecodeTestRelay() { const string stamp = "sdns://gQ84My43Ny44NS43Ojg0NDM"; var result = StampTools.Decode(stamp); Assert.Equal(StampProtocol.DNSCryptRelay, result.Protocol); Assert.Equal("83.77.85.7", result.Address); }
public void StampDecodeTest1() { const string stamp = "sdns://AQcAAAAAAAAADjIxMi40Ny4yMjguMTM2IOgBuE6mBr-wusDOQ0RbsV66ZLAvo8SqMa4QY2oHkDJNHzIuZG5zY3J5cHQtY2VydC5mci5kbnNjcnlwdC5vcmc"; var result = StampTools.Decode(stamp); Assert.Equal(StampProtocol.DnsCrypt, result.Protocol); Assert.Equal("2.dnscrypt-cert.fr.dnscrypt.org", result.ProviderName); }
public void StampDecodeTest2() { const string stamp = "sdns://AgcAAAAAAAAADTM3LjU5LjIzOC4yMTMgwzRA_TfjYt0RwSHqBHwj7OM-D_x-CDgqIHeJHIoN1P0UZG9oLmZyLmRuc2NyeXB0LmluZm8KL2Rucy1xdWVyeQ"; var result = StampTools.Decode(stamp); Assert.Equal(StampProtocol.DoH, result.Protocol); Assert.Equal("doh.fr.dnscrypt.info", result.Hostname); }
private async void CustomStampAdded(Proxy proxy) { try { if (proxy != null) { if (!string.IsNullOrEmpty(proxy.Stamp)) { var decodedStamp = StampTools.Decode(proxy.Stamp); if (decodedStamp != null) { var addStamp = false; if (decodedStamp.Protocol == DnsCrypt.Models.StampProtocol.DnsCrypt) { //simple check if the stamp is a valid cleanbrowsing stamp if (decodedStamp.ProviderName.Equals(Global.ValidCleanBrowsingDnsCryptStamp)) { addStamp = true; } } else if (decodedStamp.Protocol == DnsCrypt.Models.StampProtocol.DoH) { //simple check if the stamp is a valid cleanbrowsing stamp if (decodedStamp.Hostname.Equals(Global.ValidCleanBrowsingDohStamp)) { addStamp = true; } } else { //unsupported stamp addStamp = false; } if (addStamp) { _appConfiguration.Proxies.Add(proxy); _appConfigurationService.Configuration = _appConfiguration; _logger.Log($"{proxy.Name} - {proxy.Stamp} added", Category.Info, Priority.Medium); MessageQueue.Enqueue("New custom filter added"); await HandleDnsCrypt(Global.DefaultCustomFilterKey); } else { _logger.Log($"invalid custom stamp", Category.Warn, Priority.Medium); } } else { _logger.Log($"invalid custom stamp", Category.Warn, Priority.Medium); } } } } catch (Exception exception) { _logger.Log($"CustomStampAdded {exception.Message}", Category.Exception, Priority.High); } }
public async void MeasureTest1() { const string stamp = "sdns://AQcAAAAAAAAADjIxMi40Ny4yMjguMTM2IOgBuE6mBr-wusDOQ0RbsV66ZLAvo8SqMa4QY2oHkDJNHzIuZG5zY3J5cHQtY2VydC5mci5kbnNjcnlwdC5vcmc"; var result = StampTools.Decode(stamp); var measurement = await MeasurementTools.Proxy(result).ConfigureAwait(false); Assert.NotNull(measurement); Assert.False(measurement.Failed); }
public async void MeasureTest2() { const string stamp = "sdns://AQcAAAAAAAAAEzIwOS4yNTAuMjM1LjE3MDo0NDMgz0wbvISl_NVCSe0wDJMS79BAFZoWth1djmhuzv_n3KAiMi5kbnNjcnlwdC1jZXJ0LmRlLmRuc21hc2NoaW5lLm5ldA"; var result = StampTools.Decode(stamp); var measurement = await MeasurementTools.Proxy(result).ConfigureAwait(false); Assert.NotNull(measurement); Assert.False(measurement.Failed); }
private void SaveStamp() { if (!string.IsNullOrEmpty(Stamp)) { var decodedStamp = StampTools.Decode(Stamp.Trim()); if (decodedStamp != null) { var addStamp = false; if (decodedStamp.Protocol == DnsCrypt.Models.StampProtocol.DnsCrypt) { //simple check if the stamp is a valid cleanbrowsing stamp if (decodedStamp.ProviderName.Equals(Global.ValidCleanBrowsingDnsCryptStamp)) { _logger.Log("valid DnsCrypt stamp", Category.Info, Priority.Low); addStamp = true; } } else if (decodedStamp.Protocol == DnsCrypt.Models.StampProtocol.DoH) { //simple check if the stamp is a valid cleanbrowsing stamp if (decodedStamp.Hostname.Equals(Global.ValidCleanBrowsingDohStamp)) { _logger.Log("valid DoH stamp", Category.Info, Priority.Low); addStamp = true; } } else { //unsupported stamp _logger.Log("unsupported stamp type", Category.Warn, Priority.Medium); addStamp = false; } if (addStamp) { _eventAggregator.GetEvent <StampAddedEvent>().Publish(new Proxy { Name = Global.DefaultCustomFilterKey, Stamp = Stamp.Trim() }); NavigateToMain(); } else { MessageQueue.Enqueue("not a valid stamp://"); } } else { MessageQueue.Enqueue("not a valid stamp://"); } } }
public static List <StampFileEntry> GetRelays() { var relays = new List <StampFileEntry>(); var relayFile = Path.Combine(Directory.GetCurrentDirectory(), Global.DnsCryptProxyFolder, "relays.md"); try { if (File.Exists(relayFile)) { relays = StampTools.ReadStampFileEntries(relayFile); } } catch (Exception exception) { Log.Error(exception); } return(relays); }
private bool SetStaticStamp(string filter) { try { if (_dnscryptProxyConfiguration.Static != null) { if (_dnscryptProxyConfiguration.Static.ContainsKey(filter)) { return(true); } else { RemoveStaticStamps(); DnscryptProxyConfigurationManager.LoadConfiguration(); _dnscryptProxyConfiguration = DnscryptProxyConfigurationManager.DnscryptProxyConfiguration; var stamp = _appConfiguration.Proxies.Where(p => p.Name.Equals(filter)).FirstOrDefault(); if (stamp != null) { if (!string.IsNullOrEmpty(stamp.Stamp)) { var decodedStamp = StampTools.Decode(stamp.Stamp); if (decodedStamp != null) { _dnscryptProxyConfiguration.Static.Add(filter, new Static { stamp = stamp.Stamp }); } } } DnscryptProxyConfigurationManager.DnscryptProxyConfiguration = _dnscryptProxyConfiguration; DnscryptProxyConfigurationManager.SaveConfiguration(); return(true); } } } catch (Exception exception) { _logger.Log($"SetStaticStamp {exception.Message}", Category.Exception, Priority.High); return(false); } return(false); }
public void StampEncodeTest1() { var stampObject = new Stamp { Protocol = StampProtocol.DnsCrypt, ProviderName = "2.dnscrypt-cert.fr.dnscrypt.org", PublicKey = "e801b84ea606bfb0bac0ce43445bb15eba64b02fa3c4aa31ae10636a0790324d", Address = "212.47.228.136", Properties = new StampProperties { DnsSec = true, NoFilter = true, NoLog = true } }; var result = StampTools.Encode(stampObject); const string stamp = "sdns://AQcAAAAAAAAADjIxMi40Ny4yMjguMTM2IOgBuE6mBr-wusDOQ0RbsV66ZLAvo8SqMa4QY2oHkDJNHzIuZG5zY3J5cHQtY2VydC5mci5kbnNjcnlwdC5vcmc"; Assert.AreEqual(stamp, result); }
public void StampReadRelayFileTest() { var testFile = Path.Combine("Testfiles", "relays.md"); var stamps = StampTools.ReadStampFile(testFile); Assert.Equal(44, stamps.Count(s => s.Protocol == Models.StampProtocol.DNSCryptRelay)); }
public MainWindowViewModel( ILoggerFacade logger, IRegionManager regionManager, IEventAggregator eventAggregator, ISnackbarMessageQueue snackbarMessageQueue, IAppConfigurationService appConfigurationService) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _eventAggregator = eventAggregator ?? throw new ArgumentNullException(nameof(eventAggregator)); _regionManager = regionManager ?? throw new ArgumentNullException(nameof(regionManager)); _messageQueue = snackbarMessageQueue ?? throw new ArgumentNullException(nameof(snackbarMessageQueue)); _appConfigurationService = appConfigurationService ?? throw new ArgumentNullException(nameof(appConfigurationService)); try { _appConfiguration = _appConfigurationService.Configuration; _eventAggregator.GetEvent <StampAddedEvent>().Subscribe(CustomStampAdded); NavigateToAboutViewCommand = new DelegateCommand(NavigateToAboutView); NavigateToStampViewCommand = new DelegateCommand(NavigateToStampView); NavigateToSettingsViewCommand = new DelegateCommand(NavigateToSettingsView); OpenWebCommand = new DelegateCommand <string>(OpenUrl); CheckForUpdatesCommand = new DelegateCommand(CheckForUpdates); HandleCustomFilter = new DelegateCommand(HandleCustomStamp); HandleFamilyFilter = new DelegateCommand(async() => await HandleDnsCrypt(Global.DefaultFamilyFilterKey)); HandleAdultFilter = new DelegateCommand(async() => await HandleDnsCrypt(Global.DefaultAdultFilterKey)); IsWorking = true; IsCustomFilterEnabled = false; IsFamilyFilterEnabled = false; IsAdultFilterEnabled = false; var year = Global.CopyrightYear.ToString(); if (DateTime.UtcNow.Year != Global.CopyrightYear) { year = $"{Global.CopyrightYear} - {DateTime.UtcNow.Year}"; } Footer = $"Copyright © {year} {Global.CompanyName}. {VersionHelper.PublishVersion} {VersionHelper.PublishBuild}"; ((App)Application.Current).LoggingLevelSwitch.MinimumLevel = (Serilog.Events.LogEventLevel)_appConfiguration.LogLevel; _logger.Log($"LogLevel: {_appConfiguration.LogLevel}", Category.Debug, Priority.Low); _logger.Log($"{Global.ApplicationName} {VersionHelper.PublishVersion} {VersionHelper.PublishBuild} started", Category.Info, Priority.Medium); // check application configuration _logger.Log($"checking {Global.AppConfigurationFile}", Category.Info, Priority.Medium); var resetApplicationConfig = false; if (_appConfiguration != null) { if (_appConfiguration.Proxies != null) { foreach (var proxy in _appConfiguration.Proxies) { var decodedStamp = StampTools.Decode(proxy.Stamp); if (decodedStamp != null) { if (decodedStamp.Protocol == DnsCrypt.Models.StampProtocol.DnsCrypt) { //simple check if the stamp is a valid cleanbrowsing stamp if (!decodedStamp.ProviderName.Equals(Global.ValidCleanBrowsingDnsCryptStamp)) { resetApplicationConfig = true; } } else if (decodedStamp.Protocol == DnsCrypt.Models.StampProtocol.DoH) { //simple check if the stamp is a valid cleanbrowsing stamp if (!decodedStamp.Hostname.Equals(Global.ValidCleanBrowsingDohStamp)) { resetApplicationConfig = true; } } else { //unsupported stamp resetApplicationConfig = true; } } else { resetApplicationConfig = true; } _logger.Log($"{proxy.Name} loaded", Category.Info, Priority.Medium); } _logger.Log($"{Global.AppConfigurationFile} loaded", Category.Info, Priority.Medium); } else { resetApplicationConfig = true; } } else { resetApplicationConfig = true; _logger.Log($"failed to load {Global.AppConfigurationFile}", Category.Warn, Priority.Medium); } if (resetApplicationConfig) { _logger.Log($"reset {Global.AppConfigurationFile} to default", Category.Warn, Priority.Medium); _appConfigurationService.Reset(); _appConfiguration = _appConfigurationService.Configuration; if (_appConfiguration == null) { _logger.Log($"failed to reset {Global.AppConfigurationFile}", Category.Exception, Priority.High); Environment.Exit(-1); } else { //no validation this time, just go on } } _logger.Log($"checking {Global.DnsCryptProxyFolder} folder", Category.Info, Priority.Medium); foreach (var proxyFile in Global.DnsCryptProxyFiles) { var proxyFilePath = Path.Combine(Directory.GetCurrentDirectory(), Global.DnsCryptProxyFolder, proxyFile); if (!File.Exists(proxyFilePath)) { _logger.Log($"missing {proxyFile}", Category.Warn, Priority.Medium); } else { _logger.Log($"found {proxyFile}", Category.Info, Priority.Low); } } var isValidConfiguration = false; _logger.Log($"checking {Global.DnsCryptConfigurationFile}", Category.Info, Priority.Medium); var configurationCheck = DnsCryptProxyManager.IsConfigurationFileValid(); if (configurationCheck.Success) { isValidConfiguration = true; _logger.Log($"{Global.DnsCryptConfigurationFile} is valid", Category.Info, Priority.Medium); } else { if (configurationCheck.StandardError.Contains("[FATAL] No servers configured")) { isValidConfiguration = true; _logger.Log($"{Global.DnsCryptConfigurationFile} is valid (but no servers)", Category.Info, Priority.Medium); } } if (isValidConfiguration) { var version = DnsCryptProxyManager.GetVersion(); if (!string.IsNullOrEmpty(version)) { Title = $"{Global.ApplicationName} (dnscrypt-proxy {version})"; _logger.Log($"dnscrypt-proxy version: {version}", Category.Info, Priority.Medium); } else { Title = $"{Global.ApplicationName} (dnscrypt-proxy unknown)"; _logger.Log("dnscrypt-proxy version: unknown", Category.Warn, Priority.Medium); } _logger.Log($"loading {Global.DnsCryptConfigurationFile}", Category.Info, Priority.Medium); if (DnscryptProxyConfigurationManager.LoadConfiguration()) { _logger.Log($"{Global.DnsCryptConfigurationFile} loaded", Category.Info, Priority.Medium); _dnscryptProxyConfiguration = DnscryptProxyConfigurationManager.DnscryptProxyConfiguration; if (_dnscryptProxyConfiguration.Static != null && _dnscryptProxyConfiguration.Static.Count > 0) { if (_dnscryptProxyConfiguration.Static.ContainsKey(Global.DefaultCustomFilterKey)) { _logger.Log($"found {Global.DefaultCustomFilterKey} filter", Category.Info, Priority.Medium); IsCustomFilterEnabled = true; } else if (_dnscryptProxyConfiguration.Static.ContainsKey(Global.DefaultAdultFilterKey)) { _logger.Log($"found {Global.DefaultAdultFilterKey} filter", Category.Info, Priority.Medium); IsAdultFilterEnabled = true; } else if (_dnscryptProxyConfiguration.Static.ContainsKey(Global.DefaultFamilyFilterKey)) { _logger.Log($"found {Global.DefaultFamilyFilterKey} filter", Category.Info, Priority.Medium); IsFamilyFilterEnabled = true; } } else { _logger.Log("no static filter configured", Category.Info, Priority.Medium); } if (IsCustomFilterEnabled || IsFamilyFilterEnabled || IsAdultFilterEnabled) { if (!DnsCryptProxyManager.IsDnsCryptProxyInstalled()) { _logger.Log($"dnscrypt-proxy service is not installed, try install", Category.Info, Priority.High); //install Task.Run(() => { DnsCryptProxyManager.Install(); }).ConfigureAwait(false); Task.Delay(Global.ServiceInstallTime).ConfigureAwait(false); } else { _logger.Log($"dnscrypt-proxy service is already installed", Category.Info, Priority.Medium); } if (!DnsCryptProxyManager.IsDnsCryptProxyRunning()) { _logger.Log($"dnscrypt-proxy service is not running, try start", Category.Info, Priority.High); Task.Run(() => { DnsCryptProxyManager.Start(); }).ConfigureAwait(false); Task.Delay(Global.ServiceStartTime).ConfigureAwait(false); } else { _logger.Log($"dnscrypt-proxy service is already running", Category.Info, Priority.Medium); } if (DnsCryptProxyManager.IsDnsCryptProxyRunning()) { _logger.Log($"checking dns servers on network interfaces", Category.Info, Priority.High); if (!HandleNetworkInterfaces(true)) { _logger.Log($"could not update dns servers on network interfaces", Category.Warn, Priority.High); } } else { _logger.Log($"could not start dnscrypt-proxy", Category.Warn, Priority.High); } } } else { _logger.Log($"could not load configuration: {Global.DnsCryptConfigurationFile}", Category.Warn, Priority.High); Environment.Exit(-1); } } else { _logger.Log($"invalid {Global.DnsCryptConfigurationFile}", Category.Warn, Priority.High); Environment.Exit(-1); } } catch (Exception ex) { _logger.Log(ex.Message, Category.Exception, Priority.High); Environment.Exit(-1); } MessageQueue.Enqueue("🐞 You are using a preview version! May contain bugs! 🐞"); IsWorking = false; }
private static async Task Main(string[] args) { var showHelp = false; var list = "public-resolvers.md"; var noLogs = false; var noFilter = false; var onlyDnssec = false; var json = false; var p = new OptionSet { { "l|list=", "the path or url (starting with https://) to a resolvers.md file", v => { if (v != null) { list = v; } } }, { "nl|nologs", "only test resolvers with NoLogs support enabled.", v => { if (v != null) { noLogs = true; } } }, { "nf|nofilter", "only test resolvers with NoFilter support enabled.", v => { if (v != null) { noFilter = true; } } }, { "d|dnssec", "only test resolvers with DNSSEC support enabled.", v => { if (v != null) { onlyDnssec = true; } } }, { "j|json", "print result as JSON.", v => { if (v != null) { json = true; } } }, { "h|help", "show this message and exit", v => showHelp = v != null } }; try { p.Parse(args); } catch (OptionException e) { Console.Write("Measurement: "); Console.WriteLine(e.Message); Console.WriteLine("Try `Measurement --help' for more information."); return; } if (showHelp) { ShowHelp(p); return; } try { if (!string.IsNullOrEmpty(list)) { if (list.StartsWith("https://")) { using (var client = new HttpClient()) { if (!json) { Console.WriteLine("Try downloading remote list . . ."); } const string tmpFile = "resolvers.md"; var getDataTask = client.GetByteArrayAsync(list); var remoteListData = await getDataTask.ConfigureAwait(false); File.WriteAllBytes(tmpFile, remoteListData); if (File.Exists(tmpFile)) { list = tmpFile; } } } } } catch (Exception) { Console.WriteLine($"Could not use remote file: {list}"); } if (File.Exists(list)) { var stamps = StampTools.ReadStampFile(list, noLogs, noFilter, onlyDnssec); if (!json) { Console.WriteLine("measuring . . ."); } var stopWatch = new Stopwatch(); stopWatch.Start(); var measurementTasks = new List <Task <MeasurementResult> >(); foreach (var stamp in stamps) { if (stamp.Protocol == StampProtocol.DnsCrypt) { measurementTasks.Add(MeasurementTools.Proxy(stamp)); } } var measurements = await Task.WhenAll(measurementTasks); var measurementResults = measurements.Where(measurement => !measurement.Failed).ToList(); stopWatch.Stop(); var ts = stopWatch.Elapsed; measurementResults.Sort((a, b) => a.Time.CompareTo(b.Time)); if (!json) { Console.WriteLine("====================================="); Console.WriteLine($"{measurementResults.Count} Resolvers (fastest first)"); Console.WriteLine($"Only DNSSEC: {onlyDnssec}"); Console.WriteLine($"Only NoLogs: {noLogs}"); Console.WriteLine($"Only NoFilter: {noFilter}"); Console.WriteLine("====================================="); Console.WriteLine(); foreach (var measurement in measurementResults) { Console.WriteLine( $"{measurement.Time} ms, {measurement.Stamp.ProviderName}, " + $"NoLogs: {measurement.Stamp.Properties.NoLog}, " + $"NoFilter: {measurement.Stamp.Properties.NoFilter} " + $"DNSSEC: {measurement.Stamp.Properties.DnsSec}, " + $"Certificate Valid: {measurement.Certificate.Valid}"); } Console.WriteLine("Total processing time: " + string.Format("{0} min {1} seconds", Math.Floor(ts.TotalMinutes), ts.ToString("ss\\.ff"))); } else { Console.WriteLine(JsonConvert.SerializeObject(measurementResults.Where(m => m.Failed == false).ToList(), Formatting.Indented)); } } else { Console.WriteLine("Missing resolvers.md"); } }
public void ReadStampFileEntriesTest() { var testFile = Path.Combine("Testfiles", "relays.md"); var entries = StampTools.ReadStampFileEntries(testFile); Assert.Equal(44, entries.Count); }