add doh settings

This commit is contained in:
Fabian Freund
2025-10-03 12:18:02 +02:00
parent 805d39e300
commit 2559c1c681
19 changed files with 758 additions and 200 deletions
-17
View File
@@ -52,23 +52,6 @@
"DNS": {
"description": "Improve DNS and Proxy/SOCKS security",
"preferences": {
"network.trr.mode": {
"value": 3,
"title": "Enable DNS over HTTPS",
"requireUserOptIn": true
},
"network.trr.uri": {
"value": "https://dns.quad9.net/dns-query",
"title": "Use quad9 for Trusted Recursive Resolver (TRR)",
"description": "Quad9 is a privacy-focused DNS resolver that provides malware blocking and security features.",
"requireUserOptIn": true
},
"network.trr.custom.uri": {
"value": "https://dns.quad9.net/dns-query",
"title": "Use quad9 for custom Trusted Recursive Resolver (TRR)",
"description": "Quad9 is a privacy-focused DNS resolver that provides malware blocking and security features.",
"requireUserOptIn": true
},
"network.dns.native_https_query": {
"value": true,
"title": "Enable native DNS HTTPS Query",
+1
View File
@@ -42,6 +42,7 @@ import 'package:weblibre/features/onboarding/presentation/onboarding.dart';
import 'package:weblibre/features/settings/presentation/screens/addon_collection.dart';
import 'package:weblibre/features/settings/presentation/screens/bang_settings.dart';
import 'package:weblibre/features/settings/presentation/screens/developer_settings.dart';
import 'package:weblibre/features/settings/presentation/screens/doh_settings.dart';
import 'package:weblibre/features/settings/presentation/screens/general_settings.dart';
import 'package:weblibre/features/settings/presentation/screens/settings.dart';
import 'package:weblibre/features/settings/presentation/screens/web_engine_hardening.dart';
+25
View File
@@ -106,6 +106,11 @@ RouteBase get $settingsRoute => GoRouteData.$route(
),
],
),
GoRouteData.$route(
path: 'doh',
name: 'DohSettingsRoute',
factory: $DohSettingsRoute._fromState,
),
],
),
GoRouteData.$route(
@@ -254,6 +259,26 @@ mixin $WebEngineHardeningGroupRoute on GoRouteData {
void replace(BuildContext context) => context.replace(location);
}
mixin $DohSettingsRoute on GoRouteData {
static DohSettingsRoute _fromState(GoRouterState state) => DohSettingsRoute();
@override
String get location => GoRouteData.$location('/settings/web_engine/doh');
@override
void go(BuildContext context) => context.go(location);
@override
Future<T?> push<T>(BuildContext context) => context.push<T>(location);
@override
void pushReplacement(BuildContext context) =>
context.pushReplacement(location);
@override
void replace(BuildContext context) => context.replace(location);
}
mixin $DeveloperSettingsRoute on GoRouteData {
static DeveloperSettingsRoute _fromState(GoRouterState state) =>
DeveloperSettingsRoute();
@@ -42,6 +42,7 @@ part of 'routes.dart';
),
],
),
TypedGoRoute<DohSettingsRoute>(name: 'DohSettingsRoute', path: 'doh'),
],
),
TypedGoRoute<DeveloperSettingsRoute>(
@@ -77,6 +78,13 @@ class BangSettingsRoute extends GoRouteData with $BangSettingsRoute {
}
}
class DohSettingsRoute extends GoRouteData with $DohSettingsRoute {
@override
Widget build(BuildContext context, GoRouterState state) {
return const DohSettingsScreen();
}
}
class WebEngineSettingsRoute extends GoRouteData with $WebEngineSettingsRoute {
@override
Widget build(BuildContext context, GoRouterState state) {
@@ -125,6 +125,9 @@ class EngineSettingsReplicationService
if (previous.value?.contentBlocking != settings.contentBlocking) {
await _service.contentBlocking(settings.contentBlocking);
}
if (previous.value?.dohSettings != settings.dohSettings) {
await _service.dohSettings(settings.dohSettings);
}
} else {
await _service.setDefaultSettings(settings);
initialSettingsSent = true;
@@ -44,7 +44,7 @@ final class EngineSettingsReplicationServiceProvider
}
String _$engineSettingsReplicationServiceHash() =>
r'015bd9c923de0c09109d0fd489967f52a35ee944';
r'0bbc80fe0cff79f9e419ffa8c486d232f9eac2ee';
abstract class _$EngineSettingsReplicationService extends $Notifier<void> {
void build();
@@ -0,0 +1,191 @@
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:weblibre/features/settings/presentation/controllers/save_settings.dart';
import 'package:weblibre/features/user/data/models/engine_settings.dart';
import 'package:weblibre/features/user/domain/repositories/engine_settings.dart';
import 'package:weblibre/utils/form_validators.dart';
class DohSettingsScreen extends HookConsumerWidget {
const DohSettingsScreen();
@override
Widget build(BuildContext context, WidgetRef ref) {
final formKey = useMemoized(() => GlobalKey<FormState>());
final dohSettings = ref.watch(
engineSettingsWithDefaultsProvider.select((value) => value.dohSettings),
);
final customProviderController = useTextEditingController(
text: BuiltInDohProviders.isBuiltin(dohSettings.dohProviderUrl)
? null
: dohSettings.dohProviderUrl,
);
return Scaffold(
appBar: AppBar(title: const Text('DNS over HTTPS')),
body: SafeArea(
child: ListView(
children: [
const ListTile(
leading: Icon(MdiIcons.dns),
title: Text('Protection Level'),
subtitle: Text(
'Domain Name System (DNS) over HTTPS sends your request for a domain name through an encrypted connection, providing a secure DNS and making it harder for others to see which web site youre about to access.',
),
),
RadioGroup(
groupValue: dohSettings.dohSettingsMode,
onChanged: (value) async {
if (value != null) {
await ref
.read(saveEngineSettingsControllerProvider.notifier)
.save(
(currentSettings) =>
currentSettings.copyWith.dohSettingsMode(value),
);
}
},
child: const RadioListTile.adaptive(
value: DohSettingsMode.geckoDefault,
title: Text('Default Protection'),
subtitle: Text('DoH used only when default DNS fails'),
),
),
RadioGroup(
groupValue: dohSettings.dohSettingsMode,
onChanged: (value) async {
if (value != null) {
await ref
.read(saveEngineSettingsControllerProvider.notifier)
.save(
(currentSettings) =>
currentSettings.copyWith.dohSettingsMode(value),
);
}
},
child: const RadioListTile.adaptive(
value: DohSettingsMode.increased,
title: Text('Increased Protection'),
subtitle: Text('DoH preferred, default DNS as fallback'),
),
),
RadioGroup(
groupValue: dohSettings.dohSettingsMode,
onChanged: (value) async {
if (value != null) {
await ref
.read(saveEngineSettingsControllerProvider.notifier)
.save(
(currentSettings) =>
currentSettings.copyWith.dohSettingsMode(value),
);
}
},
child: const RadioListTile.adaptive(
value: DohSettingsMode.max,
title: Text('Max Protection'),
subtitle: Text('DoH only, no fallback'),
),
),
RadioGroup(
groupValue: dohSettings.dohSettingsMode,
onChanged: (value) async {
if (value != null) {
await ref
.read(saveEngineSettingsControllerProvider.notifier)
.save(
(currentSettings) =>
currentSettings.copyWith.dohSettingsMode(value),
);
}
},
child: const RadioListTile.adaptive(
value: DohSettingsMode.off,
title: Text('Off'),
subtitle: Text('Use your default DNS resolver'),
),
),
const ListTile(
leading: Icon(MdiIcons.routerNetwork),
title: Text('DoH Provider'),
),
RadioGroup(
groupValue: dohSettings.dohProviderUrl,
onChanged: (value) async {
if (value != null) {
await ref
.read(saveEngineSettingsControllerProvider.notifier)
.save(
(currentSettings) =>
currentSettings.copyWith.dohProviderUrl(value),
);
}
},
child: Column(
children: BuiltInDohProviders.values
.map(
(provider) => RadioListTile.adaptive(
value: provider.url,
title: Text(provider.name),
subtitle: Text(provider.url),
),
)
.toList(),
),
),
RadioGroup(
groupValue: !BuiltInDohProviders.isBuiltin(
dohSettings.dohProviderUrl,
),
onChanged: (value) {},
child: RadioListTile(
value: true,
enabled: false,
title: Column(
children: [
const Text('Custom'),
Form(
key: formKey,
child: TextFormField(
controller: customProviderController,
keyboardType: TextInputType.url,
validator: (value) {
return validateUrl(
value,
onlyHttpProtocol: true,
eagerParsing: false,
);
},
onSaved: (newProvider) async {
if (newProvider != null) {
await ref
.read(
saveEngineSettingsControllerProvider.notifier,
)
.save(
(currentSettings) => currentSettings.copyWith
.dohProviderUrl(newProvider),
);
}
},
onFieldSubmitted: (_) {
if (formKey.currentState?.validate() == true) {
formKey.currentState?.save();
}
},
),
),
],
),
),
),
],
),
),
);
}
}
@@ -262,6 +262,18 @@ class WebEngineSettingsScreen extends HookConsumerWidget {
],
),
),
ListTile(
title: const Text('DNS over HTTPS'),
contentPadding: const EdgeInsets.symmetric(
vertical: 8.0,
horizontal: 16.0,
),
leading: const Icon(MdiIcons.dns),
trailing: const Icon(Icons.chevron_right),
onTap: () async {
await DohSettingsRoute().push(context);
},
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
@@ -27,6 +27,21 @@ import 'package:nullability/nullability.dart';
part 'engine_settings.g.dart';
enum BuiltInDohProviders {
quad9('Quad9', 'https://dns.quad9.net/dns-query'),
mullvad('Mullvad', 'https://dns.mullvad.net/dns-query'),
adguard('AdGuard', 'https://dns.adguard-dns.com/dns-query'),
ffmuc('Freifunk München', 'https://doh.ffmuc.net/dns-query');
final String name;
final String url;
static bool isBuiltin(String url) =>
BuiltInDohProviders.values.any((provider) => provider.url == url);
const BuiltInDohProviders(this.name, this.url);
}
@CopyWith()
@JsonSerializable(includeIfNull: true, constructor: 'withDefaults')
class EngineSettings extends GeckoEngineSettings with FastEquatable {
@@ -66,6 +81,20 @@ class EngineSettings extends GeckoEngineSettings with FastEquatable {
@JsonKey(fromJson: _addonCollectionFromJson, toJson: _addonCollectionToJson)
final AddonCollection? addonCollection;
final DohSettingsMode dohSettingsMode;
final String dohProviderUrl;
final String dohDefaultProviderUrl;
final List<String> dohExceptionsList;
@override
@JsonKey(includeFromJson: false, includeToJson: false)
DohSettings get dohSettings => DohSettings(
dohSettingsMode: dohSettingsMode,
dohProviderUrl: dohProviderUrl,
dohDefaultProviderUrl: dohDefaultProviderUrl,
dohExceptionsList: dohExceptionsList,
);
@override
@JsonKey(includeFromJson: false, includeToJson: false)
ContentBlocking get contentBlocking => ContentBlocking(
@@ -92,6 +121,10 @@ class EngineSettings extends GeckoEngineSettings with FastEquatable {
required this.queryParameterStripping,
required this.bounceTrackingProtectionMode,
required this.addonCollection,
required this.dohSettingsMode,
required this.dohProviderUrl,
required this.dohDefaultProviderUrl,
required this.dohExceptionsList,
});
EngineSettings.withDefaults({
@@ -110,11 +143,20 @@ class EngineSettings extends GeckoEngineSettings with FastEquatable {
super.userAgent,
bool? enterpriseRootsEnabled,
this.addonCollection,
DohSettingsMode? dohSettingsMode,
String? dohProviderUrl,
String? dohDefaultProviderUrl,
List<String>? dohExceptionsList,
}) : queryParameterStripping =
queryParameterStripping ?? QueryParameterStripping.disabled,
bounceTrackingProtectionMode =
bounceTrackingProtectionMode ??
BounceTrackingProtectionMode.disabled,
dohSettingsMode = dohSettingsMode ?? DohSettingsMode.increased,
dohProviderUrl = dohProviderUrl ?? BuiltInDohProviders.quad9.url,
dohDefaultProviderUrl =
dohDefaultProviderUrl ?? BuiltInDohProviders.quad9.url,
dohExceptionsList = dohExceptionsList ?? [],
super(
javascriptEnabled: javascriptEnabled ?? true,
trackingProtectionPolicy:
@@ -155,5 +197,9 @@ class EngineSettings extends GeckoEngineSettings with FastEquatable {
queryParameterStripping,
bounceTrackingProtectionMode,
addonCollection,
dohSettingsMode,
dohProviderUrl,
dohDefaultProviderUrl,
dohExceptionsList,
];
}
@@ -53,6 +53,14 @@ abstract class _$EngineSettingsCWProxy {
EngineSettings addonCollection(AddonCollection? addonCollection);
EngineSettings dohSettingsMode(DohSettingsMode dohSettingsMode);
EngineSettings dohProviderUrl(String dohProviderUrl);
EngineSettings dohDefaultProviderUrl(String dohDefaultProviderUrl);
EngineSettings dohExceptionsList(List<String> dohExceptionsList);
/// Creates a new instance with the provided field values.
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `EngineSettings(...).copyWith.fieldName(value)`.
///
@@ -76,6 +84,10 @@ abstract class _$EngineSettingsCWProxy {
QueryParameterStripping queryParameterStripping,
BounceTrackingProtectionMode bounceTrackingProtectionMode,
AddonCollection? addonCollection,
DohSettingsMode dohSettingsMode,
String dohProviderUrl,
String dohDefaultProviderUrl,
List<String> dohExceptionsList,
});
}
@@ -160,6 +172,22 @@ class _$EngineSettingsCWProxyImpl implements _$EngineSettingsCWProxy {
EngineSettings addonCollection(AddonCollection? addonCollection) =>
call(addonCollection: addonCollection);
@override
EngineSettings dohSettingsMode(DohSettingsMode dohSettingsMode) =>
call(dohSettingsMode: dohSettingsMode);
@override
EngineSettings dohProviderUrl(String dohProviderUrl) =>
call(dohProviderUrl: dohProviderUrl);
@override
EngineSettings dohDefaultProviderUrl(String dohDefaultProviderUrl) =>
call(dohDefaultProviderUrl: dohDefaultProviderUrl);
@override
EngineSettings dohExceptionsList(List<String> dohExceptionsList) =>
call(dohExceptionsList: dohExceptionsList);
@override
/// Creates a new instance with the provided field values.
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `EngineSettings(...).copyWith.fieldName(value)`.
@@ -186,6 +214,10 @@ class _$EngineSettingsCWProxyImpl implements _$EngineSettingsCWProxy {
Object? queryParameterStripping = const $CopyWithPlaceholder(),
Object? bounceTrackingProtectionMode = const $CopyWithPlaceholder(),
Object? addonCollection = const $CopyWithPlaceholder(),
Object? dohSettingsMode = const $CopyWithPlaceholder(),
Object? dohProviderUrl = const $CopyWithPlaceholder(),
Object? dohDefaultProviderUrl = const $CopyWithPlaceholder(),
Object? dohExceptionsList = const $CopyWithPlaceholder(),
}) {
return EngineSettings(
javascriptEnabled: javascriptEnabled == const $CopyWithPlaceholder()
@@ -263,6 +295,30 @@ class _$EngineSettingsCWProxyImpl implements _$EngineSettingsCWProxy {
? _value.addonCollection
// ignore: cast_nullable_to_non_nullable
: addonCollection as AddonCollection?,
dohSettingsMode:
dohSettingsMode == const $CopyWithPlaceholder() ||
dohSettingsMode == null
? _value.dohSettingsMode
// ignore: cast_nullable_to_non_nullable
: dohSettingsMode as DohSettingsMode,
dohProviderUrl:
dohProviderUrl == const $CopyWithPlaceholder() ||
dohProviderUrl == null
? _value.dohProviderUrl
// ignore: cast_nullable_to_non_nullable
: dohProviderUrl as String,
dohDefaultProviderUrl:
dohDefaultProviderUrl == const $CopyWithPlaceholder() ||
dohDefaultProviderUrl == null
? _value.dohDefaultProviderUrl
// ignore: cast_nullable_to_non_nullable
: dohDefaultProviderUrl as String,
dohExceptionsList:
dohExceptionsList == const $CopyWithPlaceholder() ||
dohExceptionsList == null
? _value.dohExceptionsList
// ignore: cast_nullable_to_non_nullable
: dohExceptionsList as List<String>,
);
}
}
@@ -323,6 +379,15 @@ EngineSettings _$EngineSettingsFromJson(Map<String, dynamic> json) =>
addonCollection: EngineSettings._addonCollectionFromJson(
json['addonCollection'] as String?,
),
dohSettingsMode: $enumDecodeNullable(
_$DohSettingsModeEnumMap,
json['dohSettingsMode'],
),
dohProviderUrl: json['dohProviderUrl'] as String?,
dohDefaultProviderUrl: json['dohDefaultProviderUrl'] as String?,
dohExceptionsList: (json['dohExceptionsList'] as List<dynamic>?)
?.map((e) => e as String)
.toList(),
);
Map<String, dynamic> _$EngineSettingsToJson(
@@ -355,6 +420,10 @@ Map<String, dynamic> _$EngineSettingsToJson(
'addonCollection': EngineSettings._addonCollectionToJson(
instance.addonCollection,
),
'dohSettingsMode': _$DohSettingsModeEnumMap[instance.dohSettingsMode]!,
'dohProviderUrl': instance.dohProviderUrl,
'dohDefaultProviderUrl': instance.dohDefaultProviderUrl,
'dohExceptionsList': instance.dohExceptionsList,
};
const _$TrackingProtectionPolicyEnumMap = {
@@ -400,3 +469,10 @@ const _$BounceTrackingProtectionModeEnumMap = {
BounceTrackingProtectionMode.enabledStandby: 'enabledStandby',
BounceTrackingProtectionMode.enabledDryRun: 'enabledDryRun',
};
const _$DohSettingsModeEnumMap = {
DohSettingsMode.geckoDefault: 'geckoDefault',
DohSettingsMode.increased: 'increased',
DohSettingsMode.max: 'max',
DohSettingsMode.off: 'off',
};
@@ -98,6 +98,22 @@ class EngineSettingsRepository extends _$EngineSettingsRepository {
DriftSqlType.string,
db.typeMapping,
),
'dohSettingsMode': settings['dohSettingsMode']?.readAs(
DriftSqlType.string,
db.typeMapping,
),
'dohProviderUrl': settings['dohProviderUrl']?.readAs(
DriftSqlType.string,
db.typeMapping,
),
'dohDefaultProviderUrl': settings['dohDefaultProviderUrl']?.readAs(
DriftSqlType.string,
db.typeMapping,
),
'dohExceptionsList': settings['dohExceptionsList']?.readAs(
DriftSqlType.string,
db.typeMapping,
),
});
}
@@ -34,7 +34,7 @@ final class EngineSettingsRepositoryProvider
}
String _$engineSettingsRepositoryHash() =>
r'f5e50bbfc707cdae698ac201d42e165bffc7615f';
r'5e403757036edb4ef964b01cdcf96cbcbdc4d809';
abstract class _$EngineSettingsRepository
extends $StreamNotifier<EngineSettings> {