feat: custom disable ssl cert verf

Closes #88

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-01-02 14:13:13 +08:00
parent d0ef75bce7
commit f1a10a786d
4 changed files with 62 additions and 0 deletions

View File

@@ -52,6 +52,9 @@ void main() async {
],
);
}
if (GStorage.badCertificateCallback) {
HttpOverrides.global = _CustomHttpOverrides();
}
await setupServiceLocator();
Request();
await Request.setCookie();
@@ -275,3 +278,12 @@ class MyApp extends StatelessWidget {
);
}
}
class _CustomHttpOverrides extends HttpOverrides {
@override
HttpClient createHttpClient(SecurityContext? context) {
return super.createHttpClient(context)
..badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
}
}

View File

@@ -408,6 +408,13 @@ class _ExtraSettingState extends State<ExtraSetting> {
setKey: SettingBoxKey.reverseFromFirst,
defaultVal: true,
),
SetSwitchItem(
title: '禁用 SSL 证书验证',
subTitle: '谨慎开启,禁用容易受到中间人攻击',
leading: Icon(Icons.security),
needReboot: true,
setKey: SettingBoxKey.badCertificateCallback,
),
Obx(
() => ListTile(
enableFeedback: true,

View File

@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:PiliPalaX/utils/storage.dart';
import 'package:get/get.dart';
class SetSwitchItem extends StatefulWidget {
final String? title;
@@ -43,7 +44,45 @@ class _SetSwitchItemState extends State<SetSwitchItem> {
}
void switchChange(value) async {
if (widget.setKey == SettingBoxKey.badCertificateCallback &&
(value ?? !val)) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text(
'确定禁用 SSL 证书验证?',
style: TextStyle(fontSize: 18),
),
content: const Text('禁用容易受到中间人攻击'),
actions: [
TextButton(
onPressed: Get.back,
child: Text(
'取消',
style: TextStyle(
color: Theme.of(context).colorScheme.outline,
),
),
),
TextButton(
onPressed: () async {
Get.back();
await GStorage.setting
.put(SettingBoxKey.badCertificateCallback, true);
val = true;
SmartDialog.showToast('重启生效');
setState(() {});
},
child: const Text('确认'),
),
],
),
);
return;
}
val = value ?? !val;
await GStorage.setting.put(widget.setKey, val);
// if (widget.setKey == SettingBoxKey.autoUpdate && value == true) {
// Utils.checkUpdate();

View File

@@ -160,6 +160,9 @@ class GStorage {
static double get subtitleBgOpaticy =>
setting.get(SettingBoxKey.subtitleBgOpaticy, defaultValue: 0.67);
static bool get badCertificateCallback =>
setting.get(SettingBoxKey.badCertificateCallback, defaultValue: false);
static List<double> get dynamicDetailRatio => List<double>.from(setting
.get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0]));
@@ -366,6 +369,7 @@ class SettingBoxKey {
subtitlePaddingH = 'subtitlePaddingH',
subtitlePaddingB = 'subtitlePaddingB',
subtitleBgOpaticy = 'subtitleBgOpaticy',
badCertificateCallback = 'badCertificateCallback',
// Sponsor Block
enableSponsorBlock = 'enableSponsorBlock',