mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: custom disable ssl cert verf
Closes #88 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -52,6 +52,9 @@ void main() async {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (GStorage.badCertificateCallback) {
|
||||||
|
HttpOverrides.global = _CustomHttpOverrides();
|
||||||
|
}
|
||||||
await setupServiceLocator();
|
await setupServiceLocator();
|
||||||
Request();
|
Request();
|
||||||
await Request.setCookie();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -408,6 +408,13 @@ class _ExtraSettingState extends State<ExtraSetting> {
|
|||||||
setKey: SettingBoxKey.reverseFromFirst,
|
setKey: SettingBoxKey.reverseFromFirst,
|
||||||
defaultVal: true,
|
defaultVal: true,
|
||||||
),
|
),
|
||||||
|
SetSwitchItem(
|
||||||
|
title: '禁用 SSL 证书验证',
|
||||||
|
subTitle: '谨慎开启,禁用容易受到中间人攻击',
|
||||||
|
leading: Icon(Icons.security),
|
||||||
|
needReboot: true,
|
||||||
|
setKey: SettingBoxKey.badCertificateCallback,
|
||||||
|
),
|
||||||
Obx(
|
Obx(
|
||||||
() => ListTile(
|
() => ListTile(
|
||||||
enableFeedback: true,
|
enableFeedback: true,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:PiliPalaX/utils/storage.dart';
|
import 'package:PiliPalaX/utils/storage.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
class SetSwitchItem extends StatefulWidget {
|
class SetSwitchItem extends StatefulWidget {
|
||||||
final String? title;
|
final String? title;
|
||||||
@@ -43,7 +44,45 @@ class _SetSwitchItemState extends State<SetSwitchItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void switchChange(value) async {
|
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;
|
val = value ?? !val;
|
||||||
|
|
||||||
await GStorage.setting.put(widget.setKey, val);
|
await GStorage.setting.put(widget.setKey, val);
|
||||||
// if (widget.setKey == SettingBoxKey.autoUpdate && value == true) {
|
// if (widget.setKey == SettingBoxKey.autoUpdate && value == true) {
|
||||||
// Utils.checkUpdate();
|
// Utils.checkUpdate();
|
||||||
|
|||||||
@@ -160,6 +160,9 @@ class GStorage {
|
|||||||
static double get subtitleBgOpaticy =>
|
static double get subtitleBgOpaticy =>
|
||||||
setting.get(SettingBoxKey.subtitleBgOpaticy, defaultValue: 0.67);
|
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
|
static List<double> get dynamicDetailRatio => List<double>.from(setting
|
||||||
.get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0]));
|
.get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0]));
|
||||||
|
|
||||||
@@ -366,6 +369,7 @@ class SettingBoxKey {
|
|||||||
subtitlePaddingH = 'subtitlePaddingH',
|
subtitlePaddingH = 'subtitlePaddingH',
|
||||||
subtitlePaddingB = 'subtitlePaddingB',
|
subtitlePaddingB = 'subtitlePaddingB',
|
||||||
subtitleBgOpaticy = 'subtitleBgOpaticy',
|
subtitleBgOpaticy = 'subtitleBgOpaticy',
|
||||||
|
badCertificateCallback = 'badCertificateCallback',
|
||||||
|
|
||||||
// Sponsor Block
|
// Sponsor Block
|
||||||
enableSponsorBlock = 'enableSponsorBlock',
|
enableSponsorBlock = 'enableSponsorBlock',
|
||||||
|
|||||||
Reference in New Issue
Block a user